details: Allow easily changing network source

Use the same drop down for network source we use in add hardware and
create VM wizard. Allows easily trying different virtual networks or bridges.
This commit is contained in:
Cole Robinson 2011-03-17 16:33:40 -04:00
parent 035d5a2eec
commit a9617507e3
4 changed files with 150 additions and 31 deletions

View File

@ -373,6 +373,8 @@ class vmmDetails(vmmGObjectUI):
"on_disk_bus_combo_changed": self.config_enable_apply,
"on_disk_format_changed": self.config_enable_apply,
"on_network_source_combo_changed": self.config_enable_apply,
"on_network_bridge_changed": self.config_enable_apply,
"on_network_model_combo_changed": self.config_enable_apply,
"on_vport_type_changed": self.config_enable_apply,
@ -722,6 +724,11 @@ class vmmDetails(vmmGObjectUI):
disk_bus = self.window.get_widget("disk-bus-combo")
uihelpers.build_disk_bus_combo(self.vm, disk_bus)
# 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)
# Network model
net_model = self.window.get_widget("network-model-combo")
uihelpers.build_netmodel_combo(self.vm, net_model)
@ -764,19 +771,29 @@ class vmmDetails(vmmGObjectUI):
# Helper function to handle the combo/label pattern used for
# video model, sound model, network model, etc.
def set_combo_label(self, prefix, value, model_idx=0, label=""):
def set_combo_label(self, prefix, value, model_idx=0, label="",
comparefunc=None):
label = label or value
model_label = self.window.get_widget(prefix + "-label")
model_combo = self.window.get_widget(prefix + "-combo")
model_list = map(lambda x: x[model_idx], model_combo.get_model())
model_in_list = (value in model_list)
idx = -1
if comparefunc:
model_in_list, idx = comparefunc(model_combo.get_model(), value)
else:
model_list = map(lambda x: x[model_idx], model_combo.get_model())
model_in_list = (value in model_list)
if model_in_list:
idx = model_list.index(value)
model_label.set_property("visible", not model_in_list)
model_combo.set_property("visible", model_in_list)
model_label.set_text(label or "")
if model_in_list:
model_combo.set_active(model_list.index(value))
model_combo.set_active(idx)
else:
model_combo.set_active(-1)
# Helper for accessing value of combo/label pattern
def get_combo_value(self, widgetname, model_idx=0):
@ -1733,21 +1750,28 @@ class vmmDetails(vmmGObjectUI):
# Network options
def config_network_apply(self, dev_id_info):
net_list = self.window.get_widget("network-source-combo")
net_bridge = self.window.get_widget("network-bridge")
nettype, source = uihelpers.get_network_selection(net_list, net_bridge)
model = self.get_combo_label_value("network-model")
vport_type = self.window.get_widget("vport-type").get_text()
vport_managerid = self.window.get_widget("vport-managerid").get_text()
vport_typeid = self.window.get_widget("vport-typeid").get_text()
vport_typeidversion = self.window.get_widget("vport-typeidversion").get_text()
vport_instanceid = self.window.get_widget("vport-instanceid").get_text()
vport_idver = self.window.get_widget("vport-typeidversion").get_text()
vport_instid = self.window.get_widget("vport-instanceid").get_text()
return self._change_config_helper([self.vm.define_network_model,
self.vm.define_virtualport],
self.vm.define_virtualport,
self.vm.define_network_source],
[(dev_id_info, model),
(dev_id_info, vport_type,
vport_managerid,
vport_typeid,
vport_typeidversion,
vport_instanceid)])
vport_idver,
vport_instid),
(dev_id_info, nettype, source)])
# Graphics options
def config_graphics_apply(self, dev_id_info):
@ -2221,7 +2245,28 @@ class vmmDetails(vmmGObjectUI):
desc = uihelpers.pretty_network_desc(nettype, source, netobj)
self.window.get_widget("network-mac-address").set_text(net.macaddr)
self.window.get_widget("network-source-device").set_text(desc)
uihelpers.populate_network_list(
self.window.get_widget("network-source-combo"),
self.conn)
self.window.get_widget("network-source-combo").set_active(-1)
self.window.get_widget("network-bridge").set_text("")
def compare_network(model, info):
for idx in range(len(model)):
row = model[idx]
if row[0] == info[0] and row[1] == info[1]:
return True, idx
if info[0] == virtinst.VirtualNetworkInterface.TYPE_BRIDGE:
idx = (len(model) - 1)
self.window.get_widget("network-bridge").set_text(str(info[1]))
return True, idx
return False, 0
self.set_combo_label("network-source",
(nettype, source), label=desc,
comparefunc=compare_network)
# Virtualport config
show_vport = (nettype == "direct")

View File

@ -399,6 +399,14 @@ class vmmDomainBase(vmmLibvirtObject):
editdev.bus = newval
return self._redefine_device(change, devobj)
def define_network_source(self, devobj, newtype, newsource):
def change(editdev):
if not newtype:
return
editdev.source = None
editdev.type = newtype
editdev.source = newsource
return self._redefine_device(change, devobj)
def define_network_model(self, devobj, newmodel):
def change(editdev):
editdev.model = newmodel

View File

@ -332,24 +332,31 @@ def net_list_changed(net_list, bridge_box):
if active < 0:
return
if not bridge_box:
return
row = net_list.get_model()[active]
show_bridge = row[5]
bridge_box.set_property("visible", show_bridge)
def get_network_selection(net_list, bridge_entry):
idx = net_list.get_active()
if idx == -1:
return None, None
row = net_list.get_model()[net_list.get_active()]
net_type = row[0]
net_src = row[1]
net_check_bridge = row[5]
if net_check_bridge:
if net_check_bridge and bridge_entry:
net_type = VirtualNetworkInterface.TYPE_BRIDGE
net_src = bridge_entry.get_text()
return net_type, net_src
def populate_network_list(net_list, conn):
def populate_network_list(net_list, conn, show_manual_bridge=True):
model = net_list.get_model()
model.clear()
@ -477,10 +484,11 @@ def populate_network_list(net_list, conn):
model.insert(0, row)
default = 0
# After all is said and done, add a manual bridge option
manual_row = build_row(None, None, _("Specify shared device name"),
True, False, manual_bridge=True)
model.append(manual_row)
if show_manual_bridge:
# After all is said and done, add a manual bridge option
manual_row = build_row(None, None, _("Specify shared device name"),
True, False, manual_bridge=True)
model.append(manual_row)
set_active(default)
return return_warn

View File

@ -3642,25 +3642,12 @@ I/O:</property>
<widget class="GtkLabel" id="label397">
<property name="visible">True</property>
<property name="xalign">1</property>
<property name="yalign">0</property>
<property name="label" translatable="yes">Source device:</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="network-source-device">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label">label401</property>
<property name="selectable">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
@ -3741,6 +3728,77 @@ I/O:</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="network-source-box">
<property name="visible">True</property>
<child>
<widget class="GtkHBox" id="hbox19">
<property name="visible">True</property>
<child>
<widget class="GtkComboBox" id="network-source-combo">
<property name="visible">True</property>
<signal name="changed" handler="on_network_source_combo_changed"/>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="network-source-label">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label">label401</property>
<property name="selectable">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="network-bridge-box">
<property name="visible">True</property>
<property name="spacing">6</property>
<child>
<widget class="GtkLabel" id="label34">
<property name="visible">True</property>
<property name="label" translatable="yes">_Bridge name:</property>
<property name="use_underline">True</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="network-bridge">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<signal name="changed" handler="on_network_bridge_changed"/>
</widget>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
</widget>
</child>
</widget>