/usr/lib/python3/dist-packages/provisioningserver/boot/powerkvm.py is in python3-maas-provisioningserver 2.0.0~beta3+bzr4941-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | # Copyright 2014-2016 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
"""PowerKVM and PowerVM Boot Method"""
__all__ = [
'PowerKVMBootMethod',
]
import glob
import os.path
from textwrap import dedent
from urllib.parse import urlparse
from provisioningserver.boot import (
BootMethod,
BootMethodInstallError,
get_ports_archive_url,
utils,
)
from provisioningserver.boot.install_bootloader import install_bootloader
from provisioningserver.utils import typed
from provisioningserver.utils.fs import tempdir
from provisioningserver.utils.shell import call_and_check
GRUB_CONFIG = dedent("""\
configfile (pxe)/grub/grub.cfg-${net_default_mac}
configfile (pxe)/grub/grub.cfg-default-ppc64el
""")
class PowerKVMBootMethod(BootMethod):
name = "powerkvm"
bios_boot_method = "powerkvm"
template_subdir = None
bootloader_path = "bootppc64.bin"
bootloader_arches = ['ppc64el']
arch_octet = "00:0C"
def match_path(self, backend, path):
"""Doesn't need to do anything, as the UEFIBootMethod provides
the grub implementation needed.
"""
return None
def get_reader(self, backend, kernel_params, **extra):
"""Doesn't need to do anything, as the UEFIBootMethod provides
the grub implementation needed.
"""
return None
@typed
def install_bootloader(self, destination: str):
"""Installs the required files for PowerKVM/PowerVM booting into the
tftproot.
"""
ports_archive_url = get_ports_archive_url()
archive_url = ports_archive_url.strip(urlparse(ports_archive_url).path)
with tempdir() as tmp:
# Download the grub-ieee1275-bin package
data, filename = utils.get_updates_package(
'grub-ieee1275-bin', archive_url,
'main', 'ppc64el')
if data is None:
raise BootMethodInstallError(
'Failed to download grub-ieee1275-bin package from '
'the archive.')
grub_output = os.path.join(tmp, filename)
with open(grub_output, 'wb') as stream:
stream.write(data)
# Extract the package with dpkg, and install the shim
call_and_check(["dpkg", "-x", grub_output, tmp])
# Output the embedded config, so grub-mkimage can use it
config_output = os.path.join(tmp, 'grub.cfg')
with open(config_output, 'wb') as stream:
stream.write(GRUB_CONFIG.encode('utf-8'))
# Get list of grub modules
module_dir = os.path.join(
tmp, 'usr', 'lib', 'grub', 'powerpc-ieee1275')
modules = []
for module_path in glob.glob(os.path.join(module_dir, '*.mod')):
module_filename = os.path.basename(module_path)
module_name, _ = os.path.splitext(module_filename)
modules.append(module_name)
# Generate the grub bootloader
mkimage_output = os.path.join(tmp, self.bootloader_path)
args = [
'grub-mkimage',
'-o', mkimage_output,
'-O', 'powerpc-ieee1275',
'-d', module_dir,
'-c', config_output,
]
call_and_check(args + modules)
install_bootloader(
mkimage_output,
os.path.join(destination, self.bootloader_path))
|