def __keypair_cmd(self, argv): """Implements the keypair command """ # # We always show all key pairs; the -a option is redundant # but is supported for symmetry reasons. # selector = ResourceSelector() disp = DisplayOptions() region = None opt_list, args = getopt.getopt(argv, "af:lr:x") if opt_list: for opt in opt_list: if opt[0] == '-a': selector.select_all = True elif opt[0] == '-f': selector.add_filter_spec(opt[1]) elif opt[0] == '-l': disp.display = DisplayOptions.LONG elif opt[0] == '-r': region = opt[1] elif opt[0] == '-x': disp.display = DisplayOptions.EXTENDED if False: # modifying command pass else: selector.resource_id_list = args self.__keypair_list_cmd(region, selector, disp)
def __aki_cmd(self, argv): """Implements the aki command """ disp = DisplayOptions() selector = ResourceSelector() region = None opt_list, args = getopt.getopt(argv, "af:lr:tx") if opt_list: for opt in opt_list: if opt[0] == '-a': selector.select_all = True elif opt[0] == '-f': selector.add_filter_spec(opt[1]) elif opt[0] == '-l': disp.display = DisplayOptions.LONG elif opt[0] == '-r': region = opt[1] elif opt[0] == '-t': disp.display_tags = True elif opt[0] == '-x': disp.display = DisplayOptions.EXTENDED if False: # modifying command pass else: selector.resource_id_list = args self.__aki_list_cmd(region, selector, disp)
def __dhcp_cmd(self, argv): """Implements the dhcp command """ disp = DisplayOptions() selector = ResourceSelector() region = None cmd_delete = False cmd_associate = False opt_list, args = getopt.getopt(argv, "aDlr:Stx") if opt_list: for opt in opt_list: if opt[0] == '-a': selector.select_all = True elif opt[0] == '-D': cmd_delete = True elif opt[0] == '-l': disp.display = DisplayOptions.LONG elif opt[0] == '-r': region = opt[1] elif opt[0] == '-S': cmd_associate = True elif opt[0] == '-t': disp.display_tags = True elif opt[0] == '-x': disp.display = DisplayOptions.EXTENDED if cmd_delete: self.__dhcp_delete_cmd(region, args) elif cmd_associate: self.__dhcp_associate_cmd(region, args) else: selector.resource_id_list = args self.__dhcp_list_cmd(region, selector, disp)
def __key_cmd(self, argv): """Implements the key command """ # # We always show all keys; the -a option is redundant # but is supported for symmetry reasons. # selector = ResourceSelector() disp = DisplayOptions() region = None user_name = None opt_list, args = getopt.getopt(argv, "alr:u:x") if opt_list: for opt in opt_list: if opt[0] == '-a': selector.select_all = True elif opt[0] == '-l': disp.display = DisplayOptions.LONG elif opt[0] == '-r': region = opt[1] elif opt[0] == '-u': user_name = opt[1] elif opt[0] == '-x': disp.display = DisplayOptions.EXTENDED if False: # modifying command pass else: self.__key_list_cmd(region, selector, user_name, disp)
def __tag_cmd(self, argv): """Implements the tag command """ cmd_create_tags = False cmd_delete_tags = False selector = ResourceSelector() region = None opt_list, args = getopt.getopt(argv, "aCDf:k:r:t:v:") if opt_list: for opt in opt_list: if opt[0] == "-a": selector.select_all = True elif opt[0] == "-C": cmd_create_tags = True elif opt[0] == "-D": cmd_delete_tags = True elif opt[0] == "-f": selector.add_filter_spec(opt[1]) elif opt[0] == "-k": selector.add_filter("key", opt[1]) elif opt[0] == "-r": region = opt[1] elif opt[0] == "-t": selector.add_filter("resource-type", _expand_type(opt[1])) elif opt[0] == "-v": selector.add_filter("value", opt[1]) if cmd_create_tags: self.__tag_create_cmd(region, args) elif cmd_delete_tags: self.__tag_delete_cmd(region, args) else: self.__tag_list_cmd(region, selector)
def __eip_cmd(self, argv): """Implements the eip command """ in_vpc = False cmd_allocate = False cmd_release = False cmd_associate = False cmd_disassociate = False move_address = False disp = DisplayOptions() selector = ResourceSelector() region = None opt_list, args = getopt.getopt(argv, "Aaf:lmRr:StXxV") if opt_list: for opt in opt_list: if opt[0] == '-a': selector.select_all = True elif opt[0] == '-A': cmd_allocate = True elif opt[0] == '-f': selector.add_filter_spec(opt[1]) elif opt[0] == '-l': disp.display = DisplayOptions.LONG elif opt[0] == '-m': move_address = True elif opt[0] == '-R': cmd_release = True elif opt[0] == '-r': region = opt[1] elif opt[0] == '-S': cmd_associate = True elif opt[0] == '-t': disp.display_tags = True elif opt[0] == '-X': cmd_disassociate = True elif opt[0] == '-x': disp.display = DisplayOptions.EXTENDED elif opt[0] == '-V': in_vpc = True if cmd_allocate: self.__eip_allocate(region, in_vpc, args) elif cmd_release: self.__eip_release(region, args) elif cmd_associate: self.__eip_associate(region, move_address, args) elif cmd_disassociate: self.__eip_disassociate(region, args) else: selector.resource_id_list = args self.__eip_list_cmd(region, selector, disp)
def __igw_cmd(self, argv): """Implements the igw command """ disp = DisplayOptions() selector = ResourceSelector() region = None cmd_create = False cmd_delete = False cmd_detach = False cmd_attach = False opt_list, args = getopt.getopt(argv, "aCDf:lq:rStv:Xx") 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] == '-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] == '-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] == '-t': disp.display_tags = True elif opt[0] == '-v': vpc_id = opt[1] selector.add_filter('attachment.vpc-id', vpc_id) elif opt[0] == '-x': disp.display = DisplayOptions.EXTENDED elif opt[0] == '-X': cmd_detach = True if cmd_create: self.__igw_create_cmd(region) elif cmd_delete: self.__igw_delete_cmd(region, args) elif cmd_attach: self.__igw_attach_cmd(region, args) elif cmd_detach: self.__igw_detach_cmd(region, args) else: selector.resource_id_list = args self.__igw_list_cmd(region, selector, disp)
def __ami_cmd(self, argv): """Implements the ami command """ cmd_delete = False cmd_create = False description = None virtualization_type = None selector = ResourceSelector() disp = DisplayOptions() region = None owner_list = [] opt_list, args = getopt.getopt(argv, "aCd:Df:lnq:r:tU:v:x") 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] == '-d': description = 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] == '-n': disp.display_name = True elif opt[0] == '-q': selector.add_tag_filter_spec(opt[1]) elif opt[0] == '-r': region = opt[1] elif opt[0] == '-t': disp.display_tags = True elif opt[0] == '-U': owner_list.append(opt[1]) elif opt[0] == '-v': virtualization_type = opt[1] elif opt[0] == '-x': disp.display = DisplayOptions.EXTENDED if cmd_delete: selector.resource_id_list = args self.__ami_delete(region, selector) elif cmd_create: self.__ami_create(region, description, virtualization_type, args) else: selector.resource_id_list = args self.__ami_list_cmd(region, selector, disp, owner_list)
def __subnet_cmd(self, argv): """Implements the subnet command """ cmd_create = False cmd_delete = False selector = ResourceSelector() disp = DisplayOptions() region = None opt_list, args = getopt.getopt(argv, "aCDf:lq:r:xtv:") vpc_id = None 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] == '-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] == '-q': selector.add_tag_filter_spec(opt[1]) elif opt[0] == '-r': region = opt[1] elif opt[0] == '-t': disp.display_tags = True elif opt[0] == '-v': vpc_id = opt[1] selector.add_filter('vpc-id', vpc_id) elif opt[0] == '-x': disp.display = DisplayOptions.EXTENDED if cmd_create: # the vpc-id may be specified via option, or as an argument self.__subnet_create_cmd(region, vpc_id, args) elif cmd_delete: self.__subnet_delete_cmd(region, args) else: selector.resource_id_list = args self.__subnet_list_cmd(region, selector, disp)
def __vpc_cmd(self, argv): """Implements the vpc command """ cmd_delete = False cmd_create = False disp = DisplayOptions() selector = ResourceSelector() region = None opt_list, args = getopt.getopt(argv, "aCDf:lq:r:tx") 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] == '-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] == '-q': selector.add_tag_filter_spec(opt[1]) elif opt[0] == '-r': region = opt[1] elif opt[0] == '-t': disp.display_tags = True elif opt[0] == '-x': disp.display = DisplayOptions.EXTENDED if cmd_create: self.__vpc_create_cmd(region, args) elif cmd_delete: self.__vpc_delete_cmd(region, args) else: selector.resource_id_list = args self.__vpc_list_cmd(region, selector, disp)
def __eni_cmd(self, argv): """Implements the eni command """ cmd_create = False cmd_delete = False cmd_attach = False cmd_detach = False cmd_source_dest_check = False source_dest_check = None description = None disp = DisplayOptions() selector = ResourceSelector() region = None opt_list, args = getopt.getopt(argv, "aBCDd:f:i:lPq:r:StXx") if opt_list: for opt in opt_list: if opt[0] == "-a": selector.select_all = True elif opt[0] == "-B": cmd_source_dest_check = True source_dest_check = True elif opt[0] == "-C": cmd_create = True elif opt[0] == "-D": cmd_delete = True elif opt[0] == "-d": description = opt[1] elif opt[0] == "-f": selector.add_filter_spec(opt[1]) elif opt[0] == "-i": selector.add_filter("attachment.instance-id", opt[1]) elif opt[0] == "-l": disp.display = DisplayOptions.LONG elif opt[0] == "-P": cmd_source_dest_check = True source_dest_check = False 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] == "-t": disp.display_tags = True elif opt[0] == "-X": cmd_detach = True elif opt[0] == "-x": disp.display = DisplayOptions.EXTENDED if cmd_create: self.__eni_create_cmd(region, description, args) elif cmd_delete: self.__eni_delete_cmd(region, args) elif cmd_attach: self.__eni_attach_cmd(region, args) elif cmd_detach: self.__eni_detach_cmd(region, args) elif cmd_source_dest_check: self.__eni_source_dest_check(region, source_dest_check, args) else: selector.resource_id_list = args self.__eni_list_cmd(region, selector, disp)
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)
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)
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)
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)