[virt-tools-list] [PATCH 2/3] virt-manager: Add support for vsock device to hardware details UI

Slavomir Kaslev kaslevs at vmware.com
Fri Dec 7 15:02:15 UTC 2018


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

diff --git a/ui/details.ui b/ui/details.ui
index c18070c8..ba9970d8 100644
--- a/ui/details.ui
+++ b/ui/details.ui
@@ -76,6 +76,12 @@
     <property name="step_increment">1</property>
     <property name="page_increment">2</property>
   </object>
+  <object class="GtkAdjustment" id="adjustment8">
+    <property name="lower">3</property>
+    <property name="upper">2147483647</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
   <object class="GtkImage" id="image70">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -5856,6 +5862,119 @@
                             <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="alignment7">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="top_padding">3</property>
+                                <property name="left_padding">12</property>
+                                <child>
+                                  <object class="GtkGrid" id="table61">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="row_spacing">6</property>
+                                    <property name="column_spacing">6</property>
+                                    <child>
+                                      <object class="GtkLabel" id="label70">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="label" translatable="yes">Guest CID:</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">0</property>
+                                        <property name="top_attach">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkBox">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <child>
+                                          <object class="GtkCheckButton" id="vsock-auto">
+                                            <property name="label" translatable="yes">Auto</property>
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="receives_default">False</property>
+                                            <property name="margin_top">3</property>
+                                            <property name="margin_bottom">3</property>
+                                            <property name="active">True</property>
+                                            <property name="draw_indicator">True</property>
+                                            <signal name="toggled" handler="on_vsock_auto_toggled" swapped="no"/>
+                                          </object>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">True</property>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkSpinButton" id="vsock-cid">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="text" translatable="yes">3</property>
+                                            <property name="input_purpose">number</property>
+                                            <property name="adjustment">adjustment8</property>
+                                            <property name="climb_rate">1</property>
+                                            <property name="numeric">True</property>
+                                            <property name="value">3</property>
+                                            <signal name="value-changed" handler="on_vsock_cid_changed" swapped="no"/>
+                                          </object>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">True</property>
+                                            <property name="padding">12</property>
+                                            <property name="pack_type">end</property>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <placeholder/>
+                                        </child>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="top_attach">0</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                </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">controller-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..7608d70a 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -99,9 +99,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 +136,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 +145,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 +268,7 @@ def _label_for_device(dev):
     devmap = {
         "panic": _("Panic Notifier"),
         "smartcard": _("Smartcard"),
+        "vsock": _("VM Sockets"),
         "watchdog": _("Watchdog"),
     }
     return devmap[devtype]
@@ -312,6 +317,7 @@ def _icon_for_device(dev):
         "filesystem": "folder",
         "controller": "device_pci",
         "panic": "system-run",
+        "vsock": "network-idle",
     }
     return typemap[devtype]
 
@@ -584,6 +590,10 @@ class vmmDetails(vmmGObjectUI):
             "on_smartcard_mode_combo_changed": lambda *x: self.enable_apply(x,
                                                 EDIT_SMARTCARD_MODE),
 
+            "on_vsock_auto_toggled": self.vsock_auto_toggled,
+            "on_vsock_cid_changed": lambda *x: self.enable_apply(x,
+                                     EDIT_VSOCK_CID),
+
             "on_hostdev_rombar_toggled": lambda *x: self.enable_apply(
                 x, EDIT_HOSTDEV_ROMBAR),
             "on_controller_model_combo_changed": (lambda *x:
@@ -1259,6 +1269,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:
@@ -1768,6 +1780,11 @@ class vmmDetails(vmmGObjectUI):
         self.widget("video-3d").set_inconsistent(False)
         self.enable_apply(EDIT_VIDEO_3D)
 
+    def vsock_auto_toggled(self, ignore):
+        is_auto = self.widget("vsock-auto").get_active()
+        self.widget("vsock-cid").set_visible(not is_auto)
+        self.enable_apply(EDIT_VSOCK_AUTO)
+
     # Boot device / Autostart
     def config_bootdev_selected(self, ignore=None):
         boot_row = self.get_boot_selection()
@@ -1916,6 +1933,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 +2343,18 @@ class vmmDetails(vmmGObjectUI):
                                           kwargs, self.vm, self.err,
                                           devobj=devobj)
 
+    def config_vsock_apply(self, devobj):
+        kwargs = {}
+
+        if self.edited(EDIT_VSOCK_AUTO):
+            kwargs["auto_cid"] = self.widget("vsock-auto").get_active()
+        if self.edited(EDIT_VSOCK_CID):
+            kwargs["cid"] = self.widget("vsock-cid").get_value_as_int()
+
+        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,13 @@ 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):
+        is_auto = bool(dev.auto_cid)
+        cid = dev.cid
+        self.widget("vsock-auto").set_active(is_auto)
+        self.widget("vsock-cid").set_value(int(cid) if cid is not None else 3)
+        self.widget("vsock-cid").set_visible(not is_auto)
+
     def refresh_char_page(self, chardev):
         show_target_type = not (chardev.DEVICE_TYPE in
                                 ["serial", "parallel"])
@@ -3201,6 +3239,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