@@ -973,27 +973,16 @@ def _do_install(self, consolecb, meter, removeOld=False, wait=True):
973973 self ._create_devices (meter )
974974 install_xml = self .get_config_xml ()
975975 if install_xml :
976- logging .debug ("Creating guest from '%s' " % ( install_xml ) )
976+ logging .debug ("Creating guest from: \n %s " % install_xml )
977977 meter .start (size = None , text = _ ("Creating domain..." ))
978978 self .domain = self .conn .createLinux (install_xml , 0 )
979979 if self .domain is None :
980980 raise RuntimeError , _ ("Unable to create domain for the guest, aborting installation!" )
981981 meter .end (0 )
982982
983983 logging .debug ("Created guest, looking to see if it is running" )
984- # sleep in .25 second increments until either a) we find
985- # our domain or b) it's been 5 seconds. this is so that
986- # we can try to gracefully handle domain creation failures
987- num = 0
988- d = None
989- while num < (5 / .25 ): # 5 seconds, .25 second sleeps
990- try :
991- d = self .conn .lookupByName (self .name )
992- break
993- except libvirt .libvirtError , e :
994- logging .debug ("No guest running yet " + str (e ))
995- num += 1
996- time .sleep (0.25 )
984+
985+ d = _wait_for_domain (self .conn , self .name )
997986
998987 if d is None :
999988 raise RuntimeError , _ ("It appears that your installation has crashed. You should be able to find more information in the logs" )
@@ -1003,7 +992,7 @@ def _do_install(self, consolecb, meter, removeOld=False, wait=True):
1003992 child = consolecb (self .domain )
1004993
1005994 boot_xml = self .get_config_xml (install = False )
1006- logging .debug ("Saving XML boot config '%s' " % ( boot_xml ) )
995+ logging .debug ("Saving XML boot config: \n %s " % boot_xml )
1007996 self .conn .defineXML (boot_xml )
1008997
1009998 if child and wait : # if we connected the console, wait for it to finish
@@ -1025,20 +1014,8 @@ def post_install_check(self):
10251014
10261015 def connect_console (self , consolecb , wait = True ):
10271016 logging .debug ("Restarted guest, looking to see if it is running" )
1028- # sleep in .25 second increments until either a) we get running
1029- # domain ID or b) it's been 5 seconds. this is so that
1030- # we can try to gracefully handle domain restarting failures
1031- num = 0
1032- while num < (5 / .25 ): # 5 seconds, .25 second sleeps
1033- try :
1034- self .domain = self .conn .lookupByName (self .name )
1035- if self .domain and self .domain .ID () != - 1 :
1036- break
1037- except libvirt .libvirtError , e :
1038- logging .debug ("No guest existing " + str (e ))
1039- self .domain = None
1040- num += 1
1041- time .sleep (0.25 )
1017+
1018+ self .domain = _wait_for_domain (self .conn , self .name )
10421019
10431020 if self .domain is None :
10441021 raise RuntimeError , _ ("Domain has not existed. You should be able to find more information in the logs" )
@@ -1113,6 +1090,22 @@ def _lookup_device_param(self, device_key, param):
11131090 raise RuntimeError (_ ("Invalid dictionary entry for device '%s %s'" % \
11141091 (device_key , param )))
11151092
1093+ def _wait_for_domain (conn , name ):
1094+ # sleep in .25 second increments until either a) we get running
1095+ # domain ID or b) it's been 5 seconds. this is so that
1096+ # we can try to gracefully handle domain restarting failures
1097+ dom = None
1098+ for ignore in range (1 , (5 / .25 )): # 5 seconds, .25 second sleeps
1099+ try :
1100+ dom = conn .lookupByName (name )
1101+ if dom and dom .ID () != - 1 :
1102+ break
1103+ except libvirt .libvirtError , e :
1104+ logging .debug ("No guest running yet: " + str (e ))
1105+ dom = None
1106+ time .sleep (0.25 )
1107+
1108+ return dom
11161109
11171110# Back compat class to avoid ABI break
11181111XenGuest = Guest
0 commit comments