options added to accomodate networking

This commit is contained in:
ahmadbilalkhalid 2019-11-11 23:44:17 +05:00
parent e484db8025
commit 2914bd3d37
4 changed files with 43 additions and 5 deletions

25
commands/network.py Normal file
View file

@ -0,0 +1,25 @@
from commands.helper import load_dump_pretty, OTPCredentials
from decouple import config
import click
import requests
@click.group()
def network():
pass
@network.command("create")
@click.option("--name", envvar="OTP_NAME", required=True)
@click.option("--realm", envvar="OTP_REALM", required=True)
@click.option("--seed", envvar="OTP_SEED", required=True)
@click.option("--network-name", required=True)
@click.option("--network-type", required=True)
def create(name, realm, seed, network_name, network_type):
data = {
**OTPCredentials(name, realm, seed).get_json(),
"network_name": network_name,
"type": network_type
}
r = requests.post("{}/network/create".format(config('UCLOUD_API_SERVER')), json=data)
print(load_dump_pretty(r.content))

View file

@ -29,6 +29,17 @@ def list_vms(name, realm, seed):
r = requests.get("{}/user/vms".format(config('UCLOUD_API_SERVER')), json=data) r = requests.get("{}/user/vms".format(config('UCLOUD_API_SERVER')), json=data)
print(load_dump_pretty(r.content)) print(load_dump_pretty(r.content))
@user.command("network")
@click.option("--name", envvar="OTP_NAME", required=True)
@click.option("--realm", envvar="OTP_REALM", required=True)
@click.option("--seed", envvar="OTP_SEED", required=True)
def list_files(name, realm, seed):
data = OTPCredentials(name, realm, seed).get_json()
r = requests.get("{}/user/networks".format(config('UCLOUD_API_SERVER')), json=data)
print(load_dump_pretty(r.content))
@user.command("add-ssh") @user.command("add-ssh")
@click.option("--name", envvar="OTP_NAME", required=True) @click.option("--name", envvar="OTP_NAME", required=True)
@click.option("--realm", envvar="OTP_REALM", required=True) @click.option("--realm", envvar="OTP_REALM", required=True)

View file

@ -27,8 +27,9 @@ def vm():
@click.option("--ram", required=True) @click.option("--ram", required=True)
@click.option("--os-ssd", required=True) @click.option("--os-ssd", required=True)
@click.option("--hdd", default=list(), multiple=True) @click.option("--hdd", default=list(), multiple=True)
@click.option("--image-uuid", required=True) @click.option("--image", required=True)
def create(name, realm, seed, vm_name, cpu, ram, os_ssd, hdd, image_uuid): @click.option("--network", default=list(), multiple=True)
def create(name, realm, seed, vm_name, cpu, ram, os_ssd, hdd, image, network):
data = { data = {
**OTPCredentials(name, realm, seed).get_json(), **OTPCredentials(name, realm, seed).get_json(),
"vm_name": vm_name, "vm_name": vm_name,
@ -38,9 +39,9 @@ def create(name, realm, seed, vm_name, cpu, ram, os_ssd, hdd, image_uuid):
'os-ssd': os_ssd, 'os-ssd': os_ssd,
'hdd': hdd 'hdd': hdd
}, },
"image_uuid": image_uuid, "network": network,
"image": image,
} }
print(data)
r = requests.post("{}/vm/create".format(config('UCLOUD_API_SERVER')), json=data) r = requests.post("{}/vm/create".format(config('UCLOUD_API_SERVER')), json=data)
print(load_dump_pretty(r.content)) print(load_dump_pretty(r.content))

View file

@ -4,7 +4,7 @@ from commands.vm import vm
from commands.user import user from commands.user import user
from commands.host import host from commands.host import host
from commands.image import image from commands.image import image
from commands.network import network
@click.group() @click.group()
def entry_point(): def entry_point():
@ -15,6 +15,7 @@ entry_point.add_command(vm)
entry_point.add_command(user) entry_point.add_command(user)
entry_point.add_command(image) entry_point.add_command(image)
entry_point.add_command(host) entry_point.add_command(host)
entry_point.add_command(network)
if __name__ == "__main__": if __name__ == "__main__":
entry_point() entry_point()