Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix creating of interface groups #100

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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