mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #30170 from thegoodduke/for_ipset
ipset: fix comment and test
This commit is contained in:
commit
786cf61dc4
@ -430,11 +430,13 @@ def check(set=None, entry=None, family='ipv4'):
|
|||||||
if isinstance(entry, list):
|
if isinstance(entry, list):
|
||||||
entries = entry
|
entries = entry
|
||||||
else:
|
else:
|
||||||
if entry.find('-') != -1 and entry.count('-') == 1:
|
_entry = entry.split()[0]
|
||||||
start, end = entry.split('-')
|
_entry_extra = entry.split()[1:]
|
||||||
|
if _entry.find('-') != -1 and _entry.count('-') == 1:
|
||||||
|
start, end = _entry.split('-')
|
||||||
|
|
||||||
if settype == 'hash:ip':
|
if settype == 'hash:ip':
|
||||||
entries = [str(ipaddress.ip_address(ip)) for ip in long_range(
|
entries = [' '.join([str(ipaddress.ip_address(ip)), ' '.join(_entry_extra)]) for ip in long_range(
|
||||||
ipaddress.ip_address(start),
|
ipaddress.ip_address(start),
|
||||||
ipaddress.ip_address(end) + 1
|
ipaddress.ip_address(end) + 1
|
||||||
)]
|
)]
|
||||||
@ -444,17 +446,22 @@ def check(set=None, entry=None, family='ipv4'):
|
|||||||
ipaddress.ip_address(end))
|
ipaddress.ip_address(end))
|
||||||
entries = []
|
entries = []
|
||||||
for network in networks:
|
for network in networks:
|
||||||
entries.append(network.with_prefixlen)
|
_network = [str(ip) for ip in ipaddress.ip_network(network)]
|
||||||
|
if len(_network) == 1:
|
||||||
|
__network = ' '.join([str(_network[0]), ' '.join(_entry_extra)])
|
||||||
|
else:
|
||||||
|
__network = ' '.join([str(network), ' '.join(_entry_extra)])
|
||||||
|
entries.append(__network)
|
||||||
else:
|
else:
|
||||||
entries = [entry]
|
entries = [entry]
|
||||||
|
|
||||||
elif entry.find('/') != -1 and entry.count('/') == 1:
|
elif _entry.find('/') != -1 and _entry.count('/') == 1:
|
||||||
if settype == 'hash:ip':
|
if settype == 'hash:ip':
|
||||||
entries = [str(ip) for ip in ipaddress.ip_network(entry)]
|
entries = [' '.join([str(ip), ' '.join(_entry_extra)]) for ip in ipaddress.ip_network(_entry)]
|
||||||
elif settype == 'hash:net':
|
elif settype == 'hash:net':
|
||||||
_entries = [str(ip) for ip in ipaddress.ip_network(entry)]
|
_entries = [str(ip) for ip in ipaddress.ip_network(_entry)]
|
||||||
if len(_entries) == 1:
|
if len(_entries) == 1:
|
||||||
entries = [_entries[0]]
|
entries = [' '.join([_entries[0], ' '.join(_entry_extra)])]
|
||||||
else:
|
else:
|
||||||
entries = [entry]
|
entries = [entry]
|
||||||
else:
|
else:
|
||||||
|
@ -184,6 +184,7 @@ def present(name, entry=None, family='ipv4', **kwargs):
|
|||||||
'changes': {},
|
'changes': {},
|
||||||
'result': None,
|
'result': None,
|
||||||
'comment': ''}
|
'comment': ''}
|
||||||
|
test_flag = False
|
||||||
|
|
||||||
if not entry:
|
if not entry:
|
||||||
ret['result'] = False
|
ret['result'] = False
|
||||||
@ -198,19 +199,25 @@ def present(name, entry=None, family='ipv4', **kwargs):
|
|||||||
|
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
_entry = '{0}'.format(entry)
|
_entry = '{0}'.format(entry)
|
||||||
if 'comment' in kwargs:
|
if 'timeout' in kwargs:
|
||||||
_entry = '{0} comment "{1}"'.format(entry, kwargs['comment'])
|
if 'comment' in _entry:
|
||||||
|
_entry = '{0} timeout {1} {2} {3}'.format(entry.split()[0], kwargs['timeout'], entry.split()[1], entry.split()[2])
|
||||||
|
else:
|
||||||
|
_entry = '{0} timeout {1}'.format(entry.split()[0], kwargs['timeout'])
|
||||||
|
|
||||||
if __salt__['ipset.check'](kwargs['set_name'],
|
if __salt__['ipset.check'](kwargs['set_name'],
|
||||||
_entry,
|
_entry,
|
||||||
family) is True:
|
family) is True:
|
||||||
ret['result'] = True
|
if test_flag is False:
|
||||||
|
ret['result'] = True
|
||||||
ret['comment'] += 'entry for {0} already in set ({1}) for {2}\n'.format(
|
ret['comment'] += 'entry for {0} already in set ({1}) for {2}\n'.format(
|
||||||
entry,
|
entry,
|
||||||
kwargs['set_name'],
|
kwargs['set_name'],
|
||||||
family)
|
family)
|
||||||
else:
|
else:
|
||||||
if __opts__['test']:
|
if __opts__['test']:
|
||||||
|
test_flag = True
|
||||||
|
ret['result'] = None
|
||||||
ret['comment'] += 'entry {0} needs to be added to set {1} for family {2}\n'.format(
|
ret['comment'] += 'entry {0} needs to be added to set {1} for family {2}\n'.format(
|
||||||
entry,
|
entry,
|
||||||
kwargs['set_name'],
|
kwargs['set_name'],
|
||||||
|
Loading…
Reference in New Issue
Block a user