[virt-tools-list] [PATCH] details: ADD checkbox to plug/unplug network interface
Simon Kobyda
skobyda at redhat.com
Thu Aug 16 15:30:31 UTC 2018
Hardware Details -> NIC of every VM should now contain checkbox for
interface's link state. This checkbox edits domain's XML by changing
<link state='up/down'/>. If XML doesn't contain this tag, virt manager
assumes state "up".
https://bugzilla.redhat.com/show_bug.cgi?id=1614532
Signed-off-by: Simon Kobyda <skobyda at redhat.com>
---
ui/details.ui | 25 +++++++++++++++++++++++++
virtManager/details.py | 12 +++++++++++-
virtManager/domain.py | 5 ++++-
3 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/ui/details.ui b/ui/details.ui
index 88379b0e..9df12a7f 100644
--- a/ui/details.ui
+++ b/ui/details.ui
@@ -4014,6 +4014,31 @@
<property name="top_attach">2</property>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="network_link_state_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Link state</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="network_link_state_checkbox">
+ <property name="label" translatable="yes">active</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="on_network_link_state_checkbox_toggled" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">3</property>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/virtManager/details.py b/virtManager/details.py
index e9ca5bda..1797c4e8 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -69,6 +69,7 @@ from .graphwidgets import Sparkline
EDIT_NET_VPORT,
EDIT_NET_SOURCE,
EDIT_NET_MAC,
+ EDIT_NET_LINKSTATE,
EDIT_GFX_PASSWD,
EDIT_GFX_TYPE,
@@ -93,7 +94,7 @@ from .graphwidgets import Sparkline
EDIT_FS,
- EDIT_HOSTDEV_ROMBAR) = range(1, 50)
+ EDIT_HOSTDEV_ROMBAR) = range(1, 51)
# Columns in hw list model
@@ -545,6 +546,9 @@ class vmmDetails(vmmGObjectUI):
"on_network_model_combo_changed": lambda *x: self.enable_apply(x, EDIT_NET_MODEL),
"on_network_mac_entry_changed": lambda *x: self.enable_apply(x,
EDIT_NET_MAC),
+ "on_network_link_state_checkbox_toggled": lambda *x: self.enable_apply(x,
+ EDIT_NET_LINKSTATE),
+
"on_sound_model_combo_changed": lambda *x: self.enable_apply(x,
EDIT_SOUND_MODEL),
@@ -2178,6 +2182,9 @@ class vmmDetails(vmmGObjectUI):
if self.edited(EDIT_NET_MAC):
kwargs["macaddr"] = self.widget("network-mac-entry").get_text()
+ if self.edited(EDIT_NET_LINKSTATE):
+ kwargs["linkstate"] = self.widget("network_link_state_checkbox").get_active()
+
return vmmAddHardware.change_config_helper(self.vm.define_network,
kwargs, self.vm, self.err,
devobj=devobj)
@@ -2717,6 +2724,9 @@ class vmmDetails(vmmGObjectUI):
else:
self.widget("network-mac-entry").set_text(macaddr)
+ state = net.link_state == "up" or net.link_state is None
+ self.widget("network_link_state_checkbox").set_active(state)
+
self.netlist.set_dev(net)
def refresh_input_page(self):
diff --git a/virtManager/domain.py b/virtManager/domain.py
index a3166f0d..5af6ee01 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -757,7 +757,7 @@ class vmmDomain(vmmLibvirtObject):
mode=_SENTINEL, model=_SENTINEL, addrstr=_SENTINEL,
vtype=_SENTINEL, managerid=_SENTINEL, typeid=_SENTINEL,
typeidversion=_SENTINEL, instanceid=_SENTINEL,
- portgroup=_SENTINEL, macaddr=_SENTINEL):
+ portgroup=_SENTINEL, macaddr=_SENTINEL, linkstate=_SENTINEL):
xmlobj = self._make_xmlobj_to_define()
editdev = self._lookup_device_to_define(xmlobj, devobj, do_hotplug)
if not editdev:
@@ -787,6 +787,9 @@ class vmmDomain(vmmLibvirtObject):
if macaddr != _SENTINEL:
editdev.macaddr = macaddr
+ if linkstate != _SENTINEL:
+ editdev.link_state = "up" if linkstate else "down"
+
if do_hotplug:
self.hotplug(device=editdev)
else:
--
2.17.1
More information about the virt-tools-list
mailing list