Browse Source

Handle test mode when enabling ufw

tags/v0.2.0
Alexandre Anriot 6 years ago
parent
commit
c60bc71357
2 changed files with 12 additions and 7 deletions
  1. +8
    -3
      _modules/ufw.py
  2. +4
    -4
      _states/ufw.py

+ 8
- 3
_modules/ufw.py View File

@@ -22,14 +22,19 @@ def get_default_outgoing():
return policy

def set_enabled(enabled):
cmd = 'ufw --force enable' if enabled else 'ufw disable'
if __opts__['test']:
cmd = "ufw --dry-run "
else:
cmd = "ufw "
cmd += '--force enable' if enabled else 'disable'
__salt__['cmd.run'](cmd)

def add_rule(rule):
if __opts__['test']:
cmd = "ufw --dry-run " + rule
cmd = "ufw --dry-run "
else:
cmd = "ufw " + rule
cmd = "ufw "
cmd += rule
out = __salt__['cmd.run'](cmd, python_shell=True)
return out


+ 4
- 4
_states/ufw.py View File

@@ -84,15 +84,15 @@ def enabled(name, **kwargs):
if __salt__['ufw.is_enabled']():
return _unchanged(name, "UFW is already enabled")

if __opts__['test']:
return _test(name, "UFW will be enabled")

try:
__salt__['ufw.set_enabled'](True)
except (CommandExecutionError, CommandNotFoundError) as e:
return _error(name, e.message)

return _changed(name, "UFW is enabled", enabled=True)
if __opts__['test']:
return _test(name, "UFW would have been enabled")
else:
return _changed(name, "UFW is enabled", enabled=True)


def default_incoming(name, default):

Loading…
Cancel
Save