[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] [PATCH v2 1/2] virtManager: add GUI elements for showing RNG devices



Signed-off-by: Giuseppe Scrivano <gscrivan redhat com>
---
 ui/details.ui          | 271 +++++++++++++++++++++++++++++++++++++++++++++++++
 virtManager/details.py |  50 ++++++++-
 virtManager/domain.py  |   3 +
 3 files changed, 322 insertions(+), 2 deletions(-)

diff --git a/ui/details.ui b/ui/details.ui
index faf3bfb..93d15c3 100644
--- a/ui/details.ui
+++ b/ui/details.ui
@@ -6850,6 +6850,277 @@ I/O:</property>
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkFrame" id="frame21">
+                            <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="alignment28">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="left_padding">12</property>
+                                <child>
+                                  <object class="GtkGrid" id="table16">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="border_width">3</property>
+                                    <property name="row_spacing">4</property>
+                                    <property name="column_spacing">8</property>
+                                    <child>
+                                      <object class="GtkLabel" id="rng-type">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label">rng-type</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="top_attach">0</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="label90">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">1</property>
+                                        <property name="label" translatable="yes">Type:</property>
+                                        <property name="use_underline">True</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">0</property>
+                                        <property name="top_attach">0</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="rng-device">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label">rng-device</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="top_attach">1</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="rng-label1">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">1</property>
+                                        <property name="label" translatable="yes">Device:</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">0</property>
+                                        <property name="top_attach">1</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="rng-host">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label">rng-host</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="top_attach">2</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="rng-label2">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">1</property>
+                                        <property name="label" translatable="yes">Host:</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">0</property>
+                                        <property name="top_attach">2</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="rng-service">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label">rng-service</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="top_attach">3</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="rng-label3">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">1</property>
+                                        <property name="label" translatable="yes">Service:</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">0</property>
+                                        <property name="top_attach">3</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="rng-label4">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">1</property>
+                                        <property name="label" translatable="yes">Backend type:</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">0</property>
+                                        <property name="top_attach">4</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="rng-backend-type">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label">rng-backend-type</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="top_attach">4</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="rng-rate-period">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label">rng-rate-period</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="top_attach">6</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="rng-label6">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">1</property>
+                                        <property name="label" translatable="yes">Rate (period):</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">0</property>
+                                        <property name="top_attach">6</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="rng-label7">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">1</property>
+                                        <property name="label" translatable="yes">Mode:</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">0</property>
+                                        <property name="top_attach">5</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="rng-mode">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label">rng-mode</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="top_attach">5</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="rng-label5">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">1</property>
+                                        <property name="label" translatable="yes">Rate (bytes):</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">0</property>
+                                        <property name="top_attach">7</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkLabel" id="rng-rate-bytes">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="xalign">0</property>
+                                        <property name="label">rng-rate-bytes</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="top_attach">7</property>
+                                        <property name="width">1</property>
+                                        <property name="height">1</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                </child>
+                              </object>
+                            </child>
+                            <child type="label">
+                              <object class="GtkLabel" id="label89">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="label" translatable="yes">&lt;b&gt;Random Number Generator&lt;/b&gt;</property>
+                                <property name="use_markup">True</property>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">19</property>
+                          </packing>
+                        </child>
+                        <child type="tab">
+                          <object class="GtkLabel" id="label81">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label" translatable="yes">rng</property>
+                          </object>
+                          <packing>
+                            <property name="position">19</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 5147c9e..8b811f5 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -122,14 +122,16 @@ EDIT_TPM_TYPE,
  HW_LIST_TYPE_FILESYSTEM,
  HW_LIST_TYPE_SMARTCARD,
  HW_LIST_TYPE_REDIRDEV,
- HW_LIST_TYPE_TPM) = range(19)
+ HW_LIST_TYPE_TPM,
+ HW_LIST_TYPE_RNG) = range(20)
 
 remove_pages = [HW_LIST_TYPE_NIC, HW_LIST_TYPE_INPUT,
                 HW_LIST_TYPE_GRAPHICS, HW_LIST_TYPE_SOUND, HW_LIST_TYPE_CHAR,
                 HW_LIST_TYPE_HOSTDEV, HW_LIST_TYPE_DISK, HW_LIST_TYPE_VIDEO,
                 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_REDIRDEV, HW_LIST_TYPE_TPM,
+                HW_LIST_TYPE_RNG]
 
 # Boot device columns
 (BOOT_DEV_TYPE,
@@ -1245,6 +1247,8 @@ class vmmDetails(vmmGObjectUI):
                 self.refresh_redir_page()
             elif pagetype == HW_LIST_TYPE_TPM:
                 self.refresh_tpm_page()
+            elif pagetype == HW_LIST_TYPE_RNG:
+                self.refresh_rng_page()
             else:
                 pagetype = -1
         except Exception, e:
@@ -3125,6 +3129,43 @@ class vmmDetails(vmmGObjectUI):
         # Device type specific properties, only show if apply to the cur dev
         show_ui("device_path")
 
+    def refresh_rng_page(self):
+        dev = self.get_hw_selection(HW_LIST_COL_DEVICE)
+        values = {
+            "rng-type" : "type",
+            "rng-device" : "device",
+            "rng-host" : "backend_source_host",
+            "rng-service" : "backend_source_service",
+            "rng-mode" : "backend_source_mode",
+            "rng-backend-type" : "backend_type",
+            "rng-rate-bytes" : "rate_bytes",
+            "rng-rate-period" : "rate_period"
+        }
+        rewriter = {
+            "rng-type" : lambda x:
+            virtinst.VirtualRNGDevice.get_pretty_type(x),
+            "rng-backend-type" : lambda x:
+            virtinst.VirtualRNGDevice.get_pretty_backend_type(x),
+            "rng-mode" : lambda x:
+            virtinst.VirtualRNGDevice.get_pretty_mode(x)
+        }
+
+        is_egd = dev.type == virtinst.VirtualRNGDevice.TYPE_EGD
+        uihelpers.set_grid_row_visible(self.widget("rng-device"), not is_egd)
+        uihelpers.set_grid_row_visible(self.widget("rng-host"), is_egd)
+        uihelpers.set_grid_row_visible(self.widget("rng-service"), is_egd)
+        uihelpers.set_grid_row_visible(self.widget("rng-mode"), is_egd)
+        uihelpers.set_grid_row_visible(self.widget("rng-backend-type"), is_egd)
+
+        for k, prop in values.items():
+            val = "-"
+            if dev.supports_property(prop):
+                val = getattr(dev, prop) or "-"
+                r = rewriter.get(k)
+                if r:
+                    val = r(val)
+            self.widget(k).set_text(val)
+
     def refresh_char_page(self):
         chardev = self.get_hw_selection(HW_LIST_COL_DEVICE)
         if not chardev:
@@ -3589,6 +3630,11 @@ class vmmDetails(vmmGObjectUI):
             update_hwlist(HW_LIST_TYPE_TPM, tpm,
                           _("TPM"), "device_cpu")
 
+        # Populate list of RNG devices
+        for rng in self.vm.get_rng_devices():
+            update_hwlist(HW_LIST_TYPE_RNG, rng,
+                          _("RNG"), "system-run")
+
         devs = range(len(hw_list_model))
         devs.reverse()
         for i in devs:
diff --git a/virtManager/domain.py b/virtManager/domain.py
index cf20d36..1aa763e 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -55,6 +55,7 @@ def compare_device(origdev, newdev, idx):
         "smartcard" : ["mode" , "vmmindex"],
         "redirdev" : ["bus" , "type", "vmmindex"],
         "tpm"       : ["type" , "vmmindex"],
+        "rng"       : ["type" , "vmmindex"],
     }
 
     if id(origdev) == id(newdev):
@@ -1082,6 +1083,8 @@ class vmmDomain(vmmLibvirtObject):
         return self._build_device_list("redirdev")
     def get_tpm_devices(self):
         return self._build_device_list("tpm")
+    def get_rng_devices(self):
+        return self._build_device_list("rng")
 
     def get_disk_devices(self, refresh_if_nec=True, inactive=False):
         devs = self._build_device_list("disk", refresh_if_nec, inactive)
-- 
1.8.3.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]