start,shutdown,suspend,resume,delete merged into one (action)

This commit is contained in:
ahmadbilalkhalid 2019-08-01 15:05:38 +05:00
parent ec69c1552f
commit 56f3647ec3
11 changed files with 15 additions and 32 deletions

0
.gitignore vendored Normal file → Executable file
View File

0
Pipfile Normal file → Executable file
View File

0
Pipfile.lock generated Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

0
commands/__init__ Normal file → Executable file
View File

1
commands/helper.py Normal file → Executable file
View File

@ -11,5 +11,6 @@ class OTPCredentials:
seed: str
def get_json(self):
print(self.name, self.realm, self.seed)
r = {"name": self.name, "realm": self.realm, "token": TOTP(self.seed).now()}
return r

0
commands/host.py Normal file → Executable file
View File

2
commands/image.py Normal file → Executable file
View File

@ -26,5 +26,5 @@ def list(public, private):
@click.option("--image_store_name", required=True)
def create_from_file(name, uuid, image_store_name):
data = {"name": name, "uuid": uuid, "image_store": image_store_name}
r = requests.post(f"{config('UCLOUD_API_SERVER')}/image/create", data)
r = requests.post(f"{config('UCLOUD_API_SERVER')}/image/create", json=data)
print(r.content.decode("utf-8"))

0
commands/user.py Normal file → Executable file
View File

44
commands/vm.py Normal file → Executable file
View File

@ -6,9 +6,9 @@ from decouple import config
from .helper import OTPCredentials
def vm_action(action, otp, vmid):
data = {**otp.get_json(), "vmid": vmid}
r = requests.post(f"{config('UCLOUD_API_SERVER')}/vm/{action}", json=data)
def vm_command(command, otp, uuid):
data = {**otp.get_json(), "uuid": uuid, "action": command}
r = requests.post(f"{config('UCLOUD_API_SERVER')}/vm/action", json=data)
return r
@ -35,41 +35,23 @@ def create(name, realm, seed, specs, image_uuid):
print(json.loads(r.content))
@vm.command("start")
@vm.command("action")
@click.option("--name", required=True)
@click.option("--realm", required=True)
@click.option("--seed", required=True)
@click.option("--vmid", required=True)
def start(name, realm, seed, vmid):
r = vm_action("start", OTPCredentials(name, realm, seed), vmid)
@click.option("--uuid", required=True)
@click.option("--command", required=True)
def vm_action(name, realm, seed, uuid, command):
r = vm_command(command, OTPCredentials(name, realm, seed), uuid)
print(json.loads(r.content))
@vm.command("suspend")
@vm.command("status")
@click.option("--name", required=True)
@click.option("--realm", required=True)
@click.option("--seed", required=True)
@click.option("--vmid", required=True)
def suspend(name, realm, seed, vmid):
r = vm_action("suspend", OTPCredentials(name, realm, seed), vmid)
print(json.loads(r.content))
@vm.command("resume")
@click.option("--name", required=True)
@click.option("--realm", required=True)
@click.option("--seed", required=True)
@click.option("--vmid", required=True)
def resume(name, realm, seed, vmid):
r = vm_action("resume", OTPCredentials(name, realm, seed), vmid)
print(json.loads(r.content))
@vm.command("shutdown")
@click.option("--name", required=True)
@click.option("--realm", required=True)
@click.option("--seed", required=True)
@click.option("--vmid", required=True)
def shutdown(name, realm, seed, vmid):
r = vm_action("shutdown", OTPCredentials(name, realm, seed), vmid)
@click.option("--uuid", required=True)
def status(name, realm, seed, uuid):
data = {"name": name, "realm": realm, "seed": seed, "uuid": uuid}
r = requests.get(f"{config('UCLOUD_API_SERVER')}/vm/status", json=data)
print(json.loads(r.content))

0
ucloud.py Normal file → Executable file
View File