Skip to content
This repository was archived by the owner on Sep 22, 2023. It is now read-only.

Commit d7185b7

Browse files
authored
Improve admin CLI result output (#91)
* Prettify the console output for admin CLI commands * Update changelog
1 parent 49e939b commit d7185b7

File tree

5 files changed

+30
-28
lines changed

5 files changed

+30
-28
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Changes
77
* NEW: Add ``-f`` / ``--forced`` option to ``backend.ai terminate`` command
88
and add an optional ``forced`` keyword-argument to SDK API (``Kernel.destroy()``). (#89)
99

10+
* IMPROVE: Prettify the console output for admin CLI commands. (#91)
11+
1012
19.09.5 (2020-03-08)
1113
--------------------
1214

src/ai/backend/client/cli/admin/images.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from . import admin
66
from ...session import Session
7-
from ..pretty import print_error
7+
from ..pretty import print_done, print_warn, print_fail, print_error
88

99

1010
@admin.command()
@@ -29,7 +29,7 @@ def images(operation):
2929
print_error(e)
3030
sys.exit(1)
3131
if len(items) == 0:
32-
print('There are no registered images.')
32+
print_warn('There are no registered images.')
3333
return
3434
print(tabulate((item.values() for item in items),
3535
headers=(item[0] for item in fields),
@@ -49,9 +49,9 @@ def rescan_images(registry):
4949
print_error(e)
5050
sys.exit(1)
5151
if result['ok']:
52-
print("kernel image metadata updated")
52+
print_done("Updated the image metadata from the configured registries.")
5353
else:
54-
print("rescanning failed: {0}".format(result['msg']))
54+
print_fail(f"Rescanning has failed: {result['msg']}")
5555

5656

5757
@admin.command()
@@ -66,9 +66,9 @@ def alias_image(alias, target):
6666
print_error(e)
6767
sys.exit(1)
6868
if result['ok']:
69-
print("alias {0} created for target {1}".format(alias, target))
69+
print_done(f"An alias has created: {alias} -> {target}")
7070
else:
71-
print(result['msg'])
71+
print_fail(f"Aliasing has failed: {result['msg']}")
7272

7373

7474
@admin.command()
@@ -82,6 +82,6 @@ def dealias_image(alias):
8282
print_error(e)
8383
sys.exit(1)
8484
if result['ok']:
85-
print("alias {0} removed.".format(alias))
85+
print_done(f"The alias has been removed: {alias}")
8686
else:
87-
print(result['msg'])
87+
print_fail(f"Dealiasing has failed: {result['msg']}")

src/ai/backend/client/cli/admin/keypairs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from . import admin
77
from ...session import Session
8-
from ..pretty import print_error, print_fail
8+
from ..pretty import print_done, print_warn, print_error, print_fail
99

1010

1111
@admin.command()
@@ -79,8 +79,8 @@ def keypairs(ctx, user_id, is_active):
7979
print_error(e)
8080
sys.exit(1)
8181
if len(items) == 0:
82-
print('There are no matching keypairs associated '
83-
'with the user ID {0}'.format(user_id))
82+
print_warn('There are no matching keypairs associated '
83+
'with the user ID {0}'.format(user_id))
8484
return
8585
print(tabulate((item.values() for item in items),
8686
headers=(item[0] for item in fields)))
@@ -151,7 +151,7 @@ def update(access_key, resource_policy, is_admin, is_active, rate_limit):
151151
if not data['ok']:
152152
print_fail('KeyPair update has failed: {0}'.format(data['msg']))
153153
sys.exit(1)
154-
print('Key pair is updated: ' + access_key + '.')
154+
print_done('Key pair is updated: ' + access_key + '.')
155155

156156

157157
@keypairs.command()
@@ -171,7 +171,7 @@ def delete(access_key):
171171
if not data['ok']:
172172
print_fail('KeyPair deletion has failed: {0}'.format(data['msg']))
173173
sys.exit(1)
174-
print('Key pair is deleted: ' + access_key + '.')
174+
print_done('Key pair is deleted: ' + access_key + '.')
175175

176176

177177
@keypairs.command()
@@ -191,7 +191,7 @@ def activate(access_key):
191191
if not data['ok']:
192192
print_fail('KeyPair activation has failed: {0}'.format(data['msg']))
193193
sys.exit(1)
194-
print('Key pair is activated: ' + access_key + '.')
194+
print_done('Key pair is activated: ' + access_key + '.')
195195

196196

197197
@keypairs.command()
@@ -211,4 +211,4 @@ def deactivate(access_key):
211211
if not data['ok']:
212212
print_fail('KeyPair deactivation has failed: {0}'.format(data['msg']))
213213
sys.exit(1)
214-
print('Key pair is deactivated: ' + access_key + '.')
214+
print_done('Key pair is deactivated: ' + access_key + '.')

src/ai/backend/client/cli/admin/resource_policies.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from . import admin
77
from ...session import Session
8-
from ..pretty import print_error, print_fail
8+
from ..pretty import print_done, print_warn, print_error, print_fail
99

1010

1111
@admin.command()
@@ -37,7 +37,7 @@ def keypair_resource_policy(name):
3737
sys.exit(1)
3838
rows = []
3939
if info is None:
40-
print('No such resource policy.')
40+
print_warn('No such resource policy.')
4141
sys.exit(1)
4242
for name, key in fields:
4343
rows.append((name, info[key]))
@@ -72,7 +72,7 @@ def keypair_resource_policies(ctx):
7272
print_error(e)
7373
sys.exit(1)
7474
if len(items) == 0:
75-
print('There are no keypair resource policies.')
75+
print_warn('There are no keypair resource policies.')
7676
return
7777
print(tabulate((item.values() for item in items),
7878
headers=(item[0] for item in fields)))
@@ -129,7 +129,7 @@ def add(name, default_for_unspecified, total_resource_slots, max_concurrent_sess
129129
.format(data['msg']))
130130
sys.exit(1)
131131
item = data['resource_policy']
132-
print('Keypair resource policy ' + item['name'] + ' is created.')
132+
print_done('Keypair resource policy ' + item['name'] + ' is created.')
133133

134134

135135
@keypair_resource_policies.command()
@@ -179,7 +179,7 @@ def update(name, default_for_unspecified, total_resource_slots,
179179
print_fail('KeyPair Resource Policy creation has failed: {0}'
180180
.format(data['msg']))
181181
sys.exit(1)
182-
print('Update succeeded.')
182+
print_done('Update succeeded.')
183183

184184

185185
@keypair_resource_policies.command()
@@ -203,4 +203,4 @@ def delete(name):
203203
print_fail('KeyPair Resource Policy deletion has failed: {0}'
204204
.format(data['msg']))
205205
sys.exit(1)
206-
print('Resource policy ' + name + ' is deleted.')
206+
print_done('Resource policy ' + name + ' is deleted.')

src/ai/backend/client/cli/admin/scaling_groups.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from tabulate import tabulate
55

66
from . import admin
7-
from ..pretty import print_error, print_fail
7+
from ..pretty import print_done, print_warn, print_error, print_fail
88
from ...session import Session
99

1010

@@ -18,7 +18,7 @@ def list_scaling_groups(group):
1818
print_error(e)
1919
sys.exit(1)
2020
if len(resp) < 1:
21-
print('There is no scaling group available.')
21+
print_warn('There is no scaling group available.')
2222
return
2323
print(resp)
2424

@@ -127,7 +127,7 @@ def add(name, description, inactive,
127127
print_fail('Scaling group creation has failed: {0}'.format(data['msg']))
128128
sys.exit(1)
129129
item = data['scaling_group']
130-
print('Scaling group name {0} is created.'.format(item['name']))
130+
print_done('Scaling group name {0} is created.'.format(item['name']))
131131

132132

133133
@scaling_groups.command()
@@ -168,7 +168,7 @@ def update(name, description, inactive,
168168
if not data['ok']:
169169
print_fail('Scaling group update has failed: {0}'.format(data['msg']))
170170
sys.exit(1)
171-
print('Scaling group {0} is updated.'.format(name))
171+
print_done('Scaling group {0} is updated.'.format(name))
172172

173173

174174
@scaling_groups.command()
@@ -188,7 +188,7 @@ def delete(name):
188188
if not data['ok']:
189189
print_fail('Scaling group deletion has failed: {0}'.format(data['msg']))
190190
sys.exit(1)
191-
print('Scaling group is deleted: ' + name + '.')
191+
print_done('Scaling group is deleted: ' + name + '.')
192192

193193

194194
@scaling_groups.command()
@@ -211,7 +211,7 @@ def associate_scaling_group(scaling_group, domain):
211211
if not data['ok']:
212212
print_fail('Associating scaling group with domain failed: {0}'.format(data['msg']))
213213
sys.exit(1)
214-
print('Scaling group {} is assocatiated with domain {}.'.format(scaling_group, domain))
214+
print_done('Scaling group {} is assocatiated with domain {}.'.format(scaling_group, domain))
215215

216216

217217
@scaling_groups.command()
@@ -234,4 +234,4 @@ def dissociate_scaling_group(scaling_group, domain):
234234
if not data['ok']:
235235
print_fail('Dissociating scaling group from domain failed: {0}'.format(data['msg']))
236236
sys.exit(1)
237-
print('Scaling group {} is dissociated from domain {}.'.format(scaling_group, domain))
237+
print_done('Scaling group {} is dissociated from domain {}.'.format(scaling_group, domain))

0 commit comments

Comments
 (0)