summaryrefslogtreecommitdiff
path: root/virtinst
diff options
context:
space:
mode:
authorCole Robinson <crobinso@redhat.com>2022-02-17 14:51:04 -0500
committerCole Robinson <crobinso@redhat.com>2022-02-19 08:36:28 -0500
commitd70d4e6e7a42dbdc938de7af712be39accd2b3cb (patch)
tree3cba81de484ae9149926465af90a5447c041e05a /virtinst
parent39731b8bf70829b1ce72fceddc81b27c83d3a077 (diff)
downloadvirt-manager-d70d4e6e7a42dbdc938de7af712be39accd2b3cb.tar.gz
devices: tpm: Rework defaults
The code previously was just encoding the same defaults as libvirt, which doesn't really add anything. Instead, let's prefer type='emulator' model='tpm-crb', which gives the most modern virtualization friendly config. When we don't know if that will work, we mostly leave things up to libvirt to fill in. Signed-off-by: Cole Robinson <crobinso@redhat.com>
Diffstat (limited to 'virtinst')
-rw-r--r--virtinst/cli.py6
-rw-r--r--virtinst/devices/tpm.py31
-rw-r--r--virtinst/domcapabilities.py5
3 files changed, 37 insertions, 5 deletions
diff --git a/virtinst/cli.py b/virtinst/cli.py
index c0a4391a..a5d9dc08 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -4107,8 +4107,14 @@ class ParserTPM(VirtCLIParser):
self.guest.skip_default_tpm = True
return
+ # Handle --tpm /dev/tpm0
if (self.optdict.get("type", "").startswith("/")):
self.optdict["path"] = self.optdict.pop("type")
+
+ # Let --tpm default,... hit our DeviceTpm defaults code
+ if self.optdict.get("type") == "default":
+ self.optdict.pop("type")
+
return super()._parse(inst)
@classmethod
diff --git a/virtinst/devices/tpm.py b/virtinst/devices/tpm.py
index bcc19482..aca3e0f2 100644
--- a/virtinst/devices/tpm.py
+++ b/virtinst/devices/tpm.py
@@ -49,11 +49,32 @@ class DeviceTpm(Device):
# Default config #
##################
+ @staticmethod
+ def default_model(guest):
+ domcaps = guest.lookup_domcaps()
+
+ if not domcaps.devices.tpm.present and not guest.os.is_pseries():
+ # Preserve the old default when domcaps is old
+ return DeviceTpm.MODEL_CRB
+ if domcaps.devices.tpm.get_enum("model").has_value(DeviceTpm.MODEL_CRB):
+ # CRB is the modern version, and it implies version 2.0
+ return DeviceTpm.MODEL_CRB
+
+ # Let libvirt decide so we don't need to duplicate its arch logic
+ return None
+
def set_defaults(self, guest):
- if not self.type:
+ if self.device_path and not self.type:
self.type = self.TYPE_PASSTHROUGH
- if not self.model:
- self.model = self.MODEL_TIS
+ if not self.type:
+ # Libvirt requires a backend type to be specified. 'emulator'
+ # may not be available if swtpm is not installed, but trying to
+ # fallback to 'passthrough' in that case isn't really workable.
+ # Instead we specify it unconditionally and let libvirt error.
+ self.type = self.TYPE_EMULATOR
- if guest.os.is_ppc64():
- self.model = self.MODEL_SPAPR
+ # passthrough and model and version are all interconnected, so
+ # don't try to set a default model if other bits are set
+ if (self.type == self.TYPE_EMULATOR and
+ not self.model and not self.version):
+ self.model = self.default_model(guest)
diff --git a/virtinst/domcapabilities.py b/virtinst/domcapabilities.py
index 1153c980..431e7dc7 100644
--- a/virtinst/domcapabilities.py
+++ b/virtinst/domcapabilities.py
@@ -42,8 +42,13 @@ class _Enum(_HasValues):
class _CapsBlock(_HasValues):
supported = XMLProperty("./@supported", is_yesno=True)
+ _supported_present = XMLProperty("./@supported")
enums = XMLChildProperty(_Enum)
+ @property
+ def present(self):
+ return self._supported_present is not None
+
def enum_names(self):
return [e.name for e in self.enums]