netlist: Revive portgroup UI

I removed Portgroup UI in 4c3c53f773 release 3.0.0, but there's been
a steady stream of requests to bring it back. It seems it's commonly
used with some certain openvswitch config.

Maint burden isn't too bad. Let's bring it back

Fixes: https://github.com/virt-manager/virt-manager/issues/169

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2022-01-25 15:52:04 -05:00
parent c6bf106dd3
commit 6c3b5def81
7 changed files with 139 additions and 41 deletions

View File

@ -353,6 +353,17 @@ def testAddNetworks(app):
tab.combo_select("Device model:", "virtio")
_finish(addhw, check=details)
# Portgroup
_open_addhw(app, details)
tab = _select_hw(addhw, "Network", "network-tab")
tab.find("MAC Address Field", "text").set_text("00:11:00:11:00:CC")
tab.combo_select("net-source", "Virtual network 'plainbridge-portgroups'")
c = tab.find_fuzzy("Portgroup:", "combo box")
c.click_combo_entry()
lib.utils.check(lambda: c.find("engineering", "menu item").selected)
c.find("engineering", "menu item").click()
_finish(addhw, check=details)
# Manual macvtap
_open_addhw(app, details)
tab = _select_hw(addhw, "Network", "network-tab")

View File

@ -444,6 +444,16 @@ def testDetailsEditDiskNet(app):
appl.click()
lib.utils.check(lambda: not appl.sensitive)
# Portgroup
src.click()
tab.find_fuzzy("plainbridge-portgroups",
"menu item").bring_on_screen().click()
c = tab.find_fuzzy("Portgroup:", "combo box")
c.click_combo_entry()
c.find("sales").click()
appl.click()
lib.utils.check(lambda: not appl.sensitive)
def testDetailsNetIPAddress(app):
"""

View File

@ -1,51 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.36.0 -->
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<!-- n-columns=2 n-rows=5 -->
<object class="GtkGrid" id="net-source-box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="row_spacing">6</property>
<property name="column_spacing">6</property>
<property name="can-focus">False</property>
<property name="row-spacing">6</property>
<property name="column-spacing">6</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="hexpand">False</property>
<property name="label" translatable="yes">De_vice name:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">net-manual-source</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">net-manual-source</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="net-manual-source">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can-focus">True</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<signal name="changed" handler="on_net_bridge_name_changed" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">2</property>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkBox" id="net-macvtap-warn-box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="hexpand">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="stock">gtk-dialog-warning</property>
</object>
<packing>
@ -57,12 +58,12 @@
<child>
<object class="GtkLabel" id="label19">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">&lt;small&gt;In most configurations, macvtap does not work for host to guest network communication.&lt;/small&gt;</property>
<property name="use_markup">True</property>
<property name="use-markup">True</property>
<property name="wrap">True</property>
<property name="max_width_chars">35</property>
<property name="max-width-chars">35</property>
</object>
<packing>
<property name="expand">False</property>
@ -72,15 +73,15 @@
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="left-attach">0</property>
<property name="top-attach">4</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="net-source">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="hexpand">False</property>
<signal name="changed" handler="on_net_source_changed" swapped="no"/>
@ -91,20 +92,20 @@
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkBox" id="net-default-warn-box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="stock">gtk-dialog-warning</property>
</object>
<packing>
@ -116,12 +117,12 @@
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">&lt;small&gt;Failed to find a suitable default network.&lt;/small&gt;</property>
<property name="use_markup">True</property>
<property name="use-markup">True</property>
<property name="wrap">True</property>
<property name="max_width_chars">35</property>
<property name="max-width-chars">35</property>
</object>
<packing>
<property name="expand">False</property>
@ -131,21 +132,55 @@
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="hexpand">False</property>
<property name="label" translatable="yes">_Portgroup:</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">net-portgroup</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="net-portgroup">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
<property name="has-entry">True</property>
<signal name="changed" handler="on_net_portgroup_changed" swapped="no"/>
<child internal-child="entry">
<object class="GtkEntry" id="combobox-entry2">
<property name="can-focus">True</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">3</property>
</packing>
</child>
</object>
<object class="GtkLabel" id="net-source-label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="valign">start</property>
<property name="margin_top">3</property>
<property name="margin_bottom">3</property>
<property name="margin-top">3</property>
<property name="margin-bottom">3</property>
<property name="label" translatable="yes">_Network source:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">net-source</property>
<property name="use-underline">True</property>
<property name="mnemonic-widget">net-source</property>
</object>
</interface>

View File

@ -979,9 +979,8 @@ class vmmCreateVM(vmmGObjectUI):
self.widget("summary-cpu").set_text(cpu)
self._populate_summary_storage()
ignore0, nsource, ignore1 = self._netlist.get_network_selection()
expand = not nsource
if expand:
nsource = self._netlist.get_network_selection()[1]
if not nsource:
self.widget("advanced-expander").set_expanded(True)

View File

@ -1573,7 +1573,8 @@ class vmmDetails(vmmGObjectUI):
kwargs["model"] = model
if self._edited(EDIT_NET_SOURCE):
(kwargs["ntype"], kwargs["source"], kwargs["mode"]) = (
(kwargs["ntype"], kwargs["source"],
kwargs["mode"], kwargs["portgroup"]) = (
self.netlist.get_network_selection())
if self._edited(EDIT_NET_MAC):

View File

@ -67,6 +67,7 @@ class vmmNetworkList(vmmGObjectUI):
self.builder.connect_signals({
"on_net_source_changed": self._on_net_source_changed,
"on_net_portgroup_changed": self._emit_changed,
"on_net_bridge_name_changed": self._emit_changed,
})
@ -101,6 +102,11 @@ class vmmNetworkList(vmmGObjectUI):
combo.add_attribute(text, 'text', NET_ROW_LABEL)
combo.add_attribute(text, 'sensitive', NET_ROW_SENSITIVE)
combo = self.widget("net-portgroup")
model = Gtk.ListStore(str)
combo.set_model(model)
uiutil.init_combo_text_column(combo, 0)
self.conn.connect("net-added", self._repopulate_network_list)
self.conn.connect("net-removed", self._repopulate_network_list)
@ -281,10 +287,14 @@ class vmmNetworkList(vmmGObjectUI):
# This is generally the safest and most featureful default
mode = "bridge"
return net_type, net_src, mode
portgroup = None
if self.widget("net-portgroup").is_visible():
portgroup = uiutil.get_list_selection(self.widget("net-portgroup"))
return net_type, net_src, mode, portgroup
def build_device(self, macaddr, model=None):
nettype, devname, mode = self.get_network_selection()
nettype, devname, mode, portgroup = self.get_network_selection()
net = virtinst.DeviceInterface(self.conn.get_backend())
net.type = nettype
@ -292,6 +302,7 @@ class vmmNetworkList(vmmGObjectUI):
net.macaddr = macaddr
net.model = model
net.source_mode = mode
net.portgroup = portgroup
return net
@ -303,6 +314,7 @@ class vmmNetworkList(vmmGObjectUI):
def reset_state(self):
self.widget("net-default-warn-box").set_visible(False)
self.widget("net-manual-source").set_text("")
self.widget("net-portgroup").get_child().set_text("")
self._repopulate_network_list()
def set_dev(self, net):
@ -313,6 +325,10 @@ class vmmNetworkList(vmmGObjectUI):
combo.set_active_iter(rowiter)
combo.emit("changed")
if net.portgroup:
uiutil.set_list_selection(
self.widget("net-portgroup"), net.portgroup)
#############
# Listeners #
@ -350,6 +366,19 @@ class vmmNetworkList(vmmGObjectUI):
netlist.set_active(default_idx)
def _populate_portgroups(self, portgroups):
combo = self.widget("net-portgroup")
model = combo.get_model()
model.clear()
default = None
for p in portgroups:
model.append([p.name])
if p.default:
default = p.name
uiutil.set_list_selection(combo, default)
def _on_net_source_changed(self, src):
ignore = src
self._emit_changed()
@ -359,9 +388,20 @@ class vmmNetworkList(vmmGObjectUI):
nettype = rowdata.nettype
is_direct = (nettype == virtinst.DeviceInterface.TYPE_DIRECT)
is_virtual = (nettype == virtinst.DeviceInterface.TYPE_VIRTUAL)
uiutil.set_grid_row_visible(
self.widget("net-macvtap-warn-box"), is_direct)
show_bridge = rowdata.manual
uiutil.set_grid_row_visible(
self.widget("net-manual-source"), show_bridge)
portgroups = []
if is_virtual:
net = self.conn.get_net_by_name(rowdata.source)
portgroups = net.get_xmlobj().portgroups
uiutil.set_grid_row_visible(
self.widget("net-portgroup"), bool(portgroups))
self._populate_portgroups(portgroups)

View File

@ -807,7 +807,8 @@ class vmmDomain(vmmLibvirtObject):
def define_network(self, devobj, do_hotplug,
ntype=_SENTINEL, source=_SENTINEL,
mode=_SENTINEL, model=_SENTINEL,
macaddr=_SENTINEL, linkstate=_SENTINEL):
macaddr=_SENTINEL, linkstate=_SENTINEL,
portgroup=_SENTINEL):
xmlobj = self._make_xmlobj_to_define()
editdev = self._lookup_device_to_define(xmlobj, devobj, do_hotplug)
if not editdev:
@ -819,6 +820,7 @@ class vmmDomain(vmmLibvirtObject):
editdev.type = ntype
editdev.source = source
editdev.source_mode = mode or None
editdev.portgroup = portgroup or None
if model != _SENTINEL:
if editdev.model != model: