def _extract_into_snapshot(_, rootfs: str, *, import_snapshot: str) -> None:

    # Extract data
    tool.run(
        '/usr/bin/bash', '-c',
        '( cd {} ; tar -cf - . ) | ( cd {} ; tar -xf - )'.format(
            rootfs, import_snapshot))
Exemplo n.º 2
0
def _tar(efifs: str, rootfs: str, *, tarball_name: str, efi_tarball_name: str) -> None:

    # Extract data
    if efi_tarball_name:
        tool.run('/usr/bin/bash', '-c',
                 '( cd {} ; tar -cf "{}" --auto-compress .) '.format(efifs, efi_tarball_name))
    if tarball_name:
        tool.run('/usr/bin/bash', '-c',
                 '( cd {} ; tar -cf "{}" --auto-compress .) '.format(rootfs, tarball_name))
Exemplo n.º 3
0
def _extract_into_snapshot(_, rootfs: str, *, import_snapshot: str) -> None:

    # Extract data
    tool.run(
        "/usr/bin/bash",
        "-c",
        "( cd {} ; tar -cf - . ) | ( cd {} ; tar -xf - )".format(
            rootfs, import_snapshot),
    )
Exemplo n.º 4
0
def _extract_into_snapshot(_, rootfs: str, *, import_snapshot: str) -> int:
    # Extract data
    return tool.run(
        "/usr/bin/bash",
        "-c",
        f'( cd "{rootfs}" ; tar -cf - . ) | ( cd "{import_snapshot}" ; tar -xf - )',
    ).returncode
Exemplo n.º 5
0
def run_qemu(
    parse_result: typing.Any, *, drives: typing.List[str] = [], work_directory: str
) -> typing.List[str]:
    qemu_args = [
        "/usr/bin/qemu-system-x86_64",
        "--enable-kvm",
        "-cpu",
        "Penryn",  # Needed for clover to boot:-/
        "-smp",
        "cores={}".format(parse_result.cores),
        "-machine",
        "pc-q35-2.12",
        "-m",
        "size={}".format(parse_result.memory),  # memory
        "-object",
        "rng-random,filename=/dev/urandom,id=rng0",
        "-device",
        "virtio-rng-pci,rng=rng0,max-bytes=512,period=1000",
        # Random number generator
    ]

    qemu_args += _append_network(
        parse_result.hostname,
        hostfwd=parse_result.hostfwd,
        mac=parse_result.mac,
        net=parse_result.net,
        host=parse_result.host,
    )

    boot_index = 0
    for disk in drives:
        qemu_args += _append_hdd(boot_index, disk)
        boot_index += 1
    for disk in parse_result.disks:
        qemu_args += _append_hdd(boot_index, disk)
        boot_index += 1

    for fs in parse_result.ro_fs_es:
        qemu_args += _append_fs(fs, read_only=True)
    for fs in parse_result.fs_es:
        qemu_args += _append_fs(fs, read_only=False)

    if parse_result.no_graphic:
        qemu_args.append("-nographic")

    if not parse_result.use_bios:
        qemu_args += _append_efi(os.path.join(work_directory, "vars.fd"))

    if parse_result.verbatim:
        qemu_args += parse_result.verbatim

    print('Running: "{}"'.format('" "'.join(qemu_args)))
    result = tools.run(*qemu_args, work_directory=work_directory, check=False)

    if result.returncode != 0:
        print("Qemu run Failed with return code {}.".format(result.returncode))
        print("Qemu stdout: {}".format(result.stdout))
        print("Qemu stderr: {}".format(result.stderr))
Exemplo n.º 6
0
def _tar(efi_fs: str, rootfs: str, *, tarball_name: str,
         efi_tarball_name: str) -> int:

    # Extract data
    result = 0
    if efi_tarball_name:
        result = tool.run(
            "/usr/bin/bash",
            "-c",
            f'( cd {efi_fs} ; tar -cf "{efi_tarball_name}" --auto-compress .) ',
        ).returncode
    if tarball_name:
        result += tool.run(
            "/usr/bin/bash",
            "-c",
            f'( cd {rootfs} ; tar -cf "{tarball_name}" --auto-compress .) ',
        ).returncode

    return result
Exemplo n.º 7
0
def _execution(efi: str, rootfs: str, *, command: str) -> None:
    to_exec = command or '/usr/bin/bash -c "read -n1 -s"'
    prompt = "" if command else "<<< Press any key to continue >>>"

    env = os.environ
    env["EFI_MOUNT"] = efi
    env["ROOT_MOUNT"] = rootfs

    verbose("Running {}.".format(command))
    verbose('EFI_MOUNT env var set to : "{}".'.format(efi))
    verbose('ROOT_MOUNT env var set to: "{}".'.format(rootfs))

    print('EFI partition is mounted at "{}".'.format(efi))
    print('Root partition is mounted at "{}".'.format(rootfs))

    if prompt:
        print(prompt)

    tool.run(*split(to_exec), env=env)
Exemplo n.º 8
0
def run_qemu(parse_result: typing.Any, *,
             drives: typing.List[str] = [],
             work_directory: str) -> typing.List[str]:
    qemu_args = ['/usr/bin/qemu-system-x86_64',
                 '--enable-kvm',
                 '-cpu', 'host',
                 '-smp', 'cores={}'.format(parse_result.cores),
                 '-machine', 'pc-q35-2.12',
                 '-accel', 'kvm',
                 '-m', 'size={}'.format(parse_result.memory),  # memory
                 '-object', 'rng-random,filename=/dev/urandom,id=rng0',
                 '-device',
                 'virtio-rng-pci,rng=rng0,max-bytes=512,period=1000',
                 # Random number generator
                 ]

    qemu_args += _append_network(parse_result.hostname,
                                 hostfwd=parse_result.hostfwd,
                                 mac=parse_result.mac,
                                 net=parse_result.net,
                                 host=parse_result.host)

    boot_index = 0
    for disk in drives:
        qemu_args += _append_hdd(boot_index, disk)
        boot_index += 1
    for disk in parse_result.disks:
        qemu_args += _append_hdd(boot_index, disk)
        boot_index += 1

    for fs in parse_result.ro_fses:
        qemu_args += _append_fs(fs, read_only=True)
    for fs in parse_result.fses:
        qemu_args += _append_fs(fs, read_only=False)

    if parse_result.no_graphic:
        qemu_args.append('-nographic')

    if not parse_result.use_bios:
        qemu_args += _append_efi(os.path.join(work_directory, 'vars.fd'))

    if parse_result.verbatim:
        qemu_args += parse_result.verbatim

    result = tools.run(*qemu_args, work_directory=work_directory, check=False)

    if result.returncode != 0:
        print("Qemu run Failed with return code {}.".format(result.returncode))
        print("Qemu stdout: {}".format(result.stdout))
        print("Qemu stderr: {}".format(result.stderr))
Exemplo n.º 9
0
def _execution(efi: str, rootfs: str, *, command: str) -> int:
    to_exec = command or '/usr/bin/bash -c "read -n1 -s"'
    prompt = "" if command else "<<< Press any key to continue >>>"

    env = os.environ
    env["EFI_MOUNT"] = efi
    env["ROOT_MOUNT"] = rootfs

    verbose(f"Running {command}.")

    print(f'EFI partition is mounted at "{efi}".')
    print(f'Root partition is mounted at "{rootfs}".')

    if prompt:
        print(prompt)

    return tool.run(*split(to_exec), env=env).returncode