Ejemplo n.º 1
0
 def __inst_cmd(self, argv):
     """Implements the inst command
     """
     cmd_terminate = False
     cmd_run_instance = False
     cmd_start_instance = False
     cmd_stop_instance = False
     cmd_reboot_instance = False
     cmd_set_attribute = False
     #cmd_instance_access = False
     ebs_optimized = None
     instance_type = None
     disp = DisplayOptions()
     selector = ResourceSelector()
     region = None
     keypair_name = None
     user_data = None
     shutdown_action = 'stop'
     opt_list, args = getopt.getopt(argv,
                             "aABc:ef:K:klO:nq:Rr:Ss:Ttu:v:XxZz:")
     if opt_list:
         for opt in opt_list:
             if opt[0] == '-a':
                 selector.select_all = True
             elif opt[0] == '-A':
                     cmd_set_attribute = True
             elif opt[0] == '-B':
                 cmd_reboot_instance = True
             elif opt[0] == '-c':
                 instance_type = opt[1]
             elif opt[0] == '-e':
                 ebs_optimized = True
             elif opt[0] == '-f':
                 selector.add_filter_spec(opt[1])
             elif opt[0] == '-K':
                 keypair_name = opt[1]
             elif opt[0] == '-k':
                 disp.display_count = True
             elif opt[0] == '-l':
                 disp.display = DisplayOptions.LONG
             elif opt[0] == '-O':
                 disp.set_output_file(opt[1])
             elif opt[0] == '-n':
                 disp.display_name = True
             elif opt[0] == '-q':
                 selector.add_tag_filter_spec(opt[1])
             elif opt[0] == '-R':
                 cmd_run_instance = True
             elif opt[0] == '-r':
                 region = opt[1]
             elif opt[0] == '-S':
                 cmd_start_instance = True
             elif opt[0] == '-s':
                 shutdown_action = opt[1]
             elif opt[0] == '-T':
                 cmd_terminate = True
             elif opt[0] == '-t':
                 disp.display_tags = True
             elif opt[0] == '-u':
                 user_data = opt[1]
             elif opt[0] == '-v':
                 selector.add_filter('vpc-id', opt[1])
             elif opt[0] == '-x':
                 disp.display = DisplayOptions.EXTENDED
             elif opt[0] == '-Z':
                 cmd_stop_instance = True
             elif opt[0] == '-z':
                 selector.add_filter('instance-state-name', opt[1])
     if cmd_terminate:
         self.__inst_terminate_cmd(region, args)
     elif cmd_run_instance:
         self.__inst_run_cmd(region, ebs_optimized, instance_type,
                                     keypair_name, user_data,
                                     shutdown_action, args)
     elif cmd_start_instance:
         self.__inst_start_cmd(region, instance_type, args)
     elif cmd_stop_instance:
         self.__inst_stop_cmd(region, args)
     elif cmd_reboot_instance:
         self.__inst_reboot_cmd(region, args)
     elif cmd_set_attribute:
         self.__inst_set_attribute(region, args)
     else:
         selector.set_resource_ids(args, 'i-')
         self.__inst_list_cmd(region, selector, disp)
Ejemplo n.º 2
0
 def __snap_cmd(self, argv):
     """Implements the snap command
     """
     cmd_create_snapshot = False
     cmd_delete_snapshot = False
     cmd_share_snapshot = False
     cmd_unshare_snapshot = False
     description = None
     disp = DisplayOptions()
     selector = ResourceSelector()
     region = None
     opt_list, args = getopt.getopt(argv, "aCDd:f:klm:nO:o:q:r:SsxtUz:")
     if opt_list:
         for opt in opt_list:
             if opt[0] == '-a':
                 selector.select_all = True
             elif opt[0] == '-C':
                 cmd_create_snapshot = True
             elif opt[0] == '-D':
                 cmd_delete_snapshot = True
             elif opt[0] == '-d':
                 description = opt[1]
             elif opt[0] == '-f':
                 selector.add_filter_spec(opt[1])
             elif opt[0] == '-k':
                 disp.display_count = True
             elif opt[0] == '-l':
                 disp.display = DisplayOptions.LONG
             elif opt[0] == '-m':
                 selector.match_pattern = opt[1]
             elif opt[0] == '-n':
                 disp.display_name = True
             elif opt[0] == '-O':
                 disp.set_output_file(opt[1])
             elif opt[0] == '-o':
                 self.__add_display_order(disp, opt[1])
             elif opt[0] == '-q':
                 selector.add_tag_filter_spec(opt[1])
             elif opt[0] == '-r':
                 region = opt[1]
             elif opt[0] == '-S':
                 cmd_share_snapshot = True
             elif opt[0] == '-s':
                 disp.display_size = True
             elif opt[0] == '-t':
                 disp.display_tags = True
             elif opt[0] == '-x':
                 disp.display = DisplayOptions.EXTENDED
             elif opt[0] == '-U':
                 cmd_unshare_snapshot = True
             elif opt[0] == '-z':
                 selector.add_filter('status', opt[1])
     if cmd_create_snapshot:
         self.__snap_create(region, description, args)
     elif cmd_delete_snapshot:
         selector.resource_id_list = args
         self.__snap_delete(region, selector)
     elif cmd_share_snapshot:
         self.__snap_share(region, True, args)
     elif cmd_unshare_snapshot:
         self.__snap_share(region, False, args)
     else:
         selector.resource_id_list = args
         self.__snap_list_cmd(region, selector, disp)
Ejemplo n.º 3
0
 def __vol_cmd(self, argv):
     """Implements the vol command
     """
     cmd_detach = False
     cmd_attach = False
     cmd_create = False
     cmd_delete = False
     cmd_move = False
     disp = DisplayOptions()
     selector = ResourceSelector()
     region = None
     instance_id = None
     # Volume type, when creating a new volume
     vol_type = None
     opt_list, args = getopt.getopt(argv, "aCc:Df:i:klMnO:o:q:r:SstXxz:")
     if opt_list:
         for opt in opt_list:
             if opt[0] == '-a':
                 selector.select_all = True
             elif opt[0] == '-C':
                 cmd_create = True
             elif opt[0] == '-c':
                 vol_type = opt[1]
             elif opt[0] == '-D':
                 cmd_delete = True
             elif opt[0] == '-f':
                 selector.add_filter_spec(opt[1])
             elif opt[0] == '-l':
                 disp.display = DisplayOptions.LONG
             elif opt[0] == '-i':
                 instance_id = opt[1]
                 selector.add_filter('attachment.instance-id', instance_id)
             elif opt[0] == '-k':
                 disp.display_count = True
             elif opt[0] == '-M':
                 cmd_move = True
             elif opt[0] == '-n':
                 disp.display_name = True
             elif opt[0] == '-O':
                 disp.set_output_file(opt[1])
             elif opt[0] == '-o':
                 self.__add_display_order(disp, opt[1])
             elif opt[0] == '-q':
                 selector.add_tag_filter_spec(opt[1])
             elif opt[0] == '-r':
                 region = opt[1]
             elif opt[0] == '-S':
                 cmd_attach = True
             elif opt[0] == '-s':
                 disp.display_size = True
             elif opt[0] == '-t':
                 disp.display_tags = True
             elif opt[0] == '-X':
                 cmd_detach = True
             elif opt[0] == '-x':
                 disp.display = DisplayOptions.EXTENDED
             elif opt[0] == '-z':
                 selector.add_filter('status', opt[1])
     if cmd_detach:
         selector.resource_id_list = args
         self.__vol_detach_cmd(region, instance_id, selector)
     elif cmd_attach:
         self.__vol_attach_cmd(region, args)
     elif cmd_create:
         self.__vol_create_cmd(region, vol_type, args)
     elif cmd_delete:
         selector.resource_id_list = args
         self.__vol_delete_cmd(region, selector)
     elif cmd_move:
         self.__vol_move_cmd(region, args)
     else:
         selector.resource_id_list = args
         self.__vol_list_cmd(region, selector, disp)
Ejemplo n.º 4
0
 def __sg_cmd(self, argv):
     """Implements the sg command
     """
     cmd_authorize = False
     cmd_revoke = False
     cmd_delete = False
     cmd_create = False
     selector = ResourceSelector()
     disp = DisplayOptions()
     region = None
     subnet_spec = None
     port_spec = None
     principal_sg_id = None
     vpc_id = None   # used when creating a SG
     opt_list, args = getopt.getopt(argv, "aACDf:g:kln:p:q:Rr:s:tv:x")
     for opt in opt_list:
         if opt[0] == '-A':
             cmd_authorize = True
         elif opt[0] == '-C':
             cmd_create = True
         elif opt[0] == '-D':
             cmd_delete = True
         elif opt[0] == '-a':
             selector.select_all = True
         elif opt[0] == '-f':
             selector.add_filter_spec(opt[1])
         elif opt[0] == '-g':
             principal_sg_id = opt[1]
         elif opt[0] == '-k':
             disp.display_count = True
         elif opt[0] == '-l':
             disp.display = DisplayOptions.LONG
         elif opt[0] == '-n':
             selector.add_filter('group-name', opt[1])
         elif opt[0] == '-p':
             port_spec = _PortSpec(opt[1])
         elif opt[0] == '-q':
             selector.add_tag_filter_spec(opt[1])
         elif opt[0] == '-R':
             cmd_revoke = True
         elif opt[0] == '-r':
             region = opt[1]
         elif opt[0] == '-s':
             subnet_spec = opt[1]
         elif opt[0] == '-t':
             disp.display_tags = True
         elif opt[0] == '-v':
             selector.add_filter('vpc-id', opt[1])
             vpc_id = opt[1]
         elif opt[0] == '-x':
             disp.display = DisplayOptions.EXTENDED
     if cmd_authorize:
         self.__sg_authorize_cmd(region, True, args,
                             port_spec, subnet_spec, principal_sg_id)
     elif cmd_revoke:
         self.__sg_authorize_cmd(region, False, args,
                             port_spec, subnet_spec, principal_sg_id)
     elif cmd_delete:
         self.__sg_delete_cmd(region, args)
     elif cmd_create:
         self.__sg_create_cmd(region, vpc_id, args)
     else:
         selector.resource_id_list = args
         self.__sg_list_cmd(region, selector, disp)