uncloud-cli/ucloud_cli/commands/image.py

32 lines
881 B
Python
Raw Normal View History

2019-12-02 17:37:14 +00:00
from ucloud_cli.commands.helper import load_dump_pretty
from ucloud_cli.config import env_vars
from os.path import join as join_path
2019-07-17 14:58:39 +00:00
import click
import requests
2019-07-17 14:58:39 +00:00
2019-07-17 14:58:39 +00:00
@click.group()
def image():
pass
@image.command("list")
@click.option("--public", is_flag=True)
def _list(public):
2019-07-17 14:58:39 +00:00
if public:
r = requests.get(join_path(env_vars.get("UCLOUD_API_SERVER"), "image", "list-public"))
print(load_dump_pretty(r.content))
2019-07-17 14:58:39 +00:00
@image.command("create-from-file")
@click.option("--name", required=True)
@click.option("--uuid", required=True)
@click.option("--image-store-name", required=True)
2019-07-17 14:58:39 +00:00
def create_from_file(name, uuid, image_store_name):
data = {"name": name, "uuid": uuid, "image_store": image_store_name}
r = requests.post(
join_path(env_vars.get("UCLOUD_API_SERVER"), "image", "create"), json=data
)
print(load_dump_pretty(r.content))