2020import io
2121import logging
2222import os
23- import sys
2423
2524from novaclient .v2 import servers
2625from osc_lib .cli import parseractions
@@ -189,12 +188,6 @@ def _prep_server_detail(compute_client, image_client, server):
189188 return info
190189
191190
192- def _show_progress (progress ):
193- if progress :
194- sys .stdout .write ('\r Progress: %s' % progress )
195- sys .stdout .flush ()
196-
197-
198191class AddFixedIP (command .Command ):
199192 _description = _ ("Add fixed IP address to server" )
200193
@@ -580,6 +573,12 @@ def get_parser(self, prog_name):
580573 return parser
581574
582575 def take_action (self , parsed_args ):
576+
577+ def _show_progress (progress ):
578+ if progress :
579+ self .app .stdout .write ('\r Progress: %s' % progress )
580+ self .app .stdout .flush ()
581+
583582 compute_client = self .app .client_manager .compute
584583 volume_client = self .app .client_manager .volume
585584 image_client = self .app .client_manager .image
@@ -814,11 +813,11 @@ def take_action(self, parsed_args):
814813 server .id ,
815814 callback = _show_progress ,
816815 ):
817- sys .stdout .write ('\n ' )
816+ self . app .stdout .write ('\n ' )
818817 else :
819818 LOG .error (_ ('Error creating server: %s' ),
820819 parsed_args .server_name )
821- sys .stdout .write (_ ('Error creating server\n ' ))
820+ self . app .stdout .write (_ ('Error creating server\n ' ))
822821 raise SystemExit
823822
824823 details = _prep_server_detail (compute_client , image_client , server )
@@ -872,6 +871,12 @@ def get_parser(self, prog_name):
872871 return parser
873872
874873 def take_action (self , parsed_args ):
874+
875+ def _show_progress (progress ):
876+ if progress :
877+ self .app .stdout .write ('\r Progress: %s' % progress )
878+ self .app .stdout .flush ()
879+
875880 compute_client = self .app .client_manager .compute
876881 for server in parsed_args .server :
877882 server_obj = utils .find_resource (
@@ -883,11 +888,11 @@ def take_action(self, parsed_args):
883888 server_obj .id ,
884889 callback = _show_progress ,
885890 ):
886- sys .stdout .write ('\n ' )
891+ self . app .stdout .write ('\n ' )
887892 else :
888893 LOG .error (_ ('Error deleting server: %s' ),
889894 server_obj .id )
890- sys .stdout .write (_ ('Error deleting server\n ' ))
895+ self . app .stdout .write (_ ('Error deleting server\n ' ))
891896 raise SystemExit
892897
893898
@@ -1290,6 +1295,11 @@ def get_parser(self, prog_name):
12901295
12911296 def take_action (self , parsed_args ):
12921297
1298+ def _show_progress (progress ):
1299+ if progress :
1300+ self .app .stdout .write ('\r Progress: %s' % progress )
1301+ self .app .stdout .flush ()
1302+
12931303 compute_client = self .app .client_manager .compute
12941304
12951305 server = utils .find_resource (
@@ -1315,11 +1325,11 @@ def take_action(self, parsed_args):
13151325 server .id ,
13161326 callback = _show_progress ,
13171327 ):
1318- sys .stdout .write (_ ('Complete\n ' ))
1328+ self . app .stdout .write (_ ('Complete\n ' ))
13191329 else :
13201330 LOG .error (_ ('Error migrating server: %s' ),
13211331 server .id )
1322- sys .stdout .write (_ ('Error migrating server\n ' ))
1332+ self . app .stdout .write (_ ('Error migrating server\n ' ))
13231333 raise SystemExit
13241334
13251335
@@ -1380,6 +1390,12 @@ def get_parser(self, prog_name):
13801390 return parser
13811391
13821392 def take_action (self , parsed_args ):
1393+
1394+ def _show_progress (progress ):
1395+ if progress :
1396+ self .app .stdout .write ('\r Progress: %s' % progress )
1397+ self .app .stdout .flush ()
1398+
13831399 compute_client = self .app .client_manager .compute
13841400 server = utils .find_resource (
13851401 compute_client .servers , parsed_args .server )
@@ -1391,11 +1407,11 @@ def take_action(self, parsed_args):
13911407 server .id ,
13921408 callback = _show_progress ,
13931409 ):
1394- sys .stdout .write (_ ('Complete\n ' ))
1410+ self . app .stdout .write (_ ('Complete\n ' ))
13951411 else :
13961412 LOG .error (_ ('Error rebooting server: %s' ),
13971413 server .id )
1398- sys .stdout .write (_ ('Error rebooting server\n ' ))
1414+ self . app .stdout .write (_ ('Error rebooting server\n ' ))
13991415 raise SystemExit
14001416
14011417
@@ -1428,6 +1444,12 @@ def get_parser(self, prog_name):
14281444 return parser
14291445
14301446 def take_action (self , parsed_args ):
1447+
1448+ def _show_progress (progress ):
1449+ if progress :
1450+ self .app .stdout .write ('\r Progress: %s' % progress )
1451+ self .app .stdout .flush ()
1452+
14311453 compute_client = self .app .client_manager .compute
14321454 image_client = self .app .client_manager .image
14331455
@@ -1445,11 +1467,11 @@ def take_action(self, parsed_args):
14451467 server .id ,
14461468 callback = _show_progress ,
14471469 ):
1448- sys .stdout .write (_ ('Complete\n ' ))
1470+ self . app .stdout .write (_ ('Complete\n ' ))
14491471 else :
14501472 LOG .error (_ ('Error rebuilding server: %s' ),
14511473 server .id )
1452- sys .stdout .write (_ ('Error rebuilding server\n ' ))
1474+ self . app .stdout .write (_ ('Error rebuilding server\n ' ))
14531475 raise SystemExit
14541476
14551477 details = _prep_server_detail (compute_client , image_client , server )
@@ -1727,6 +1749,11 @@ def get_parser(self, prog_name):
17271749
17281750 def take_action (self , parsed_args ):
17291751
1752+ def _show_progress (progress ):
1753+ if progress :
1754+ self .app .stdout .write ('\r Progress: %s' % progress )
1755+ self .app .stdout .flush ()
1756+
17301757 compute_client = self .app .client_manager .compute
17311758 server = utils .find_resource (
17321759 compute_client .servers ,
@@ -1745,11 +1772,11 @@ def take_action(self, parsed_args):
17451772 success_status = ['active' , 'verify_resize' ],
17461773 callback = _show_progress ,
17471774 ):
1748- sys .stdout .write (_ ('Complete\n ' ))
1775+ self . app .stdout .write (_ ('Complete\n ' ))
17491776 else :
17501777 LOG .error (_ ('Error resizing server: %s' ),
17511778 server .id )
1752- sys .stdout .write (_ ('Error resizing server\n ' ))
1779+ self . app .stdout .write (_ ('Error resizing server\n ' ))
17531780 raise SystemExit
17541781 elif parsed_args .confirm :
17551782 compute_client .servers .confirm_resize (server )
@@ -1915,7 +1942,9 @@ def take_action(self, parsed_args):
19151942 if parsed_args .diagnostics :
19161943 (resp , data ) = server .diagnostics ()
19171944 if not resp .status_code == 200 :
1918- sys .stderr .write (_ ("Error retrieving diagnostics data\n " ))
1945+ self .app .stderr .write (_ (
1946+ "Error retrieving diagnostics data\n "
1947+ ))
19191948 return ({}, {})
19201949 else :
19211950 data = _prep_server_detail (compute_client ,
0 commit comments