diff --git a/plugins/module_utils/interface_group.py b/plugins/module_utils/interface_group.py index 2021488e..bffd4b07 100644 --- a/plugins/module_utils/interface_group.py +++ b/plugins/module_utils/interface_group.py @@ -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'] = '' @@ -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 """