From 595770163a4e4242b6937fc0ded9582d62159793 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Wed, 4 Sep 2024 12:52:31 +0200 Subject: live: add boot entries into /refresh payload Add 'efi' key into the refresh payload. The value for that key has the following structure: 'efi': { 'entries': [ { "order": 0, "name": "Boot0000", "active": false, "description": "grub" }, { "order": 1, "name": "Boot0001", "active": true, "description": "UEFI: PXE IP4 Realtek PCIe GBE Family Controller" } ] } If the client is not a EFI system it won't add the 'efi' field. If an entry is not in the boot order it won't have the 'order' field. --- src/live/ogOperations.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/live/ogOperations.py') diff --git a/src/live/ogOperations.py b/src/live/ogOperations.py index 010af05..9c32cce 100644 --- a/src/live/ogOperations.py +++ b/src/live/ogOperations.py @@ -157,6 +157,33 @@ class OgLiveOperations: 'checksum': image_checksum}) return cache_contents + def _get_boot_entry_data(self): + data = {} + + if not is_uefi_supported(): + return data + + try: + efibootmgr_out = run_efibootmgr_json() + except Exception as e: + logging.warning(e) + return data + + data['entries'] = [] + for idx, entry_name in enumerate(efibootmgr_out['BootOrder']): + entry_name = 'Boot' + entry_name + for entry in efibootmgr_out['vars']: + if entry['name'] == entry_name: + entry['order'] = idx + data['entries'].append(entry) + break + + for entry in efibootmgr_out['vars']: + if not 'order' in entry: + data['entries'].append(entry) + + return data + def _compute_md5(self, path, bs=2**20): m = hashlib.md5() with open(path, 'rb') as f: @@ -756,6 +783,10 @@ class OgLiveOperations: json_body['cache'] = self._get_cache_contents() + boot_entry_data = self._get_boot_entry_data() + if boot_entry_data: + json_body['efi'] = boot_entry_data + generate_menu(json_body['partition_setup']) generate_cache_txt() self._restartBrowser(self._url) -- cgit v1.2.3-18-g5258