a
This commit is contained in:
parent
c90dacabe5
commit
96d3a41477
4 changed files with 79 additions and 30 deletions
0
Pipfile.lock
generated
Normal file → Executable file
0
Pipfile.lock
generated
Normal file → Executable file
|
@ -14,5 +14,7 @@ class OTPCredentials:
|
|||
|
||||
|
||||
def load_dump_pretty(content):
|
||||
if isinstance(content, bytes):
|
||||
content = content.decode("utf-8")
|
||||
parsed = json.loads(content)
|
||||
return json.dumps(parsed, indent=4, sort_keys=True)
|
||||
|
|
|
@ -28,3 +28,34 @@ def list_vms(name, realm, seed):
|
|||
data = OTPCredentials(name, realm, seed).get_json()
|
||||
r = requests.get("{}/user/vms".format(config('UCLOUD_API_SERVER')), json=data)
|
||||
print(load_dump_pretty(r.content))
|
||||
|
||||
@user.command("add-ssh")
|
||||
@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("--key_name", required=True)
|
||||
@click.option("--key", required=True)
|
||||
def add_ssh(name, realm, seed, key_name, key):
|
||||
otp = OTPCredentials(name, realm, seed)
|
||||
data = {
|
||||
**otp.get_json(),
|
||||
"key_name": key_name,
|
||||
"key": key
|
||||
}
|
||||
r = requests.get("{}/user/add-ssh".format(config('UCLOUD_API_SERVER')), json=data)
|
||||
print(load_dump_pretty(r.content))
|
||||
|
||||
|
||||
@user.command("remove-ssh")
|
||||
@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("--key_name", required=True)
|
||||
def remove_ssh(name, realm, seed, key_name):
|
||||
otp = OTPCredentials(name, realm, seed)
|
||||
data = {
|
||||
**otp.get_json(),
|
||||
"key_name": key_name,
|
||||
}
|
||||
r = requests.get("{}/user/remove-ssh".format(config('UCLOUD_API_SERVER')), json=data)
|
||||
print(load_dump_pretty(r.content))
|
||||
|
|
|
@ -7,8 +7,8 @@ import click
|
|||
import requests
|
||||
|
||||
|
||||
def vm_command(command, otp, uuid):
|
||||
data = {**otp.get_json(), "uuid": uuid, "action": command}
|
||||
def vm_command(command, otp, vm_name, **kwargs):
|
||||
data = {**otp.get_json(), "vm_name": vm_name, "action": command, **kwargs}
|
||||
r = requests.post("{}/vm/action".format(config('UCLOUD_API_SERVER')), json=data)
|
||||
return r
|
||||
|
||||
|
@ -22,16 +22,25 @@ def vm():
|
|||
@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("--specs", required=True)
|
||||
@click.option("--image_uuid", required=True)
|
||||
def create(name, realm, seed, specs, image_uuid):
|
||||
with open(specs, "r") as specs_f:
|
||||
specs = json.loads(specs_f.read())
|
||||
@click.option("--vm-name", required=True)
|
||||
@click.option("--cpu", required=True, type=int)
|
||||
@click.option("--ram", required=True)
|
||||
@click.option("--os-ssd", required=True)
|
||||
@click.option("--hdd", default=list(), multiple=True)
|
||||
@click.option("--image-uuid", required=True)
|
||||
def create(name, realm, seed, vm_name, cpu, ram, os_ssd, hdd, image_uuid):
|
||||
data = {
|
||||
**OTPCredentials(name, realm, seed).get_json(),
|
||||
"specs": specs,
|
||||
"vm_name": vm_name,
|
||||
"specs": {
|
||||
'cpu': cpu,
|
||||
'ram': ram,
|
||||
'os-ssd': os_ssd,
|
||||
'hdd': hdd
|
||||
},
|
||||
"image_uuid": image_uuid,
|
||||
}
|
||||
print(data)
|
||||
r = requests.post("{}/vm/create".format(config('UCLOUD_API_SERVER')), json=data)
|
||||
print(load_dump_pretty(r.content))
|
||||
|
||||
|
@ -40,9 +49,10 @@ def create(name, realm, seed, specs, image_uuid):
|
|||
@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("--uuid", required=True)
|
||||
def start(name, realm, seed, uuid):
|
||||
r = vm_command("start", OTPCredentials(name, realm, seed), uuid)
|
||||
@click.option("--vm_name", required=True)
|
||||
@click.option("--in_support_of")
|
||||
def start(name, realm, seed, vm_name, in_support_of):
|
||||
r = vm_command("start", OTPCredentials(name, realm, seed), vm_name, in_support_of=in_support_of)
|
||||
print(load_dump_pretty(r.content))
|
||||
|
||||
|
||||
|
@ -50,9 +60,10 @@ def start(name, realm, seed, uuid):
|
|||
@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("--uuid", required=True)
|
||||
def stop(name, realm, seed, uuid):
|
||||
r = vm_command("stop", OTPCredentials(name, realm, seed), uuid)
|
||||
@click.option("--vm_name", required=True)
|
||||
@click.option("--in_support_of")
|
||||
def stop(name, realm, seed, vm_name, in_support_of):
|
||||
r = vm_command("stop", OTPCredentials(name, realm, seed), vm_name, in_support_of=in_support_of)
|
||||
print(load_dump_pretty(r.content))
|
||||
|
||||
|
||||
|
@ -60,9 +71,10 @@ def stop(name, realm, seed, uuid):
|
|||
@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("--uuid", required=True)
|
||||
def delete(name, realm, seed, uuid):
|
||||
r = vm_command("delete", OTPCredentials(name, realm, seed), uuid)
|
||||
@click.option("--vm_name", required=True)
|
||||
@click.option("--in_support_of")
|
||||
def delete(name, realm, seed, vm_name, in_support_of):
|
||||
r = vm_command("delete", OTPCredentials(name, realm, seed), vm_name, in_support_of=in_support_of)
|
||||
print(load_dump_pretty(r.content))
|
||||
|
||||
|
||||
|
@ -70,9 +82,11 @@ def delete(name, realm, seed, uuid):
|
|||
@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("--uuid", required=True)
|
||||
def status(name, realm, seed, uuid):
|
||||
data = {"name": name, "realm": realm, "seed": seed, "uuid": uuid}
|
||||
@click.option("--vm_name", required=True)
|
||||
@click.option("--in_support_of")
|
||||
def status(name, realm, seed, vm_name, in_support_of):
|
||||
otp = OTPCredentials(name, realm, seed)
|
||||
data = {**otp.get_json(), "vm_name": vm_name, "in_support_of": in_support_of}
|
||||
r = requests.get("{}/vm/status".format(config('UCLOUD_API_SERVER')), json=data)
|
||||
print(load_dump_pretty(r.content))
|
||||
|
||||
|
@ -81,14 +95,16 @@ def status(name, realm, seed, uuid):
|
|||
@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("--uuid", required=True)
|
||||
@click.option("--vm_name", required=True)
|
||||
@click.option("--destination", required=True)
|
||||
def vm_migration(name, realm, seed, uuid, destination):
|
||||
@click.option("--in_support_of")
|
||||
def vm_migration(name, realm, seed, vm_name, destination, in_support_of):
|
||||
otp = OTPCredentials(name, realm, seed)
|
||||
data = {
|
||||
**otp.get_json(),
|
||||
"uuid": uuid,
|
||||
"destination": destination
|
||||
"vm_name": vm_name,
|
||||
"destination": destination,
|
||||
"in_support_of": in_support_of,
|
||||
}
|
||||
r = requests.post("{}/vm/migrate".format(config('UCLOUD_API_SERVER')), json=data)
|
||||
print(load_dump_pretty(r.content))
|
||||
|
|
Loading…
Reference in a new issue