details: show TPM device model and allow updating it

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@linux.vnet.ibm.com>
This commit is contained in:
Stefan Berger 2018-06-08 17:42:44 -04:00 committed by Cole Robinson
parent c802f2b3b8
commit a557ed18f9
4 changed files with 94 additions and 1 deletions

View File

@ -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>

View File

@ -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 = []

View File

@ -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")

View File

@ -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 #