[virt-tools-list] [PATCH v3 3/4] virt-manager: Add support for vsock device to Hardware Details UI

Slavomir Kaslev kaslevs at vmware.com
Fri Dec 14 14:34:19 UTC 2018


Add support for vsock devices to Hardware Details UI so that vsock devices can
be configured or removed.

Signed-off-by: Slavomir Kaslev <kaslevs at vmware.com>
---
 ui/details.ui          | 46 ++++++++++++++++++++++++++++++++++++++++++
 virtManager/details.py | 42 +++++++++++++++++++++++++++++++++++---
 virtManager/domain.py  | 17 ++++++++++++++++
 3 files changed, 102 insertions(+), 3 deletions(-)

diff --git a/ui/details.ui b/ui/details.ui
index c18070c8..069db47b 100644
--- a/ui/details.ui
+++ b/ui/details.ui
@@ -5856,6 +5856,52 @@
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkFrame" id="frame25">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label_xalign">0</property>
+                            <property name="shadow_type">none</property>
+                            <child>
+                              <object class="GtkAlignment" id="vsock-align">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="top_padding">3</property>
+                                <property name="left_padding">12</property>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                              </object>
+                            </child>
+                            <child type="label">
+                              <object class="GtkLabel" id="label67">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="label" translatable="yes"><b>VM Sockets</b></property>
+                                <property name="use_markup">True</property>
+                              </object>
+                            </child>
+                            <child internal-child="accessible">
+                              <object class="AtkObject" id="frame25-atkobject">
+                                <property name="AtkObject::accessible-name">vsock-tab</property>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">22</property>
+                          </packing>
+                        </child>
+                        <child type="tab">
+                          <object class="GtkLabel" id="label95">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label" translatable="yes">vsock</property>
+                          </object>
+                          <packing>
+                            <property name="position">22</property>
+                            <property name="tab_fill">False</property>
+                          </packing>
+                        </child>
                       </object>
                       <packing>
                         <property name="expand">True</property>
diff --git a/virtManager/details.py b/virtManager/details.py
index b7e7fc14..782d547c 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -29,6 +29,7 @@ from .netlist import vmmNetworkList
 from .oslist import vmmOSList
 from .snapshots import vmmSnapshotPage
 from .storagebrowse import vmmStorageBrowser
+from .vsockdetails import vmmVsockDetails
 
 
 # Parameters that can be edited in the details window
@@ -99,9 +100,12 @@ from .storagebrowse import vmmStorageBrowser
  EDIT_TPM_TYPE,
  EDIT_TPM_MODEL,
 
+ EDIT_VSOCK_AUTO,
+ EDIT_VSOCK_CID,
+
  EDIT_FS,
 
- EDIT_HOSTDEV_ROMBAR) = range(1, 56)
+ EDIT_HOSTDEV_ROMBAR) = range(1, 58)
 
 
 # Columns in hw list model
@@ -133,7 +137,8 @@ from .storagebrowse import vmmStorageBrowser
  HW_LIST_TYPE_REDIRDEV,
  HW_LIST_TYPE_TPM,
  HW_LIST_TYPE_RNG,
- HW_LIST_TYPE_PANIC) = range(22)
+ HW_LIST_TYPE_PANIC,
+ HW_LIST_TYPE_VSOCK) = range(23)
 
 remove_pages = [HW_LIST_TYPE_NIC, HW_LIST_TYPE_INPUT,
                 HW_LIST_TYPE_GRAPHICS, HW_LIST_TYPE_SOUND, HW_LIST_TYPE_CHAR,
@@ -141,7 +146,7 @@ remove_pages = [HW_LIST_TYPE_NIC, HW_LIST_TYPE_INPUT,
                 HW_LIST_TYPE_WATCHDOG, HW_LIST_TYPE_CONTROLLER,
                 HW_LIST_TYPE_FILESYSTEM, HW_LIST_TYPE_SMARTCARD,
                 HW_LIST_TYPE_REDIRDEV, HW_LIST_TYPE_TPM,
-                HW_LIST_TYPE_RNG, HW_LIST_TYPE_PANIC]
+                HW_LIST_TYPE_RNG, HW_LIST_TYPE_PANIC, HW_LIST_TYPE_VSOCK]
 
 # Boot device columns
 (BOOT_KEY,
@@ -264,6 +269,7 @@ def _label_for_device(dev):
     devmap = {
         "panic": _("Panic Notifier"),
         "smartcard": _("Smartcard"),
+        "vsock": _("VM Sockets"),
         "watchdog": _("Watchdog"),
     }
     return devmap[devtype]
@@ -312,6 +318,7 @@ def _icon_for_device(dev):
         "filesystem": "folder",
         "controller": "device_pci",
         "panic": "system-run",
+        "vsock": "network-idle",
     }
     return typemap[devtype]
 
@@ -452,6 +459,13 @@ class vmmDetails(vmmGObjectUI):
         self.netlist.connect("changed-vport",
             lambda x: self.enable_apply(x, EDIT_NET_VPORT))
 
+        self.vsockdetails = vmmVsockDetails(self.vm, self.builder, self.topwin)
+        self.widget("vsock-align").add(self.vsockdetails.top_box)
+        self.vsockdetails.connect("changed-auto-cid",
+            lambda *x: self.enable_apply(x, EDIT_VSOCK_AUTO))
+        self.vsockdetails.connect("changed-cid",
+            lambda *x: self.enable_apply(x, EDIT_VSOCK_CID))
+
         # Set default window size
         w, h = self.vm.get_details_window_size()
         if w <= 0:
@@ -1259,6 +1273,8 @@ class vmmDetails(vmmGObjectUI):
                 self.refresh_rng_page(dev)
             elif pagetype == HW_LIST_TYPE_PANIC:
                 self.refresh_panic_page(dev)
+            elif pagetype == HW_LIST_TYPE_VSOCK:
+                self.refresh_vsock_page(dev)
             else:
                 pagetype = -1
         except Exception as e:
@@ -1916,6 +1932,8 @@ class vmmDetails(vmmGObjectUI):
                 ret = self.config_hostdev_apply(key)
             elif pagetype is HW_LIST_TYPE_TPM:
                 ret = self.config_tpm_apply(key)
+            elif pagetype is HW_LIST_TYPE_VSOCK:
+                ret = self.config_vsock_apply(key)
             else:
                 ret = False
         except Exception as e:
@@ -2324,6 +2342,19 @@ class vmmDetails(vmmGObjectUI):
                                           kwargs, self.vm, self.err,
                                           devobj=devobj)
 
+    def config_vsock_apply(self, devobj):
+        auto_cid, cid = self.vsockdetails.get_values()
+
+        kwargs = {}
+
+        if self.edited(EDIT_VSOCK_AUTO):
+            kwargs["auto_cid"] = auto_cid
+        if self.edited(EDIT_VSOCK_CID):
+            kwargs["cid"] = cid
+
+        return vmmAddHardware.change_config_helper(self.vm.define_vsock,
+                                          kwargs, self.vm, self.err,
+                                          devobj=devobj)
 
     # Device removal
     def remove_device(self, devobj):
@@ -2820,6 +2851,9 @@ class vmmDetails(vmmGObjectUI):
         self.widget("rng-type").set_text(dev.get_pretty_type(dev.type))
         self.widget("rng-device").set_text(dev.device or "")
 
+    def refresh_vsock_page(self, dev):
+        self.vsockdetails.set_dev(dev)
+
     def refresh_char_page(self, chardev):
         show_target_type = not (chardev.DEVICE_TYPE in
                                 ["serial", "parallel"])
@@ -3201,6 +3235,8 @@ class vmmDetails(vmmGObjectUI):
             update_hwlist(HW_LIST_TYPE_RNG, dev)
         for dev in self.vm.xmlobj.devices.panic:
             update_hwlist(HW_LIST_TYPE_PANIC, dev)
+        for dev in self.vm.xmlobj.devices.vsock:
+            update_hwlist(HW_LIST_TYPE_VSOCK, dev)
 
         devs = list(range(len(hw_list_model)))
         devs.reverse()
diff --git a/virtManager/domain.py b/virtManager/domain.py
index 4fcc716e..a06dd0ad 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -49,6 +49,7 @@ def compare_device(origdev, newdev, idx):
         "tpm":           ["type", "xmlindex"],
         "rng":           ["type", "xmlindex"],
         "panic":         ["type", "xmlindex"],
+        "vsock":         ["xmlindex"],
     }
 
     if id(origdev) == id(newdev):
@@ -959,6 +960,22 @@ class vmmDomain(vmmLibvirtObject):
         else:
             self._redefine_xmlobj(xmlobj)
 
+    def define_vsock(self, devobj, do_hotplug,
+            auto_cid=_SENTINEL, cid=_SENTINEL):
+        xmlobj = self._make_xmlobj_to_define()
+        editdev = self._lookup_device_to_define(xmlobj, devobj, do_hotplug)
+        if not editdev:
+            return
+
+        if auto_cid != _SENTINEL:
+            editdev.auto_cid = auto_cid
+        if cid != _SENTINEL:
+            editdev.cid = cid
+
+        if do_hotplug:
+            self.hotplug(device=editdev)
+        else:
+            self._redefine_xmlobj(xmlobj)
 
     ####################
     # Hotplug routines #
-- 
2.19.1




More information about the virt-tools-list mailing list