[virt-tools-list] [PATCH v2 2/4] virt-manager: Add vsock sockets details UI

Slavomir Kaslev kaslevs at vmware.com
Tue Dec 11 14:46:34 UTC 2018


Add vsock details UI which will be shared between Hardware Details and Add
Hardware UIs.

Signed-off-by: Slavomir Kaslev <kaslevs at vmware.com>
---
 ui/vsockdetails.ui          | 90 +++++++++++++++++++++++++++++++++++++
 virtManager/vsockdetails.py | 76 +++++++++++++++++++++++++++++++
 2 files changed, 166 insertions(+)
 create mode 100644 ui/vsockdetails.ui
 create mode 100644 virtManager/vsockdetails.py

diff --git a/ui/vsockdetails.ui b/ui/vsockdetails.ui
new file mode 100644
index 00000000..7f607b2b
--- /dev/null
+++ b/ui/vsockdetails.ui
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface>
+  <requires lib="gtk+" version="3.14"/>
+  <object class="GtkAdjustment" id="adjustment5">
+    <property name="lower">3</property>
+    <property name="upper">4294967295</property>
+    <property name="value">3</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+  <object class="GtkGrid" id="vsock-box">
+    <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="label4">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">end</property>
+        <property name="label" translatable="yes">Guest C_ID:</property>
+        <property name="use_underline">True</property>
+        <property name="mnemonic_widget">vsock-cid</property>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkBox" id="vox-cid-box">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkCheckButton" id="vsock-auto">
+            <property name="label" translatable="yes">A_uto</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">False</property>
+            <property name="halign">start</property>
+            <property name="use_underline">True</property>
+            <property name="draw_indicator">True</property>
+            <signal name="toggled" handler="on_vsock_auto_toggled" swapped="no"/>
+            <child internal-child="accessible">
+              <object class="AtkObject" id="vsock-auto-atkobject">
+                <property name="AtkObject::accessible-name">vsock-auto</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</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="invisible_char">●</property>
+            <property name="text" translatable="yes">5900</property>
+            <property name="adjustment">adjustment5</property>
+            <property name="climb_rate">1</property>
+            <property name="snap_to_ticks">True</property>
+            <property name="numeric">True</property>
+            <property name="update_policy">if-valid</property>
+            <property name="value">5900</property>
+            <signal name="value-changed" handler="on_vsock_cid_changed" swapped="no"/>
+            <child internal-child="accessible">
+              <object class="AtkObject" id="vsock-cid-atkobject">
+                <property name="AtkObject::accessible-name">vsock-cid</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="top_attach">0</property>
+      </packing>
+    </child>
+  </object>
+</interface>
diff --git a/virtManager/vsockdetails.py b/virtManager/vsockdetails.py
new file mode 100644
index 00000000..58b4de89
--- /dev/null
+++ b/virtManager/vsockdetails.py
@@ -0,0 +1,76 @@
+# Copyright (C) 2018 VMware, Inc.
+#
+# Copyright 2018
+# Slavomir Kaslev <kaslevs at vmware.com>
+#
+# This work is licensed under the GNU GPLv2 or later.
+# See the COPYING file in the top-level directory.
+
+from virtinst import DeviceVsock
+
+from . import uiutil
+from .baseclass import vmmGObjectUI
+
+
+class vmmVsockDetails(vmmGObjectUI):
+    __gsignals__ = {
+        "changed-auto-cid": (vmmGObjectUI.RUN_FIRST, None, []),
+        "changed-cid": (vmmGObjectUI.RUN_FIRST, None, []),
+    }
+
+    def __init__(self, vm, builder, topwin):
+        super().__init__("vsockdetails.ui", None,
+                         builder=builder, topwin=topwin)
+        self.vm = vm
+        self.conn = vm.conn
+
+        self.builder.connect_signals({
+            "on_vsock_auto_toggled": self._vsock_auto_toggled,
+            "on_vsock_cid_changed": lambda ignore: self.emit("changed-cid"),
+        })
+
+        self.top_box = self.widget("vsock-box")
+
+    def _cleanup(self):
+        self.vm = None
+        self.conn = None
+
+
+    ##############
+    # Public API #
+    ##############
+
+    def reset_state(self):
+        self.widget("vsock-auto").set_active(True)
+        self.widget("vsock-cid").set_value(DeviceVsock.MIN_GUEST_CID)
+        self.widget("vsock-cid").set_visible(False)
+
+    def get_values(self):
+        auto_cid = self.widget("vsock-auto").get_active()
+        if auto_cid:
+            return auto_cid, None
+
+        return auto_cid, uiutil.spin_get_helper(self.widget("vsock-cid"))
+
+    def set_dev(self, dev):
+        self.reset_state()
+
+        is_auto = bool(dev.auto_cid)
+        if dev.cid is not None:
+            cid = int(dev.cid)
+        else:
+            cid = DeviceVsock.MIN_GUEST_CID
+
+        self.widget("vsock-auto").set_active(is_auto)
+        self.widget("vsock-cid").set_value(cid)
+        self.widget("vsock-cid").set_visible(not is_auto)
+
+
+    #############
+    # Listeners #
+    #############
+
+    def _vsock_auto_toggled(self, ignore):
+        is_auto = self.widget("vsock-auto").get_active()
+        self.widget("vsock-cid").set_visible(not is_auto)
+        self.emit("changed-auto-cid")
-- 
2.19.1




More information about the virt-tools-list mailing list