[PATCH v2 6/6] details: show TPM device model and allow updating it

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

 



Show the TPM device model and allow updating it. If a TPM 1.2 has been
chosen, we only allow the TIS interface to be selected. In case of a
TPM 2.0 we also enable the choice of the CRB interface.

Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxxxxxxxxxx>
---
 ui/details.ui              | 33 +++++++++++++++++++++++++++++++++
 virtManager/addhardware.py | 25 +++++++++++++++++++++++++
 virtManager/details.py     | 26 +++++++++++++++++++++++++-
 virtManager/domain.py      | 11 +++++++++++
 4 files changed, 94 insertions(+), 1 deletion(-)

diff --git a/ui/details.ui b/ui/details.ui
index efc2748f..3018354b 100644
--- a/ui/details.ui
+++ b/ui/details.ui
@@ -5469,6 +5469,39 @@
                                             <property name="top_attach">2</property>
                                           </packing>
                                         </child>
+                                        <child>
+                                          <object class="GtkLabel" id="tpm-model-label">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="halign">end</property>
+                                            <property name="label" translatable="yes">Device mode_l:</property>
+                                            <property name="use_underline">True</property>
+                                            <property name="mnemonic_widget">tpm-model-combobox</property>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">0</property>
+                                            <property name="top_attach">3</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkComboBox" id="tpm-model">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="halign">start</property>
+                                            <property name="hexpand">False</property>
+                                            <property name="has_entry">True</property>
+                                            <signal name="changed" handler="on_tpm_model_combo_changed" swapped="no"/>
+                                            <child internal-child="entry">
+                                              <object class="GtkEntry" id="tpm-model-combobox">
+                                                <property name="can_focus">True</property>
+                                              </object>
+                                            </child>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">1</property>
+                                            <property name="top_attach">3</property>
+                                          </packing>
+                                        </child>
                                       </object>
                                     </child>
                                   </object>
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 6fd6a5eb..e6619d66 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -689,6 +689,31 @@ class vmmAddHardware(vmmGObjectUI):
             values.append([t, t])
         _build_combo(self.widget("tpm-version"), values)
 
+    @staticmethod
+    def _get_tpm_model_list(vm, tpmversion):
+        mod_list = []
+        if vm.is_hvm():
+            mod_list.append("tpm-tis")
+            if tpmversion != '1.2':
+                mod_list.append("tpm-crb")
+            mod_list.sort()
+        return mod_list
+
+    @staticmethod
+    def populate_tpm_model_combo(vm, combo, tpmversion):
+        model = combo.get_model()
+        model.clear()
+
+        mod_list = vmmAddHardware._get_tpm_model_list(vm, tpmversion)
+        for m in mod_list:
+            model.append([m, DeviceTpm.get_pretty_model(m)])
+        combo.set_active(0)
+
+    @staticmethod
+    def build_tpm_model_combo(vm, combo, tpmversion):
+        _build_combo(combo, [])
+        vmmAddHardware.populate_tpm_model_combo(vm, combo, tpmversion)
+
 
     def _build_panic_model_combo(self):
         values = []
diff --git a/virtManager/details.py b/virtManager/details.py
index d2996bd1..c2e4ecda 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -89,10 +89,11 @@ from .graphwidgets import Sparkline
  EDIT_CONTROLLER_MODEL,
 
  EDIT_TPM_TYPE,
+ EDIT_TPM_MODEL,
 
  EDIT_FS,
 
- EDIT_HOSTDEV_ROMBAR) = range(1, 49)
+ EDIT_HOSTDEV_ROMBAR) = range(1, 50)
 
 
 # Columns in hw list model
@@ -573,6 +574,8 @@ class vmmDetails(vmmGObjectUI):
 
             "on_hw_list_button_press_event": self.popup_addhw_menu,
 
+            "on_tpm_model_combo_changed": lambda *x: self.enable_apply(x, EDIT_TPM_MODEL),
+
             # Listeners stored in vmmConsolePages
             "on_details_menu_view_fullscreen_activate": (
                 self.console.details_toggle_fullscreen),
@@ -1046,6 +1049,10 @@ class vmmDetails(vmmGObjectUI):
         sc_mode = self.widget("smartcard-mode")
         vmmAddHardware.build_smartcard_mode_combo(self.vm, sc_mode)
 
+        # TPM model
+        tpm_model = self.widget("tpm-model")
+        vmmAddHardware.build_tpm_model_combo(self.vm, tpm_model, None)
+
         # Controller model
         combo = self.widget("controller-model")
         model = Gtk.ListStore(str, str)
@@ -1905,6 +1912,8 @@ class vmmDetails(vmmGObjectUI):
                 ret = self.config_filesystem_apply(key)
             elif pagetype is HW_LIST_TYPE_HOSTDEV:
                 ret = self.config_hostdev_apply(key)
+            elif pagetype is HW_LIST_TYPE_TPM:
+                ret = self.config_tpm_apply(key)
             else:
                 ret = False
         except Exception as e:
@@ -2263,6 +2272,17 @@ class vmmDetails(vmmGObjectUI):
                                           kwargs, self.vm, self.err,
                                           devobj=devobj)
 
+    def config_tpm_apply(self, devobj):
+        kwargs = {}
+
+        if self.edited(EDIT_TPM_MODEL):
+            model = uiutil.get_list_selection(self.widget("tpm-model"))
+            kwargs["model"] = model
+
+        return vmmAddHardware.change_config_helper(self.vm.define_tpm,
+                                          kwargs, self.vm, self.err,
+                                          devobj=devobj)
+
 
     # Device removal
     def remove_device(self, devobj):
@@ -2781,6 +2801,10 @@ class vmmDetails(vmmGObjectUI):
         self.widget("tpm-dev-type").set_text(
                 virtinst.DeviceTpm.get_pretty_type(dev_type))
 
+        vmmAddHardware.populate_tpm_model_combo(
+            self.vm, self.widget("tpm-model"), tpmdev.version)
+        uiutil.set_list_selection(self.widget("tpm-model"), tpmdev.model)
+
         # Device type specific properties, only show if apply to the cur dev
         show_ui("device_path")
         show_ui("version")
diff --git a/virtManager/domain.py b/virtManager/domain.py
index 1cc03682..f48cfa18 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -982,6 +982,17 @@ class vmmDomain(vmmLibvirtObject):
         else:
             self._redefine_xmlobj(xmlobj)
 
+    def define_tpm(self, devobj, do_hotplug, model=_SENTINEL):
+        xmlobj = self._make_xmlobj_to_define()
+        editdev = self._lookup_device_to_define(xmlobj, devobj, do_hotplug)
+        if not editdev:
+            return
+
+        if model != _SENTINEL:
+            editdev.model = model
+
+        self._redefine_xmlobj(xmlobj)
+
 
     ####################
     # Hotplug routines #
-- 
2.14.4

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list



[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux