Add GUI elements for adding a TPM device to a guest

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
This commit is contained in:
Stefan Berger 2013-06-25 21:45:09 -04:00 committed by Cole Robinson
parent 2766dd5c6a
commit 4453305d64
3 changed files with 222 additions and 1 deletions

View File

@ -2782,6 +2782,129 @@ access in the guest.</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="page5-box2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">1</property>
<child>
<object class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="label34">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Please indicate what TPM device type to connect to the virtual machine.</property>
<property name="use_markup">True</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="tpm-param-box">
<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="alignment21">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="top_padding">2</property>
<property name="left_padding">24</property>
<child>
<object class="GtkTable" id="table12">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">2</property>
<property name="n_columns">2</property>
<property name="column_spacing">8</property>
<property name="row_spacing">12</property>
<child>
<object class="GtkComboBox" id="tpm-type">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="changed" handler="on_tpm_device_type_changed" swapped="no"/>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label35">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">_Backend:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">tpm-type</property>
</object>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="tpm-device-path-label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Device Path:</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkEntry" id="tpm-device-path">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options">GTK_FILL</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="position">13</property>
</packing>
</child>
<child>
<object class="GtkVBox" id="vbox58">
<property name="visible">True</property>

View File

@ -30,7 +30,7 @@ import virtinst
from virtinst import (VirtualCharDevice,
VirtualVideoDevice, VirtualWatchdog,
VirtualFilesystem, VirtualSmartCardDevice,
VirtualRedirDevice)
VirtualRedirDevice, VirtualTPMDevice)
from virtinst.VirtualController import VirtualControllerSCSI
import virtManager.util as util
@ -52,6 +52,7 @@ PAGE_WATCHDOG = 9
PAGE_FILESYSTEM = 10
PAGE_SMARTCARD = 11
PAGE_USBREDIR = 12
PAGE_TPM = 13
char_widget_mappings = {
"source_path" : "char-path",
@ -65,6 +66,11 @@ char_widget_mappings = {
}
tpm_widget_mappings = {
"device_path" : "tpm-device-path",
}
class vmmAddHardware(vmmGObjectUI):
def __init__(self, vm):
vmmGObjectUI.__init__(self, "vmm-add-hardware.ui", "vmm-add-hardware")
@ -95,6 +101,8 @@ class vmmAddHardware(vmmGObjectUI):
"on_char_device_type_changed": self.change_char_device_type,
"on_tpm_device_type_changed": self.change_tpm_device_type,
"on_fs_type_combo_changed": self.change_fs_type,
"on_fs_driver_combo_changed": self.change_fs_driver,
"on_fs_source_browse_clicked": self.browse_fs_source,
@ -347,6 +355,10 @@ class vmmAddHardware(vmmGObjectUI):
combo = self.widget("usbredir-list")
uihelpers.build_redir_type_combo(self.vm, combo)
# TPM widgets
combo = self.widget("tpm-type")
uihelpers.build_tpm_type_combo(self.vm, combo)
# Available HW options
is_local = not self.conn.is_remote()
is_storage_capable = self.conn.is_storage_capable()
@ -413,6 +425,8 @@ class vmmAddHardware(vmmGObjectUI):
True, None)
add_hw_option("USB Redirection", "device_usb", PAGE_USBREDIR,
True, None)
add_hw_option("TPM", "device_cpu", PAGE_TPM,
True, None)
def reset_state(self):
# Storage init
@ -808,6 +822,12 @@ class vmmAddHardware(vmmGObjectUI):
typebox = self.widget("usbredir-list")
return typebox.get_model()[typebox.get_active()][0]
# TPM getters
def get_config_tpm_type(self):
typ = self.widget("tpm-type")
typestr = typ.get_model().get_value(typ.get_active_iter(), 0)
return typestr
################
# UI listeners #
################
@ -1006,6 +1026,8 @@ class vmmAddHardware(vmmGObjectUI):
return _("Smartcard")
if page == PAGE_USBREDIR:
return _("USB Redirection")
if page == PAGE_TPM:
return _("TPM")
if page == PAGE_CHAR:
return self.get_char_type().capitalize() + " Device"
@ -1020,6 +1042,29 @@ class vmmAddHardware(vmmGObjectUI):
"""foreground="#FFF">%s</span>""") % title
self.widget("page-title-label").set_markup(markup)
def change_tpm_device_type(self, src):
idx = src.get_active()
if idx < 0:
return
devtype = src.get_model()[src.get_active()][0]
conn = self.conn.vmm
self._dev = VirtualTPMDevice.get_dev_instance(conn,
devtype)
show_something = False
for param_name, widget_name in tpm_widget_mappings.items():
make_visible = self._dev.supports_property(param_name)
if make_visible:
show_something = True
self.widget(widget_name).set_property("visible", make_visible)
self.widget(widget_name + "-label").set_property("visible",
make_visible)
self.widget("tpm-param-box").set_property("visible", show_something)
def change_char_device_type(self, src):
self._update_doc("char_type")
idx = src.get_active()
@ -1229,6 +1274,8 @@ class vmmAddHardware(vmmGObjectUI):
return self.validate_page_smartcard()
elif page_num == PAGE_USBREDIR:
return self.validate_page_usbredir()
elif page_num == PAGE_TPM:
return self.validate_page_tpm()
def validate_page_storage(self):
bus, device = self.get_config_disk_target()
@ -1577,6 +1624,27 @@ class vmmAddHardware(vmmGObjectUI):
return self.err.val_err(_("USB redirected device parameter error"),
str(e))
def validate_page_tpm(self):
conn = self.conn.vmm
typ = self.get_config_tpm_type()
device_path = self.widget("tpm-device-path").get_text()
value_mappings = {
"device_path" : device_path,
}
try:
self._dev = VirtualTPMDevice.get_dev_instance(conn, typ)
for param_name, val in value_mappings.items():
if self._dev.supports_property(param_name):
setattr(self._dev, param_name, val)
# Dump XML for sanity checking
self._dev.get_xml_config()
except Exception, e:
return self.err.val_err(_("TPM device parameter error"), e)
####################
# Unsorted helpers #

View File

@ -311,6 +311,36 @@ def populate_redir_type_combo(vm, combo):
model.append(["tcp", "TCP", True])
def build_tpm_type_combo(vm, combo):
dev_model = Gtk.ListStore(str, str)
combo.set_model(dev_model)
text = Gtk.CellRendererText()
combo.pack_start(text, True)
combo.add_attribute(text, 'text', 1)
dev_model.set_sort_column_id(0, Gtk.SortType.ASCENDING)
populate_tpm_type_combo(vm, combo)
idx = -1
for rowid in range(len(combo.get_model())):
idx = 0
row = combo.get_model()[rowid]
if row[0] == virtinst.VirtualTPMDevice.TYPE_DEFAULT:
idx = rowid
break
combo.set_active(idx)
def populate_tpm_type_combo(vm, combo):
ignore = vm
types = combo.get_model()
types.clear()
# [xml value, label]
types.append(["passthrough", "Passthrough device (passthrough)"])
def build_netmodel_combo(vm, combo):
dev_model = Gtk.ListStore(str, str)
combo.set_model(dev_model)