def assign(name, value):
    '''
    Assign a single sysctl parameter for this minion

    CLI Example:

    .. code-block:: bash

        salt '*' sysctl.assign net.ipv4.ip_forward 1
    '''
    value = six.text_type(value)

    if six.PY3:
        tran_tab = name.translate(''.maketrans('./', '/.'))
    else:
        if isinstance(name, unicode):  # pylint: disable=incompatible-py3-code,undefined-variable
            trans_args = {ord('/'): u'.', ord('.'): u'/'}
        else:
            trans_args = string.maketrans('./', '/.')
        tran_tab = name.translate(trans_args)

    sysctl_file = '/proc/sys/{0}'.format(tran_tab)
    if not os.path.exists(sysctl_file):
        raise CommandExecutionError('sysctl {0} does not exist'.format(name))

    ret = {}
    cmd = 'sysctl -w {0}="{1}"'.format(name, value)
    data = __salt__['cmd.run_all'](cmd, python_shell=False)
    out = data['stdout']
    err = data['stderr']

    # Example:
    #    # sysctl -w net.ipv4.tcp_rmem="4096 87380 16777216"
    #    net.ipv4.tcp_rmem = 4096 87380 16777216
    regex = re.compile(r'^{0}\s+=\s+{1}$'.format(re.escape(name), re.escape(value)))

    if not regex.match(out) or 'Invalid argument' in six.text_type(err):
        if data['retcode'] != 0 and err:
            error = err
        else:
            error = out
        raise CommandExecutionError('sysctl -w failed: {0}'.format(error))
    new_name, new_value = out.split(' = ', 1)
    ret[new_name] = new_value
    return ret
def assign ( name , value ) : value = six . text_type ( value ) if six . PY3 : tran_tab = name . translate ( '' . maketrans ( './' , '/.' ) ) else : if isinstance ( name , unicode ) : trans_args = { ord ( '/' ) : u'.' , ord ( '.' ) : u'/' } else : trans_args = string . maketrans ( './' , '/.' ) tran_tab = name . translate ( trans_args ) sysctl_file = '/proc/sys/{0}' . format ( tran_tab ) if not os . path . exists ( sysctl_file ) : raise CommandExecutionError ( 'sysctl {0} does not exist' . format ( name ) ) ret = { } cmd = 'sysctl -w {0}="{1}"' . format ( name , value ) data = __salt__ [ 'cmd.run_all' ] ( cmd , python_shell = False ) out = data [ 'stdout' ] err = data [ 'stderr' ] regex = re . compile ( r'^{0}\s+=\s+{1}$' . format ( re . escape ( name ) , re . escape ( value ) ) ) if not regex . match ( out ) or 'Invalid argument' in six . text_type ( err ) : if data [ 'retcode' ] != 0 and err : error = err else : error = out raise CommandExecutionError ( 'sysctl -w failed: {0}' . format ( error ) ) new_name , new_value = out . split ( ' = ' , 1 ) ret [ new_name ] = new_value return ret
Assign a single sysctl parameter for this minion

    CLI Example:

    .. code-block:: bash

        salt '*' sysctl.assign net.ipv4.ip_forward 1