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

Commit

Permalink
Add "--id-only" option for listing session ids only with ps command
Browse files Browse the repository at this point in the history
* "backend.ai ps --id-only" lists session ids only: eg) 984e3e78ac 43317a1bf1.
* All current session can be terminated by "backend.ai rm $(backend.ai ps --id-only)"
  • Loading branch information
adrysn committed Dec 12, 2018
1 parent 3da34d6 commit 83400e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/ai/backend/client/cli/admin/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ def sessions(args):
'''
fields = [
('Session ID', 'sess_id'),
('Lang/runtime', 'lang'),
('Tag', 'tag'),
('Created At', 'created_at',),
('Terminated At', 'terminated_at'),
('Status', 'status'),
('Memory Slot', 'mem_slot'),
('CPU Slot', 'cpu_slot'),
('GPU Slot', 'gpu_slot'),
]
if not args.id_only:
fields.extend([
('Lang/runtime', 'lang'),
('Tag', 'tag'),
('Created At', 'created_at',),
('Terminated At', 'terminated_at'),
('Status', 'status'),
('Memory Slot', 'mem_slot'),
('CPU Slot', 'cpu_slot'),
('GPU Slot', 'gpu_slot'),
])
if args.access_key is None:
q = 'query($status:String) {' \
' compute_sessions(status:$status) { $fields }' \
Expand All @@ -45,8 +48,12 @@ def sessions(args):
if len(resp['compute_sessions']) == 0:
print('There are no compute sessions currently running.')
return
print(tabulate((item.values() for item in resp['compute_sessions']),
headers=(item[0] for item in fields)))
if args.id_only:
for item in resp['compute_sessions']:
print(item['sess_id'], end=' ')
else:
print(tabulate((item.values() for item in resp['compute_sessions']),
headers=(item[0] for item in fields)))


sessions.add_argument('--status', type=str, default='RUNNING',
Expand All @@ -57,6 +64,8 @@ def sessions(args):
sessions.add_argument('--access-key', type=str, default=None,
help='Get sessions for a specific access key '
'(only works if you are a super-admin)')
sessions.add_argument('--id-only', action='store_true', default=False,
help='Display session ids only.')


@admin.register_command
Expand Down
5 changes: 5 additions & 0 deletions src/ai/backend/client/cli/ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ def ps(args):
inner_args = Namespace()
inner_args.status = 'RUNNING'
inner_args.access_key = None
inner_args.id_only = args.id_only
sessions(inner_args)


ps.add_argument('--id-only', action='store_true', default=False,
help='Display session ids only.')

0 comments on commit 83400e5

Please sign in to comment.