Skip to content

Commit

Permalink
Adapt code to new uefi certificates API
Browse files Browse the repository at this point in the history
See: xapi-project/xen-api#4659

`Host` API is deprecated in favor of `Pool` API

Signed-off-by: BenjiReis <benjamin.reis@vates.fr>
  • Loading branch information
benjamreis committed Apr 1, 2022
1 parent b1bc71b commit 456d50a
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions scripts/secureboot-certs
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,6 @@ def session_init():


def clear(session):
hosts = Host.get_all(session)
for host in hosts:
host.set_certs(b"")
print("Cleared certificates from XAPI DB for host %s." % host.uuid)

for pool in Pool.get_all(session):
pool.set_certs(b"")
print("Cleared certificates from XAPI DB for pool %s." % pool.uuid)
Expand Down Expand Up @@ -393,10 +388,6 @@ def install(session, args):
data = base64.b64encode(tarball.getvalue())
tarball.close()

hosts = Host.get_all(session)
for host in hosts:
host.set_certs(data)

pool = Pool.get_all(session)[0]
if not pool:
print("Could not retrieve pool from XAPI")
Expand Down Expand Up @@ -557,16 +548,9 @@ class Host(object):
def uuid(self):
return self.xapi_class.get_uuid(self.opaque_ref)

def get_certs(self):
if self.__certs is None:
self.__certs = self.xapi_class.get_uefi_certificates(self.opaque_ref)
return self.__certs

def set_certs(self, data):
self.xapi_class.set_uefi_certificates(self.opaque_ref, data)

def save_certs_to_disk(self):
decoded = base64.b64decode(self.get_certs())
pool = Pool.get_all(self.session)[0]
decoded = base64.b64decode(pool.get_certs())

d = cd_tempdir()
_, fname = tempfile.mkstemp()
Expand Down Expand Up @@ -649,6 +633,16 @@ def print_cert(path, uuid, klass, verbose=False):
print("")


def get_certs(self):
if self.__certs is None:
self.__certs = self.xapi_class.get_uefi_certificates(self.opaque_ref)
return self.__certs


def set_certs(self, data):
self.xapi_class.set_uefi_certificates(self.opaque_ref, data)


def report(session, verbose=False):
try:
print("\n{} -- Report".format(os.path.basename(sys.argv[0])))
Expand Down

0 comments on commit 456d50a

Please sign in to comment.