Example #1
0
def clear_git_lock(role, remote=None, **kwargs):
    '''
    .. versionadded:: 2015.8.2

    Remove the update locks for Salt components (gitfs, git_pillar, winrepo)
    which use gitfs backend code from salt.utils.gitfs.

    .. note::
        Running :py:func:`cache.clear_all <salt.runners.cache.clear_all>` will
        not include this function as it does for pillar, grains, and mine.

        Additionally, executing this function with a ``role`` of ``gitfs`` is
        equivalent to running ``salt-run fileserver.clear_lock backend=git``.

    role
        Which type of lock to remove (``gitfs``, ``git_pillar``, or
        ``winrepo``)

    remote
        If specified, then any remotes which contain the passed string will
        have their lock cleared. For example, a ``remote`` value of **github**
        will remove the lock from all github.com remotes.

    type : update,checkout,mountpoint
        The types of lock to clear. Can be one or more of ``update``,
        ``checkout``, and ``mountpoint``, and can be passed either as a
        comma-separated or Python list.

        .. versionadded:: 2015.8.8
        .. versionchanged:: 2018.3.0
            ``mountpoint`` lock type added

    CLI Examples:

    .. code-block:: bash

        salt-run cache.clear_git_lock gitfs
        salt-run cache.clear_git_lock git_pillar
        salt-run cache.clear_git_lock git_pillar type=update
        salt-run cache.clear_git_lock git_pillar type=update,checkout
        salt-run cache.clear_git_lock git_pillar type='["update", "mountpoint"]'
    '''
    kwargs = salt.utils.args.clean_kwargs(**kwargs)
    type_ = salt.utils.args.split_input(
        kwargs.pop('type', ['update', 'checkout', 'mountpoint']))
    if kwargs:
        salt.utils.args.invalid_kwargs(kwargs)

    if role == 'gitfs':
        git_objects = [
            salt.utils.gitfs.GitFS(
                __opts__,
                __opts__['gitfs_remotes'],
                per_remote_overrides=salt.fileserver.gitfs.
                PER_REMOTE_OVERRIDES,
                per_remote_only=salt.fileserver.gitfs.PER_REMOTE_ONLY)
        ]
    elif role == 'git_pillar':
        git_objects = []
        for ext_pillar in __opts__['ext_pillar']:
            key = next(iter(ext_pillar))
            if key == 'git':
                if not isinstance(ext_pillar['git'], list):
                    continue
                obj = salt.utils.gitfs.GitPillar(
                    __opts__,
                    ext_pillar['git'],
                    per_remote_overrides=salt.pillar.git_pillar.
                    PER_REMOTE_OVERRIDES,
                    per_remote_only=salt.pillar.git_pillar.PER_REMOTE_ONLY,
                    global_only=salt.pillar.git_pillar.GLOBAL_ONLY)
                git_objects.append(obj)
    elif role == 'winrepo':
        winrepo_dir = __opts__['winrepo_dir']
        winrepo_remotes = __opts__['winrepo_remotes']

        git_objects = []
        for remotes, base_dir in ((winrepo_remotes, winrepo_dir),
                                  (__opts__['winrepo_remotes_ng'],
                                   __opts__['winrepo_dir_ng'])):
            obj = salt.utils.gitfs.WinRepo(
                __opts__,
                remotes,
                per_remote_overrides=salt.runners.winrepo.PER_REMOTE_OVERRIDES,
                per_remote_only=salt.runners.winrepo.PER_REMOTE_ONLY,
                global_only=salt.runners.winrepo.GLOBAL_ONLY,
                cache_root=base_dir)
            git_objects.append(obj)
    else:
        raise SaltInvocationError('Invalid role \'{0}\''.format(role))

    ret = {}
    for obj in git_objects:
        for lock_type in type_:
            cleared, errors = _clear_lock(obj.clear_lock,
                                          role,
                                          remote=remote,
                                          lock_type=lock_type)
            if cleared:
                ret.setdefault('cleared', []).extend(cleared)
            if errors:
                ret.setdefault('errors', []).extend(errors)
    if not ret:
        return 'No locks were removed'
    return ret
Example #2
0
File: cache.py Project: bryson/salt
def clear_git_lock(role, remote=None, **kwargs):
    '''
    .. versionadded:: 2015.8.2

    Remove the update locks for Salt components (gitfs, git_pillar, winrepo)
    which use gitfs backend code from salt.utils.gitfs.

    .. note::
        Running :py:func:`cache.clear_all <salt.runners.cache.clear_all>` will
        not include this function as it does for pillar, grains, and mine.

        Additionally, executing this function with a ``role`` of ``gitfs`` is
        equivalent to running ``salt-run fileserver.clear_lock backend=git``.

    role
        Which type of lock to remove (``gitfs``, ``git_pillar``, or
        ``winrepo``)

    remote
        If specified, then any remotes which contain the passed string will
        have their lock cleared. For example, a ``remote`` value of **github**
        will remove the lock from all github.com remotes.

    type : update,checkout
        The types of lock to clear. Can be ``update``, ``checkout``, or both of
    et (either comma-separated or as a Python list).

        .. versionadded:: 2015.8.8

    CLI Example:

    .. code-block:: bash

        salt-run cache.clear_git_lock git_pillar
    '''
    kwargs = salt.utils.clean_kwargs(**kwargs)
    type_ = salt.utils.split_input(kwargs.pop('type', ['update', 'checkout']))
    if kwargs:
        salt.utils.invalid_kwargs(kwargs)

    if role == 'gitfs':
        git_objects = [salt.utils.gitfs.GitFS(__opts__)]
        git_objects[0].init_remotes(__opts__['gitfs_remotes'],
                                    __GITFS_OVERRIDES)
    elif role == 'git_pillar':
        git_objects = []
        for ext_pillar in __opts__['ext_pillar']:
            key = next(iter(ext_pillar))
            if key == 'git':
                if not isinstance(ext_pillar['git'], list):
                    continue
                obj = salt.utils.gitfs.GitPillar(__opts__)
                obj.init_remotes(ext_pillar['git'], __GIT_PILLAR_OVERRIDES)
                git_objects.append(obj)
    elif role == 'winrepo':
        if 'win_repo' in __opts__:
            salt.utils.warn_until(
                'Nitrogen',
                'The \'win_repo\' config option is deprecated, please use '
                '\'winrepo_dir\' instead.'
            )
            winrepo_dir = __opts__['win_repo']
        else:
            winrepo_dir = __opts__['winrepo_dir']

        if 'win_gitrepos' in __opts__:
            salt.utils.warn_until(
                'Nitrogen',
                'The \'win_gitrepos\' config option is deprecated, please use '
                '\'winrepo_remotes\' instead.'
            )
            winrepo_remotes = __opts__['win_gitrepos']
        else:
            winrepo_remotes = __opts__['winrepo_remotes']

        git_objects = []
        for remotes, base_dir in (
            (winrepo_remotes, winrepo_dir),
            (__opts__['winrepo_remotes_ng'], __opts__['winrepo_dir_ng'])
        ):
            obj = salt.utils.gitfs.WinRepo(__opts__, base_dir)
            obj.init_remotes(remotes, __WINREPO_OVERRIDES)
            git_objects.append(obj)
    else:
        raise SaltInvocationError('Invalid role \'{0}\''.format(role))

    ret = {}
    for obj in git_objects:
        for lock_type in type_:
            cleared, errors = _clear_lock(obj.clear_lock,
                                          role,
                                          remote=remote,
                                          lock_type=lock_type)
            if cleared:
                ret.setdefault('cleared', []).extend(cleared)
            if errors:
                ret.setdefault('errors', []).extend(errors)
    if not ret:
        return 'No locks were removed'
    return ret
Example #3
0
def clear_git_lock(role, remote=None, **kwargs):
    '''
    .. versionadded:: 2015.8.2

    Remove the update locks for Salt components (gitfs, git_pillar, winrepo)
    which use gitfs backend code from salt.utils.gitfs.

    .. note::
        Running :py:func:`cache.clear_all <salt.runners.cache.clear_all>` will
        not include this function as it does for pillar, grains, and mine.

        Additionally, executing this function with a ``role`` of ``gitfs`` is
        equivalent to running ``salt-run fileserver.clear_lock backend=git``.

    role
        Which type of lock to remove (``gitfs``, ``git_pillar``, or
        ``winrepo``)

    remote
        If specified, then any remotes which contain the passed string will
        have their lock cleared. For example, a ``remote`` value of **github**
        will remove the lock from all github.com remotes.

    type : update,checkout
        The types of lock to clear. Can be ``update``, ``checkout``, or both of
    et (either comma-separated or as a Python list).

        .. versionadded:: 2015.8.8

    CLI Example:

    .. code-block:: bash

        salt-run cache.clear_git_lock git_pillar
    '''
    kwargs = salt.utils.clean_kwargs(**kwargs)
    type_ = salt.utils.split_input(kwargs.pop('type', ['update', 'checkout']))
    if kwargs:
        salt.utils.invalid_kwargs(kwargs)

    if role == 'gitfs':
        git_objects = [salt.utils.gitfs.GitFS(__opts__)]
        git_objects[0].init_remotes(__opts__['gitfs_remotes'],
                                    __GITFS_OVERRIDES)
    elif role == 'git_pillar':
        git_objects = []
        for ext_pillar in __opts__['ext_pillar']:
            key = next(iter(ext_pillar))
            if key == 'git':
                if not isinstance(ext_pillar['git'], list):
                    continue
                obj = salt.utils.gitfs.GitPillar(__opts__)
                obj.init_remotes(ext_pillar['git'], __GIT_PILLAR_OVERRIDES)
                git_objects.append(obj)
    elif role == 'winrepo':
        winrepo_dir = __opts__['winrepo_dir']
        winrepo_remotes = __opts__['winrepo_remotes']

        git_objects = []
        for remotes, base_dir in ((winrepo_remotes, winrepo_dir),
                                  (__opts__['winrepo_remotes_ng'],
                                   __opts__['winrepo_dir_ng'])):
            obj = salt.utils.gitfs.WinRepo(__opts__, base_dir)
            obj.init_remotes(remotes, __WINREPO_OVERRIDES)
            git_objects.append(obj)
    else:
        raise SaltInvocationError('Invalid role \'{0}\''.format(role))

    ret = {}
    for obj in git_objects:
        for lock_type in type_:
            cleared, errors = _clear_lock(obj.clear_lock,
                                          role,
                                          remote=remote,
                                          lock_type=lock_type)
            if cleared:
                ret.setdefault('cleared', []).extend(cleared)
            if errors:
                ret.setdefault('errors', []).extend(errors)
    if not ret:
        return 'No locks were removed'
    return ret
def clear_git_lock(role, remote=None):
    '''
    .. versionadded:: 2015.8.2

    Remove the update locks for Salt components (gitfs, git_pillar, winrepo)
    which use gitfs backend code from salt.utils.gitfs.

    .. note::
        Running :py:func:`cache.clear_all <salt.runners.cache.clear_all>` will
        not include this function as it does for pillar, grains, and mine.

        Additionally, executing this function with a ``role`` of ``gitfs`` is
        equivalent to running ``salt-run fileserver.clear_lock backend=git``.

    role
        Which type of lock to remove (``gitfs``, ``git_pillar``, or
        ``winrepo``)

    remote
        If specified, then any remotes which contain the passed string will
        have their lock cleared. For example, a ``remote`` value of **github**
        will remove the lock from all github.com remotes.

    CLI Example:

    .. code-block:: bash

        salt-run cache.clear_git_lock git_pillar
    '''
    if role == 'gitfs':
        git_objects = [salt.utils.gitfs.GitFS(__opts__)]
        git_objects[0].init_remotes(__opts__['gitfs_remotes'],
                                    __GITFS_OVERRIDES)
    elif role == 'git_pillar':
        git_objects = []
        for ext_pillar in __opts__['ext_pillar']:
            key = next(iter(ext_pillar))
            if key == 'git':
                if not isinstance(ext_pillar['git'], list):
                    continue
                obj = salt.utils.gitfs.GitPillar(__opts__)
                obj.init_remotes(ext_pillar['git'], __GIT_PILLAR_OVERRIDES)
                git_objects.append(obj)
    elif role == 'winrepo':
        if 'win_repo' in __opts__:
            salt.utils.warn_until(
                'Nitrogen',
                'The \'win_repo\' config option is deprecated, please use '
                '\'winrepo_dir\' instead.'
            )
            winrepo_dir = __opts__['win_repo']
        else:
            winrepo_dir = __opts__['winrepo_dir']

        if 'win_gitrepos' in __opts__:
            salt.utils.warn_until(
                'Nitrogen',
                'The \'win_gitrepos\' config option is deprecated, please use '
                '\'winrepo_remotes\' instead.'
            )
            winrepo_remotes = __opts__['win_gitrepos']
        else:
            winrepo_remotes = __opts__['winrepo_remotes']

        git_objects = []
        for remotes, base_dir in (
            (winrepo_remotes, winrepo_dir),
            (__opts__['winrepo_remotes_ng'], __opts__['winrepo_dir_ng'])
        ):
            obj = salt.utils.gitfs.WinRepo(__opts__, base_dir)
            obj.init_remotes(remotes, __WINREPO_OVERRIDES)
            git_objects.append(obj)
    else:
        raise SaltInvocationError('Invalid role \'{0}\''.format(role))

    ret = {}
    for obj in git_objects:
        cleared, errors = _clear_lock(obj.clear_lock, role, remote)
        if cleared:
            ret.setdefault('cleared', []).extend(cleared)
        if errors:
            ret.setdefault('errors', []).extend(errors)
    if not ret:
        ret = 'No locks were removed'
    salt.output.display_output(ret, 'nested', opts=__opts__)