def __call__(self, parse_result: typing.Any) -> None:
        container_name = parse_result.override_system_name
        if not container_name:
            container_name = parse_result.system_name
            if container_name.startswith('system-'):
                container_name = container_name[7:]

        container_dir = os.path.join('/var/lib/machines', container_name)
        import_dir = container_dir + '_import'

        try:
            btrfs = BtrfsHelper('/usr/bin/btrfs')
            btrfs.create_subvolume(import_dir)

            # Mount filessytems and copy the rootfs into import_dir:
            tool.execute_with_system_mounted(
                lambda e, r: _extract_into_snapshot(
                    e, r, import_snapshot=import_dir),
                repository=parse_result.repository,
                system_name=parse_result.system_name,
                system_version=parse_result.system_version)

            # Delete *old* container-name:
            if btrfs.is_subvolume(container_dir):
                btrfs.delete_subvolume(container_dir)

            # Copy over container filesystem:
            btrfs.create_snapshot(import_dir, container_dir, read_only=True)

        finally:
            btrfs.delete_subvolume(import_dir)
Exemplo n.º 2
0
 def __call__(self, parse_result: typing.Any) -> None:
     tool.execute_with_system_mounted(
         lambda e, r: _execution(e, r, command=parse_result.command),
         repository=parse_result.repository,
         system_name=parse_result.system_name,
         system_version=parse_result.system_version,
     )
Exemplo n.º 3
0
    def __call__(self, parse_result: typing.Any) -> None:
        if not parse_result.tarball and not parse_result.efi_tarball:
            return

        # Mount filessytems and copy the rootfs into import_dir:
        tool.execute_with_system_mounted(
            lambda e, r:
                _tar(e, r, tarball_name=parse_result.tarball,
                     efi_tarball_name=parse_result.efi_tarball),
            repository=parse_result.repository,
            system_name=parse_result.system_name,
            system_version=parse_result.system_version)
Exemplo n.º 4
0
    def __call__(self, *, parse_result: typing.Any, tmp_dir: str,
                 image_file: str) -> int:
        if not parse_result.efi_device:
            print("No --efi-device provided, stopping.")
            exit(1)
        if not parse_result.image_device:
            print("No --image-device provided, stopping.")
            exit(1)

        with mount.Mount(
                parse_result.image_device,
                os.path.join(tmp_dir, "images"),
                options=parse_result.image_options,
                fs_type=parse_result.image_fs_type,
        ) as images_mnt:
            _copy_file(image_file,
                       images_mnt,
                       overwrite=parse_result.overwrite)

        with mount.Mount(
                parse_result.efi_device,
                os.path.join(tmp_dir, "efi_dest"),
                options=parse_result.efi_options,
                fs_type=parse_result.efi_fs_type,
        ) as efi_dest_mnt:
            return tool.execute_with_system_mounted(
                lambda e, _: _copy_efi(
                    e,
                    efi_dest_mnt,
                    include_bootloader=parse_result.include_bootloader,
                    overwrite=parse_result.overwrite,
                ),
                image_file=image_file,
                tmp_dir=tmp_dir,
            )
Exemplo n.º 5
0
    def __call__(
        self, *, parse_result: typing.Any, tmp_dir: str, image_file: str
    ) -> int:
        container_name = parse_result.override_system_name
        if not container_name:
            container_name = parse_result.system_name
            if container_name.startswith("system-"):
                container_name = container_name[7:]
        read_write = parse_result.read_write

        container_dir = os.path.join(parse_result.machines_dir, container_name)
        import_dir = container_dir + "_import"

        try:
            btrfs = BtrfsHelper("/usr/bin/btrfs")
            btrfs.create_subvolume(import_dir)

            # Mount filessystems and copy the rootfs into import_dir:
            result = tool.execute_with_system_mounted(
                lambda e, r: _extract_into_snapshot(e, r, import_snapshot=import_dir),
                image_file=image_file,
                tmp_dir=tmp_dir,
            )

            # Delete *old* container-name:
            if btrfs.is_subvolume(container_dir):
                btrfs.delete_subvolume(container_dir)

            # Copy over container filesystem:
            btrfs.create_snapshot(import_dir, container_dir, read_only=not read_write)

        finally:
            btrfs.delete_subvolume(import_dir)

        return result
Exemplo n.º 6
0
def create_qemu_image(
    image_path: str,
    *,
    image_size: int,
    image_format: str = "qcow2",
    system_image_file: str,
    tmp_dir: str,
) -> str:
    trace(f"Creating image file {image_path}.")
    with disk.NbdDevice.new_image_file(image_path,
                                       image_size,
                                       disk_format=image_format) as device:
        _create_hdd_image(device)

        debug("mounting data partition for further setup.")
        with mount.Mount(
                device.device(3),
                os.path.join(tmp_dir, "data"),
                fs_type="btrfs",
                options="subvolid=0",
                fallback_cwd=os.getcwd(),
        ) as data_dir:
            _setup_btrfs(data_dir)

            trace("Copying image file")
            copyfile(
                system_image_file,
                os.path.join(data_dir, ".images",
                             os.path.basename(system_image_file)),
            )

            with mount.Mount(
                    device.device(1),
                    os.path.join(tmp_dir, "efi_dest"),
                    options="defaults",
                    fs_type="vfat",
            ) as efi_dest_mnt:
                tool.execute_with_system_mounted(
                    lambda e, _: _copy_efi(
                        e,
                        efi_dest_mnt,
                    ),
                    image_file=system_image_file,
                    tmp_dir=tmp_dir,
                )

    return image_path
Exemplo n.º 7
0
 def __call__(
     self, *, parse_result: typing.Any, tmp_dir: str, image_file: str
 ) -> int:
     return tool.execute_with_system_mounted(
         lambda e, r: _execution(e, r, command=parse_result.command),
         image_file=image_file,
         tmp_dir=tmp_dir,
     )
Exemplo n.º 8
0
    def __call__(self, *, parse_result: typing.Any, tmp_dir: str,
                 image_file: str) -> int:
        if not parse_result.tarball and not parse_result.efi_tarball:
            return 1

        assert os.path.isfile(image_file)

        # Mount filessystems and copy the rootfs into import_dir:
        return tool.execute_with_system_mounted(
            lambda e, r: _tar(
                e,
                r,
                tarball_name=parse_result.tarball,
                efi_tarball_name=parse_result.efi_tarball,
            ),
            image_file=image_file,
            tmp_dir=tmp_dir,
        )