mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Merge pull request #13417 from techhat/iptables
Check for iptables before trying to run iptables
This commit is contained in:
commit
94bee6758a
@ -14,20 +14,16 @@ import salt.utils
|
||||
from salt.state import STATE_INTERNAL_KEYWORDS as _STATE_INTERNAL_KEYWORDS
|
||||
from salt.exceptions import SaltException
|
||||
import salt.modules.cmdmod as salt_cmd
|
||||
HAS_CHECK = False
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Only load the module if iptables is installed
|
||||
'''
|
||||
global HAS_CHECK
|
||||
if '--check' in salt_cmd.run('iptables --help', output_loglevel='quiet'):
|
||||
HAS_CHECK = True
|
||||
if not salt.utils.which('iptables'):
|
||||
return False
|
||||
|
||||
if salt.utils.which('iptables'):
|
||||
return True
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def _iptables_cmd(family='ipv4'):
|
||||
@ -484,6 +480,9 @@ def check(table='filter', chain=None, rule=None, family='ipv4'):
|
||||
if not rule:
|
||||
return 'Error: Rule needs to be specified'
|
||||
|
||||
if '--check' in salt_cmd.run('iptables --help', output_loglevel='quiet'):
|
||||
HAS_CHECK = True
|
||||
|
||||
if HAS_CHECK is False:
|
||||
cmd = '{0}-save' . format(_iptables_cmd(family))
|
||||
out = __salt__['cmd.run'](cmd).find('-A {1} {2}'.format(
|
||||
|
Loading…
Reference in New Issue
Block a user