Older versions of ipset don't support comments

This should also fix a problem where the module will report incorrectly if there
isn't a comment.
This commit is contained in:
justinta89 2016-01-14 16:12:10 -07:00
parent e77585de17
commit 67d4997316

View file

@ -425,11 +425,16 @@ def check(set=None, entry=None, family='ipv4'):
else:
_entry = entry.split()[0]
_entry_extra = entry.split()[1:]
if _entry.find('-') != -1 and _entry.count('-') == 1:
start, end = _entry.split('-')
if entry.find('-') != -1 and entry.count('-') == 1:
start, end = entry.split('-')
if settype == 'hash:ip':
entries = [' '.join([str(ipaddress.ip_address(ip)), ' '.join(_entry_extra)]) for ip in range(
if _entry_extra:
entries = [' '.join([str(ipaddress.ip_address(ip)), ' '.join(_entry_extra)]) for ip in range(
ipaddress.ip_address(start),
ipaddress.ip_address(end) + 1
)]
entries = [' '.join([str(ipaddress.ip_address(ip))]) for ip in range(
ipaddress.ip_address(start),
ipaddress.ip_address(end) + 1
)]
@ -439,22 +444,31 @@ def check(set=None, entry=None, family='ipv4'):
ipaddress.ip_address(end))
entries = []
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)])
if _entry_extra:
__network = ' '.join([str(_network[0]), ' '.join(_entry_extra)])
__network = ' '.join([str(_network[0])])
else:
__network = ' '.join([str(network), ' '.join(_entry_extra)])
if _entry_extra:
__network = ' '.join([str(network), ' '.join(_entry_extra)])
__network = ' '.join([str(network)])
entries.append(__network)
else:
entries = [entry]
elif _entry.find('/') != -1 and _entry.count('/') == 1:
if settype == 'hash:ip':
entries = [' '.join([str(ip), ' '.join(_entry_extra)]) for ip in ipaddress.ip_network(_entry)]
if _entry_extra:
entries = [' '.join([str(ip), ' '.join(_entry_extra)]) for ip in ipaddress.ip_network(_entry)]
entries = [' '.join([str(ip)]) for ip in ipaddress.ip_network(_entry)]
elif settype == 'hash:net':
_entries = [str(ip) for ip in ipaddress.ip_network(_entry)]
if len(_entries) == 1:
entries = [' '.join([_entries[0], ' '.join(_entry_extra)])]
if _entry_extra:
entries = [' '.join([_entries[0], ' '.join(_entry_extra)])]
entries = [' '.join([_entries[0]])]
else:
entries = [entry]
else: