コード例 #1
0
def create_source_overlay(mounts_dir,
                          scratch_dir,
                          xfs_info,
                          storage_info,
                          mount_target=None):
    """
    Context manager that prepares the source system overlay and yields the mount.
    """
    api.current_logger().debug(
        'Creating source overlay in {scratch_dir} with mounts in {mounts_dir}'.
        format(scratch_dir=scratch_dir, mounts_dir=mounts_dir))
    try:
        _create_mounts_dir(scratch_dir, mounts_dir)
        mounts = _prepare_required_mounts(scratch_dir, mounts_dir,
                                          _get_mountpoints(storage_info),
                                          xfs_info)
        with mounts.pop('/') as root_mount:
            with mounting.OverlayMount(
                    name='system_overlay', source='/',
                    workdir=root_mount.target) as root_overlay:
                if mount_target:
                    target = mounting.BindMount(source=root_overlay.target,
                                                target=mount_target)
                else:
                    target = mounting.NullMount(target=root_overlay.target)
                with target:
                    with _build_overlay_mount(root_overlay, mounts) as overlay:
                        with _mount_dnf_cache(overlay.target):
                            yield overlay
    except Exception:
        cleanup_scratch(scratch_dir, mounts_dir)
        raise
コード例 #2
0
def create_source_overlay(mounts_dir,
                          scratch_dir,
                          xfs_present,
                          cleanup=True,
                          detach=False):
    """
    Context manager that prepares the source system overlay and yields the mount.
    """
    api.current_logger().debug(
        'Creating source overlay in {scratch_dir} with mounts in {mounts_dir}'.
        format(scratch_dir=scratch_dir, mounts_dir=mounts_dir))
    with _prepare_mounts(mounts_dir, scratch_dir, cleanup, detach,
                         xfs_present) as mounts:
        with mounting.OverlayMount(name='source_overlay',
                                   source='/',
                                   workdir=mounts.target) as overlay:
            with _mount_dnf_cache(overlay.target):
                yield overlay
コード例 #3
0
def _build_overlay_mount(root_mount, mounts):
    if not root_mount:
        raise StopActorExecutionError(
            'Root mount point has not been prepared for overlayfs.')
    if not mounts:
        yield root_mount
    else:
        current = mounts.keys()[0]
        current_mount = mounts.pop(current)
        name = _mount_name(current)
        with mounting.OverlayMount(name=name,
                                   source=current,
                                   workdir=current_mount.target) as overlay:
            with mounting.BindMount(source=overlay.target,
                                    target=os.path.join(
                                        root_mount.target,
                                        current.lstrip('/'))):
                with _build_overlay_mount(root_mount, mounts) as mount:
                    yield mount
コード例 #4
0
ファイル: overlaygen.py プロジェクト: yarda/leapp-repository
def _overlay_if(condition, name, source, workdir):
    if condition:
        return mounting.OverlayMount(name=name, source=source, workdir=workdir)
    return mounting.NullMount(target=source)