From 6cf4da60a42d54ee704307007b2a2451ee583b45 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 29 Aug 2006 15:52:19 -0400 Subject: [PATCH] Extract disk & network device information from domain XML --- src/virt-manager.glade | 6 +-- src/virtManager/details.py | 85 +++++++++++++++++++++++++++++++++++++- src/virtManager/domain.py | 78 ++++++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+), 4 deletions(-) diff --git a/src/virt-manager.glade b/src/virt-manager.glade index df522b06..6279490a 100644 --- a/src/virt-manager.glade +++ b/src/virt-manager.glade @@ -2142,7 +2142,7 @@ Máirín Duffy <duffy@redhat.com> True True True - False + True False True False @@ -2445,11 +2445,11 @@ Máirín Duffy <duffy@redhat.com> GTK_CORNER_TOP_LEFT - + True True True - False + True False True False diff --git a/src/virtManager/details.py b/src/virtManager/details.py index ba95719d..79ed0da0 100644 --- a/src/virtManager/details.py +++ b/src/virtManager/details.py @@ -127,6 +127,12 @@ class vmmDetails(gobject.GObject): self.update_widget_states(vm, vm.status()) self.refresh_resources(vm) + self.prepare_disk_list() + self.populate_disk_list() + + self.prepare_network_list() + self.populate_network_list() + def show(self): dialog = self.window.get_widget("vmm-details") dialog.show_all() @@ -279,5 +285,82 @@ class vmmDetails(gobject.GObject): newmem = self.vm.set_memory(memory*1024) self.window.get_widget("config-memory-apply").set_sensitive(False) self.window.get_widget("state-vm-memory").set_text("%d MB" % (newmem/1024)) - + + def prepare_disk_list(self): + disks = self.window.get_widget("storage-view") + disksModel = gtk.TreeStore(str,str,str,str) + disks.set_model(disksModel) + + diskType_col = gtk.TreeViewColumn("Type") + diskType_text = gtk.CellRendererText() + diskType_col.pack_start(diskType_text, True) + diskType_col.add_attribute(diskType_text, 'text', 0) + + diskSrc_col = gtk.TreeViewColumn("Source") + diskSrc_text = gtk.CellRendererText() + diskSrc_col.pack_start(diskSrc_text, True) + diskSrc_col.add_attribute(diskSrc_text, 'text', 1) + + diskDevice_col = gtk.TreeViewColumn("Device") + diskDevice_text = gtk.CellRendererText() + diskDevice_col.pack_start(diskDevice_text, True) + diskDevice_col.add_attribute(diskDevice_text, 'text', 2) + + diskDst_col = gtk.TreeViewColumn(_("Destination")) + diskDst_text = gtk.CellRendererText() + diskDst_col.pack_start(diskDst_text, True) + diskDst_col.add_attribute(diskDst_text, 'text', 3) + + disks.append_column(diskType_col) + disks.append_column(diskSrc_col) + disks.append_column(diskDevice_col) + disks.append_column(diskDst_col) + + def populate_disk_list(self): + diskList = self.vm.get_disk_devices() + + disks = self.window.get_widget("storage-view") + disksModel = disks.get_model() + for d in diskList: + disksModel.append(None, d) + + def prepare_network_list(self): + nets = self.window.get_widget("network-view") + netsModel = gtk.TreeStore(str,str,str,str) + nets.set_model(netsModel) + + netType_col = gtk.TreeViewColumn("Type") + netType_text = gtk.CellRendererText() + netType_col.pack_start(netType_text, True) + netType_col.add_attribute(netType_text, 'text', 0) + + netSrc_col = gtk.TreeViewColumn("Source") + netSrc_text = gtk.CellRendererText() + netSrc_col.pack_start(netSrc_text, True) + netSrc_col.add_attribute(netSrc_text, 'text', 1) + + netDevice_col = gtk.TreeViewColumn("Device") + netDevice_text = gtk.CellRendererText() + netDevice_col.pack_start(netDevice_text, True) + netDevice_col.add_attribute(netDevice_text, 'text', 2) + + netDst_col = gtk.TreeViewColumn(_("MAC address")) + netDst_text = gtk.CellRendererText() + netDst_col.pack_start(netDst_text, True) + netDst_col.add_attribute(netDst_text, 'text', 3) + + nets.append_column(netType_col) + nets.append_column(netSrc_col) + nets.append_column(netDevice_col) + nets.append_column(netDst_col) + + def populate_network_list(self): + netList = self.vm.get_network_devices() + + nets = self.window.get_widget("network-view") + netsModel = nets.get_model() + for d in netList: + netsModel.append(None, d) + + gobject.type_register(vmmDetails) diff --git a/src/virtManager/domain.py b/src/virtManager/domain.py index e044fe6a..4506d872 100644 --- a/src/virtManager/domain.py +++ b/src/virtManager/domain.py @@ -21,6 +21,7 @@ import gobject import libvirt import libxml2 import os +import sys class vmmDomain(gobject.GObject): __gsignals__ = { @@ -306,6 +307,83 @@ class vmmDomain(gobject.GObject): port = int(port) return [type, "localhost", port] + def get_disk_devices(self): + xml = self.vm.XMLDesc(0) + doc = None + try: + doc = libxml2.parseDoc(xml) + except: + return [] + ctx = doc.xpathNewContext() + disks = [] + try: + ret = ctx.xpathEval("/domain/devices/disk") + for node in ret: + type = node.prop("type") + srcpath = None + devdst = None + for child in node.children: + if child.name == "source": + if type == "file": + srcpath = child.prop("file") + elif type == "block": + srcpath = child.prop("dev") + elif child.name == "target": + devdst = child.prop("dev") + + if srcpath == None: + raise "missing source path" + if devdst == None: + raise "missing destination device" + + devtype = node.prop("device") + if devtype == None: + devtype = "disk" + disks.append([type, srcpath, devtype, devdst]) + + finally: + if ctx != None: + ctx.xpathFreeContext() + if doc != None: + doc.freeDoc() + return disks + + def get_network_devices(self): + xml = self.vm.XMLDesc(0) + doc = None + try: + doc = libxml2.parseDoc(xml) + except: + return [] + ctx = doc.xpathNewContext() + disks = [] + try: + ret = ctx.xpathEval("/domain/devices/interface") + + for node in ret: + type = node.prop("type") + devmac = None + source = None + for child in node.children: + if child.name == "source": + if type == "bridge": + source = child.prop("bridge") + elif child.name == "mac": + devmac = child.prop("address") + + if source == None: + source = "-" + + devdst = "eth%d" % len(disks) + + disks.append([type, source, devdst, devmac]) + finally: + if ctx != None: + ctx.xpathFreeContext() + if doc != None: + doc.freeDoc() + return disks + def set_vcpu_count(self, vcpus): vcpus = int(vcpus) self.vm.setVcpus(vcpus)