예제 #1
0
def _wrapper(orig, pre='', post='', err_=None, run_args=None, **kwargs):
    '''
    Helper function that wraps the execution of freebsd-update command.

    orig:
        Originating function that called _wrapper().

    pre:
        String that will be prepended to freebsd-update command.

    post:
        String that will be appended to freebsd-update command.

    err_:
        Dictionary on which return codes and stout/stderr are copied.

    run_args:
        Arguments to be passed on cmd.run_all.

    kwargs:
        Parameters of freebsd-update command.
    '''
    ret = ''  # the message to be returned
    cmd = _cmd(**kwargs)
    cmd_str = ' '.join([x for x in (pre, cmd, post, orig)])
    if run_args and isinstance(run_args, dict):
        res = __salt__['cmd.run_all'](cmd_str, **run_args)
    else:
        res = __salt__['cmd.run_all'](cmd_str)

    if isinstance(err_, dict):  # copy return values if asked to
        for k, v in six.itermitems(res):
            err_[k] = v

    if 'retcode' in res and res['retcode'] != 0:
        msg = ' '.join([x for x in (res['stdout'], res['stderr']) if x])
        ret = 'Unable to run "{0}" with run_args="{1}". Error: {2}'.format(
            cmd_str, run_args, msg)
        log.error(ret)
    else:
        try:
            ret = res['stdout']
        except KeyError:
            log.error(
                "cmd.run_all did not return a dictionary with a key named 'stdout'"
            )
    return ret
예제 #2
0
def _wrapper(orig, pre='', post='', err_=None, run_args=None, **kwargs):
    '''
    Helper function that wraps the execution of freebsd-update command.

    orig:
        Originating function that called _wrapper().

    pre:
        String that will be prepended to freebsd-update command.

    post:
        String that will be appended to freebsd-update command.

    err_:
        Dictionary on which return codes and stout/stderr are copied.

    run_args:
        Arguments to be passed on cmd.run_all.

    kwargs:
        Parameters of freebsd-update command.
    '''
    ret = ''    # the message to be returned
    cmd = _cmd(**kwargs)
    cmd_str = ' '.join([x for x in (pre, cmd, post, orig)])
    if run_args and isinstance(run_args, dict):
        res = __salt__['cmd.run_all'](cmd_str, **run_args)
    else:
        res = __salt__['cmd.run_all'](cmd_str)

    if isinstance(err_, dict):  # copy return values if asked to
        for k, v in six.itermitems(res):
            err_[k] = v

    if 'retcode' in res and res['retcode'] != 0:
        msg = ' '.join([x for x in (res['stdout'], res['stderr']) if x])
        ret = 'Unable to run "{0}" with run_args="{1}". Error: {2}'.format(cmd_str, run_args, msg)
        log.error(ret)
    else:
        try:
            ret = res['stdout']
        except KeyError:
            log.error("cmd.run_all did not return a dictionary with a key named 'stdout'")
    return ret