Bladeren bron

Handle test mode when enabling ufw

tags/v0.2.0
Alexandre Anriot 6 jaren geleden
bovenliggende
commit
c60bc71357
2 gewijzigde bestanden met toevoegingen van 12 en 7 verwijderingen
  1. +8
    -3
      _modules/ufw.py
  2. +4
    -4
      _states/ufw.py

+ 8
- 3
_modules/ufw.py Bestand weergeven

@@ -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 Bestand weergeven

@@ -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):

Laden…
Annuleren
Opslaan