summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2012-03-07 12:49:38 -0500
committerDaniel P. Berrange <berrange@redhat.com>2012-03-23 19:23:13 +0000
commit81ac4e729c0ca9e8fdb8064db30ae05eb8ce74a7 (patch)
treeb07ae89e1d2d1cabd2d0e55852759e19b17b02fa
parentc0f678778afefc71649253e685e8f5d6af96b3a9 (diff)
downloadnova-81ac4e729c0ca9e8fdb8064db30ae05eb8ce74a7.tar.gz
nova-81ac4e729c0ca9e8fdb8064db30ae05eb8ce74a7.tar.xz
nova-81ac4e729c0ca9e8fdb8064db30ae05eb8ce74a7.zip
Introduce a class for storing libvirt CPU configuration
Extend the libvirt config APIs to include a new class LibvirtConfigCPU for storing host/guest CPU configuration data blueprint libvirt-xml-config-apis Change-Id: Ib508637c1e0ca69860d461b0a480347c59165e6b Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
-rw-r--r--nova/tests/test_libvirt_config.py37
-rw-r--r--nova/virt/libvirt/config.py40
2 files changed, 77 insertions, 0 deletions
diff --git a/nova/tests/test_libvirt_config.py b/nova/tests/test_libvirt_config.py
index 186fb5a18..8d6ede1be 100644
--- a/nova/tests/test_libvirt_config.py
+++ b/nova/tests/test_libvirt_config.py
@@ -361,3 +361,40 @@ class LibvirtConfigGuestTest(LibvirtConfigBaseTest):
</disk>
</devices>
</domain>""")
+
+
+class LibvirtConfigCPUTest(LibvirtConfigBaseTest):
+
+ def test_config_cpu(self):
+ obj = config.LibvirtConfigCPU()
+ obj.vendor = "AMD"
+ obj.model = "Quad-Core AMD Opteron(tm) Processor 2350"
+ obj.arch = "x86_64"
+ obj.add_feature("svm")
+ obj.add_feature("extapic")
+ obj.add_feature("constant_tsc")
+
+ xml = obj.to_xml()
+ self.assertXmlEqual(xml, """
+ <cpu>
+ <arch>x86_64</arch>
+ <model>Quad-Core AMD Opteron(tm) Processor 2350</model>
+ <vendor>AMD</vendor>
+ <feature name="svm"/>
+ <feature name="extapic"/>
+ <feature name="constant_tsc"/>
+ </cpu>""")
+
+ def test_config_topology(self):
+ obj = config.LibvirtConfigCPU()
+ obj.vendor = "AMD"
+ obj.sockets = 2
+ obj.cores = 4
+ obj.threads = 2
+
+ xml = obj.to_xml()
+ self.assertXmlEqual(xml, """
+ <cpu>
+ <vendor>AMD</vendor>
+ <topology cores="4" threads="2" sockets="2"/>
+ </cpu>""")
diff --git a/nova/virt/libvirt/config.py b/nova/virt/libvirt/config.py
index 44790a068..e4f99a7ba 100644
--- a/nova/virt/libvirt/config.py
+++ b/nova/virt/libvirt/config.py
@@ -356,3 +356,43 @@ class LibvirtConfigGuest(LibvirtConfigObject):
def add_device(self, dev):
self.devices.append(dev)
+
+
+class LibvirtConfigCPU(LibvirtConfigObject):
+
+ def __init__(self, **kwargs):
+ super(LibvirtConfigCPU, self).__init__(root_name="cpu",
+ **kwargs)
+
+ self.arch = None
+ self.model = None
+ self.vendor = None
+ self.sockets = None
+ self.cores = None
+ self.threads = None
+ self.features = []
+
+ def add_feature(self, name):
+ self.features.append(name)
+
+ def format_dom(self):
+ cpu = super(LibvirtConfigCPU, self).format_dom()
+ if self.arch:
+ cpu.append(self._text_node("arch", self.arch))
+ if self.model:
+ cpu.append(self._text_node("model", self.model))
+ if self.vendor:
+ cpu.append(self._text_node("vendor", self.vendor))
+ if (self.sockets is not None and
+ self.cores is not None and
+ self.threads is not None):
+ cpu.append(etree.Element("topology",
+ sockets=str(self.sockets),
+ cores=str(self.cores),
+ threads=str(self.threads)))
+
+ for f in self.features:
+ cpu.append(etree.Element("feature",
+ name=f))
+
+ return cpu