diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/Pipfile b/Pipfile old mode 100644 new mode 100755 diff --git a/Pipfile.lock b/Pipfile.lock old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/commands/__init__ b/commands/__init__ old mode 100644 new mode 100755 diff --git a/commands/helper.py b/commands/helper.py old mode 100644 new mode 100755 index 9b5444f..eea8b0e --- a/commands/helper.py +++ b/commands/helper.py @@ -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 diff --git a/commands/host.py b/commands/host.py old mode 100644 new mode 100755 diff --git a/commands/image.py b/commands/image.py old mode 100644 new mode 100755 index 7979320..138bea2 --- a/commands/image.py +++ b/commands/image.py @@ -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")) diff --git a/commands/user.py b/commands/user.py old mode 100644 new mode 100755 diff --git a/commands/vm.py b/commands/vm.py old mode 100644 new mode 100755 index 8744fbe..a873396 --- a/commands/vm.py +++ b/commands/vm.py @@ -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)) diff --git a/ucloud.py b/ucloud.py old mode 100644 new mode 100755