2020import io
2121import logging
2222import os
23- import sys
2423
2524from novaclient .v2 import servers
2625from osc_lib .cli import parseractions
@@ -190,12 +189,6 @@ def _prep_server_detail(compute_client, image_client, server):
190189 return info
191190
192191
193- def _show_progress (progress ):
194- if progress :
195- sys .stdout .write ('\r Progress: %s' % progress )
196- sys .stdout .flush ()
197-
198-
199192class AddFixedIP (command .Command ):
200193 _description = _ ("Add fixed IP address to server" )
201194
@@ -598,6 +591,12 @@ def get_parser(self, prog_name):
598591 return parser
599592
600593 def take_action (self , parsed_args ):
594+
595+ def _show_progress (progress ):
596+ if progress :
597+ self .app .stdout .write ('\r Progress: %s' % progress )
598+ self .app .stdout .flush ()
599+
601600 compute_client = self .app .client_manager .compute
602601 volume_client = self .app .client_manager .volume
603602 image_client = self .app .client_manager .image
@@ -832,11 +831,11 @@ def take_action(self, parsed_args):
832831 server .id ,
833832 callback = _show_progress ,
834833 ):
835- sys .stdout .write ('\n ' )
834+ self . app .stdout .write ('\n ' )
836835 else :
837836 LOG .error (_ ('Error creating server: %s' ),
838837 parsed_args .server_name )
839- sys .stdout .write (_ ('Error creating server\n ' ))
838+ self . app .stdout .write (_ ('Error creating server\n ' ))
840839 raise SystemExit
841840
842841 details = _prep_server_detail (compute_client , image_client , server )
@@ -890,6 +889,12 @@ def get_parser(self, prog_name):
890889 return parser
891890
892891 def take_action (self , parsed_args ):
892+
893+ def _show_progress (progress ):
894+ if progress :
895+ self .app .stdout .write ('\r Progress: %s' % progress )
896+ self .app .stdout .flush ()
897+
893898 compute_client = self .app .client_manager .compute
894899 for server in parsed_args .server :
895900 server_obj = utils .find_resource (
@@ -901,11 +906,11 @@ def take_action(self, parsed_args):
901906 server_obj .id ,
902907 callback = _show_progress ,
903908 ):
904- sys .stdout .write ('\n ' )
909+ self . app .stdout .write ('\n ' )
905910 else :
906911 LOG .error (_ ('Error deleting server: %s' ),
907912 server_obj .id )
908- sys .stdout .write (_ ('Error deleting server\n ' ))
913+ self . app .stdout .write (_ ('Error deleting server\n ' ))
909914 raise SystemExit
910915
911916
@@ -1308,6 +1313,11 @@ def get_parser(self, prog_name):
13081313
13091314 def take_action (self , parsed_args ):
13101315
1316+ def _show_progress (progress ):
1317+ if progress :
1318+ self .app .stdout .write ('\r Progress: %s' % progress )
1319+ self .app .stdout .flush ()
1320+
13111321 compute_client = self .app .client_manager .compute
13121322
13131323 server = utils .find_resource (
@@ -1333,11 +1343,11 @@ def take_action(self, parsed_args):
13331343 server .id ,
13341344 callback = _show_progress ,
13351345 ):
1336- sys .stdout .write (_ ('Complete\n ' ))
1346+ self . app .stdout .write (_ ('Complete\n ' ))
13371347 else :
13381348 LOG .error (_ ('Error migrating server: %s' ),
13391349 server .id )
1340- sys .stdout .write (_ ('Error migrating server\n ' ))
1350+ self . app .stdout .write (_ ('Error migrating server\n ' ))
13411351 raise SystemExit
13421352
13431353
@@ -1398,6 +1408,12 @@ def get_parser(self, prog_name):
13981408 return parser
13991409
14001410 def take_action (self , parsed_args ):
1411+
1412+ def _show_progress (progress ):
1413+ if progress :
1414+ self .app .stdout .write ('\r Progress: %s' % progress )
1415+ self .app .stdout .flush ()
1416+
14011417 compute_client = self .app .client_manager .compute
14021418 server = utils .find_resource (
14031419 compute_client .servers , parsed_args .server )
@@ -1409,11 +1425,11 @@ def take_action(self, parsed_args):
14091425 server .id ,
14101426 callback = _show_progress ,
14111427 ):
1412- sys .stdout .write (_ ('Complete\n ' ))
1428+ self . app .stdout .write (_ ('Complete\n ' ))
14131429 else :
14141430 LOG .error (_ ('Error rebooting server: %s' ),
14151431 server .id )
1416- sys .stdout .write (_ ('Error rebooting server\n ' ))
1432+ self . app .stdout .write (_ ('Error rebooting server\n ' ))
14171433 raise SystemExit
14181434
14191435
@@ -1446,6 +1462,12 @@ def get_parser(self, prog_name):
14461462 return parser
14471463
14481464 def take_action (self , parsed_args ):
1465+
1466+ def _show_progress (progress ):
1467+ if progress :
1468+ self .app .stdout .write ('\r Progress: %s' % progress )
1469+ self .app .stdout .flush ()
1470+
14491471 compute_client = self .app .client_manager .compute
14501472 image_client = self .app .client_manager .image
14511473
@@ -1463,11 +1485,11 @@ def take_action(self, parsed_args):
14631485 server .id ,
14641486 callback = _show_progress ,
14651487 ):
1466- sys .stdout .write (_ ('Complete\n ' ))
1488+ self . app .stdout .write (_ ('Complete\n ' ))
14671489 else :
14681490 LOG .error (_ ('Error rebuilding server: %s' ),
14691491 server .id )
1470- sys .stdout .write (_ ('Error rebuilding server\n ' ))
1492+ self . app .stdout .write (_ ('Error rebuilding server\n ' ))
14711493 raise SystemExit
14721494
14731495 details = _prep_server_detail (compute_client , image_client , server )
@@ -1752,6 +1774,11 @@ def get_parser(self, prog_name):
17521774
17531775 def take_action (self , parsed_args ):
17541776
1777+ def _show_progress (progress ):
1778+ if progress :
1779+ self .app .stdout .write ('\r Progress: %s' % progress )
1780+ self .app .stdout .flush ()
1781+
17551782 compute_client = self .app .client_manager .compute
17561783 server = utils .find_resource (
17571784 compute_client .servers ,
@@ -1770,11 +1797,11 @@ def take_action(self, parsed_args):
17701797 success_status = ['active' , 'verify_resize' ],
17711798 callback = _show_progress ,
17721799 ):
1773- sys .stdout .write (_ ('Complete\n ' ))
1800+ self . app .stdout .write (_ ('Complete\n ' ))
17741801 else :
17751802 LOG .error (_ ('Error resizing server: %s' ),
17761803 server .id )
1777- sys .stdout .write (_ ('Error resizing server\n ' ))
1804+ self . app .stdout .write (_ ('Error resizing server\n ' ))
17781805 raise SystemExit
17791806 elif parsed_args .confirm :
17801807 compute_client .servers .confirm_resize (server )
@@ -1940,7 +1967,9 @@ def take_action(self, parsed_args):
19401967 if parsed_args .diagnostics :
19411968 (resp , data ) = server .diagnostics ()
19421969 if not resp .status_code == 200 :
1943- sys .stderr .write (_ ("Error retrieving diagnostics data\n " ))
1970+ self .app .stderr .write (_ (
1971+ "Error retrieving diagnostics data\n "
1972+ ))
19441973 return ({}, {})
19451974 else :
19461975 data = _prep_server_detail (compute_client ,
0 commit comments