Skip to content

Commit

Permalink
Add vtpm methods to VM class
Browse files Browse the repository at this point in the history
This adds get_vtpm(), create_vtpm(), and destroy_vtpm() methods to the
VM class.

vm.get_vtpm() returns the vtpm uuid associated to the vm if it exists,
None otherwise.

vm.create_vtpm() creates a vtpm and associates it to the vm. It returns
the newly created vtpm uuid, or fails if a vtpm is already associated to
the vm.

vm.destroy_vm() destroys the existing vtpm associated to the vm if one
exists. It doesn't fail if no vtpm is associated to the vm.

Signed-off-by: Thierry Escande <[email protected]>
  • Loading branch information
tescande committed Sep 13, 2023
1 parent 69330b4 commit b80a02a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,19 @@ def get_all_efi_bins(self):

return binaries

def get_vtpm_uuid(self):
return self.host.xe('vtpm-list', {'vm': self.uuid}, minimal=True)

def create_vtpm(self):
logging.info("Creating vTPM for vm %s" % self.uuid)
return self.host.xe('vtpm-create', {'vm-uuid': self.uuid})

def destroy_vtpm(self):
vtpm_uuid = self.get_vtpm_uuid()
assert vtpm_uuid, "A vTPM must be present"
logging.info("Destroying vTPM %s" % vtpm_uuid)
return self.host.xe('vtpm-destroy', {'uuid': vtpm_uuid}, force=True)

def clone(self):
name = self.name() + '_clone_for_tests'
logging.info("Clone VM")
Expand Down

0 comments on commit b80a02a

Please sign in to comment.