def upgrade(name=None, pkgs=None, refresh=True, **kwargs):
    '''
    Upgrades all packages via ``apk upgrade`` or a specific package if name or
    pkgs is specified. Name is ignored if pkgs is specified

    Returns a dict containing the changes.

        {'<package>':  {'old': '<old-version>',
                        'new': '<new-version>'}}

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.upgrade
    '''
    ret = {'changes': {},
           'result': True,
           'comment': '',
           }

    if salt.utils.data.is_true(refresh):
        refresh_db()

    old = list_pkgs()

    pkg_to_upgrade = []

    if name and not pkgs:
        if ',' in name:
            pkg_to_upgrade = name.split(',')
        else:
            pkg_to_upgrade = [name]

    if pkgs:
        pkg_to_upgrade.extend(pkgs)

    if pkg_to_upgrade:
        cmd = ['apk', 'add', '-u']
        cmd.extend(pkg_to_upgrade)
    else:
        cmd = ['apk', 'upgrade']

    call = __salt__['cmd.run_all'](cmd,
                                   output_loglevel='trace',
                                   python_shell=False,
                                   redirect_stderr=True)

    if call['retcode'] != 0:
        ret['result'] = False
        if call['stdout']:
            ret['comment'] = call['stdout']

    __context__.pop('pkg.list_pkgs', None)
    new = list_pkgs()
    ret['changes'] = salt.utils.data.compare_dicts(old, new)

    return ret
def upgrade ( name = None , pkgs = None , refresh = True , ** kwargs ) : ret = { 'changes' : { } , 'result' : True , 'comment' : '' , } if salt . utils . data . is_true ( refresh ) : refresh_db ( ) old = list_pkgs ( ) pkg_to_upgrade = [ ] if name and not pkgs : if ',' in name : pkg_to_upgrade = name . split ( ',' ) else : pkg_to_upgrade = [ name ] if pkgs : pkg_to_upgrade . extend ( pkgs ) if pkg_to_upgrade : cmd = [ 'apk' , 'add' , '-u' ] cmd . extend ( pkg_to_upgrade ) else : cmd = [ 'apk' , 'upgrade' ] call = __salt__ [ 'cmd.run_all' ] ( cmd , output_loglevel = 'trace' , python_shell = False , redirect_stderr = True ) if call [ 'retcode' ] != 0 : ret [ 'result' ] = False if call [ 'stdout' ] : ret [ 'comment' ] = call [ 'stdout' ] __context__ . pop ( 'pkg.list_pkgs' , None ) new = list_pkgs ( ) ret [ 'changes' ] = salt . utils . data . compare_dicts ( old , new ) return ret
Upgrades all packages via ``apk upgrade`` or a specific package if name or
    pkgs is specified. Name is ignored if pkgs is specified

    Returns a dict containing the changes.

        {'<package>':  {'old': '<old-version>',
                        'new': '<new-version>'}}

    CLI Example:

    .. code-block:: bash

        salt '*' pkg.upgrade