2014-01-28 05:58:45 +08:00
|
|
|
#
|
|
|
|
# Copyright (C) 2014 Red Hat, Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from gi.repository import Gtk
|
|
|
|
from gi.repository import GObject
|
|
|
|
|
|
|
|
import virtinst
|
2014-09-13 04:10:45 +08:00
|
|
|
from . import uiutil
|
|
|
|
from .baseclass import vmmGObjectUI
|
2014-01-28 05:58:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
class vmmNetworkList(vmmGObjectUI):
|
|
|
|
__gsignals__ = {
|
|
|
|
"changed": (GObject.SignalFlags.RUN_FIRST, None, []),
|
|
|
|
"changed-vport": (GObject.SignalFlags.RUN_FIRST, None, [])
|
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self, conn, builder, topwin):
|
|
|
|
vmmGObjectUI.__init__(self, "netlist.ui",
|
|
|
|
None, builder=builder, topwin=topwin)
|
|
|
|
self.conn = conn
|
|
|
|
|
|
|
|
self.builder.connect_signals({
|
|
|
|
"on_net_source_changed": self._on_net_source_changed,
|
|
|
|
"on_net_source_mode_changed": self._emit_changed,
|
2014-06-01 03:51:24 +08:00
|
|
|
"on_net_portgroup_changed": self._emit_changed,
|
2014-01-28 05:58:45 +08:00
|
|
|
"on_net_bridge_name_changed": self._emit_changed,
|
|
|
|
|
|
|
|
"on_vport_type_changed": self._emit_vport_changed,
|
|
|
|
"on_vport_managerid_changed": self._emit_vport_changed,
|
|
|
|
"on_vport_typeid_changed": self._emit_vport_changed,
|
|
|
|
"on_vport_typeidversion_changed": self._emit_vport_changed,
|
|
|
|
"on_vport_instanceid_changed": self._emit_vport_changed,
|
|
|
|
})
|
|
|
|
|
|
|
|
self._init_ui()
|
|
|
|
self.top_label = self.widget("net-source-label")
|
|
|
|
self.top_box = self.widget("net-source-box")
|
|
|
|
self.top_vport = self.widget("vport-expander")
|
|
|
|
|
|
|
|
def _cleanup(self):
|
2014-01-29 03:40:17 +08:00
|
|
|
try:
|
|
|
|
self.conn.disconnect_by_func(self._repopulate_network_list)
|
2014-02-06 03:25:13 +08:00
|
|
|
self.conn.disconnect_by_func(self._repopulate_network_list)
|
|
|
|
self.conn.disconnect_by_func(self._repopulate_network_list)
|
|
|
|
self.conn.disconnect_by_func(self._repopulate_network_list)
|
2017-07-24 16:26:48 +08:00
|
|
|
except Exception:
|
2014-01-29 03:40:17 +08:00
|
|
|
pass
|
|
|
|
|
2014-01-28 05:58:45 +08:00
|
|
|
self.conn = None
|
|
|
|
|
|
|
|
|
|
|
|
##########################
|
|
|
|
# Initialization methods #
|
|
|
|
##########################
|
|
|
|
|
|
|
|
def _init_ui(self):
|
|
|
|
# [ network type, source name, label, sensitive?, net is active,
|
|
|
|
# manual bridge, net instance]
|
|
|
|
model = Gtk.ListStore(str, str, str, bool, bool, bool, object)
|
|
|
|
combo = self.widget("net-source")
|
|
|
|
combo.set_model(model)
|
|
|
|
|
|
|
|
text = Gtk.CellRendererText()
|
|
|
|
combo.pack_start(text, True)
|
|
|
|
combo.add_attribute(text, 'text', 2)
|
|
|
|
combo.add_attribute(text, 'sensitive', 3)
|
|
|
|
|
|
|
|
combo = self.widget("net-source-mode")
|
|
|
|
# [xml value, label]
|
|
|
|
model = Gtk.ListStore(str, str)
|
|
|
|
combo.set_model(model)
|
2015-04-11 01:04:02 +08:00
|
|
|
uiutil.init_combo_text_column(combo, 1)
|
2014-01-28 05:58:45 +08:00
|
|
|
|
2016-02-05 23:18:16 +08:00
|
|
|
model.append(["bridge", _("Bridge")])
|
2014-01-28 05:58:45 +08:00
|
|
|
model.append(["vepa", "VEPA"])
|
2016-02-05 23:18:16 +08:00
|
|
|
model.append(["private", _("Private")])
|
|
|
|
model.append(["passthrough", _("Passthrough")])
|
2014-01-28 05:58:45 +08:00
|
|
|
combo.set_active(0)
|
|
|
|
|
2014-06-01 03:51:24 +08:00
|
|
|
combo = self.widget("net-portgroup")
|
|
|
|
# [xml value, label]
|
|
|
|
model = Gtk.ListStore(str, str)
|
|
|
|
combo.set_model(model)
|
2015-04-11 01:04:02 +08:00
|
|
|
uiutil.init_combo_text_column(combo, 1)
|
2014-06-01 03:51:24 +08:00
|
|
|
|
2014-01-29 03:40:17 +08:00
|
|
|
self.conn.connect("net-added", self._repopulate_network_list)
|
|
|
|
self.conn.connect("net-removed", self._repopulate_network_list)
|
|
|
|
self.conn.connect("interface-added", self._repopulate_network_list)
|
|
|
|
self.conn.connect("interface-removed", self._repopulate_network_list)
|
|
|
|
|
2014-01-28 05:58:45 +08:00
|
|
|
def _pretty_network_desc(self, nettype, source=None, netobj=None):
|
|
|
|
if nettype == virtinst.VirtualNetworkInterface.TYPE_USER:
|
|
|
|
return _("Usermode networking")
|
|
|
|
|
|
|
|
extra = None
|
|
|
|
if nettype == virtinst.VirtualNetworkInterface.TYPE_BRIDGE:
|
|
|
|
ret = _("Bridge")
|
|
|
|
elif nettype == virtinst.VirtualNetworkInterface.TYPE_VIRTUAL:
|
|
|
|
ret = _("Virtual network")
|
|
|
|
if netobj:
|
|
|
|
extra = ": %s" % netobj.pretty_forward_mode()
|
|
|
|
else:
|
|
|
|
ret = nettype.capitalize()
|
|
|
|
|
|
|
|
if source:
|
|
|
|
ret += " '%s'" % source
|
|
|
|
if extra:
|
|
|
|
ret += " %s" % extra
|
|
|
|
|
|
|
|
return ret
|
|
|
|
|
2014-06-18 05:04:49 +08:00
|
|
|
def _build_source_row(self, nettype, source_name,
|
2017-09-20 15:36:27 +08:00
|
|
|
label, is_sensitive, is_running, manual_bridge=False, key=None):
|
2014-06-18 05:04:49 +08:00
|
|
|
return [nettype, source_name, label,
|
2014-01-28 05:58:45 +08:00
|
|
|
is_sensitive, is_running, manual_bridge,
|
|
|
|
key]
|
|
|
|
|
|
|
|
def _find_virtual_networks(self):
|
2014-06-18 05:04:49 +08:00
|
|
|
rows = []
|
2014-01-28 05:58:45 +08:00
|
|
|
vnet_bridges = []
|
2014-06-18 05:04:49 +08:00
|
|
|
default_label = None
|
2014-01-28 05:58:45 +08:00
|
|
|
|
2014-06-03 05:17:47 +08:00
|
|
|
for net in self.conn.list_nets():
|
2014-01-28 05:58:45 +08:00
|
|
|
nettype = virtinst.VirtualNetworkInterface.TYPE_VIRTUAL
|
|
|
|
|
|
|
|
label = self._pretty_network_desc(nettype, net.get_name(), net)
|
|
|
|
if not net.is_active():
|
|
|
|
label += " (%s)" % _("Inactive")
|
|
|
|
|
2017-03-23 23:06:56 +08:00
|
|
|
if net.get_xmlobj().virtualport_type == "openvswitch":
|
|
|
|
label += " (OpenVSwitch)"
|
|
|
|
|
2014-01-28 05:58:45 +08:00
|
|
|
if net.get_name() == "default":
|
2014-06-18 05:04:49 +08:00
|
|
|
default_label = label
|
2014-01-28 05:58:45 +08:00
|
|
|
|
2014-06-18 05:04:49 +08:00
|
|
|
rows.append(self._build_source_row(
|
2014-01-28 05:58:45 +08:00
|
|
|
nettype, net.get_name(), label, True,
|
2014-06-18 05:04:49 +08:00
|
|
|
net.is_active(), key=net.get_connkey()))
|
2014-01-28 05:58:45 +08:00
|
|
|
|
|
|
|
# Build a list of vnet bridges, so we know not to list them
|
|
|
|
# in the physical interface list
|
|
|
|
vnet_bridge = net.get_bridge_device()
|
|
|
|
if vnet_bridge:
|
|
|
|
vnet_bridges.append(vnet_bridge)
|
|
|
|
|
2014-06-18 05:04:49 +08:00
|
|
|
if not rows:
|
2014-01-28 05:58:45 +08:00
|
|
|
label = _("No virtual networks available")
|
2014-06-18 05:04:49 +08:00
|
|
|
rows.append(self._build_source_row(
|
|
|
|
None, None, label, False, False))
|
2014-01-28 05:58:45 +08:00
|
|
|
|
2014-06-18 05:04:49 +08:00
|
|
|
return rows, vnet_bridges, default_label
|
2014-01-28 05:58:45 +08:00
|
|
|
|
|
|
|
def _find_physical_devices(self, vnet_bridges):
|
2014-06-18 05:04:49 +08:00
|
|
|
rows = []
|
|
|
|
can_default = False
|
|
|
|
default_label = None
|
|
|
|
skip_ifaces = ["lo"]
|
|
|
|
|
2014-01-28 05:58:45 +08:00
|
|
|
vnet_taps = []
|
2014-06-03 05:17:47 +08:00
|
|
|
for vm in self.conn.list_vms():
|
2014-01-28 05:58:45 +08:00
|
|
|
for nic in vm.get_network_devices(refresh_if_nec=False):
|
|
|
|
if nic.target_dev and nic.target_dev not in vnet_taps:
|
|
|
|
vnet_taps.append(nic.target_dev)
|
|
|
|
|
2014-06-18 05:04:49 +08:00
|
|
|
netdevs = {}
|
|
|
|
for iface in self.conn.list_interfaces():
|
|
|
|
netdevs[iface.get_name()] = [
|
|
|
|
iface.get_name(), iface.is_bridge(), iface.get_slave_names()]
|
2015-04-10 21:37:03 +08:00
|
|
|
for nodedev in self.conn.filter_nodedevs("net"):
|
2015-04-08 02:12:00 +08:00
|
|
|
if nodedev.xmlobj.interface not in netdevs:
|
|
|
|
netdevs[nodedev.xmlobj.interface] = [nodedev.xmlobj.interface,
|
|
|
|
False, []]
|
2014-06-18 05:04:49 +08:00
|
|
|
|
|
|
|
# For every bridge used by a virtual network, and any slaves of
|
|
|
|
# those devices, don't list them.
|
|
|
|
for vnet_bridge in vnet_bridges:
|
|
|
|
slave_names = netdevs.pop(vnet_bridge, [None, None, []])[2]
|
|
|
|
for slave in slave_names:
|
|
|
|
netdevs.pop(slave, None)
|
|
|
|
|
|
|
|
for name, is_bridge, slave_names in netdevs.values():
|
|
|
|
if ((name in vnet_taps) or
|
|
|
|
(name in [v + "-nic" for v in vnet_bridges]) or
|
|
|
|
(name in skip_ifaces)):
|
2014-01-28 05:58:45 +08:00
|
|
|
# Don't list this, as it is basically duplicating
|
|
|
|
# virtual net info
|
|
|
|
continue
|
|
|
|
|
2014-06-18 05:04:49 +08:00
|
|
|
sensitive = True
|
|
|
|
source_name = name
|
|
|
|
|
|
|
|
label = _("Host device %s") % (name)
|
|
|
|
if is_bridge:
|
|
|
|
nettype = virtinst.VirtualNetworkInterface.TYPE_BRIDGE
|
|
|
|
if slave_names:
|
2015-03-25 20:47:21 +08:00
|
|
|
extra = (_("Host device %s") % slave_names[0])
|
2014-06-18 05:04:49 +08:00
|
|
|
can_default = True
|
2014-01-28 05:58:45 +08:00
|
|
|
else:
|
2015-03-25 20:47:21 +08:00
|
|
|
extra = _("Empty bridge")
|
|
|
|
label = _("Bridge %s: %s") % (name, extra)
|
2014-06-18 05:04:49 +08:00
|
|
|
|
|
|
|
elif self.conn.check_support(
|
2014-01-28 05:58:45 +08:00
|
|
|
self.conn.SUPPORT_CONN_DIRECT_INTERFACE):
|
2014-06-18 05:04:49 +08:00
|
|
|
nettype = virtinst.VirtualNetworkInterface.TYPE_DIRECT
|
|
|
|
label += (": %s" % _("macvtap"))
|
2014-01-28 05:58:45 +08:00
|
|
|
|
2014-06-18 05:04:49 +08:00
|
|
|
else:
|
|
|
|
nettype = None
|
|
|
|
sensitive = False
|
|
|
|
source_name = None
|
2015-03-25 20:47:21 +08:00
|
|
|
label += (": %s" % _("Not bridged"))
|
2014-01-28 05:58:45 +08:00
|
|
|
|
2014-06-18 05:04:49 +08:00
|
|
|
if can_default and not default_label:
|
|
|
|
default_label = label
|
2014-01-28 05:58:45 +08:00
|
|
|
|
2014-06-18 05:04:49 +08:00
|
|
|
rows.append(self._build_source_row(
|
|
|
|
nettype, source_name, label, sensitive, True,
|
|
|
|
key=name))
|
2014-01-28 05:58:45 +08:00
|
|
|
|
2014-06-18 05:04:49 +08:00
|
|
|
return rows, default_label
|
2014-01-28 05:58:45 +08:00
|
|
|
|
2015-11-03 03:41:18 +08:00
|
|
|
def _populate_network_model(self, model):
|
2014-01-28 05:58:45 +08:00
|
|
|
model.clear()
|
|
|
|
|
2015-09-25 04:32:04 +08:00
|
|
|
def _add_manual_bridge_row():
|
|
|
|
manual_row = self._build_source_row(
|
|
|
|
None, None, _("Specify shared device name"),
|
|
|
|
True, False, manual_bridge=True)
|
|
|
|
model.append(manual_row)
|
|
|
|
|
2014-01-28 05:58:45 +08:00
|
|
|
if self.conn.is_qemu_session():
|
|
|
|
nettype = virtinst.VirtualNetworkInterface.TYPE_USER
|
|
|
|
r = self._build_source_row(
|
|
|
|
nettype, None, self._pretty_network_desc(nettype), True, True)
|
|
|
|
model.append(r)
|
2015-09-25 04:32:04 +08:00
|
|
|
|
|
|
|
_add_manual_bridge_row()
|
2014-01-28 05:58:45 +08:00
|
|
|
return
|
|
|
|
|
2014-06-18 05:04:49 +08:00
|
|
|
(vnets, vnet_bridges, default_net) = self._find_virtual_networks()
|
|
|
|
(iface_rows, default_bridge) = self._find_physical_devices(
|
2014-01-28 05:58:45 +08:00
|
|
|
vnet_bridges)
|
|
|
|
|
2014-06-18 05:04:49 +08:00
|
|
|
# Sorting is:
|
|
|
|
# 1) Bridges
|
|
|
|
# 2) Virtual networks
|
|
|
|
# 3) direct/macvtap
|
|
|
|
# 4) Disabled list entries
|
|
|
|
# Each category sorted alphabetically
|
|
|
|
bridges = [row for row in iface_rows if row[0] == "bridge"]
|
|
|
|
direct = [row for row in iface_rows if row[0] == "direct"]
|
|
|
|
disabled = [row for row in iface_rows if row[0] is None]
|
|
|
|
|
|
|
|
for rows in [bridges, vnets, direct, disabled]:
|
|
|
|
rows.sort(key=lambda r: r[2])
|
|
|
|
for row in rows:
|
2014-01-28 05:58:45 +08:00
|
|
|
model.append(row)
|
|
|
|
|
|
|
|
# If there is a bridge device, default to that
|
|
|
|
# If not, use 'default' network
|
|
|
|
# If not present, use first list entry
|
|
|
|
# If list empty, use no network devices
|
2014-06-18 05:04:49 +08:00
|
|
|
label = default_bridge or default_net
|
2014-01-28 05:58:45 +08:00
|
|
|
|
|
|
|
default = 0
|
|
|
|
if not len(model):
|
|
|
|
row = self._build_source_row(
|
|
|
|
None, None, _("No networking"), True, False)
|
|
|
|
model.insert(0, row)
|
|
|
|
default = 0
|
|
|
|
elif label:
|
2017-10-11 19:36:03 +08:00
|
|
|
default = [idx for idx, model_label in enumerate(model) if
|
|
|
|
model_label[2] == label][0]
|
2014-01-28 05:58:45 +08:00
|
|
|
|
2015-09-25 04:32:04 +08:00
|
|
|
_add_manual_bridge_row()
|
2015-11-03 03:41:18 +08:00
|
|
|
return default
|
2014-01-28 05:58:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
###############
|
|
|
|
# Public APIs #
|
|
|
|
###############
|
|
|
|
|
|
|
|
def get_network_row(self):
|
2015-05-20 05:17:53 +08:00
|
|
|
return uiutil.get_list_selected_row(self.widget("net-source"))
|
2014-01-28 05:58:45 +08:00
|
|
|
|
|
|
|
def get_network_selection(self):
|
|
|
|
bridge_entry = self.widget("net-bridge-name")
|
2014-04-03 22:53:54 +08:00
|
|
|
row = self.get_network_row()
|
2014-01-28 05:58:45 +08:00
|
|
|
if not row:
|
2014-06-01 03:51:24 +08:00
|
|
|
return None, None, None, None
|
2014-01-28 05:58:45 +08:00
|
|
|
|
|
|
|
net_type = row[0]
|
|
|
|
net_src = row[1]
|
|
|
|
net_check_bridge = row[5]
|
|
|
|
|
|
|
|
if net_check_bridge and bridge_entry:
|
|
|
|
net_type = virtinst.VirtualNetworkInterface.TYPE_BRIDGE
|
2017-10-19 16:56:42 +08:00
|
|
|
net_src = bridge_entry.get_text() or None
|
2014-01-28 05:58:45 +08:00
|
|
|
|
|
|
|
mode = None
|
|
|
|
if self.widget("net-source-mode").is_visible():
|
2015-05-20 05:54:53 +08:00
|
|
|
mode = uiutil.get_list_selection(self.widget("net-source-mode"))
|
2014-01-28 05:58:45 +08:00
|
|
|
|
2014-06-01 03:51:24 +08:00
|
|
|
portgroup = None
|
|
|
|
if self.widget("net-portgroup").is_visible():
|
2015-05-20 05:54:53 +08:00
|
|
|
portgroup = uiutil.get_list_selection(self.widget("net-portgroup"))
|
2014-06-01 03:51:24 +08:00
|
|
|
|
2015-04-07 04:41:02 +08:00
|
|
|
return net_type, net_src, mode, portgroup or None
|
2014-01-28 05:58:45 +08:00
|
|
|
|
|
|
|
def get_vport(self):
|
|
|
|
vport_type = self.widget("vport-type").get_text()
|
|
|
|
vport_managerid = self.widget("vport-managerid").get_text()
|
|
|
|
vport_typeid = self.widget("vport-typeid").get_text()
|
|
|
|
vport_idver = self.widget("vport-typeidversion").get_text()
|
|
|
|
vport_instid = self.widget("vport-instanceid").get_text()
|
|
|
|
|
|
|
|
return (vport_type, vport_managerid, vport_typeid,
|
|
|
|
vport_idver, vport_instid)
|
|
|
|
|
|
|
|
def validate_network(self, macaddr, model=None):
|
2014-06-01 03:51:24 +08:00
|
|
|
nettype, devname, mode, portgroup = self.get_network_selection()
|
2014-01-28 05:58:45 +08:00
|
|
|
if nettype is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
net = None
|
|
|
|
|
|
|
|
# Make sure VirtualNetwork is running
|
|
|
|
netobj = None
|
|
|
|
if nettype == virtinst.VirtualNetworkInterface.TYPE_VIRTUAL:
|
2014-06-03 05:17:47 +08:00
|
|
|
for net in self.conn.list_nets():
|
2014-01-28 05:58:45 +08:00
|
|
|
if net.get_name() == devname:
|
|
|
|
netobj = net
|
|
|
|
break
|
|
|
|
|
|
|
|
if netobj and not netobj.is_active():
|
|
|
|
res = self.err.yes_no(_("Virtual Network is not active."),
|
|
|
|
_("Virtual Network '%s' is not active. "
|
|
|
|
"Would you like to start the network "
|
|
|
|
"now?") % devname)
|
|
|
|
if not res:
|
|
|
|
return False
|
|
|
|
|
|
|
|
# Try to start the network
|
|
|
|
try:
|
|
|
|
netobj.start()
|
|
|
|
logging.info("Started network '%s'", devname)
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2014-01-28 05:58:45 +08:00
|
|
|
return self.err.show_err(_("Could not start virtual network "
|
|
|
|
"'%s': %s") % (devname, str(e)))
|
|
|
|
|
|
|
|
# Create network device
|
|
|
|
try:
|
|
|
|
net = virtinst.VirtualNetworkInterface(self.conn.get_backend())
|
|
|
|
net.type = nettype
|
|
|
|
net.source = devname
|
|
|
|
net.macaddr = macaddr
|
|
|
|
net.model = model
|
|
|
|
net.source_mode = mode
|
2014-06-01 03:51:24 +08:00
|
|
|
net.portgroup = portgroup
|
2014-01-28 05:58:45 +08:00
|
|
|
if net.model == "spapr-vlan":
|
|
|
|
net.address.set_addrstr("spapr-vio")
|
|
|
|
|
|
|
|
if net.type == "direct":
|
|
|
|
(vport_type, vport_managerid, vport_typeid,
|
|
|
|
vport_idver, vport_instid) = self.get_vport()
|
|
|
|
|
|
|
|
net.virtualport.type = vport_type or None
|
|
|
|
net.virtualport.managerid = vport_managerid or None
|
|
|
|
net.virtualport.typeid = vport_typeid or None
|
|
|
|
net.virtualport.typeidversion = vport_idver or None
|
|
|
|
net.virtualport.instanceid = vport_instid or None
|
2017-05-06 00:47:21 +08:00
|
|
|
except Exception as e:
|
2014-01-28 05:58:45 +08:00
|
|
|
return self.err.val_err(_("Error with network parameters."), e)
|
|
|
|
|
|
|
|
# Make sure there is no mac address collision
|
|
|
|
isfatal, errmsg = net.is_conflict_net(net.conn, net.macaddr)
|
|
|
|
if isfatal:
|
|
|
|
return self.err.val_err(_("Mac address collision."), errmsg)
|
|
|
|
elif errmsg is not None:
|
|
|
|
retv = self.err.yes_no(_("Mac address collision."),
|
|
|
|
_("%s Are you sure you want to use this address?") % errmsg)
|
|
|
|
if not retv:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return net
|
|
|
|
|
|
|
|
def reset_state(self):
|
2015-11-03 03:41:18 +08:00
|
|
|
self._repopulate_network_list()
|
2014-01-28 05:58:45 +08:00
|
|
|
|
2014-06-18 05:04:49 +08:00
|
|
|
net_err = None
|
|
|
|
if (not self.conn.is_nodedev_capable() or
|
|
|
|
not self.conn.is_interface_capable()):
|
|
|
|
net_err = _("Libvirt version does not support "
|
|
|
|
"physical interface listing.")
|
|
|
|
|
2014-01-28 05:58:45 +08:00
|
|
|
net_warn = self.widget("net-source-warn")
|
|
|
|
net_warn.set_visible(bool(net_err))
|
|
|
|
net_warn.set_tooltip_text(net_err or "")
|
|
|
|
|
|
|
|
self.widget("net-bridge-name").set_text("")
|
|
|
|
self.widget("net-source-mode").set_active(0)
|
2014-06-01 03:51:24 +08:00
|
|
|
self.widget("net-portgroup").get_child().set_text("")
|
2014-01-28 05:58:45 +08:00
|
|
|
|
|
|
|
self.widget("vport-type").set_text("")
|
|
|
|
self.widget("vport-managerid").set_text("")
|
|
|
|
self.widget("vport-typeid").set_text("")
|
|
|
|
self.widget("vport-typeidversion").set_text("")
|
|
|
|
self.widget("vport-instanceid").set_text("")
|
|
|
|
|
|
|
|
def set_dev(self, net):
|
|
|
|
self.reset_state()
|
|
|
|
|
|
|
|
nettype = net.type
|
|
|
|
source = net.source
|
|
|
|
source_mode = net.source_mode
|
|
|
|
is_direct = (net.type == "direct")
|
|
|
|
|
2015-05-20 06:22:49 +08:00
|
|
|
uiutil.set_list_selection(self.widget("net-source-mode"), source_mode)
|
2014-01-28 05:58:45 +08:00
|
|
|
|
|
|
|
# Virtualport config
|
|
|
|
self.widget("vport-expander").set_visible(is_direct)
|
|
|
|
|
|
|
|
vport = net.virtualport
|
|
|
|
self.widget("vport-type").set_text(vport.type or "")
|
|
|
|
self.widget("vport-managerid").set_text(str(vport.managerid or ""))
|
|
|
|
self.widget("vport-typeid").set_text(str(vport.typeid or ""))
|
|
|
|
self.widget("vport-typeidversion").set_text(
|
|
|
|
str(vport.typeidversion or ""))
|
|
|
|
self.widget("vport-instanceid").set_text(vport.instanceid or "")
|
|
|
|
|
|
|
|
# Find the matching row in the net list
|
|
|
|
combo = self.widget("net-source")
|
|
|
|
rowiter = None
|
|
|
|
for row in combo.get_model():
|
|
|
|
if row[0] == nettype and row[1] == source:
|
|
|
|
rowiter = row.iter
|
|
|
|
break
|
|
|
|
if not rowiter:
|
|
|
|
if nettype == "bridge":
|
|
|
|
rowiter = combo.get_model()[-1].iter
|
|
|
|
self.widget("net-bridge-name").set_text(source)
|
|
|
|
if not rowiter:
|
|
|
|
desc = self._pretty_network_desc(nettype, source)
|
|
|
|
combo.get_model().insert(0,
|
|
|
|
self._build_source_row(nettype, source, desc, True, True))
|
|
|
|
rowiter = combo.get_model()[0].iter
|
|
|
|
|
|
|
|
combo.set_active_iter(rowiter)
|
|
|
|
combo.emit("changed")
|
|
|
|
|
2014-06-01 03:51:24 +08:00
|
|
|
if net.portgroup:
|
2015-05-20 06:22:49 +08:00
|
|
|
uiutil.set_list_selection(self.widget("net-portgroup"), net.portgroup)
|
2014-06-01 03:51:24 +08:00
|
|
|
|
2014-01-28 05:58:45 +08:00
|
|
|
|
|
|
|
#############
|
|
|
|
# Listeners #
|
|
|
|
#############
|
|
|
|
|
|
|
|
def _emit_changed(self, *args, **kwargs):
|
2016-04-19 04:42:12 +08:00
|
|
|
ignore1 = args
|
|
|
|
ignore2 = kwargs
|
2014-01-28 05:58:45 +08:00
|
|
|
self.emit("changed")
|
|
|
|
|
|
|
|
def _emit_vport_changed(self, *args, **kwargs):
|
2016-04-19 04:42:12 +08:00
|
|
|
ignore1 = args
|
|
|
|
ignore2 = kwargs
|
2014-01-28 05:58:45 +08:00
|
|
|
self.emit("changed-vport")
|
|
|
|
|
2014-01-29 03:40:17 +08:00
|
|
|
def _repopulate_network_list(self, *args, **kwargs):
|
2016-04-19 04:42:12 +08:00
|
|
|
ignore1 = args
|
|
|
|
ignore2 = kwargs
|
2014-01-29 03:40:17 +08:00
|
|
|
|
|
|
|
netlist = self.widget("net-source")
|
2015-11-03 03:41:18 +08:00
|
|
|
current_label = uiutil.get_list_selection(netlist, column=2)
|
|
|
|
|
|
|
|
model = netlist.get_model()
|
|
|
|
try:
|
|
|
|
netlist.set_model(None)
|
|
|
|
default_idx = self._populate_network_model(model)
|
|
|
|
finally:
|
|
|
|
netlist.set_model(model)
|
2014-01-29 03:40:17 +08:00
|
|
|
|
|
|
|
for row in netlist.get_model():
|
2015-11-03 03:41:18 +08:00
|
|
|
if current_label and row[2] == current_label:
|
2014-01-29 03:40:17 +08:00
|
|
|
netlist.set_active_iter(row.iter)
|
|
|
|
return
|
|
|
|
|
2015-11-03 03:41:18 +08:00
|
|
|
if default_idx is None:
|
|
|
|
default_idx = 0
|
|
|
|
netlist.set_active(default_idx)
|
|
|
|
|
|
|
|
|
2014-06-01 03:51:24 +08:00
|
|
|
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, p.name])
|
|
|
|
if p.default:
|
|
|
|
default = p.name
|
|
|
|
|
2015-05-20 06:22:49 +08:00
|
|
|
uiutil.set_list_selection(combo, default)
|
2014-06-01 03:51:24 +08:00
|
|
|
|
2014-01-28 05:58:45 +08:00
|
|
|
def _on_net_source_changed(self, src):
|
2014-04-03 22:53:54 +08:00
|
|
|
ignore = src
|
2014-01-28 05:58:45 +08:00
|
|
|
self._emit_changed()
|
2014-04-03 22:53:54 +08:00
|
|
|
row = self.get_network_row()
|
2014-01-28 05:58:45 +08:00
|
|
|
if not row:
|
|
|
|
return
|
|
|
|
|
2017-03-23 23:06:56 +08:00
|
|
|
is_openvswitch = row[2].endswith("(OpenVSwitch)")
|
2014-01-28 05:58:45 +08:00
|
|
|
is_direct = (row[0] == virtinst.VirtualNetworkInterface.TYPE_DIRECT)
|
2017-03-23 23:06:56 +08:00
|
|
|
self.widget("vport-expander").set_visible(is_direct or is_openvswitch)
|
2014-01-28 05:58:45 +08:00
|
|
|
uiutil.set_grid_row_visible(self.widget("net-source-mode"), is_direct)
|
|
|
|
uiutil.set_grid_row_visible(
|
|
|
|
self.widget("net-macvtap-warn-box"), is_direct)
|
|
|
|
if is_direct and self.widget("net-source-mode").get_active() == -1:
|
|
|
|
self.widget("net-source-mode").set_active(0)
|
|
|
|
|
|
|
|
show_bridge = row[5]
|
|
|
|
uiutil.set_grid_row_visible(
|
|
|
|
self.widget("net-bridge-name"), show_bridge)
|
2014-06-01 03:51:24 +08:00
|
|
|
|
|
|
|
portgroups = []
|
2014-06-03 05:17:47 +08:00
|
|
|
connkey = row[6]
|
|
|
|
if connkey and row[0] == virtinst.VirtualNetworkInterface.TYPE_VIRTUAL:
|
|
|
|
portgroups = self.conn.get_net(connkey).get_xmlobj().portgroups
|
2014-06-01 03:51:24 +08:00
|
|
|
|
|
|
|
uiutil.set_grid_row_visible(
|
|
|
|
self.widget("net-portgroup"), bool(portgroups))
|
|
|
|
self._populate_portgroups(portgroups)
|