[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] [PATCH] virt-manager: make mode for direct interfaces selectable



The following patch adds support to select the mode for direct 
interfaces.

Signed-off-by: Gerhard Stenzel <gerhard stenzel de ibm com>

Index: virt-manager/src/virtManager/details.py
===================================================================
--- virt-manager.orig/src/virtManager/details.py
+++ virt-manager/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,12 @@ 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")
+        uihelpers.init_network_list(net_source, net_bridge, source_mode_box)
+
+        # 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 +1878,8 @@ class vmmDetails(vmmGObjectUI):
         net_bridge = self.window.get_widget("network-bridge")
         nettype, source = uihelpers.get_network_selection(net_list, net_bridge)
 
+        source_mode = self.get_combo_label_value("network-source-mode")
+
         model = self.get_combo_label_value("network-model")
 
         vport_type = self.window.get_widget("vport-type").get_text()
@@ -1889,7 +1897,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 +2398,7 @@ class vmmDetails(vmmGObjectUI):
 
         nettype = net.type
         source = net.get_source()
+        source_mode = net.source_mode
         model = net.model
 
         netobj = None
@@ -2429,6 +2438,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
Index: virt-manager/src/virtManager/domain.py
===================================================================
--- virt-manager.orig/src/virtManager/domain.py
+++ virt-manager/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):
Index: virt-manager/src/virtManager/uihelpers.py
===================================================================
--- virt-manager.orig/src/virtManager/uihelpers.py
+++ virt-manager/src/virtManager/uihelpers.py
@@ -193,6 +193,26 @@ def build_watchdogaction_combo(vm, combo
     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)
@@ -312,20 +332,20 @@ def pretty_network_desc(nettype, source=
 
     return ret
 
-def init_network_list(net_list, bridge_box):
+def init_network_list(net_list, bridge_box, source_mode_box=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)
 
     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):
     active = net_list.get_active()
     if active < 0:
         return
@@ -334,6 +354,10 @@ def net_list_changed(net_list, bridge_bo
         return
 
     row = net_list.get_model()[active]
+
+    if source_mode_box != None:
+        source_mode_box.set_property("visible", row[4])
+
     show_bridge = row[5]
 
     bridge_box.set_property("visible", show_bridge)
Index: virt-manager/src/vmm-details.glade
===================================================================
--- virt-manager.orig/src/vmm-details.glade
+++ virt-manager/src/vmm-details.glade
@@ -3846,6 +3846,48 @@ I/O:</property>
                                                     <property name="position">1</property>
                                                   </packing>
                                                 </child>
+                                                <child>
+                                                  <widget class="GtkHBox" id="network-source-mode-box">
+                                                    <property name="visible">True</property>
+                                                    <property name="spacing">6</property>
+                                                    <child>
+                                                      <widget class="GtkLabel" id="label8">
+                                                        <property name="visible">True</property>
+                                                        <property name="label" translatable="yes">_Mode:</property>
+                                                        <property name="use_underline">True</property>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">False</property>
+                                                        <property name="position">0</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <widget class="GtkComboBox" id="network-source-mode-combo">
+                                                        <property name="visible">True</property>
+                                                        <signal name="changed" handler="on_network_source_mode_combo_changed"/>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">False</property>
+                                                        <property name="position">1</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <widget class="GtkLabel" id="network-source-mode-label">
+                                                        <property name="visible">True</property>
+                                                        <property name="xalign">0</property>
+                                                        <property name="label">unknown mode</property>
+                                                        <property name="selectable">True</property>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">False</property>
+                                                        <property name="position">2</property>
+                                                      </packing>
+                                                    </child>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="position">2</property>
+                                                  </packing>
+                                                </child>
                                               </widget>
                                               <packing>
                                                 <property name="left_attach">1</property>

===================================================================

Best regards, 

Gerhard Stenzel
-------------------------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]