Skip to content

Commit

Permalink
Merge pull request #34232 from thegoodduke/for_2015.5_ipset
Browse files Browse the repository at this point in the history
ipset: fix commont containing blank
  • Loading branch information
Mike Place committed Jun 23, 2016
2 parents 5411ebb + 344eb60 commit cb1e8bf
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions salt/states/ipset.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ def present(name, entry=None, family='ipv4', **kwargs):
'''
ret = {'name': name,
'changes': {},
'result': None,
'result': True,
'comment': ''}
test_flag = False

if not entry:
ret['result'] = False
Expand All @@ -198,25 +197,24 @@ def present(name, entry=None, family='ipv4', **kwargs):
entries.append(entry)

for entry in entries:
_entry = '{0}'.format(entry)
if 'timeout' in kwargs:
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'])
entry_opts = ''
if ' ' in entry:
entry, entry_opts = entry.split(' ', 1)
if 'timeout' in kwargs and 'timeout' not in entry_opts:
entry_opts = 'timeout {0} {1}'.format(kwargs['timeout'], entry_opts)
if 'comment' in kwargs and 'comment' not in entry_opts:
entry_opts = '{0} comment "{1}"'.format(entry_opts, kwargs['comment'])
_entry = ' '.join([entry, entry_opts]).strip()

if __salt__['ipset.check'](kwargs['set_name'],
_entry,
family) is True:
if test_flag is False:
ret['result'] = True
ret['comment'] += 'entry for {0} already in set ({1}) for {2}\n'.format(
entry,
kwargs['set_name'],
family)
else:
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(
entry,
Expand All @@ -226,7 +224,6 @@ def present(name, entry=None, family='ipv4', **kwargs):
command = __salt__['ipset.add'](kwargs['set_name'], entry, family, **kwargs)
if 'Error' not in command:
ret['changes'] = {'locale': name}
ret['result'] = True
ret['comment'] += 'entry {0} added to set {1} for family {2}\n'.format(
kwargs['set_name'],
_entry,
Expand Down Expand Up @@ -255,7 +252,7 @@ def absent(name, entry=None, entries=None, family='ipv4', **kwargs):
'''
ret = {'name': name,
'changes': {},
'result': None,
'result': True,
'comment': ''}

if not entry:
Expand All @@ -270,23 +267,27 @@ def absent(name, entry=None, entries=None, family='ipv4', **kwargs):
entries.append(entry)

for entry in entries:
_entry = '{0}'.format(entry)

if 'comment' in kwargs:
_entry = '{0} comment "{1}"'.format(entry, kwargs['comment'])
entry_opts = ''
if ' ' in entry:
entry, entry_opts = entry.split(' ', 1)
if 'timeout' in kwargs and 'timeout' not in entry_opts:
entry_opts = 'timeout {0} {1}'.format(kwargs['timeout'], entry_opts)
if 'comment' in kwargs and 'comment' not in entry_opts:
entry_opts = '{0} comment "{1}"'.format(entry_opts, kwargs['comment'])
_entry = ' '.join([entry, entry_opts]).strip()

log.debug('_entry {0}'.format(_entry))
if not __salt__['ipset.check'](kwargs['set_name'],
_entry,
family) is True:
ret['result'] = True
ret['comment'] += 'ipset entry for {0} not present in set ({1}) for {2}\n'.format(
_entry,
kwargs['set_name'],
family)
else:

if __opts__['test']:
ret['result'] = None
ret['comment'] += 'ipset entry {0} needs to removed from set {1} for family {2}\n'.format(
entry,
kwargs['set_name'],
Expand All @@ -295,7 +296,6 @@ def absent(name, entry=None, entries=None, family='ipv4', **kwargs):
command = __salt__['ipset.delete'](kwargs['set_name'], entry, family, **kwargs)
if 'Error' not in command:
ret['changes'] = {'locale': name}
ret['result'] = True
ret['comment'] += 'ipset entry {1} for set {0} removed for family {2}\n'.format(
kwargs['set_name'],
_entry,
Expand Down

0 comments on commit cb1e8bf

Please sign in to comment.