From 699db61fcfea892745082109b31b5747eb6b141f Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Thu, 25 Feb 2010 21:13:33 -0500 Subject: [PATCH] host: interface: Display IP configuration --- src/virtManager/host.py | 32 ++++++- src/virtManager/interface.py | 54 +++++++++++- src/vmm-host.glade | 156 ++++++++++++++++++++++++++++++++++- 3 files changed, 236 insertions(+), 6 deletions(-) diff --git a/src/virtManager/host.py b/src/virtManager/host.py index 2ff9edf4e..192904b60 100644 --- a/src/virtManager/host.py +++ b/src/virtManager/host.py @@ -958,6 +958,8 @@ class vmmHost(gobject.GObject): mac = interface.get_mac() active = interface.is_active() startmode = interface.get_startmode() + ipv4 = interface.get_ipv4() + ipv6 = interface.get_ipv6() self.window.get_widget("interface-details").set_sensitive(True) self.window.get_widget("interface-name").set_markup( @@ -987,10 +989,38 @@ class vmmHost(gobject.GObject): break idx += 1 - used_by = util.iface_in_use_by(self.conn, name) self.window.get_widget("interface-inuseby").set_text(used_by or "-") + # IP info + self.window.get_widget("interface-ipv4-expander").set_property( + "visible", bool(ipv4)) + self.window.get_widget("interface-ipv6-expander").set_property( + "visible", bool(ipv6)) + + if ipv4: + mode = ipv4[0] and "DHCP" or "Static" + addr = ipv4[1] or "-" + self.window.get_widget("interface-ipv4-mode").set_text(mode) + self.window.get_widget("interface-ipv4-address").set_text(addr) + + if ipv6: + mode = "" + if ipv6[1]: + mode = "Autoconf " + + if ipv6[0]: + mode += "DHCP" + else: + mode = "Static" + + addrstr = "-" + if ipv6[2]: + addrstr = reduce(lambda x,y: x + "\n" + y, ipv6[2]) + + self.window.get_widget("interface-ipv6-mode").set_text(mode) + self.window.get_widget("interface-ipv6-address").set_text(addrstr) + self.window.get_widget("interface-delete").set_sensitive(not active) self.window.get_widget("interface-stop").set_sensitive(active) self.window.get_widget("interface-start").set_sensitive(not active) diff --git a/src/virtManager/interface.py b/src/virtManager/interface.py index 805298486..c15401ad8 100644 --- a/src/virtManager/interface.py +++ b/src/virtManager/interface.py @@ -52,6 +52,9 @@ class vmmInterface(vmmLibvirtObject): def _define(self, xml): return self.get_connection().define_interface(xml) + def xpath(self, path): + return virtinst.util.get_xml_path(self.get_xml(), path) + def set_active(self, state): self.active = state self.refresh_xml() @@ -63,8 +66,7 @@ class vmmInterface(vmmLibvirtObject): return self.name def get_mac(self): - return virtinst.util.get_xml_path(self.get_xml(), - "/interface/mac/@address") + return self.xpath("/interface/mac/@address") def start(self): self.interface.create(0) @@ -95,8 +97,8 @@ class vmmInterface(vmmLibvirtObject): return "Interface" def get_startmode(self): - return virtinst.util.get_xml_path(self.get_xml(), - "/interface/start/@mode") or "none" + return self.xpath("/interface/start/@mode") or "none" + def set_startmode(self, newmode): def set_start_xml(doc, ctx): node = ctx.xpathEval("/interface/start[1]") @@ -142,5 +144,49 @@ class vmmInterface(vmmLibvirtObject): slaves = self.get_slaves() return map(lambda x: x[0], slaves) + def get_ipv4(self): + base_xpath = "/interface/protocol[@family='ipv4']" + if not self.xpath(base_xpath): + return [] + + dhcp = bool(self.xpath("count(%s/dhcp)" % base_xpath)) + addr = self.xpath(base_xpath + "/ip/@address") + if addr: + prefix = self.xpath(base_xpath + "/ip[@address='%s']/@prefix" % + addr) + if prefix: + addr += "/%s" % prefix + + return [dhcp, addr] + + def get_ipv6(self): + base_xpath = "/interface/protocol[@family='ipv6']" + if not self.xpath(base_xpath): + return [] + + dhcp = bool(self.xpath("count(%s/dhcp)" % base_xpath)) + autoconf = bool(self.xpath("count(%s/autoconf)" % base_xpath)) + + def addr_func(ctx): + nodes = ctx.xpathEval(base_xpath + "/ip") + nodes = nodes or [] + ret = [] + + for node in nodes: + addr = node.prop("address") + pref = node.prop("prefix") + + if not addr: + continue + + if pref: + addr += "/%s" % pref + ret.append(addr) + + return ret + + ret = virtinst.util.get_xml_path(self.get_xml(), func=addr_func) + + return [dhcp, autoconf, ret] gobject.type_register(vmmInterface) diff --git a/src/vmm-host.glade b/src/vmm-host.glade index 3f9497ce1..e784dd964 100644 --- a/src/vmm-host.glade +++ b/src/vmm-host.glade @@ -1694,6 +1694,160 @@ 0 + + + True + True + True + + + True + 2 + 2 + 6 + 5 + + + True + 0 + Mode: + + + GTK_FILL + + + + + True + 0 + label + + + 1 + 2 + + + + + True + 0 + Address: + + + 1 + 2 + GTK_FILL + + + + + True + 0 + label + + + 1 + 2 + 1 + 2 + + + + + + + True + <b>IPv4 Configuration</b> + True + + + label_item + + + + + False + 1 + + + + + True + True + + + True + 2 + 2 + 6 + 5 + + + True + 0 + Mode: + + + GTK_FILL + + + + + True + 0 + label + + + 1 + 2 + + + + + True + 0 + 0 + Address: + + + 1 + 2 + GTK_FILL + + + + + True + 0 + 0 + label + + + 1 + 2 + 1 + 2 + GTK_FILL + + + + + + + True + <b>IPv6 Configuration</b> + True + + + label_item + + + + + False + 2 + + True @@ -1732,7 +1886,7 @@ - 1 + 3