diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-06-28 16:49:39 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-06-28 16:49:39 +0000 |
| commit | 6ae0c333aa1a9fe83eea807a90d83b6f466caacf (patch) | |
| tree | a05fb0a55659d9bd94c7840ecc3ff965df76e626 /nova/virt | |
| parent | de5a01559e76216e4ff675b2051063d284ed25be (diff) | |
| parent | 272407be59a9de094fa73a557d0823adf03b506b (diff) | |
Merge "Add libvirt config classes for handling capabilities XML doc"
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/libvirt/config.py | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/nova/virt/libvirt/config.py b/nova/virt/libvirt/config.py index b432b860f..edde66d7c 100644 --- a/nova/virt/libvirt/config.py +++ b/nova/virt/libvirt/config.py @@ -67,6 +67,94 @@ class LibvirtConfigObject(object): return xml_str +class LibvirtConfigCaps(LibvirtConfigObject): + + def __init__(self, **kwargs): + super(LibvirtConfigCaps, self).__init__(root_name="capabilities", + **kwargs) + self.host = None + self.guests = [] + + def parse_dom(self, xmldoc): + super(LibvirtConfigCaps, self).parse_dom(xmldoc) + + for c in xmldoc.getchildren(): + if c.tag == "host": + host = LibvirtConfigCapsHost() + host.parse_dom(c) + self.host = host + elif c.tag == "guest": + guest = LibvirtConfigCapsGuest() + guest.parse_dom(c) + self.guests.append(guest) + + def format_dom(self): + caps = super(LibvirtConfigCaps, self).format_dom() + + if self.host: + caps.append(self.host.format_dom()) + for g in self.guests: + caps.append(g.format_dom()) + + return caps + + +class LibvirtConfigCapsHost(LibvirtConfigObject): + + def __init__(self, **kwargs): + super(LibvirtConfigCapsHost, self).__init__(root_name="host", + **kwargs) + + self.cpu = None + + def parse_dom(self, xmldoc): + super(LibvirtConfigCapsHost, self).parse_dom(xmldoc) + + for c in xmldoc.getchildren(): + if c.tag == "cpu": + cpu = LibvirtConfigCPU() + cpu.parse_dom(c) + self.cpu = cpu + + def format_dom(self): + caps = super(LibvirtConfigCapsHost, self).format_dom() + + if self.cpu: + caps.append(self.cpu.format_dom()) + + return caps + + +class LibvirtConfigCapsGuest(LibvirtConfigObject): + + def __init__(self, **kwargs): + super(LibvirtConfigCapsGuest, self).__init__(root_name="guest", + **kwargs) + + self.arch = None + self.ostype = None + + def parse_dom(self, xmldoc): + super(LibvirtConfigCapsGuest, self).parse_dom(xmldoc) + + for c in xmldoc.getchildren(): + if c.tag == "os_type": + self.ostype = c.text + elif c.tag == "arch": + self.arch = c.get("name") + + def format_dom(self): + caps = super(LibvirtConfigCapsGuest, self).format_dom() + + if self.ostype is not None: + caps.append(self._text_node("os_type", self.ostype)) + if self.arch: + arch = etree.Element("arch", name=self.arch) + caps.append(arch) + + return caps + + class LibvirtConfigGuestTimer(LibvirtConfigObject): def __init__(self, **kwargs): @@ -132,6 +220,11 @@ class LibvirtConfigCPUFeature(LibvirtConfigObject): self.name = name + def parse_dom(self, xmldoc): + super(LibvirtConfigCPUFeature, self).parse_dom(xmldoc) + + self.name = xmldoc.get("name") + def format_dom(self): ft = super(LibvirtConfigCPUFeature, self).format_dom() @@ -156,6 +249,25 @@ class LibvirtConfigCPU(LibvirtConfigObject): self.features = [] + def parse_dom(self, xmldoc): + super(LibvirtConfigCPU, self).parse_dom(xmldoc) + + for c in xmldoc.getchildren(): + if c.tag == "arch": + self.arch = c.text + elif c.tag == "model": + self.model = c.text + elif c.tag == "vendor": + self.vendor = c.text + elif c.tag == "topology": + self.sockets = int(c.get("sockets")) + self.cores = int(c.get("cores")) + self.threads = int(c.get("threads")) + elif c.tag == "feature": + f = LibvirtConfigCPUFeature() + f.parse_dom(c) + self.add_feature(f) + def format_dom(self): cpu = super(LibvirtConfigCPU, self).format_dom() |
