libvirt: add support for configuring hyperv enlightenments in XML

Extend the guest XML config classes to cope with the following
hyperv enlightenments:

   <features>
     <hyperv>
       <relaxed state='on'/>
       <vapic state='on'/>
       <spinlocks state='on' retries='4095'/>
     </hyperv>
   <features/>

Related-bug: #1400315
Change-Id: Ieff2ae44bf90e09152a56859709707ccdf83cbc9
This commit is contained in:
Daniel P. Berrange 2014-12-08 13:49:01 +00:00
parent 3afdc2a2b0
commit 189b682ff3
2 changed files with 57 additions and 0 deletions

View File

@ -1269,6 +1269,35 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest):
</interface>""")
class LibvirtConfigGuestFeatureTest(LibvirtConfigBaseTest):
def test_feature_hyperv_relaxed(self):
obj = config.LibvirtConfigGuestFeatureHyperV()
obj.relaxed = True
xml = obj.to_xml()
self.assertXmlEqual(xml, """
<hyperv>
<relaxed state="on"/>
</hyperv>""")
def test_feature_hyperv_all(self):
obj = config.LibvirtConfigGuestFeatureHyperV()
obj.relaxed = True
obj.vapic = True
obj.spinlocks = True
xml = obj.to_xml()
self.assertXmlEqual(xml, """
<hyperv>
<relaxed state="on"/>
<vapic state="on"/>
<spinlocks state="on" retries="4095"/>
</hyperv>""")
class LibvirtConfigGuestTest(LibvirtConfigBaseTest):
def test_config_lxc(self):

View File

@ -1733,6 +1733,34 @@ class LibvirtConfigGuestFeaturePAE(LibvirtConfigGuestFeature):
**kwargs)
class LibvirtConfigGuestFeatureHyperV(LibvirtConfigGuestFeature):
# QEMU requires at least this value to be set
MIN_SPINLOCK_RETRIES = 4095
def __init__(self, **kwargs):
super(LibvirtConfigGuestFeatureHyperV, self).__init__("hyperv",
**kwargs)
self.relaxed = False
self.vapic = False
self.spinlocks = False
self.spinlock_retries = self.MIN_SPINLOCK_RETRIES
def format_dom(self):
root = super(LibvirtConfigGuestFeatureHyperV, self).format_dom()
if self.relaxed:
root.append(etree.Element("relaxed", state="on"))
if self.vapic:
root.append(etree.Element("vapic", state="on"))
if self.spinlocks:
root.append(etree.Element("spinlocks", state="on",
retries=str(self.spinlock_retries)))
return root
class LibvirtConfigGuest(LibvirtConfigObject):
def __init__(self, **kwargs):