uncloud-cli/commands/host.py

37 lines
1,019 B
Python
Raw Normal View History

2019-07-17 14:58:39 +00:00
import json
2019-09-13 12:33:19 +00:00
from commands.helper import OTPCredentials, load_dump_pretty
2019-07-17 14:58:39 +00:00
from decouple import config
2019-09-13 12:33:19 +00:00
import click
import requests
2019-07-17 14:58:39 +00:00
@click.group()
def host():
pass
@host.command("add")
@click.option("--name", envvar="OTP_NAME", required=True)
@click.option("--realm", envvar="OTP_REALM", required=True)
@click.option("--seed", envvar="OTP_SEED", required=True)
2019-07-17 14:58:39 +00:00
@click.option("--specs", required=True)
@click.option("--hostname", required=True)
def add_host(name, realm, seed, specs, hostname):
with open(specs, "r") as specs_f:
specs = json.loads(specs_f.read())
data = {
**OTPCredentials(name, realm, seed).get_json(),
"specs": specs,
"hostname": hostname,
}
2019-09-13 12:33:19 +00:00
r = requests.post("{}/host/create".format(config('UCLOUD_API_SERVER')), json=data)
print(load_dump_pretty(r.content))
2019-07-17 14:58:39 +00:00
@host.command("list")
def list_host():
2019-09-13 12:33:19 +00:00
r = requests.get("{}/host/list".format(config('UCLOUD_API_SERVER')))
print(load_dump_pretty(r.content))