#NEWLINE# def _poll_for_status( nova_client , server_id , final_ok_states , poll_period = 20 , status_field = 'status' ) : #NEWLINE# #INDENT# LOG . debug ( 'Poll instance %(id)s, waiting for any of statuses %(statuses)s' , dict ( id = server_id , statuses = final_ok_states ) ) #NEWLINE# while True : #NEWLINE# #INDENT# obj = nova_client . servers . get ( server_id ) #NEWLINE# err_msg = check_server_console ( nova_client , server_id ) #NEWLINE# if err_msg : #NEWLINE# #INDENT# raise Exception ( ( 'Critical error in instance %s console: %s' % ( server_id , err_msg ) ) ) #NEWLINE# #UNINDENT# status = getattr ( obj , status_field ) #NEWLINE# if status : #NEWLINE# #INDENT# status = status . lower ( ) #NEWLINE# #UNINDENT# LOG . debug ( 'Instance %(id)s has status %(status)s' , dict ( id = server_id , status = status ) ) #NEWLINE# if ( status in final_ok_states ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( status == 'error' ) or ( status == 'paused' ) ) : #NEWLINE# #INDENT# raise Exception ( obj . fault [ 'message' ] ) #NEWLINE# #UNINDENT# #UNINDENT# time . sleep ( poll_period )