def ecs_security_groups(args): j_content = ECSApi().query_security_groups() if len(j_content['security_groups']) == 0: print("No security_groups") else: for security_group in j_content['security_groups']: print(json.dumps(security_group, indent=4, sort_keys=True))
def ecs_network_detach(args): arg_check(args, 2) j_content = ECSApi().delete_nics(args[0], args[1:]) if "job_id" not in j_content: print("Error") else: print(json.dumps(j_content, indent=4, sort_keys=True))
def ecs_stop(args): arg_check(args, 1) j_content = ECSApi().stop_ecss(args) if "job_id" not in j_content: print("Error") else: print(json.dumps(j_content, indent=4, sort_keys=True))
def ecs_block_attach(args): arg_check(args, 3, 3) j_content = ECSApi().attach_volume(*args) if "job_id" not in j_content: print("Error") else: print(json.dumps(j_content, indent=4, sort_keys=True))
def ecs_evs_create(args): arg_check(args, 3, 4) j_content = ECSApi().create_evss(*args) if "job_id" not in j_content: print("Error") else: print(json.dumps(j_content, indent=4, sort_keys=True))
def ecs_resize(args): arg_check(args, 2, 2) j_content = ECSApi().resize_ecs(args[0], args[1]) if "job_id" not in j_content: print("Error") else: print(json.dumps(j_content, indent=4, sort_keys=True))
def ecs_rename(args): arg_check(args, 2, 2) j_content = ECSApi().modify_ecs_info(args[0], args[1]) if 'server' not in j_content: print("No server") else: print(json.dumps(j_content['server'], indent=4, sort_keys=True))
def ecs_keypair_list(args): j_content = ECSApi().query_ssh_keypairs() if len(j_content['keypairs']) == 0: print("No keypairs") else: for keypair in j_content['keypairs']: print(keypair["keypair"]["name"])
def ecs_projects(args): j_content = ECSApi().query_projects() if len(j_content['projects']) == 0: print("No projects") else: for project in j_content['projects']: print(json.dumps(project, indent=4, sort_keys=True))
def ecs_network_attach(args): arg_check(args, 4, 4) j_content = ECSApi().add_nics(*args) if "job_id" not in j_content: print("Error") else: print(json.dumps(j_content, indent=4, sort_keys=True))
def ecs_availability_zones(args): j_content = ECSApi().query_availability_zones() if len(j_content['availabilityZoneInfo']) == 0: print("No availability zones") else: for availabilityzone in j_content['availabilityZoneInfo']: print(availabilityzone['zoneName'])
def ecs_info(args): j_content = ECSApi().query_ecs_detail() if len(j_content['servers']) == 0: print("No servers") else: for server in j_content['servers']: print(json.dumps(server, indent=4, sort_keys=True))
def ecs_eips(args): j_content = ECSApi().query_eips() if len(j_content['publicips']) == 0: print("No publicips") else: print '%-36s\t%-15s\t%-10s' % ("ID", "Public IP Address", "Status") for publicip in j_content['publicips']: print '%-36s\t%-15s\t%-10s' % (publicip['id'], publicip['public_ip_address'], publicip['status'])
def ecs_vpcs(args): j_content = ECSApi().query_vpcs() if len(j_content['vpcs']) == 0: print("No vpcs") else: print '%-36s\t%-20s\t%-10s' % ("ID", "Name", "CIDR") for vpc in j_content['vpcs']: print '%-36s\t%-20s\t%-10s' % (vpc['id'], vpc['name'], vpc['cidr'])
def ecs_flavors(args): j_content = ECSApi().list_flavors() if len(j_content['flavors']) == 0: print("No flavors") else: print '%-12s\t%-12s' % ("ID", "Name") for flavor in j_content['flavors']: print '%-12s\t%-12s' % (flavor['id'], flavor['name'])
def ecs_list(args): j_content = ECSApi().query_ecs() if len(j_content['servers']) == 0: print("No servers") else: print '%-36s\t%s' % ("ID", "Name") for server in j_content['servers']: print '%-36s\t%s' % (server["id"].encode('ascii', 'ignore'), server["name"].encode('ascii', 'ignore'))
def ecs_subnets(args): arg_check(args, 1, 1) j_content = ECSApi().query_subnets(args[0]) if len(j_content['subnets']) == 0: print("No subnets") else: print '%-36s\t%-20s\t%-10s' % ("ID", "Name", "CIDR") for subnet in j_content['subnets']: print '%-36s\t%-20s\t%-10s' % (subnet['id'], subnet['name'], subnet['cidr'])
def ecs_images(args): j_content = ECSApi().query_images() if len(j_content['images']) == 0: print("No images") else: print '%-36s\t%-36s\t%-36s\t%-20s' % ("ID", "Name", "OS Version", "Created_date") for image in j_content['images']: print '%-36s\t%-36s\t%-36s\t%-20s' % \ (image['id'], image['name'], image['__os_version'], image['created_at'])
def ecs_project_info(args): arg_check(args, 1, 1) j_content = ECSApi().query_project_info(args[0]) if len(j_content['projects']) == 0: print("No projects") else: print '%-32s\t%s' % ("ID", "Name") for project in j_content['projects']: print '%-32s\t%s' % (project['id'], project['name'])
def ecs_evs_list(args): j_content = ECSApi().query_evss() if len(j_content['volumes']) == 0: print("No EVSs") else: print '%-36s\t%-40s\t%-5s\t%-10s\t%-10s\t%-10s' % ("ID", "Name", "Size", "Type", "AZ", "Status") for volume in j_content['volumes']: print '%-36s\t%-40s\t%-5s\t%-10s\t%-10s\t%-10s' % \ (volume["id"], volume["name"], volume["size"], volume["volume_type"], volume["availability_zone"], volume["status"])
def ecs_network_list(args): arg_check(args, 1, 1) j_content = ECSApi().query_nics(args[0]) if len(j_content['interfaceAttachments']) == 0: print("No NICs") else: print '%-3s\t%-36s\t%-15s\t%-10s' % ("No.", "ID", "IP Address", "State") for i, nic in enumerate(j_content['interfaceAttachments']): print '%3s\t%-36s\t%-15s\t%-10s' % \ (str(i), nic["port_id"], nic["fixed_ips"][0]["ip_address"], nic["port_state"])
def ecs_block_list(args): arg_check(args, 1, 1) j_content = ECSApi().query_volumes(args[0]) if len(j_content['volumeAttachments']) == 0: print("No volumes") else: print '%-3s\t%-36s\t%-15s' % ("No.", "ID", "Device") for i, volume in enumerate(j_content['volumeAttachments']): print '%3s\t%-36s\t%-15s' % \ (str(i), volume["id"], volume["device"])
def ecs_create(json_ecs): j_content = ECSApi().create_ecss(json_ecs) if "job_id" not in j_content: print("Error") else: print(json.dumps(j_content, indent=4, sort_keys=True))
def task_status(args): arg_check(args, 1, 1) j_content = ECSApi().query_task_status(args[0]) print(json.dumps(j_content, indent=4, sort_keys=True))
def ecs_evs_delete(args): arg_check(args, 1, 1) j_content = ECSApi().delete_evs(args[0]) print(json.dumps(j_content, indent=4, sort_keys=True))
def ecs_block_detach(args): arg_check(args, 2, 2) ECSApi().detach_volume(*args)