示例#1
0
 def execute(self, args):
     if len(args) != 1:
         self.parser.error("please specify a <tag_name> for this cluster")
     cfg = self.cfg
     use_experimental = cfg.globals.get('enable_experimental')
     if self.opts.spot_bid is not None and not use_experimental:
         raise exception.ExperimentalFeature('Using spot instances')
     tag = self.tag = args[0]
     template = self.opts.cluster_template
     if not template:
         template = cfg.get_default_cluster_template(tag)
         log.info("Using default cluster template: %s" % template)
     cluster_exists = cluster.cluster_exists(tag, cfg)
     create = not self.opts.no_create
     if not cluster_exists and not create:
         raise exception.ClusterDoesNotExist(tag)
     scluster = cfg.get_cluster_template(template, tag)
     scluster.update(self.specified_options_dict)
     validate_running = self.opts.no_create
     validate_only = self.opts.validate_only
     try:
         scluster._validate(validate_running=validate_running)
         if validate_only:
             return
     except exception.ClusterValidationError,e:
         log.error('settings for cluster template "%s" are not valid:' % template)
         raise
示例#2
0
文件: cli.py 项目: astraw/StarCluster
 def execute(self, args):
     if len(args) != 1:
         self.parser.error("please specify a <tag_name> for this cluster")
     cfg = self.cfg
     use_experimental = cfg.globals.get('enable_experimental')
     if self.opts.spot_bid is not None and not use_experimental:
         raise exception.ExperimentalFeature('Using spot instances')
     tag = self.tag = args[0]
     template = self.opts.cluster_template
     if not template:
         template = cfg.get_default_cluster_template(tag)
         log.info("Using default cluster template: %s" % template)
     scluster = cfg.get_cluster_template(template, tag)
     scluster.update(self.specified_options_dict)
     if cluster.cluster_exists(tag,cfg) and not self.opts.no_create:
         raise exception.ClusterExists(tag)
     #from starcluster.utils import ipy_shell; ipy_shell();
     check_running = self.opts.no_create
     if check_running:
         log.info("Validating existing instances...")
         if scluster.is_running_valid():
             log.info('Existing instances are valid')
         else:
             log.error('existing instances are not compatible with cluster' + \
                       ' template settings')
             sys.exit(1)
     log.info("Validating cluster template settings...")
     if scluster.is_valid():
         log.info('Cluster template settings are valid')
         if not self.opts.validate_only:
             if self.opts.spot_bid is not None:
                 cmd = ' '.join(sys.argv[1:]) + ' --no-create'
                 launch_group = static.SECURITY_GROUP_TEMPLATE % tag
                 msg = experimental.spotmsg % {'cmd':cmd, 
                                               'launch_group': launch_group}
                 self.warn_experimental(msg)
             self.catch_ctrl_c()
             scluster.start(create=not self.opts.no_create)
             if self.opts.login_master:
                 cluster.ssh_to_master(tag, self.cfg)
     else:
         log.error('settings for cluster template "%s" are not valid' % template)
         sys.exit(1)