Пример #1
0
    def main(self):
        # Create global options parser.
        self.gparser = gparser = self.create_global_parser()
        # Declare subcommands.
        subcmds = all_cmds
        # subcommand completions
        scmap = {}
        for sc in subcmds:
            for n in sc.names:
                scmap[n] = sc

        if optcomplete:
            listcter = optcomplete.ListCompleter(scmap.keys())
            subcter = optcomplete.NoneCompleter()
            optcomplete.autocomplete(
                gparser, listcter, None, subcter, subcommands=scmap)
        elif 'COMP_LINE' in os.environ:
            return -1

        gopts, sc, opts, args = self.parse_subcommands(gparser, subcmds)
        if args and args[0] == 'help':
            sc.parser.print_help()
            sys.exit(0)
        try:
            sc.execute(args)
        except exception.BaseException, e:
            lines = e.msg.splitlines()
            for l in lines:
                log.error(l)
            sys.exit(1)
Пример #2
0
 def _completer(self):
     try:
         rimages = self.ec2.registered_images
         completion_list = [i.id for i in rimages]
         return optcomplete.ListCompleter(completion_list)
     except Exception, e:
         log.error('something went wrong fix me: %s' % e)
Пример #3
0
 def handle_completion(self):
     if self.is_completion_active():
         gparser = self.create_global_parser(no_usage=True, add_help=False)
         # set sys.path to COMP_LINE if it exists
         self._init_completion()
         # fetch the global options
         gopts = self.get_global_opts()
         # try to load StarClusterConfig into global options
         if gopts:
             try:
                 cfg = config.StarClusterConfig(gopts.CONFIG)
                 cfg.load()
             except exception.ConfigError:
                 cfg = None
             gopts.CONFIG = cfg
         scmap = {}
         for sc in commands.all_cmds:
             sc.gopts = gopts
             for n in sc.names:
                 scmap[n] = sc
         listcter = optcomplete.ListCompleter(scmap.keys())
         subcter = optcomplete.NoneCompleter()
         optcomplete.autocomplete(gparser,
                                  listcter,
                                  None,
                                  subcter,
                                  subcommands=scmap)
         sys.exit(1)
Пример #4
0
    def main(self):
        # Create global options parser.
        self.gparser = gparser = self.create_global_parser()
        # Declare subcommands.
        subcmds = commands.all_cmds
        # subcommand completions
        scmap = {}
        for sc in subcmds:
            for n in sc.names:
                scmap[n] = sc

        if optcomplete:
            listcter = optcomplete.ListCompleter(scmap.keys())
            subcter = optcomplete.NoneCompleter()
            optcomplete.autocomplete(gparser,
                                     listcter,
                                     None,
                                     subcter,
                                     subcommands=scmap)
        elif 'COMP_LINE' in os.environ:
            return -1

        gopts, sc, opts, args = self.parse_subcommands(gparser, subcmds)
        if args and args[0] == 'help':
            sc.parser.print_help()
            sys.exit(0)
        try:
            sc.execute(args)
        except (EC2ResponseError, S3ResponseError, BotoServerError), e:
            log.error("%s: %s" % (e.error_code, e.error_message))
            sys.exit(1)
Пример #5
0
 def _completer(self):
     try:
         rimages = self.ec2.registered_images
         completion_list = [i.id for i in rimages if
                            i.root_device_type == "instance-store"]
         return optcomplete.ListCompleter(completion_list)
     except Exception, e:
         log.error('something went wrong fix me: %s' % e)
Пример #6
0
 def _completer(self):
     try:
         cm = self.cm
         clusters = cm.get_cluster_security_groups()
         completion_list = [cm.get_tag_from_sg(sg.name) \
                            for sg in clusters]
         return optcomplete.ListCompleter(completion_list)
     except Exception, e:
         log.error('something went wrong fix me: %s' % e)
Пример #7
0
 def _completer(self):
     try:
         instances = self.ec2.get_all_instances()
         completion_list = [i.id for i in instances]
         if self.show_dns_names:
             completion_list.extend([i.dns_name for i in instances])
         return optcomplete.ListCompleter(completion_list)
     except Exception, e:
         log.error('something went wrong fix me: %s' % e)
Пример #8
0
 def _completer(self):
     try:
         cm = self.cm
         clusters = cm.get_cluster_security_groups()
         compl_list = [cm.get_tag_from_sg(sg.name) for sg in clusters]
         max_num_nodes = 0
         for scluster in clusters:
             num_instances = len(scluster.instances())
             if num_instances > max_num_nodes:
                 max_num_nodes = num_instances
         compl_list.extend(['master'])
         compl_list.extend([str(i) for i in range(0, num_instances)])
         compl_list.extend(["node%03d" % i \
                            for i in range(1, num_instances)])
         return optcomplete.ListCompleter(compl_list)
     except Exception, e:
         print e
         log.error('something went wrong fix me: %s' % e)
Пример #9
0
 def addopts(self, parser):
     templates = []
     if self.cfg:
         templates = self.cfg.get_cluster_names().keys()
     parser.add_option("-x", "--no-create", dest="no_create",
                       action="store_true", default=False,
                       help="do not launch new EC2 instances when " + \
                       "starting cluster (use existing instances instead)")
     parser.add_option("-o", "--create-only", dest="create_only",
                       action="store_true", default=False,
                       help="only launch/start EC2 instances, " + \
                       "do not perform any setup routines")
     parser.add_option("-v", "--validate-only", dest="validate_only",
                       action="store_true", default=False,
                       help="only validate cluster settings, do " + \
                       "not start a cluster")
     parser.add_option("-V", "--skip-validation", dest="validate",
                       action="store_false", default=True,
                       help="do not validate cluster settings")
     parser.add_option("-l", "--login-master", dest="login_master",
                       action="store_true", default=False,
                       help="login to master node after launch")
     parser.add_option("-q", "--disable-queue", dest="disable_queue",
                       action="store_true", default=None,
                       help="do not configure a queueing system (SGE)")
     parser.add_option("--force-spot-master",
                       dest="force_spot_master", action="store_true",
                       default=None, help="when creating a spot cluster "
                       "the default is to launch the master as "
                       "a flat-rate instance for stability. this option "
                       "forces launching the master node as a spot "
                       "instance when a spot cluster is requested.")
     opt = parser.add_option("-c", "--cluster-template", action="store",
                             dest="cluster_template", choices=templates,
                             default=None, help="cluster template to use "
                             "from the config file")
     if optcomplete:
         opt.completer = optcomplete.ListCompleter(opt.choices)
     parser.add_option("-r", "--refresh-interval", dest="refresh_interval",
                       type="int", action="callback", default=None,
                       callback=self._positive_int,
                       help="refresh interval when waiting for cluster " + \
                       "nodes to come up (default: 30)")
     parser.add_option("-b", "--bid", dest="spot_bid", action="store",
                       type="float", default=None,
                       help="requests spot instances instead of flat " + \
                       "rate instances. Uses SPOT_BID as max bid for " + \
                       "the request.")
     parser.add_option("-d", "--description", dest="cluster_description",
                       action="store", type="string",
                       default="Cluster requested at %s" % \
                       time.strftime("%Y%m%d%H%M"),
                       help="brief description of cluster")
     parser.add_option("-s", "--cluster-size", dest="cluster_size",
                       action="callback", type="int", default=None,
                       callback=self._positive_int,
                       help="number of ec2 instances to launch")
     parser.add_option("-u", "--cluster-user", dest="cluster_user",
                       action="store", type="string", default=None,
                       help="name of user to create on cluster " + \
                       "(defaults to sgeadmin)")
     opt = parser.add_option("-S", "--cluster-shell", dest="cluster_shell",
                             action="store",
                             choices=static.AVAILABLE_SHELLS.keys(),
                             default=None,
                             help="shell for cluster user " + \
                             "(defaults to bash)")
     if optcomplete:
         opt.completer = optcomplete.ListCompleter(opt.choices)
     parser.add_option("-m", "--master-image-id", dest="master_image_id",
                       action="store", type="string", default=None,
                       help="AMI to use when launching master")
     parser.add_option("-n", "--node-image-id", dest="node_image_id",
                       action="store", type="string", default=None,
                       help="AMI to use when launching nodes")
     parser.add_option("-I", "--master-instance-type",
                       dest="master_instance_type", action="store",
                       choices=static.INSTANCE_TYPES.keys(), default=None,
                       help="instance type for the master instance")
     opt = parser.add_option("-i", "--node-instance-type",
                             dest="node_instance_type", action="store",
                             choices=static.INSTANCE_TYPES.keys(),
                             default=None,
                             help="instance type for the node instances")
     if optcomplete:
         opt.completer = optcomplete.ListCompleter(opt.choices)
     parser.add_option("-a", "--availability-zone",
                       dest="availability_zone", action="store",
                       type="string", default=None,
                       help="availability zone to launch instances in")
     parser.add_option("-k", "--keyname", dest="keyname", action="store",
                       type="string", default=None,
                       help="name of the keypair to use when "
                       "launching the cluster")
     parser.add_option("-K", "--key-location", dest="key_location",
                       action="store", type="string", default=None,
                       metavar="FILE",
                       help="path to an ssh private key that matches the "
                       "cluster keypair")
Пример #10
0
 def _completer(self):
     try:
         completion_list = [v.id for v in self.ec2.get_volumes()]
         return optcomplete.ListCompleter(completion_list)
     except Exception, e:
         log.error('something went wrong fix me: %s' % e)
Пример #11
0
    def addopts(self, parser):

        #### CHANGEDprint Dumper ;
        log.info(
            "0.92.rc2    XXXXX commands.start.addopts    utils.config_file: %s",
            utils.config_file)
        #cfg = config.StarClusterConfig().load()
        cfg = config.StarClusterConfig(utils.config_file).load()

        templates = cfg.get_cluster_names().keys()
        opt = parser.add_option("-c", "--cluster-template", action="store",
                                dest="cluster_template", choices=templates,
                                default=None,
                                help="cluster template to use " + \
                                "from the config file")
        parser.add_option("-x", "--no-create", dest="no_create",
                          action="store_true", default=False,
                          help="Do not launch new EC2 instances when " + \
                          "starting cluster (use existing instances instead)")
        parser.add_option("-o", "--create-only", dest="create_only",
                          action="store_true", default=False,
                          help="Only launch/start EC2 instances, " + \
                          "do not perform any setup routines")
        parser.add_option("-v", "--validate-only", dest="validate_only",
                          action="store_true", default=False,
                          help="Only validate cluster settings, do " + \
                          "not start a cluster")
        parser.add_option("-V",
                          "--skip-validation",
                          dest="validate",
                          action="store_false",
                          default=True,
                          help="Do not validate cluster settings")
        parser.add_option("-l",
                          "--login-master",
                          dest="login_master",
                          action="store_true",
                          default=False,
                          help="ssh to ec2 cluster master node after launch")
        parser.add_option("-q",
                          "--disable-queue",
                          dest="disable_queue",
                          action="store_true",
                          default=None,
                          help="Do not configure a queueing system (SGE)")
        parser.add_option("-r", "--refresh-interval", dest="refresh_interval",
                          type="int", action="callback", default=None,
                          callback=self._positive_int,
                          help="Refresh interval when waiting for cluster " + \
                          "nodes to come up (default: 30)")
        parser.add_option("-b", "--bid", dest="spot_bid", action="store",
                          type="float", default=None,
                          help="Requests spot instances instead of flat " + \
                          "rate instances. Uses SPOT_BID as max bid for " + \
                          "the request.")
        if optcomplete:
            opt.completer = optcomplete.ListCompleter(opt.choices)
        parser.add_option("-d", "--description", dest="cluster_description",
                          action="store", type="string",
                          default="Cluster requested at %s" % \
                          time.strftime("%Y%m%d%H%M"),
                          help="brief description of cluster")
        parser.add_option("-s",
                          "--cluster-size",
                          dest="cluster_size",
                          action="callback",
                          type="int",
                          default=None,
                          callback=self._positive_int,
                          help="number of ec2 instances to launch")
        parser.add_option("-u", "--cluster-user", dest="cluster_user",
                          action="store", type="string", default=None,
                          help="name of user to create on cluster " + \
                          "(defaults to sgeadmin)")
        opt = parser.add_option("-S", "--cluster-shell", dest="cluster_shell",
                                action="store",
                                choices=static.AVAILABLE_SHELLS.keys(),
                                default=None,
                                help="shell for cluster user " + \
                                "(defaults to bash)")
        if optcomplete:
            opt.completer = optcomplete.ListCompleter(opt.choices)
        parser.add_option("-m",
                          "--master-image-id",
                          dest="master_image_id",
                          action="store",
                          type="string",
                          default=None,
                          help="AMI to use when launching master")
        parser.add_option("-n",
                          "--node-image-id",
                          dest="node_image_id",
                          action="store",
                          type="string",
                          default=None,
                          help="AMI to use when launching nodes")
        parser.add_option("-I",
                          "--master-instance-type",
                          dest="master_instance_type",
                          action="store",
                          choices=static.INSTANCE_TYPES.keys(),
                          default=None,
                          help="specify machine type for the master instance")
        opt = parser.add_option("-i", "--node-instance-type",
                                dest="node_instance_type", action="store",
                                choices=static.INSTANCE_TYPES.keys(),
                                default=None,
                                help="specify machine type for the node " + \
                                "instances")
        if optcomplete:
            opt.completer = optcomplete.ListCompleter(opt.choices)
        parser.add_option("-a",
                          "--availability-zone",
                          dest="availability_zone",
                          action="store",
                          type="string",
                          default=None,
                          help="availability zone to launch ec2 instances in")
        parser.add_option("-k", "--keyname", dest="keyname", action="store",
                          type="string", default=None,
                          help="name of the AWS keypair to use when " + \
                          "launching the cluster")
        parser.add_option("-K",
                          "--key-location",
                          dest="key_location",
                          action="store",
                          type="string",
                          default=None,
                          metavar="FILE",
                          help="path to ssh private key used for this cluster")