From a505618f52580a3ca111a97ffd352328f9070835 Mon Sep 17 00:00:00 2001 From: Gerhard Stenzel Date: Tue, 19 Apr 2011 13:08:15 +0200 Subject: [PATCH] virt-manager: make mode for direct interfaces selectable Next try ... The following patch adds support to select the mode for direct interfaces. crobinso: small fixes to make check-pylint happy Signed-off-by: Gerhard Stenzel --- src/virtManager/details.py | 23 +++++++++++++++-- src/virtManager/domain.py | 3 ++- src/virtManager/uihelpers.py | 33 ++++++++++++++++++++++--- src/vmm-details.glade | 48 +++++++++++++++++++++++++++++++++++- 4 files changed, 100 insertions(+), 7 deletions(-) diff --git a/src/virtManager/details.py b/src/virtManager/details.py index e56b6b593..3ae578fef 100644 --- a/src/virtManager/details.py +++ b/src/virtManager/details.py @@ -378,6 +378,7 @@ class vmmDetails(vmmGObjectUI): "on_network_source_combo_changed": self.config_enable_apply, "on_network_bridge_changed": self.config_enable_apply, + "on_network-source-mode-combo_changed": self.config_enable_apply, "on_network_model_combo_changed": self.config_enable_apply, "on_vport_type_changed": self.config_enable_apply, @@ -791,7 +792,14 @@ class vmmDetails(vmmGObjectUI): # Network source net_source = self.window.get_widget("network-source-combo") net_bridge = self.window.get_widget("network-bridge-box") - uihelpers.init_network_list(net_source, net_bridge) + source_mode_box = self.window.get_widget("network-source-mode-box") + source_mode_label = self.window.get_widget("network-source-mode") + vport_expander = self.window.get_widget("vport-expander") + uihelpers.init_network_list(net_source, net_bridge, source_mode_box, source_mode_label, vport_expander) + + # source mode + source_mode = self.window.get_widget("network-source-mode-combo") + uihelpers.build_source_mode_combo(self.vm, source_mode) # Network model net_model = self.window.get_widget("network-model-combo") @@ -1872,6 +1880,11 @@ class vmmDetails(vmmGObjectUI): net_bridge = self.window.get_widget("network-bridge") nettype, source = uihelpers.get_network_selection(net_list, net_bridge) + if (nettype == "direct"): + source_mode = self.get_combo_label_value("network-source-mode") + else: + source_mode = "" + model = self.get_combo_label_value("network-model") vport_type = self.window.get_widget("vport-type").get_text() @@ -1889,7 +1902,7 @@ class vmmDetails(vmmGObjectUI): vport_typeid, vport_idver, vport_instid), - (dev_id_info, nettype, source)]) + (dev_id_info, nettype, source, source_mode)]) # Graphics options def _do_change_spicevmc(self, gdev, newgtype): @@ -2390,6 +2403,7 @@ class vmmDetails(vmmGObjectUI): nettype = net.type source = net.get_source() + source_mode = net.source_mode model = net.model netobj = None @@ -2429,6 +2443,11 @@ class vmmDetails(vmmGObjectUI): (nettype, source), label=desc, comparefunc=compare_network) + # source mode + uihelpers.populate_source_mode_combo(self.vm, + self.window.get_widget("network-source-mode-combo")) + self.set_combo_label("network-source-mode", source_mode) + # Virtualport config show_vport = (nettype == "direct") vport = net.virtualport diff --git a/src/virtManager/domain.py b/src/virtManager/domain.py index 837e1c906..9797ff8bb 100644 --- a/src/virtManager/domain.py +++ b/src/virtManager/domain.py @@ -427,13 +427,14 @@ class vmmDomainBase(vmmLibvirtObject): editdev.bus = newval return self._redefine_device(change, devobj) - def define_network_source(self, devobj, newtype, newsource): + def define_network_source(self, devobj, newtype, newsource, newmode): def change(editdev): if not newtype: return editdev.source = None editdev.type = newtype editdev.source = newsource + editdev.source_mode = newmode return self._redefine_device(change, devobj) def define_network_model(self, devobj, newmodel): def change(editdev): diff --git a/src/virtManager/uihelpers.py b/src/virtManager/uihelpers.py index b3d3ad809..53b175ce3 100644 --- a/src/virtManager/uihelpers.py +++ b/src/virtManager/uihelpers.py @@ -192,6 +192,26 @@ def build_watchdogaction_combo(vm, combo, no_default=False): if len(dev_model) > 0: combo.set_active(0) +def build_source_mode_combo(vm, combo): + source_mode = gtk.ListStore(str, str) + combo.set_model(source_mode) + text = gtk.CellRendererText() + combo.pack_start(text, True) + combo.add_attribute(text, 'text', 1) + + populate_source_mode_combo(vm, combo) + combo.set_active(0) + +def populate_source_mode_combo(vm, combo): + model = combo.get_model() + model.clear() + + # [xml value, label] + model.append([None, _("")]) + model.append(["vepa", "vepa"]) + model.append(["bridge", "bridge"]) + model.append(["private", "private"]) + def build_netmodel_combo(vm, combo): dev_model = gtk.ListStore(str, str) combo.set_model(dev_model) @@ -311,20 +331,20 @@ def pretty_network_desc(nettype, source=None, netobj=None): return ret -def init_network_list(net_list, bridge_box): +def init_network_list(net_list, bridge_box, source_mode_box=None, source_mode_label=None, vport_expander=None): # [ network type, source name, label, sensitive?, net is active, # manual bridge, net instance] net_model = gtk.ListStore(str, str, str, bool, bool, bool, object) net_list.set_model(net_model) - net_list.connect("changed", net_list_changed, bridge_box) + net_list.connect("changed", net_list_changed, bridge_box, source_mode_box,source_mode_label, vport_expander) text = gtk.CellRendererText() net_list.pack_start(text, True) net_list.add_attribute(text, 'text', 2) net_list.add_attribute(text, 'sensitive', 3) -def net_list_changed(net_list, bridge_box): +def net_list_changed(net_list, bridge_box, source_mode_box, source_mode_label, vport_expander): active = net_list.get_active() if active < 0: return @@ -333,6 +353,13 @@ def net_list_changed(net_list, bridge_box): return row = net_list.get_model()[active] + + if source_mode_box != None: + show_source_mode = (row[0] == VirtualNetworkInterface.TYPE_DIRECT) + source_mode_box.set_property("visible", show_source_mode) + source_mode_label.set_property("visible", show_source_mode) + vport_expander.set_property("visible", show_source_mode) + show_bridge = row[5] bridge_box.set_property("visible", show_bridge) diff --git a/src/vmm-details.glade b/src/vmm-details.glade index fa3c80fda..f10d7707d 100644 --- a/src/vmm-details.glade +++ b/src/vmm-details.glade @@ -3687,7 +3687,7 @@ I/O: True 3 - 3 + 4 2 8 4 @@ -3852,6 +3852,52 @@ I/O: 2 + + + True + 6 + + + True + + + + False + 0 + + + + + True + 0 + unknown mode + True + + + False + 1 + + + + + 1 + 2 + 3 + 4 + + + + + True + 1 + Source mode: + True + + + 3 + 4 + +