uncloud-cli/ucloud_cli/commands/host.py

38 lines
1.2 KiB
Python
Executable file

import click
import requests
from .helper import OTPCredentials, load_dump_pretty
from ucloud_cli.config import env_vars
from os.path import join as join_path
@click.group()
def host():
pass
@host.command("create")
@click.option("--name", required=True, default=env_vars.get("OTP_NAME"))
@click.option("--realm", required=True, default=env_vars.get("OTP_REALM"))
@click.option("--seed", required=True, default=env_vars.get("OTP_SEED"))
@click.option("--hostname", 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)
def create(name, realm, seed, hostname, cpu, ram, os_ssd, hdd):
data = {
**OTPCredentials(name, realm, seed).get_json(),
"hostname": hostname,
"specs": {"cpu": cpu, "ram": ram, "os-ssd": os_ssd, "hdd": hdd},
}
r = requests.post(
join_path(env_vars.get("UCLOUD_API_SERVER"), "host", "create"), json=data
)
print(load_dump_pretty(r.content))
@host.command("list")
def list_host():
r = requests.get(join_path(env_vars.get("UCLOUD_API_SERVER"), "host", "list"))
print(load_dump_pretty(r.content))