Package starcluster :: Package commands :: Module start
[hide private]
[frames] | no frames]

Source Code for Module starcluster.commands.start

  1  #!/usr/bin/env python 
  2   
  3  import time 
  4   
  5  from starcluster import config 
  6  from starcluster import static 
  7  from starcluster import exception 
  8  from starcluster import optcomplete 
  9  from starcluster.templates import user_msgs 
 10  from starcluster.logger import log 
 11   
 12  from completers import ClusterCompleter 
 13   
 14   
15 -class CmdStart(ClusterCompleter):
16 """ 17 start [options] <cluster_tag> 18 19 Start a new cluster 20 21 Example: 22 23 $ starcluster start mynewcluster 24 25 This will launch a cluster named "mynewcluster" using the settings from 26 the default cluster template defined in the configuration file. The 27 default cluster template is specified by the 'default_template' option in 28 the [global] section of the config. To use another template besides the 29 default use the -c (--cluster-template) option: 30 31 $ starcluster start -c largecluster mynewcluster 32 33 This will launch a cluster named "mynewcluster" using the settings from 34 the "largecluster" cluster template instead of the default template. 35 """ 36 names = ['start'] 37 38 tag = None 39
40 - def addopts(self, parser):
41 cfg = config.StarClusterConfig().load() 42 templates = cfg.get_cluster_names().keys() 43 parser.add_option("-x", "--no-create", dest="no_create", 44 action="store_true", default=False, 45 help="do not launch new EC2 instances when " + \ 46 "starting cluster (use existing instances instead)") 47 parser.add_option("-o", "--create-only", dest="create_only", 48 action="store_true", default=False, 49 help="only launch/start EC2 instances, " + \ 50 "do not perform any setup routines") 51 parser.add_option("-v", "--validate-only", dest="validate_only", 52 action="store_true", default=False, 53 help="only validate cluster settings, do " + \ 54 "not start a cluster") 55 parser.add_option("-V", "--skip-validation", dest="validate", 56 action="store_false", default=True, 57 help="do not validate cluster settings") 58 parser.add_option("-l", "--login-master", dest="login_master", 59 action="store_true", default=False, 60 help="login to master node after launch") 61 parser.add_option("-q", "--disable-queue", dest="disable_queue", 62 action="store_true", default=None, 63 help="do not configure a queueing system (SGE)") 64 parser.add_option("--force-spot-master", 65 dest="force_spot_master", action="store_true", 66 default=None, help="when creating a spot cluster " 67 "the default is to launch the master as " 68 "a flat-rate instance for stability. this option " 69 "forces launching the master node as a spot " 70 "instance when a spot cluster is requested.") 71 opt = parser.add_option("-c", "--cluster-template", action="store", 72 dest="cluster_template", choices=templates, 73 default=None, 74 help="cluster template to use " + \ 75 "from the config file") 76 parser.add_option("-r", "--refresh-interval", dest="refresh_interval", 77 type="int", action="callback", default=None, 78 callback=self._positive_int, 79 help="refresh interval when waiting for cluster " + \ 80 "nodes to come up (default: 30)") 81 parser.add_option("-b", "--bid", dest="spot_bid", action="store", 82 type="float", default=None, 83 help="requests spot instances instead of flat " + \ 84 "rate instances. Uses SPOT_BID as max bid for " + \ 85 "the request.") 86 if optcomplete: 87 opt.completer = optcomplete.ListCompleter(opt.choices) 88 parser.add_option("-d", "--description", dest="cluster_description", 89 action="store", type="string", 90 default="Cluster requested at %s" % \ 91 time.strftime("%Y%m%d%H%M"), 92 help="brief description of cluster") 93 parser.add_option("-s", "--cluster-size", dest="cluster_size", 94 action="callback", type="int", default=None, 95 callback=self._positive_int, 96 help="number of ec2 instances to launch") 97 parser.add_option("-u", "--cluster-user", dest="cluster_user", 98 action="store", type="string", default=None, 99 help="name of user to create on cluster " + \ 100 "(defaults to sgeadmin)") 101 opt = parser.add_option("-S", "--cluster-shell", dest="cluster_shell", 102 action="store", 103 choices=static.AVAILABLE_SHELLS.keys(), 104 default=None, 105 help="shell for cluster user " + \ 106 "(defaults to bash)") 107 if optcomplete: 108 opt.completer = optcomplete.ListCompleter(opt.choices) 109 parser.add_option("-m", "--master-image-id", dest="master_image_id", 110 action="store", type="string", default=None, 111 help="AMI to use when launching master") 112 parser.add_option("-n", "--node-image-id", dest="node_image_id", 113 action="store", type="string", default=None, 114 help="AMI to use when launching nodes") 115 parser.add_option("-I", "--master-instance-type", 116 dest="master_instance_type", action="store", 117 choices=static.INSTANCE_TYPES.keys(), default=None, 118 help="instance type for the master instance") 119 opt = parser.add_option("-i", "--node-instance-type", 120 dest="node_instance_type", action="store", 121 choices=static.INSTANCE_TYPES.keys(), 122 default=None, 123 help="instance type for the node instances") 124 if optcomplete: 125 opt.completer = optcomplete.ListCompleter(opt.choices) 126 parser.add_option("-a", "--availability-zone", 127 dest="availability_zone", action="store", 128 type="string", default=None, 129 help="availability zone to launch instances in") 130 parser.add_option("-k", "--keyname", dest="keyname", action="store", 131 type="string", default=None, 132 help="name of the keypair to use when " 133 "launching the cluster") 134 parser.add_option("-K", "--key-location", dest="key_location", 135 action="store", type="string", default=None, 136 metavar="FILE", 137 help="path to an ssh private key that matches the" 138 "cluster keypair")
139
140 - def cancel_command(self, signum, frame):
142
143 - def execute(self, args):
144 if len(args) != 1: 145 self.parser.error("please specify a <cluster_tag>") 146 tag = self.tag = args[0] 147 create = not self.opts.no_create 148 create_only = self.opts.create_only 149 scluster = self.cm.get_cluster_or_none(tag) 150 validate = self.opts.validate 151 validate_running = self.opts.no_create 152 validate_only = self.opts.validate_only 153 if scluster and create: 154 stopped_ebs = scluster.is_cluster_stopped() 155 is_ebs = False 156 if not stopped_ebs: 157 is_ebs = scluster.is_ebs_cluster() 158 raise exception.ClusterExists(tag, is_ebs=is_ebs, 159 stopped_ebs=stopped_ebs) 160 if not scluster and not create: 161 raise exception.ClusterDoesNotExist(tag) 162 elif scluster: 163 validate_running = True 164 else: 165 template = self.opts.cluster_template 166 if not template: 167 try: 168 template = self.cm.get_default_cluster_template() 169 except exception.NoDefaultTemplateFound, e: 170 try: 171 ctmpl = e.options[0] 172 except IndexError: 173 ctmpl = "smallcluster" 174 e.msg += " \n\nAlternatively, you can specify a cluster " 175 e.msg += "template to use by passing the '-c' option to " 176 e.msg += "the 'start' command, e.g.:\n\n" 177 e.msg += " $ starcluster start -c %s %s" % (ctmpl, tag) 178 raise e 179 log.info("Using default cluster template: %s" % template) 180 scluster = self.cm.get_cluster_template(template, tag) 181 scluster.update(self.specified_options_dict) 182 if not self.opts.refresh_interval: 183 interval = self.cfg.globals.get("refresh_interval") 184 scluster.refresh_interval = interval 185 if self.opts.spot_bid is not None and not self.opts.no_create: 186 msg = user_msgs.spotmsg % {'size': scluster.cluster_size, 187 'tag': tag} 188 if not validate_only and not create_only: 189 self.warn_experimental(msg, num_secs=5) 190 self.catch_ctrl_c() 191 scluster.start(create=create, create_only=create_only, 192 validate=validate, validate_only=validate_only, 193 validate_running=validate_running) 194 if validate_only: 195 return 196 log.info(user_msgs.cluster_started_msg % { 197 'tag': scluster.cluster_tag, 198 }, extra=dict(__textwrap__=True, __raw__=True)) 199 if self.opts.login_master: 200 scluster.ssh_to_master()
201