guest: Only use define+start logic for vz

Handling this for qemu, which may need UNDEFINE_NVRAM flags to do
the cleanup, is a pain, so move this logic to only apply to vz
driver which doesn't support createXML

Mentioned on list: https://www.redhat.com/archives/virt-tools-list/2017-April/msg00037.html
This commit is contained in:
Cole Robinson 2017-04-27 13:11:13 -04:00
parent 7aee124d9a
commit 8181e86098
2 changed files with 38 additions and 19 deletions

View File

@ -784,6 +784,8 @@ c.add_compare("--disk %(BLOCKVOL)s --cdrom %(EXISTIMG1)s --livecd --hvm", "xen-h
#####################
c = vinst.add_category("vz", "--connect %(URI-VZ)s --noautoconsole")
c.add_valid("--container") # validate the special define+start logic
c.add_invalid("--container --transient") # doesn't support --transient
c.add_compare(""" \
--container \
--filesystem type=template,source=centos-7-x86_64,target="/" \

View File

@ -383,6 +383,31 @@ class Guest(XMLBuilder):
return install_xml, final_xml
def _manual_transient_create(self, install_xml, final_xml, needs_boot):
"""
For hypervisors (like vz) that don't implement createXML,
we need to define+start, and undefine on start failure
"""
domain = self.conn.defineXML(install_xml or final_xml)
if not needs_boot:
return domain
# Handle undefining the VM if the initial startup fails
try:
domain.create()
except:
import sys
exc_info = sys.exc_info()
try:
domain.undefine()
except:
pass
raise exc_info[0], exc_info[1], exc_info[2]
if install_xml and install_xml != final_xml:
domain = self.conn.defineXML(final_xml)
return domain
def _create_guest(self, meter, install_xml, final_xml, doboot, transient):
"""
Actually do the XML logging, guest defining/creating
@ -392,27 +417,19 @@ class Guest(XMLBuilder):
meter_label = _("Creating domain...")
meter = util.ensure_meter(meter)
meter.start(size=None, text=meter_label)
needs_boot = doboot or self.installer.has_install_phase()
if self.type == "vz":
if transient:
raise RuntimeError(_("Domain type 'vz' doesn't support "
"transient installs."))
domain = self._manual_transient_create(
install_xml, final_xml, needs_boot)
if transient:
domain = self.conn.createXML(install_xml or final_xml, 0)
else:
# Not all hypervisors (vz) support createXML, so avoid it here
domain = self.conn.defineXML(install_xml or final_xml)
# Handle undefining the VM if the initial startup fails
if doboot or self.installer.has_install_phase():
try:
domain.create()
except:
import sys
exc_info = sys.exc_info()
try:
domain.undefine()
except:
pass
raise exc_info[0], exc_info[1], exc_info[2]
if install_xml and install_xml != final_xml:
if transient or needs_boot:
domain = self.conn.createXML(install_xml or final_xml, 0)
if not transient:
domain = self.conn.defineXML(final_xml)
self.domain = domain