def _run(name, **kwargs):
    '''
    .. deprecated:: 2017.7.0
       Function name stays the same, behaviour will change.

    Run a single module function

    ``name``
        The module function to execute

    ``returner``
        Specify the returner to send the return of the module execution to

    ``kwargs``
        Pass any arguments needed to execute the function
    '''
    ret = {'name': name,
           'changes': {},
           'comment': '',
           'result': None}
    if name not in __salt__:
        ret['comment'] = 'Module function {0} is not available'.format(name)
        ret['result'] = False
        return ret

    if __opts__['test']:
        ret['comment'] = 'Module function {0} is set to execute'.format(name)
        return ret

    aspec = salt.utils.args.get_function_argspec(__salt__[name])
    args = []
    defaults = {}

    arglen = 0
    deflen = 0
    if isinstance(aspec.args, list):
        arglen = len(aspec.args)
    if isinstance(aspec.defaults, tuple):
        deflen = len(aspec.defaults)
    # Match up the defaults with the respective args
    for ind in range(arglen - 1, -1, -1):
        minus = arglen - ind
        if deflen - minus > -1:
            defaults[aspec.args[ind]] = aspec.defaults[-minus]
    # overwrite passed default kwargs
    for arg in defaults:
        if arg == 'name':
            if 'm_name' in kwargs:
                defaults[arg] = kwargs.pop('m_name')
        elif arg == 'fun':
            if 'm_fun' in kwargs:
                defaults[arg] = kwargs.pop('m_fun')
        elif arg == 'state':
            if 'm_state' in kwargs:
                defaults[arg] = kwargs.pop('m_state')
        elif arg == 'saltenv':
            if 'm_saltenv' in kwargs:
                defaults[arg] = kwargs.pop('m_saltenv')
        if arg in kwargs:
            defaults[arg] = kwargs.pop(arg)
    missing = set()
    for arg in aspec.args:
        if arg == 'name':
            rarg = 'm_name'
        elif arg == 'fun':
            rarg = 'm_fun'
        elif arg == 'names':
            rarg = 'm_names'
        elif arg == 'state':
            rarg = 'm_state'
        elif arg == 'saltenv':
            rarg = 'm_saltenv'
        else:
            rarg = arg
        if rarg not in kwargs and arg not in defaults:
            missing.add(rarg)
            continue
        if arg in defaults:
            args.append(defaults[arg])
        else:
            args.append(kwargs.pop(rarg))
    if missing:
        comment = 'The following arguments are missing:'
        for arg in missing:
            comment += ' {0}'.format(arg)
        ret['comment'] = comment
        ret['result'] = False
        return ret

    if aspec.varargs:
        if aspec.varargs == 'name':
            rarg = 'm_name'
        elif aspec.varargs == 'fun':
            rarg = 'm_fun'
        elif aspec.varargs == 'names':
            rarg = 'm_names'
        elif aspec.varargs == 'state':
            rarg = 'm_state'
        elif aspec.varargs == 'saltenv':
            rarg = 'm_saltenv'
        else:
            rarg = aspec.varargs

        if rarg in kwargs:
            varargs = kwargs.pop(rarg)

            if not isinstance(varargs, list):
                msg = "'{0}' must be a list."
                ret['comment'] = msg.format(aspec.varargs)
                ret['result'] = False
                return ret

            args.extend(varargs)

    nkwargs = {}
    if aspec.keywords and aspec.keywords in kwargs:
        nkwargs = kwargs.pop(aspec.keywords)
        if not isinstance(nkwargs, dict):
            msg = "'{0}' must be a dict."
            ret['comment'] = msg.format(aspec.keywords)
            ret['result'] = False
            return ret

    try:
        if aspec.keywords:
            mret = __salt__[name](*args, **nkwargs)
        else:
            mret = __salt__[name](*args)
    except Exception as e:
        ret['comment'] = 'Module function {0} threw an exception. Exception: {1}'.format(name, e)
        ret['result'] = False
        return ret
    else:
        if mret is not None or mret is not {}:
            ret['changes']['ret'] = mret

    if 'returner' in kwargs:
        ret_ret = {
                'id': __opts__['id'],
                'ret': mret,
                'fun': name,
                'jid': salt.utils.jid.gen_jid(__opts__)}
        returners = salt.loader.returners(__opts__, __salt__)
        if kwargs['returner'] in returners:
            returners[kwargs['returner']](ret_ret)
    ret['comment'] = 'Module function {0} executed'.format(name)
    ret['result'] = _get_result(mret, ret['changes'])

    return ret
def _run ( name , ** kwargs ) : ret = { 'name' : name , 'changes' : { } , 'comment' : '' , 'result' : None } if name not in __salt__ : ret [ 'comment' ] = 'Module function {0} is not available' . format ( name ) ret [ 'result' ] = False return ret if __opts__ [ 'test' ] : ret [ 'comment' ] = 'Module function {0} is set to execute' . format ( name ) return ret aspec = salt . utils . args . get_function_argspec ( __salt__ [ name ] ) args = [ ] defaults = { } arglen = 0 deflen = 0 if isinstance ( aspec . args , list ) : arglen = len ( aspec . args ) if isinstance ( aspec . defaults , tuple ) : deflen = len ( aspec . defaults ) for ind in range ( arglen - 1 , - 1 , - 1 ) : minus = arglen - ind if deflen - minus > - 1 : defaults [ aspec . args [ ind ] ] = aspec . defaults [ - minus ] for arg in defaults : if arg == 'name' : if 'm_name' in kwargs : defaults [ arg ] = kwargs . pop ( 'm_name' ) elif arg == 'fun' : if 'm_fun' in kwargs : defaults [ arg ] = kwargs . pop ( 'm_fun' ) elif arg == 'state' : if 'm_state' in kwargs : defaults [ arg ] = kwargs . pop ( 'm_state' ) elif arg == 'saltenv' : if 'm_saltenv' in kwargs : defaults [ arg ] = kwargs . pop ( 'm_saltenv' ) if arg in kwargs : defaults [ arg ] = kwargs . pop ( arg ) missing = set ( ) for arg in aspec . args : if arg == 'name' : rarg = 'm_name' elif arg == 'fun' : rarg = 'm_fun' elif arg == 'names' : rarg = 'm_names' elif arg == 'state' : rarg = 'm_state' elif arg == 'saltenv' : rarg = 'm_saltenv' else : rarg = arg if rarg not in kwargs and arg not in defaults : missing . add ( rarg ) continue if arg in defaults : args . append ( defaults [ arg ] ) else : args . append ( kwargs . pop ( rarg ) ) if missing : comment = 'The following arguments are missing:' for arg in missing : comment += ' {0}' . format ( arg ) ret [ 'comment' ] = comment ret [ 'result' ] = False return ret if aspec . varargs : if aspec . varargs == 'name' : rarg = 'm_name' elif aspec . varargs == 'fun' : rarg = 'm_fun' elif aspec . varargs == 'names' : rarg = 'm_names' elif aspec . varargs == 'state' : rarg = 'm_state' elif aspec . varargs == 'saltenv' : rarg = 'm_saltenv' else : rarg = aspec . varargs if rarg in kwargs : varargs = kwargs . pop ( rarg ) if not isinstance ( varargs , list ) : msg = "'{0}' must be a list." ret [ 'comment' ] = msg . format ( aspec . varargs ) ret [ 'result' ] = False return ret args . extend ( varargs ) nkwargs = { } if aspec . keywords and aspec . keywords in kwargs : nkwargs = kwargs . pop ( aspec . keywords ) if not isinstance ( nkwargs , dict ) : msg = "'{0}' must be a dict." ret [ 'comment' ] = msg . format ( aspec . keywords ) ret [ 'result' ] = False return ret try : if aspec . keywords : mret = __salt__ [ name ] ( * args , ** nkwargs ) else : mret = __salt__ [ name ] ( * args ) except Exception as e : ret [ 'comment' ] = 'Module function {0} threw an exception. Exception: {1}' . format ( name , e ) ret [ 'result' ] = False return ret else : if mret is not None or mret is not { } : ret [ 'changes' ] [ 'ret' ] = mret if 'returner' in kwargs : ret_ret = { 'id' : __opts__ [ 'id' ] , 'ret' : mret , 'fun' : name , 'jid' : salt . utils . jid . gen_jid ( __opts__ ) } returners = salt . loader . returners ( __opts__ , __salt__ ) if kwargs [ 'returner' ] in returners : returners [ kwargs [ 'returner' ] ] ( ret_ret ) ret [ 'comment' ] = 'Module function {0} executed' . format ( name ) ret [ 'result' ] = _get_result ( mret , ret [ 'changes' ] ) return ret
.. deprecated:: 2017.7.0
       Function name stays the same, behaviour will change.

    Run a single module function

    ``name``
        The module function to execute

    ``returner``
        Specify the returner to send the return of the module execution to

    ``kwargs``
        Pass any arguments needed to execute the function