From 81ac4e729c0ca9e8fdb8064db30ae05eb8ce74a7 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Wed, 7 Mar 2012 12:49:38 -0500 Subject: 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 --- nova/virt/libvirt/config.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'nova/virt') 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 -- cgit