From d70d4e6e7a42dbdc938de7af712be39accd2b3cb Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Thu, 17 Feb 2022 14:51:04 -0500 Subject: 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 --- virtinst/cli.py | 6 ++++++ virtinst/devices/tpm.py | 31 ++++++++++++++++++++++++++----- virtinst/domcapabilities.py | 5 +++++ 3 files changed, 37 insertions(+), 5 deletions(-) (limited to 'virtinst') 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] -- cgit v1.2.1