@ -278,6 +278,9 @@ from ansible.module_utils.ovirt import (
class HostsModule ( BaseModule ) :
class HostsModule ( BaseModule ) :
def __init__ ( self , start_event = None , * args , * * kwargs ) :
super ( HostsModule , self ) . __init__ ( * args , * * kwargs )
self . start_event = start_event
def build_entity ( self ) :
def build_entity ( self ) :
return otypes . Host (
return otypes . Host (
@ -344,13 +347,24 @@ class HostsModule(BaseModule):
timeout = self . param ( ' timeout ' ) ,
timeout = self . param ( ' timeout ' ) ,
)
)
def raise_host_exception ( self ) :
events = self . _connection . system_service ( ) . events_service ( ) . list ( from_ = int ( self . start_event . index ) )
error_events = [
event . description for event in events
if event . host is not None and ( event . host . id == self . param ( ' id ' ) or event . host . name == self . param ( ' name ' ) ) and
event . severity in [ otypes . LogSeverity . WARNING , otypes . LogSeverity . ERROR ]
]
if error_events :
raise Exception ( " Error message: %s " % error_events )
return True
def failed_state_after_reinstall ( self , host , count = 0 ) :
def failed_state_after_reinstall ( self , host , count = 0 ) :
if host . status in [
if host . status in [
hoststate . ERROR ,
hoststate . ERROR ,
hoststate . INSTALL_FAILED ,
hoststate . INSTALL_FAILED ,
hoststate . NON_OPERATIONAL ,
hoststate . NON_OPERATIONAL ,
] :
] :
return True
return self . raise_host_exception ( )
# If host is in non-responsive state after upgrade/install
# If host is in non-responsive state after upgrade/install
# let's wait for few seconds and re-check again the state:
# let's wait for few seconds and re-check again the state:
@ -362,7 +376,7 @@ class HostsModule(BaseModule):
count + 1 ,
count + 1 ,
)
)
else :
else :
return True
return self . raise_host_exception ( )
return False
return False
@ -460,10 +474,12 @@ def main():
auth = module . params . pop ( ' auth ' )
auth = module . params . pop ( ' auth ' )
connection = create_connection ( auth )
connection = create_connection ( auth )
hosts_service = connection . system_service ( ) . hosts_service ( )
hosts_service = connection . system_service ( ) . hosts_service ( )
start_event = connection . system_service ( ) . events_service ( ) . list ( max = 1 ) [ 0 ]
hosts_module = HostsModule (
hosts_module = HostsModule (
connection = connection ,
connection = connection ,
module = module ,
module = module ,
service = hosts_service ,
service = hosts_service ,
start_event = start_event ,
)
)
state = module . params [ ' state ' ]
state = module . params [ ' state ' ]