Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit a8f0b1b

Browse files
committed
Clean up virt-install install process.
1 parent e396160 commit a8f0b1b

1 file changed

Lines changed: 87 additions & 69 deletions

File tree

virt-install

Lines changed: 87 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -655,85 +655,38 @@ def main():
655655

656656
progresscb = progress.TextMeter()
657657

658-
# we've got everything -- try to start the install
659-
try:
660-
def domain_is_shutdown(dom):
661-
info = dom.info()
662-
state = info[0]
663-
cpu_time = info[4]
664-
665-
if state == libvirt.VIR_DOMAIN_SHUTOFF:
666-
return True
667-
668-
# If --wait was specified, the dom object we have was looked up
669-
# before initially shutting down, which seems to bogus up the
670-
# info data (all 0's). So, if it is bogus, assume the domain is
671-
# shutdown. We will catch the error later.
672-
return state == libvirt.VIR_DOMAIN_NOSTATE and cpu_time == 0
673658

674-
print _("\n\nStarting install...")
659+
# we've got everything -- try to start the install
660+
print _("\n\nStarting install...")
675661

662+
try:
676663
start_time = time.time()
677664

678-
started = False
679-
while True:
680-
if not started:
681-
dom = guest.start_install(conscb, progresscb, wait=(not wait))
682-
elif continue_inst:
683-
dom = guest.continue_install(conscb, progresscb,
684-
wait=(not wait))
685-
continue_inst = False
686-
else:
687-
break
665+
# Do first install phase
666+
dom = do_install(guest, conscb, progresscb, wait, wait_time,
667+
start_time, guest.start_install)
688668

689-
if dom is None:
690-
print _("Guest installation failed")
691-
sys.exit(0)
692-
elif dom.info()[0] != libvirt.VIR_DOMAIN_SHUTOFF:
693-
# domain seems to be running
694-
if wait:
695-
print _("Domain installation still in progress. Waiting"+\
696-
((wait_time > 0)
697-
and (_(" %d minutes") % (int(wait_time) / 60))
698-
or "") + \
699-
" for domain to complete installation.")
700-
while True:
701-
if domain_is_shutdown(dom):
702-
print _("Domain has shutdown. Continuing.")
703-
try:
704-
# Lookup a new domain object incase current
705-
# one returned bogus data (see comment in
706-
# domain_is_shutdown
707-
dom = guest.conn.lookupByName(guest.name)
708-
except Exception, e:
709-
raise RuntimeError(_("Could not lookup domain after install: %s" % str(e)))
710-
break
711-
if wait_time < 0 or \
712-
((time.time() - start_time) < wait_time):
713-
time.sleep(2)
714-
else:
715-
print _("Installation has exceeded specified time"
716-
"limit. Exiting application.")
717-
sys.exit(1)
718-
else:
719-
print _("Domain installation still in progress. "
720-
"You can reconnect to \nthe console to complete "
721-
"the installation process.")
722-
sys.exit(0)
723-
724-
if not started:
725-
started = True
726-
if not guest.post_install_check():
727-
print _("Domain installation does not appear to have been\n successful. If it was, you can restart your domain\n by running 'virsh start %s'; otherwise, please\n restart your installation.") %(guest.name,)
728-
sys.exit(0)
669+
# This should be valid even before doing continue install
670+
if not guest.post_install_check():
671+
print _("Domain installation does not appear to have been\n "
672+
"successful. If it was, you can restart your domain\n "
673+
"by running 'virsh start %s'; otherwise, please\n "
674+
"restart your installation.") % guest.name
675+
sys.exit(0)
676+
677+
if continue_inst:
678+
dom = do_install(guest, conscb, progresscb, wait, wait_time,
679+
start_time, guest.continue_install)
729680

730681
if options.noreboot:
731-
print _("Guest installation complete... you can restart your domain\n"
732-
"by running 'virsh start %s'") %(guest.name,)
682+
print _("Guest installation complete... you can restart your "
683+
"domain\nby running 'virsh start %s'") % guest.name
733684
else:
685+
# FIXME: Should we say 'installation' complete for livecd, import?
734686
print _("Guest installation complete... restarting guest.")
735687
dom.create()
736688
guest.connect_console(conscb)
689+
737690
except KeyboardInterrupt, e:
738691
guest.terminate_console()
739692
print _("Guest install interrupted.")
@@ -743,9 +696,74 @@ def main():
743696
sys.exit(e.code)
744697
except Exception, e:
745698
print str(e)
746-
print _("Domain installation may not have been\n successful. If it was, you can restart your domain\n by running 'virsh start %s'; otherwise, please\n restart your installation.") %(guest.name,)
699+
print (_("Domain installation may not have been\n successful. If it "
700+
"was, you can restart your domain\n by running 'virsh start "
701+
"%s'; otherwise, please\n restart your installation.") %
702+
guest.name)
747703
raise
748704

705+
def domain_is_shutdown(dom):
706+
info = dom.info()
707+
state = info[0]
708+
cpu_time = info[4]
709+
710+
if state == libvirt.VIR_DOMAIN_SHUTOFF:
711+
return True
712+
713+
# If --wait was specified, the dom object we have was looked up
714+
# before initially shutting down, which seems to bogus up the
715+
# info data (all 0's). So, if it is bogus, assume the domain is
716+
# shutdown. We will catch the error later.
717+
return state == libvirt.VIR_DOMAIN_NOSTATE and cpu_time == 0
718+
719+
def do_install(guest, conscb, progresscb, wait, wait_time, start_time,
720+
install_func):
721+
722+
dom = install_func(conscb, progresscb, wait=(not wait))
723+
724+
if dom is None:
725+
print _("Guest installation failed.")
726+
sys.exit(0)
727+
728+
if domain_is_shutdown(dom):
729+
return dom
730+
731+
# Domain seems to be running
732+
if wait:
733+
timestr = ""
734+
if wait_time > 0:
735+
timestr = _("%d minutes ") % (int(wait_time) / 60)
736+
737+
print _("Domain installation still in progress. Waiting %s"
738+
"for domain to complete installation.") % timestr
739+
740+
# Wait loop
741+
while True:
742+
if domain_is_shutdown(dom):
743+
print _("Domain has shutdown. Continuing.")
744+
try:
745+
# Lookup a new domain object incase current
746+
# one returned bogus data (see comment in
747+
# domain_is_shutdown
748+
dom = guest.conn.lookupByName(guest.name)
749+
except Exception, e:
750+
raise RuntimeError(_("Could not lookup domain after "
751+
"install: %s" % str(e)))
752+
break
753+
754+
if wait_time < 0 or ((time.time() - start_time) < wait_time):
755+
time.sleep(2)
756+
else:
757+
print _("Installation has exceeded specified time limit. "
758+
"Exiting application.")
759+
sys.exit(1)
760+
else:
761+
print _("Domain installation still in progress. You can reconnect"
762+
" to \nthe console to complete the installation process.")
763+
sys.exit(0)
764+
765+
return dom
766+
749767
if __name__ == "__main__":
750768
try:
751769
main()

0 commit comments

Comments
 (0)