|
|
|
@@ -0,0 +1,214 @@
|
|
|
|
|
import argparse
|
|
|
|
|
import json
|
|
|
|
|
from tabulate import tabulate
|
|
|
|
|
from api_client.client import IaaSClient # Assuming the IaaSClient class is in a file named iaas_client.py
|
|
|
|
|
|
|
|
|
|
def print_table(data, headers):
|
|
|
|
|
"""Helper function to print data in a table format."""
|
|
|
|
|
if data:
|
|
|
|
|
print(tabulate(data, headers=headers, tablefmt="pretty"))
|
|
|
|
|
else:
|
|
|
|
|
print("No data available.")
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
parser = argparse.ArgumentParser(description="IaaS CLI Client")
|
|
|
|
|
parser.add_argument('--api-key', required=True, help="API key for authentication")
|
|
|
|
|
parser.add_argument('--base-url', default="http://localhost:5000/api", help="Base URL for the API")
|
|
|
|
|
|
|
|
|
|
subparsers = parser.add_subparsers(dest='command', help='Available commands')
|
|
|
|
|
|
|
|
|
|
# Universes
|
|
|
|
|
universes_parser = subparsers.add_parser('universes', help='Manage universes')
|
|
|
|
|
universes_subparsers = universes_parser.add_subparsers(dest='universes_command', help='Universes commands')
|
|
|
|
|
|
|
|
|
|
list_universes_parser = universes_subparsers.add_parser('list', help='List all universes')
|
|
|
|
|
|
|
|
|
|
create_universe_parser = universes_subparsers.add_parser('create', help='Create a new universe')
|
|
|
|
|
create_universe_parser.add_argument('--name', required=True, help='Name of the universe')
|
|
|
|
|
create_universe_parser.add_argument('--description', required=True, help='Description of the universe')
|
|
|
|
|
|
|
|
|
|
# Projects
|
|
|
|
|
projects_parser = subparsers.add_parser('projects', help='Manage projects')
|
|
|
|
|
projects_subparsers = projects_parser.add_subparsers(dest='projects_command', help='Projects commands')
|
|
|
|
|
|
|
|
|
|
list_projects_parser = projects_subparsers.add_parser('list', help='List all projects')
|
|
|
|
|
|
|
|
|
|
create_project_parser = projects_subparsers.add_parser('create', help='Create a new project')
|
|
|
|
|
create_project_parser.add_argument('--name', required=True, help='Name of the project')
|
|
|
|
|
create_project_parser.add_argument('--universe-id', required=True, help='Universe ID for the project')
|
|
|
|
|
|
|
|
|
|
# VDCs
|
|
|
|
|
vdcs_parser = subparsers.add_parser('vdcs', help='Manage VDCs')
|
|
|
|
|
vdcs_subparsers = vdcs_parser.add_subparsers(dest='vdcs_command', help='VDCs commands')
|
|
|
|
|
|
|
|
|
|
list_vdcs_parser = vdcs_subparsers.add_parser('list', help='List all VDCs')
|
|
|
|
|
|
|
|
|
|
create_vdc_parser = vdcs_subparsers.add_parser('create', help='Create a new VDC')
|
|
|
|
|
create_vdc_parser.add_argument('--name', required=True, help='Name of the VDC')
|
|
|
|
|
create_vdc_parser.add_argument('--project-id', required=True, help='Project ID for the VDC')
|
|
|
|
|
|
|
|
|
|
# Networks
|
|
|
|
|
networks_parser = subparsers.add_parser('networks', help='Manage networks')
|
|
|
|
|
networks_subparsers = networks_parser.add_subparsers(dest='networks_command', help='Networks commands')
|
|
|
|
|
|
|
|
|
|
list_networks_parser = networks_subparsers.add_parser('list', help='List all networks')
|
|
|
|
|
|
|
|
|
|
create_network_parser = networks_subparsers.add_parser('create', help='Create a new network')
|
|
|
|
|
create_network_parser.add_argument('--name', required=True, help='Name of the network')
|
|
|
|
|
create_network_parser.add_argument('--vdc-id', required=True, help='VDC ID for the network')
|
|
|
|
|
|
|
|
|
|
# Network Ports
|
|
|
|
|
network_ports_parser = subparsers.add_parser('network-ports', help='Manage network ports')
|
|
|
|
|
network_ports_parser.add_argument('--network-id', required=True, help='Network ID to list ports for')
|
|
|
|
|
|
|
|
|
|
# Regions
|
|
|
|
|
regions_parser = subparsers.add_parser('regions', help='Manage regions')
|
|
|
|
|
regions_subparsers = regions_parser.add_subparsers(dest='regions_command', help='Regions commands')
|
|
|
|
|
|
|
|
|
|
list_regions_parser = regions_subparsers.add_parser('list', help='List all regions')
|
|
|
|
|
|
|
|
|
|
create_region_parser = regions_subparsers.add_parser('create', help='Create a new region')
|
|
|
|
|
create_region_parser.add_argument('--name', required=True, help='Name of the region')
|
|
|
|
|
create_region_parser.add_argument('--description', required=True, help='Description of the region')
|
|
|
|
|
|
|
|
|
|
# Region Access
|
|
|
|
|
region_access_parser = subparsers.add_parser('region-access', help='Get region access')
|
|
|
|
|
region_access_parser.add_argument('--region-id', required=True, help='Region ID to get access for')
|
|
|
|
|
|
|
|
|
|
# Workload Hosts
|
|
|
|
|
workload_hosts_parser = subparsers.add_parser('workload-hosts', help='Manage workload hosts')
|
|
|
|
|
workload_hosts_subparsers = workload_hosts_parser.add_subparsers(dest='workload_hosts_command', help='Workload hosts commands')
|
|
|
|
|
|
|
|
|
|
list_workload_hosts_parser = workload_hosts_subparsers.add_parser('list', help='List all workload hosts')
|
|
|
|
|
|
|
|
|
|
get_workload_host_parser = workload_hosts_subparsers.add_parser('get', help='Get a specific workload host')
|
|
|
|
|
get_workload_host_parser.add_argument('--workload-host-id', required=True, help='Workload host ID')
|
|
|
|
|
|
|
|
|
|
# Images
|
|
|
|
|
images_parser = subparsers.add_parser('images', help='Manage images')
|
|
|
|
|
images_subparsers = images_parser.add_subparsers(dest='images_command', help='Images commands')
|
|
|
|
|
|
|
|
|
|
list_images_parser = images_subparsers.add_parser('list', help='List all images')
|
|
|
|
|
|
|
|
|
|
get_image_parser = images_subparsers.add_parser('get', help='Get a specific image')
|
|
|
|
|
get_image_parser.add_argument('--image-id', required=True, help='Image ID')
|
|
|
|
|
|
|
|
|
|
edit_image_parser = images_subparsers.add_parser('edit', help='Edit an image')
|
|
|
|
|
edit_image_parser.add_argument('--image-id', required=True, help='Image ID')
|
|
|
|
|
edit_image_parser.add_argument('--data', required=True, help='JSON data to update the image')
|
|
|
|
|
|
|
|
|
|
create_image_parser = images_subparsers.add_parser('create', help='Create a new image')
|
|
|
|
|
create_image_parser.add_argument('--data', required=True, help='JSON data to create the image')
|
|
|
|
|
|
|
|
|
|
# Containers
|
|
|
|
|
containers_parser = subparsers.add_parser('containers', help='Manage containers')
|
|
|
|
|
containers_subparsers = containers_parser.add_subparsers(dest='containers_command', help='Containers commands')
|
|
|
|
|
|
|
|
|
|
list_containers_parser = containers_subparsers.add_parser('list', help='List all containers')
|
|
|
|
|
|
|
|
|
|
get_container_parser = containers_subparsers.add_parser('get', help='Get a specific container')
|
|
|
|
|
get_container_parser.add_argument('--container-id', required=True, help='Container ID')
|
|
|
|
|
|
|
|
|
|
edit_container_parser = containers_subparsers.add_parser('edit', help='Edit a container')
|
|
|
|
|
edit_container_parser.add_argument('--container-id', required=True, help='Container ID')
|
|
|
|
|
edit_container_parser.add_argument('--data', required=True, help='JSON data to update the container')
|
|
|
|
|
|
|
|
|
|
create_container_parser = containers_subparsers.add_parser('create', help='Create a new container')
|
|
|
|
|
create_container_parser.add_argument('--data', required=True, help='JSON data to create the container')
|
|
|
|
|
|
|
|
|
|
delete_container_parser = containers_subparsers.add_parser('delete', help='Delete a container')
|
|
|
|
|
delete_container_parser.add_argument('--container-id', required=True, help='Container ID')
|
|
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
client = IaaSClient(api_key=args.api_key, base_url=args.base_url)
|
|
|
|
|
|
|
|
|
|
if args.command == 'universes':
|
|
|
|
|
if args.universes_command == 'list':
|
|
|
|
|
result = client.get_universes()
|
|
|
|
|
print_table(result, headers=["ID", "Name", "Description"])
|
|
|
|
|
elif args.universes_command == 'create':
|
|
|
|
|
result = client.create_universe(args.name, args.description)
|
|
|
|
|
print(json.dumps(result, indent=2))
|
|
|
|
|
|
|
|
|
|
elif args.command == 'projects':
|
|
|
|
|
if args.projects_command == 'list':
|
|
|
|
|
result = client.get_projects()
|
|
|
|
|
print_table(result, headers=["ID", "Name", "Universe ID"])
|
|
|
|
|
elif args.projects_command == 'create':
|
|
|
|
|
result = client.create_project(args.name, args.universe_id)
|
|
|
|
|
print(json.dumps(result, indent=2))
|
|
|
|
|
|
|
|
|
|
elif args.command == 'vdcs':
|
|
|
|
|
if args.vdcs_command == 'list':
|
|
|
|
|
result = client.get_vdcs()
|
|
|
|
|
print_table(result, headers=["ID", "Name", "Project ID"])
|
|
|
|
|
elif args.vdcs_command == 'create':
|
|
|
|
|
result = client.create_vdc(args.name, args.project_id)
|
|
|
|
|
print(json.dumps(result, indent=2))
|
|
|
|
|
|
|
|
|
|
elif args.command == 'networks':
|
|
|
|
|
if args.networks_command == 'list':
|
|
|
|
|
result = client.get_networks()
|
|
|
|
|
print_table(result, headers=["ID", "Name", "VDC ID"])
|
|
|
|
|
elif args.networks_command == 'create':
|
|
|
|
|
result = client.create_network(args.name, args.vdc_id)
|
|
|
|
|
print(json.dumps(result, indent=2))
|
|
|
|
|
|
|
|
|
|
elif args.command == 'network-ports':
|
|
|
|
|
result = client.get_network_ports_by_network(args.network_id)
|
|
|
|
|
print_table(result, headers=["ID", "Network ID", "Port Details"])
|
|
|
|
|
|
|
|
|
|
elif args.command == 'regions':
|
|
|
|
|
if args.regions_command == 'list':
|
|
|
|
|
result = client.get_regions()
|
|
|
|
|
print_table(result, headers=["ID", "Name", "Description"])
|
|
|
|
|
elif args.regions_command == 'create':
|
|
|
|
|
result = client.create_region(args.name, args.description)
|
|
|
|
|
print(json.dumps(result, indent=2))
|
|
|
|
|
|
|
|
|
|
elif args.command == 'region-access':
|
|
|
|
|
result = client.get_region_access(args.region_id)
|
|
|
|
|
print_table(result, headers=["ID", "Region ID", "Access Details"])
|
|
|
|
|
|
|
|
|
|
elif args.command == 'workload-hosts':
|
|
|
|
|
if args.workload_hosts_command == 'list':
|
|
|
|
|
result = client.get_workload_hosts()
|
|
|
|
|
print_table(result, headers=["ID", "Host Name", "Status"])
|
|
|
|
|
elif args.workload_hosts_command == 'get':
|
|
|
|
|
result = client.get_workload_host(args.workload_host_id)
|
|
|
|
|
print(json.dumps(result, indent=2))
|
|
|
|
|
|
|
|
|
|
elif args.command == 'images':
|
|
|
|
|
if args.images_command == 'list':
|
|
|
|
|
result = client.get_images()
|
|
|
|
|
print_table(result, headers=["ID", "Name", "Size", "Status"])
|
|
|
|
|
elif args.images_command == 'get':
|
|
|
|
|
result = client.get_image(args.image_id)
|
|
|
|
|
print(json.dumps(result, indent=2))
|
|
|
|
|
elif args.images_command == 'edit':
|
|
|
|
|
result = client.edit_image(args.image_id, json.loads(args.data))
|
|
|
|
|
print(json.dumps(result, indent=2))
|
|
|
|
|
elif args.images_command == 'create':
|
|
|
|
|
result = client.create_image(json.loads(args.data))
|
|
|
|
|
print(json.dumps(result, indent=2))
|
|
|
|
|
|
|
|
|
|
elif args.command == 'containers':
|
|
|
|
|
if args.containers_command == 'list':
|
|
|
|
|
result = client.get_containers()
|
|
|
|
|
print_table(result, headers=["ID", "Name", "Status", "Image ID"])
|
|
|
|
|
elif args.containers_command == 'get':
|
|
|
|
|
result = client.get_container(args.container_id)
|
|
|
|
|
print(json.dumps(result, indent=2))
|
|
|
|
|
elif args.containers_command == 'edit':
|
|
|
|
|
result = client.edit_container(args.container_id, json.loads(args.data))
|
|
|
|
|
print(json.dumps(result, indent=2))
|
|
|
|
|
elif args.containers_command == 'create':
|
|
|
|
|
result = client.create_container(json.loads(args.data))
|
|
|
|
|
print(json.dumps(result, indent=2))
|
|
|
|
|
elif args.containers_command == 'delete':
|
|
|
|
|
result = client.delete_container(args.container_id)
|
|
|
|
|
print(json.dumps(result, indent=2))
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|