|
Added
Link Here
|
| 1 |
--- salt/modules/linux_sysctl.py.orig 2020-06-17 18:05:55 UTC |
| 2 |
+++ salt/modules/linux_sysctl.py |
| 3 |
@@ -66,8 +66,8 @@ def show(config_file=False): |
| 4 |
""" |
| 5 |
Return a list of sysctl parameters for this minion |
| 6 |
|
| 7 |
- :param config_file: Pull data from the system configuration file |
| 8 |
- instead of the live kernel. |
| 9 |
+ config: Pull the data from the system configuration file |
| 10 |
+ instead of the live data. |
| 11 |
|
| 12 |
CLI Example: |
| 13 |
|
| 14 |
@@ -108,13 +108,10 @@ def show(config_file=False): |
| 15 |
return ret |
| 16 |
|
| 17 |
|
| 18 |
-def get(name, ignore=False): |
| 19 |
+def get(name): |
| 20 |
""" |
| 21 |
Return a single sysctl parameter for this minion |
| 22 |
|
| 23 |
- :param name: Name of sysctl setting |
| 24 |
- :param ignore: Optional boolean to pass --ignore to sysctl (Default: False) |
| 25 |
- |
| 26 |
CLI Example: |
| 27 |
|
| 28 |
.. code-block:: bash |
| 29 |
@@ -122,20 +119,14 @@ def get(name, ignore=False): |
| 30 |
salt '*' sysctl.get net.ipv4.ip_forward |
| 31 |
""" |
| 32 |
cmd = "sysctl -n {0}".format(name) |
| 33 |
- if ignore: |
| 34 |
- cmd += " --ignore" |
| 35 |
out = __salt__["cmd.run"](cmd, python_shell=False) |
| 36 |
return out |
| 37 |
|
| 38 |
|
| 39 |
-def assign(name, value, ignore=False): |
| 40 |
+def assign(name, value): |
| 41 |
""" |
| 42 |
Assign a single sysctl parameter for this minion |
| 43 |
|
| 44 |
- :param name: Name of sysctl setting |
| 45 |
- :param value: Desired value of sysctl setting |
| 46 |
- :param ignore: Optional boolean to pass --ignore to sysctl (Default: False) |
| 47 |
- |
| 48 |
CLI Example: |
| 49 |
|
| 50 |
.. code-block:: bash |
| 51 |
@@ -156,13 +147,11 @@ def assign(name, value, ignore=False): |
| 52 |
tran_tab = name.translate(trans_args) |
| 53 |
|
| 54 |
sysctl_file = "/proc/sys/{0}".format(tran_tab) |
| 55 |
- if not ignore and not os.path.exists(sysctl_file): |
| 56 |
+ if not os.path.exists(sysctl_file): |
| 57 |
raise CommandExecutionError("sysctl {0} does not exist".format(name)) |
| 58 |
|
| 59 |
ret = {} |
| 60 |
cmd = 'sysctl -w {0}="{1}"'.format(name, value) |
| 61 |
- if ignore: |
| 62 |
- cmd += " --ignore" |
| 63 |
data = __salt__["cmd.run_all"](cmd, python_shell=False) |
| 64 |
out = data["stdout"] |
| 65 |
err = data["stderr"] |
| 66 |
@@ -175,9 +164,6 @@ def assign(name, value, ignore=False): |
| 67 |
if not regex.match(out) or "Invalid argument" in six.text_type(err): |
| 68 |
if data["retcode"] != 0 and err: |
| 69 |
error = err |
| 70 |
- elif ignore: |
| 71 |
- ret[name] = "ignored" |
| 72 |
- return ret |
| 73 |
else: |
| 74 |
error = out |
| 75 |
raise CommandExecutionError("sysctl -w failed: {0}".format(error)) |
| 76 |
@@ -186,17 +172,12 @@ def assign(name, value, ignore=False): |
| 77 |
return ret |
| 78 |
|
| 79 |
|
| 80 |
-def persist(name, value, config=None, ignore=False): |
| 81 |
+def persist(name, value, config=None): |
| 82 |
""" |
| 83 |
Assign and persist a simple sysctl parameter for this minion. If ``config`` |
| 84 |
is not specified, a sensible default will be chosen using |
| 85 |
:mod:`sysctl.default_config <salt.modules.linux_sysctl.default_config>`. |
| 86 |
|
| 87 |
- :param name: Name of sysctl setting |
| 88 |
- :param value: Desired value of sysctl setting |
| 89 |
- :param config: Optional path to sysctl.conf |
| 90 |
- :param ignore: Optional boolean to pass --ignore to sysctl (Default: False) |
| 91 |
- |
| 92 |
CLI Example: |
| 93 |
|
| 94 |
.. code-block:: bash |
| 95 |
@@ -259,11 +240,8 @@ def persist(name, value, config=None, ignore=False): |
| 96 |
# This is the line to edit |
| 97 |
if six.text_type(comps[1]) == six.text_type(value): |
| 98 |
# It is correct in the config, check if it is correct in /proc |
| 99 |
- current_setting = get(name, ignore) |
| 100 |
- if not current_setting: |
| 101 |
- return "Ignored" |
| 102 |
- if six.text_type(current_setting) != six.text_type(value): |
| 103 |
- assign(name, value, ignore) |
| 104 |
+ if six.text_type(get(name)) != six.text_type(value): |
| 105 |
+ assign(name, value) |
| 106 |
return "Updated" |
| 107 |
else: |
| 108 |
return "Already set" |
| 109 |
@@ -282,5 +260,5 @@ def persist(name, value, config=None, ignore=False): |
| 110 |
msg = "Could not write to file: {0}" |
| 111 |
raise CommandExecutionError(msg.format(config)) |
| 112 |
|
| 113 |
- assign(name, value, ignore) |
| 114 |
+ assign(name, value) |
| 115 |
return "Updated" |