host: interface: Display IP configuration

This commit is contained in:
Cole Robinson 2010-02-25 21:13:33 -05:00
parent f777773ed9
commit 699db61fcf
3 changed files with 236 additions and 6 deletions

View File

@ -958,6 +958,8 @@ class vmmHost(gobject.GObject):
mac = interface.get_mac() mac = interface.get_mac()
active = interface.is_active() active = interface.is_active()
startmode = interface.get_startmode() 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-details").set_sensitive(True)
self.window.get_widget("interface-name").set_markup( self.window.get_widget("interface-name").set_markup(
@ -987,10 +989,38 @@ class vmmHost(gobject.GObject):
break break
idx += 1 idx += 1
used_by = util.iface_in_use_by(self.conn, name) used_by = util.iface_in_use_by(self.conn, name)
self.window.get_widget("interface-inuseby").set_text(used_by or "-") 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-delete").set_sensitive(not active)
self.window.get_widget("interface-stop").set_sensitive(active) self.window.get_widget("interface-stop").set_sensitive(active)
self.window.get_widget("interface-start").set_sensitive(not active) self.window.get_widget("interface-start").set_sensitive(not active)

View File

@ -52,6 +52,9 @@ class vmmInterface(vmmLibvirtObject):
def _define(self, xml): def _define(self, xml):
return self.get_connection().define_interface(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): def set_active(self, state):
self.active = state self.active = state
self.refresh_xml() self.refresh_xml()
@ -63,8 +66,7 @@ class vmmInterface(vmmLibvirtObject):
return self.name return self.name
def get_mac(self): def get_mac(self):
return virtinst.util.get_xml_path(self.get_xml(), return self.xpath("/interface/mac/@address")
"/interface/mac/@address")
def start(self): def start(self):
self.interface.create(0) self.interface.create(0)
@ -95,8 +97,8 @@ class vmmInterface(vmmLibvirtObject):
return "Interface" return "Interface"
def get_startmode(self): def get_startmode(self):
return virtinst.util.get_xml_path(self.get_xml(), return self.xpath("/interface/start/@mode") or "none"
"/interface/start/@mode") or "none"
def set_startmode(self, newmode): def set_startmode(self, newmode):
def set_start_xml(doc, ctx): def set_start_xml(doc, ctx):
node = ctx.xpathEval("/interface/start[1]") node = ctx.xpathEval("/interface/start[1]")
@ -142,5 +144,49 @@ class vmmInterface(vmmLibvirtObject):
slaves = self.get_slaves() slaves = self.get_slaves()
return map(lambda x: x[0], 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) gobject.type_register(vmmInterface)

View File

@ -1694,6 +1694,160 @@
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkExpander" id="interface-ipv4-expander">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="use_markup">True</property>
<child>
<widget class="GtkTable" id="table6">
<property name="visible">True</property>
<property name="n_rows">2</property>
<property name="n_columns">2</property>
<property name="column_spacing">6</property>
<property name="row_spacing">5</property>
<child>
<widget class="GtkLabel" id="label28">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Mode:</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="interface-ipv4-mode">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label">label</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label31">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Address:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="interface-ipv4-address">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label">label</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
</widget>
</child>
<child>
<widget class="GtkLabel" id="label23">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;IPv4 Configuration&lt;/b&gt;</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="type">label_item</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkExpander" id="interface-ipv6-expander">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<widget class="GtkTable" id="table7">
<property name="visible">True</property>
<property name="n_rows">2</property>
<property name="n_columns">2</property>
<property name="column_spacing">6</property>
<property name="row_spacing">5</property>
<child>
<widget class="GtkLabel" id="label29">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Mode:</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="interface-ipv6-mode">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label">label</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label32">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="label" translatable="yes">Address:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="interface-ipv6-address">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<property name="label">label</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
</widget>
</child>
<child>
<widget class="GtkLabel" id="label25">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;IPv6 Configuration&lt;/b&gt;</property>
<property name="use_markup">True</property>
</widget>
<packing>
<property name="type">label_item</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
<child> <child>
<widget class="GtkVBox" id="interface-child-box"> <widget class="GtkVBox" id="interface-child-box">
<property name="visible">True</property> <property name="visible">True</property>
@ -1732,7 +1886,7 @@
</child> </child>
</widget> </widget>
<packing> <packing>
<property name="position">1</property> <property name="position">3</property>
</packing> </packing>
</child> </child>
</widget> </widget>