示例#1
0
def _setup_scratch_directory(
    system_context: SystemContext, btrfs_helper: BtrfsHelper
) -> None:
    btrfs_helper.create_subvolume(system_context.fs_directory)
    btrfs_helper.create_subvolume(system_context.cache_directory)
    btrfs_helper.create_subvolume(system_context.meta_directory)
    btrfs_helper.create_subvolume(system_context.boot_directory)
    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)
示例#3
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:]
            if container_name.startswith("arch-"):
                container_name = container_name[5:]
            elif container_name.startswith("clr-"):
                container_name = container_name[4:]
        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