This repository was archived by the owner on May 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects_user.py
More file actions
82 lines (76 loc) · 2.61 KB
/
objects_user.py
File metadata and controls
82 lines (76 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import sys
import click
from ..log import logger
from ..util import to_table, to_pretty_json, to_dict
from .. import Cloudscale, CloudscaleApiException, CloudscaleException
from . import abort_if_false
@click.group()
@click.option('--api-token', '-a', envvar='CLOUDSCALE_API_TOKEN', help="API token.")
@click.option('--profile', '-p', help="Profile used in config file.")
@click.pass_context
def objects_user(ctx, profile, api_token):
try:
ctx.obj = Cloudscale(api_token, profile)
except CloudscaleException as e:
logger.error(e)
sys.exit(1)
@click.option('--filter-tag')
@objects_user.command("list")
@click.pass_obj
def cmd_list(cloudscale, filter_tag):
try:
response = cloudscale.objects_user.get_all(filter_tag)
if response:
headers = ['display_name', 'id', 'tags']
table = to_table(response, headers)
click.echo(table)
except CloudscaleApiException as e:
logger.error(e)
sys.exit(1)
@click.option('--id', '--uuid', 'uuid', required=True)
@objects_user.command("show")
@click.pass_obj
def cmd_show(cloudscale, uuid):
try:
response = cloudscale.objects_user.get_by_uuid(uuid)
click.echo(to_pretty_json(response))
except CloudscaleApiException as e:
logger.error(e)
sys.exit(1)
@click.option('--display-name', required=True)
@click.option('--tags', multiple=True)
@objects_user.command("create")
@click.pass_obj
def cmd_create(cloudscale, display_name, tags):
try:
response = cloudscale.objects_user.create(display_name, to_dict(tags))
click.echo(to_pretty_json(response))
except CloudscaleApiException as e:
logger.error(e)
sys.exit(1)
@click.option('--id', '--uuid', 'uuid', required=True)
@click.option('--display-name')
@click.option('--tags', multiple=True)
@objects_user.command("update")
@click.pass_obj
def cmd_update(cloudscale, uuid, display_name, tags):
try:
cloudscale.objects_user.update(uuid, display_name, to_dict(tags))
response = cloudscale.objects_user.get_by_uuid(uuid)
click.echo(to_pretty_json(response))
except CloudscaleApiException as e:
logger.error(e)
sys.exit(1)
@click.option('--id', '--uuid', 'uuid', required=True)
@click.option('--force', '-f', is_flag=True, callback=abort_if_false,
expose_value=False,
prompt='Delete?')
@objects_user.command("delete")
@click.pass_obj
def cmd_delete(cloudscale, uuid):
try:
cloudscale.objects_user.delete(uuid)
click.echo("Deleted!")
except CloudscaleApiException as e:
logger.error(e)
sys.exit(1)