Skip to content

Commit

Permalink
[pfsense_interface_group] Fix creation
Browse files Browse the repository at this point in the history
Fixes #74

Check that members list is unique
  • Loading branch information
opoplawski committed Jan 4, 2024
1 parent c8e714f commit b5c56d6
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions plugins/module_utils/interface_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,14 @@ def _validate_params(self):
self.module.fail_json(msg='Group name cannot have more than 15 characters.')
if re.match('[0-9]$', params['name']) is not None:
self.module.fail_json(msg='Group name cannot end with a digit.')
# Make sure list of interfaces is a unique set
if len(params['members']) > len(set(params['members'])):
self.module.fail_json(msg='List of members is not unique.')
# TODO - check that name isn't in use by any interfaces

##############################
# XML processing
#
def _copy_and_add_target(self):
""" create the XML target_elt """
self.pfsense.copy_dict_to_element(self.obj, self.target_elt)

def _copy_and_update_target(self):
""" update the XML target_elt """
before = self.pfsense.element_to_dict(self.target_elt)
changed = self.pfsense.copy_dict_to_element(self.obj, self.target_elt)
if self._remove_deleted_params():
changed = True

self.diff['before'] = before
if changed:
self.diff['after'] = self.pfsense.element_to_dict(self.target_elt)
self.result['changed'] = True
else:
self.diff['after'] = self.obj

return (before, changed)

def _create_target(self):
""" create the XML target_elt """
self.diff['before'] = ''
Expand All @@ -110,8 +93,13 @@ def _create_target(self):

def _find_target(self):
""" find the XML target_elt """
target_elt = self.root_elt.findall("ifgroupentry[ifname='{0}']".format(self.obj['ifname']))[0]
return target_elt
result = self.root_elt.findall("ifgroupentry[ifname='{0}']".format(self.obj['ifname']))
if len(result) == 1:
return result[0]
elif len(result) > 1:
self.module.fail_json(msg='Found multiple interface groups for name {0}.'.format(self.obj['ifname']))
else:
return None

def _pre_remove_target_elt(self):
""" processing before removing elt """
Expand Down

0 comments on commit b5c56d6

Please sign in to comment.