@@ -846,23 +846,23 @@ def start(image, session_id, owner, # base args
846
846
847
847
848
848
@main .command (aliases = ['rm' , 'kill' ])
849
- @click .argument ('sess_id_or_alias ' , metavar = 'SESSID' , nargs = - 1 )
849
+ @click .argument ('session_ids ' , metavar = 'SESSID' , nargs = - 1 )
850
850
@click .option ('-o' , '--owner' , '--owner-access-key' , metavar = 'ACCESS_KEY' ,
851
851
help = 'Specify the owner of the target session explicitly.' )
852
852
@click .option ('-s' , '--stats' , is_flag = True ,
853
853
help = 'Show resource usage statistics after termination' )
854
- def terminate (sess_id_or_alias , owner , stats ):
854
+ def terminate (session_ids , owner , stats ):
855
855
'''
856
856
Terminate the given session.
857
857
858
- SESSID: session ID or its alias given when creating the session.
858
+ SESSID: session ID given/generated when creating the session.
859
859
'''
860
860
print_wait ('Terminating the session(s)...' )
861
861
with Session () as session :
862
862
has_failure = False
863
- for sess in sess_id_or_alias :
863
+ for session_id in session_ids :
864
864
try :
865
- kernel = session .Kernel (sess , owner )
865
+ kernel = session .Kernel (session_id , owner )
866
866
ret = kernel .destroy ()
867
867
except BackendAPIError as e :
868
868
print_error (e )
@@ -874,16 +874,49 @@ def terminate(sess_id_or_alias, owner, stats):
874
874
except Exception as e :
875
875
print_error (e )
876
876
has_failure = True
877
- if has_failure :
878
- sys .exit (1 )
879
877
else :
880
- print_done ('Done.' )
878
+ if not has_failure :
879
+ print_done ('Done.' )
881
880
if stats :
882
881
stats = ret .get ('stats' , None ) if ret else None
883
882
if stats :
884
883
print (_format_stats (stats ))
885
884
else :
886
885
print ('Statistics is not available.' )
886
+ if has_failure :
887
+ sys .exit (1 )
888
+
889
+
890
+ @main .command ()
891
+ @click .argument ('session_ids' , metavar = 'SESSID' , nargs = - 1 )
892
+ def restart (session_ids ):
893
+ '''
894
+ Restart the given session.
895
+
896
+ SESSID: session ID given/generated when creating the session.
897
+ '''
898
+ print_wait ('Restarting the session(s)...' )
899
+ with Session () as session :
900
+ has_failure = False
901
+ for sess in session_ids :
902
+ try :
903
+ kernel = session .Kernel (sess )
904
+ kernel .restart ()
905
+ except BackendAPIError as e :
906
+ print_error (e )
907
+ if e .status == 404 :
908
+ print_info (
909
+ 'If you are an admin, use "-o" / "--owner" option '
910
+ 'to terminate other user\' s session.' )
911
+ has_failure = True
912
+ except Exception as e :
913
+ print_error (e )
914
+ has_failure = True
915
+ else :
916
+ if not has_failure :
917
+ print_done ('Done.' )
918
+ if has_failure :
919
+ sys .exit (1 )
887
920
888
921
889
922
@main .command ()
0 commit comments