39
39
import yaml
40
40
41
41
import click
42
+ import colorama
42
43
import pendulum
43
44
from rich import progress as rich_progress
44
45
@@ -1301,13 +1302,12 @@ def _terminate_or_stop_clusters(names: Tuple[str],
1301
1302
abort = True ,
1302
1303
show_default = True )
1303
1304
1304
- progress = rich_progress .Progress (transient = True )
1305
1305
operation = 'Terminating' if terminate else 'Stopping'
1306
1306
plural = 's' if len (to_down ) > 1 else ''
1307
+ progress = rich_progress .Progress (transient = True )
1307
1308
task = progress .add_task (
1308
1309
f'[bold cyan]{ operation } { len (to_down )} cluster{ plural } [/]' ,
1309
1310
total = len (to_down ))
1310
- progress .start ()
1311
1311
1312
1312
def _terminate_or_stop (record ):
1313
1313
name = record ['name' ]
@@ -1317,30 +1317,36 @@ def _terminate_or_stop(record):
1317
1317
handle .launched_resources .use_spot and not terminate ):
1318
1318
# Disable spot instances to be stopped.
1319
1319
# TODO(suquark): enable GCP+spot to be stopped in the future.
1320
- progress . stop ()
1321
- click . secho (
1322
- f'Stopping cluster { name } ... skipped, because spot instances '
1323
- 'may lose attached volumes. ' ,
1324
- fg = 'green' )
1325
- click . echo ( ' To terminate the cluster, run: ' , nl = False )
1326
- click . secho ( f'sky down { name } ' , bold = True )
1320
+ message = (
1321
+ f' { colorama . Fore . GREEN } Stopping cluster { name } ... skipped.'
1322
+ f'{ colorama . Style . RESET_ALL } \n '
1323
+ ' The spot instances may lose attached volumes.\n '
1324
+ ' To terminate the cluster, run: '
1325
+ f' { colorama . Style . BRIGHT } sky down { name } '
1326
+ f' { colorama . Style . RESET_ALL } ' )
1327
1327
else :
1328
1328
success = backend .teardown (handle , terminate = terminate , purge = purge )
1329
- progress .stop ()
1330
1329
if success :
1331
- click .secho (f'{ operation } cluster { name } ...done.' , fg = 'green' )
1330
+ message = (
1331
+ f'{ colorama .Fore .GREEN } { operation } cluster { name } ...done.'
1332
+ f'{ colorama .Style .RESET_ALL } ' )
1332
1333
if not terminate :
1333
- click .echo (' To restart the cluster, run: ' , nl = False )
1334
- click .secho (f'sky start { name } ' , bold = True )
1334
+ message += ('\n To restart the cluster, run: '
1335
+ f'{ colorama .Style .BRIGHT } sky start { name } '
1336
+ f'{ colorama .Style .RESET_ALL } ' )
1335
1337
else :
1336
- click .secho (
1337
- f'{ operation } cluster { name } ...failed. '
1338
- 'Please check the logs and try again.' ,
1339
- fg = 'red' )
1338
+ message = (
1339
+ f'{ colorama .Fore .RED } { operation } cluster { name } ...failed. '
1340
+ 'Please check the logs and try again.'
1341
+ f'{ colorama .Style .RESET_ALL } ' )
1342
+ progress .stop ()
1343
+ click .echo (message )
1340
1344
progress .update (task , advance = 1 )
1341
1345
progress .start ()
1342
1346
1343
- backend_utils .run_in_parallel (_terminate_or_stop , to_down )
1347
+ with progress :
1348
+ backend_utils .run_in_parallel (_terminate_or_stop , to_down )
1349
+ progress .live .transient = False
1344
1350
1345
1351
1346
1352
@_interactive_node_cli_command
0 commit comments