summaryrefslogtreecommitdiff
path: root/virtinst
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2018-09-02 09:02:32 -0400
committerCole Robinson <crobinso@redhat.com>2018-09-04 14:55:04 -0400
commit9a5b903086ea23350a6b219d2d0a01594e039268 (patch)
tree449d859aa604e2e4d945dbeb3f213328cfc3825b /virtinst
parent640a0686500a4665d3507b44c270099356a03e42 (diff)
downloadvirt-manager-9a5b903086ea23350a6b219d2d0a01594e039268.tar.gz
domain: features: Add set_defaults
And move all the Guest logic there. We need to add an xmlbuilder helper _prop_is_unset to be able to determine if a bool property is unset, in our quest to remove default_* xmlbuilder bits
Diffstat (limited to 'virtinst')
-rw-r--r--virtinst/domain/features.py55
-rw-r--r--virtinst/guest.py52
-rw-r--r--virtinst/xmlbuilder.py8
3 files changed, 62 insertions, 53 deletions
diff --git a/virtinst/domain/features.py b/virtinst/domain/features.py
index 6f0eaa4e..eefaf4df 100644
--- a/virtinst/domain/features.py
+++ b/virtinst/domain/features.py
@@ -15,12 +15,9 @@ class DomainFeatures(XMLBuilder):
XML_NAME = "features"
_XML_PROP_ORDER = ["acpi", "apic", "pae", "gic_version"]
- acpi = XMLProperty("./acpi", is_bool=True,
- default_name="default", default_cb=lambda s: False)
- apic = XMLProperty("./apic", is_bool=True,
- default_name="default", default_cb=lambda s: False)
- pae = XMLProperty("./pae", is_bool=True,
- default_name="default", default_cb=lambda s: False)
+ acpi = XMLProperty("./acpi", is_bool=True)
+ apic = XMLProperty("./apic", is_bool=True)
+ pae = XMLProperty("./pae", is_bool=True)
gic_version = XMLProperty("./gic/@version")
hap = XMLProperty("./hap", is_bool=True)
@@ -38,11 +35,49 @@ class DomainFeatures(XMLBuilder):
is_int=True)
hyperv_synic = XMLProperty("./hyperv/synic/@state", is_onoff=True)
- vmport = XMLProperty("./vmport/@state", is_onoff=True,
- default_name="default", default_cb=lambda s: False)
+ vmport = XMLProperty("./vmport/@state", is_onoff=True)
kvm_hidden = XMLProperty("./kvm/hidden/@state", is_onoff=True)
pvspinlock = XMLProperty("./pvspinlock/@state", is_onoff=True)
smm = XMLProperty("./smm/@state", is_onoff=True)
- vmcoreinfo = XMLProperty("./vmcoreinfo", is_bool=True,
- default_name="default", default_cb=lambda s: False)
+ vmcoreinfo = XMLProperty("./vmcoreinfo", is_bool=True)
+
+
+ ##################
+ # Default config #
+ ##################
+
+ def set_defaults(self, guest):
+ if guest.os.is_container():
+ self.acpi = None
+ self.apic = None
+ self.pae = None
+ if guest.is_full_os_container() and guest.type != "vz":
+ self.privnet = True
+ return
+
+ if not guest.os.is_hvm():
+ return
+
+ if self._prop_is_unset("acpi"):
+ self.acpi = guest.capsinfo.guest.supports_acpi()
+ if self._prop_is_unset("apic"):
+ self.apic = guest.capsinfo.guest.supports_apic()
+ if self._prop_is_unset("pae"):
+ if (guest.os.is_hvm() and
+ guest.type == "xen" and
+ guest.os.arch == "x86_64"):
+ self.pae = True
+ else:
+ self.pae = guest.capsinfo.guest.supports_pae()
+
+ if (guest.hyperv_supported() and
+ self.conn.check_support(self.conn.SUPPORT_CONN_HYPERV_VAPIC)):
+ if self.hyperv_relaxed is None:
+ self.hyperv_relaxed = True
+ if self.hyperv_vapic is None:
+ self.hyperv_vapic = True
+ if self.hyperv_spinlocks is None:
+ self.hyperv_spinlocks = True
+ if self.hyperv_spinlocks_retries is None:
+ self.hyperv_spinlocks_retries = 8191
diff --git a/virtinst/guest.py b/virtinst/guest.py
index 7ebab436..b6e30ba2 100644
--- a/virtinst/guest.py
+++ b/virtinst/guest.py
@@ -754,7 +754,7 @@ class Guest(XMLBuilder):
self._set_clock_defaults()
self._set_emulator_defaults()
self._set_cpu_defaults()
- self._set_feature_defaults()
+ self.features.set_defaults(self)
self._set_pm_defaults()
for dev in self.devices.get_all():
@@ -764,7 +764,7 @@ class Guest(XMLBuilder):
self._add_implied_controllers()
self._add_spice_devices()
- def _is_full_os_container(self):
+ def is_full_os_container(self):
if not self.os.is_container():
return False
for fs in self.devices.filesystem:
@@ -774,7 +774,7 @@ class Guest(XMLBuilder):
def _set_osxml_defaults(self):
if self.os.is_container() and not self.os.init:
- if self._is_full_os_container():
+ if self.is_full_os_container():
self.os.init = "/sbin/init"
self.os.init = self.os.init or "/bin/sh"
@@ -824,7 +824,7 @@ class Guest(XMLBuilder):
hv_clock = self.conn.check_support(self.conn.SUPPORT_CONN_HYPERV_CLOCK)
hv_clock_rhel = self.conn.check_support(self.conn.SUPPORT_CONN_HYPERV_CLOCK_RHEL)
- if (self.osinfo.is_windows() and self._hyperv_supported() and
+ if (self.hyperv_supported() and
(hv_clock or (self.stable_defaults() and hv_clock_rhel))):
hyperv = self.clock.timers.add_new()
hyperv.name = "hypervclock"
@@ -894,7 +894,9 @@ class Guest(XMLBuilder):
if self.osinfo.broken_x2apic():
self.cpu.add_feature("x2apic", policy="disable")
- def _hyperv_supported(self):
+ def hyperv_supported(self):
+ if not self.osinfo.is_windows():
+ return False
if (self.os.loader_type == "pflash" and
self.os_variant in ("win2k8r2", "win7")):
return False
@@ -905,7 +907,7 @@ class Guest(XMLBuilder):
# changed through manual intervention via the customize wizard.
# UEFI doesn't work with hyperv bits
- if not self._hyperv_supported():
+ if not self.hyperv_supported():
self.features.hyperv_relaxed = None
self.features.hyperv_vapic = None
self.features.hyperv_spinlocks = None
@@ -914,42 +916,6 @@ class Guest(XMLBuilder):
if i.name == "hypervclock":
self.clock.remove_timer(i)
- def _set_feature_defaults(self):
- if self.os.is_container():
- self.features.acpi = None
- self.features.apic = None
- self.features.pae = None
- if self._is_full_os_container() and self.type != "vz":
- self.features.privnet = True
- return
-
- if not self.os.is_hvm():
- return
-
- if self.features.acpi == "default":
- self.features.acpi = self.capsinfo.guest.supports_acpi()
- if self.features.apic == "default":
- self.features.apic = self.capsinfo.guest.supports_apic()
- if self.features.pae == "default":
- if (self.os.is_hvm() and
- self.type == "xen" and
- self.os.arch == "x86_64"):
- self.features.pae = True
- else:
- self.features.pae = self.capsinfo.guest.supports_pae()
-
- if (self.osinfo.is_windows() and
- self._hyperv_supported() and
- self.conn.check_support(self.conn.SUPPORT_CONN_HYPERV_VAPIC)):
- if self.features.hyperv_relaxed is None:
- self.features.hyperv_relaxed = True
- if self.features.hyperv_vapic is None:
- self.features.hyperv_vapic = True
- if self.features.hyperv_spinlocks is None:
- self.features.hyperv_spinlocks = True
- if self.features.hyperv_spinlocks_retries is None:
- self.features.hyperv_spinlocks_retries = 8191
-
def _set_pm_defaults(self):
# When the suspend feature is exposed to VMs, an ACPI shutdown
# event triggers a suspend in the guest, which causes a lot of
@@ -1113,7 +1079,7 @@ class Guest(XMLBuilder):
if not self.has_spice():
return
- if (self.features.vmport == "default" and
+ if (self.features.vmport is None and
self.os.is_x86() and
self.conn.check_support(self.conn.SUPPORT_CONN_VMPORT)):
self.features.vmport = False
diff --git a/virtinst/xmlbuilder.py b/virtinst/xmlbuilder.py
index e02b42de..7f520add 100644
--- a/virtinst/xmlbuilder.py
+++ b/virtinst/xmlbuilder.py
@@ -744,6 +744,14 @@ class XMLBuilder(object):
self._xmlstate.xmlapi.node_force_remove(xpath)
self._set_child_xpaths()
+ def _prop_is_unset(self, propname):
+ """
+ Return True if the property name has never had a value set
+ """
+ if getattr(self, propname):
+ return False
+ return propname not in self._propstore
+
#################################
# Private XML building routines #