diff --git a/plugins/module_utils/firewall_alias_utils.py b/plugins/module_utils/firewall_alias_utils.py index ec76f6c5..2f03933e 100644 --- a/plugins/module_utils/firewall_alias_utils.py +++ b/plugins/module_utils/firewall_alias_utils.py @@ -19,7 +19,7 @@ from ansible_collections.puzzle.opnsense.plugins.module_utils.system_access_users_utils import ( Group, ) -from ansible_collections.puzzle.opnsense.plugins.module_utils.interfaces_configuration_utils import ( # pylint: disable=C0301 +from ansible_collections.puzzle.opnsense.plugins.module_utils.interfaces_configuration_utils import ( # pylint: disable=C0301 InterfacesSet, ) from ansible_collections.puzzle.opnsense.plugins.module_utils.enum_utils import ListEnum @@ -109,7 +109,6 @@ class FirewallAlias: # pylint: disable=too-many-instance-attributes def __init__(self, **kwargs): - # set default attributes self.uuid: Optional[str] = kwargs.get("uuid", str(uuid.uuid4())) self.enabled: bool = True @@ -135,7 +134,6 @@ def __post_init__(self): # Check if the value is a string and the field_type is a subclass of ListEnum if isinstance(value, str) and issubclass(field_type, ListEnum): - # Convert string to ListEnum setattr(self, field_name, field_type.from_string(value)) @@ -270,7 +268,6 @@ def to_etree(self) -> Element: del firewall_alias_dict["uuid"] for alias_key, alias_val in firewall_alias_dict.copy().items(): - if alias_key in ["enabled", "counters"]: firewall_alias_dict[alias_key] = "0" if alias_val is False else "1" continue @@ -504,7 +501,6 @@ def set_authgroup(self, type_opnvpngroup_alias: FirewallAlias) -> None: gid_content = [] for group in type_opnvpngroup_alias.content: - gid_content.append( next((g for g in self.group_list if g.name == group), None).gid ) @@ -608,7 +604,6 @@ def validate_content( } for content_value in content_values: - # since not all types need validation, unhandled types are ingnored if not content_type_map.get(content_type.value): return True @@ -618,7 +613,6 @@ def validate_content( ) if not validation_function(content_value): - raise OPNsenseContentValidationError( content_type_map[content_type.value]["error_message"].format( entry=content_value diff --git a/plugins/module_utils/interfaces_configuration_utils.py b/plugins/module_utils/interfaces_configuration_utils.py index 8b6dd631..fc49c292 100644 --- a/plugins/module_utils/interfaces_configuration_utils.py +++ b/plugins/module_utils/interfaces_configuration_utils.py @@ -18,21 +18,26 @@ from ansible_collections.puzzle.opnsense.plugins.module_utils.config_utils import ( OPNsenseModuleConfig, ) + + class OPNSenseDeviceNotFoundError(Exception): """ Exception raised when a Device is not found. """ + class OPNSenseDeviceAlreadyAssignedError(Exception): """ Exception raised when a Device is already assigned to an Interface """ + class OPNSenseInterfaceNotFoundError(Exception): """ Exception raised when an Interface is not found. """ + class OPNSenseGetInterfacesError(Exception): """ Exception raised if the function can't query the local device @@ -100,12 +105,11 @@ def from_xml(element: Element) -> "InterfaceConfiguration": # Create the InterfaceConfiguration instance interface_configuration = InterfaceConfiguration( identifier=identifier, - extra_attrs=extra_attrs # Include all other attributes + extra_attrs=extra_attrs, # Include all other attributes ) return interface_configuration - def to_etree(self) -> Element: """ Serializes the instance to an XML Element, including extra attributes. @@ -124,8 +128,6 @@ def to_etree(self) -> Element: # Create the main element main_element = Element(interface_configuration_dict["identifier"]) - # Serialize the device to ensure it is always present - #SubElement(main_element, "if").text = interface_configuration_dict["extra_attrs"].get("if") # Serialize extra attributes for key, value in interface_configuration_dict["extra_attrs"].items(): @@ -160,7 +162,7 @@ def from_ansible_module_params(cls, params: dict) -> "InterfaceConfiguration": elif value is not None: extra_attrs[key] = str(value) - return cls(identifier,extra_attrs) + return cls(identifier, extra_attrs) class InterfacesSet(OPNsenseModuleConfig): @@ -197,7 +199,6 @@ def __init__(self, path: str = "/conf/config.xml"): self._interfaces_configuration = self._load_interfaces() def _load_interfaces(self) -> List["InterfaceConfiguration"]: - element_tree_interfaces: Element = self.get("interfaces") return [ @@ -225,8 +226,10 @@ def changed(self) -> bool: return True for current, saved in zip(current_interfaces, saved_interfaces): - if current.identifier != saved.identifier or \ - current.extra_attrs != saved.extra_attrs: + if ( + current.identifier != saved.identifier + or current.extra_attrs != saved.extra_attrs + ): return True return False @@ -321,14 +324,20 @@ def add_or_update(self, interface_configuration: InterfaceConfiguration) -> None # Merge extra_attrs for attr, value in interface_configuration.extra_attrs.items(): if attr == "if" and value not in device_interfaces_set: - raise OPNSenseInterfaceNotFoundError("Interface was not found on OPNsense Instance!") # pylint: disable=C0301 + raise OPNSenseInterfaceNotFoundError( + "Interface was not found on OPNsense Instance!" + ) # pylint: disable=C0301 interface_to_update.extra_attrs[attr] = value else: - raise OPNSenseDeviceAlreadyAssignedError("This device is already assigned, please unassign this device first") # pylint: disable=C0301 + raise OPNSenseDeviceAlreadyAssignedError( + "This device is already assigned, please unassign this device first" + ) # pylint: disable=C0301 # Update the internal list with the complete updated configuration self._interfaces_configuration = [ - interface_to_update if iface.identifier == interface_to_update.identifier else iface + interface_to_update + if iface.identifier == interface_to_update.identifier + else iface for iface in self._interfaces_configuration ] else: @@ -341,7 +350,9 @@ def add_or_update(self, interface_configuration: InterfaceConfiguration) -> None if value: interface_to_add.extra_attrs.update({attr: value}) if interface_to_add.extra_attrs["if"] not in device_interfaces_set: - raise OPNSenseInterfaceNotFoundError("Interface was not found on OPNsense Instance!") # pylint: disable=C0301 + raise OPNSenseInterfaceNotFoundError( + "Interface was not found on OPNsense Instance!" + ) # pylint: disable=C0301 self._interfaces_configuration.append(interface_to_add) def remove(self, interface_configuration: InterfaceConfiguration) -> None: @@ -357,7 +368,9 @@ def remove(self, interface_configuration: InterfaceConfiguration) -> None: if interface_configuration in self._interfaces_configuration: self._interfaces_configuration.remove(interface_configuration) else: - raise OPNSenseInterfaceNotFoundError(f"Interface {interface_configuration.identifier} not found.") # pylint: disable=C0301 + raise OPNSenseInterfaceNotFoundError( + f"Interface {interface_configuration.identifier} not found." + ) # pylint: disable=C0301 def find(self, **kwargs) -> Optional[InterfaceConfiguration]: """ diff --git a/plugins/modules/firewall_alias.py b/plugins/modules/firewall_alias.py index 1f76b75c..ffd3fbab 100644 --- a/plugins/modules/firewall_alias.py +++ b/plugins/modules/firewall_alias.py @@ -286,7 +286,6 @@ def main(): ansible_alias_state: str = module.params.get("state") with FirewallAliasSet() as alias_set: - if ansible_alias_state == "present": alias_set.add_or_update(ansible_alias) else: diff --git a/plugins/modules/interfaces_configuration.py b/plugins/modules/interfaces_configuration.py index a5b97cab..7bf7f3c9 100644 --- a/plugins/modules/interfaces_configuration.py +++ b/plugins/modules/interfaces_configuration.py @@ -520,7 +520,7 @@ import ipaddress from ansible.module_utils.basic import AnsibleModule -from ansible_collections.puzzle.opnsense.plugins.module_utils.interfaces_configuration_utils import ( # pylint: disable=C0301 +from ansible_collections.puzzle.opnsense.plugins.module_utils.interfaces_configuration_utils import ( # pylint: disable=C0301 InterfacesSet, InterfaceConfiguration, OPNSenseDeviceNotFoundError, @@ -528,6 +528,7 @@ OPNSenseGetInterfacesError, ) + def validate_ipaddr_and_subnet(ipaddr, subnet): """ Validates the given IP address and subnet. @@ -557,6 +558,7 @@ def validate_ipaddr_and_subnet(ipaddr, subnet): except ValueError as e: raise ValueError(f"Invalid value for ipaddr or subnet: {e}") from e + # Function to convert aliases to base arguments def convert_aliases(args, alias_map): """ @@ -575,6 +577,7 @@ def convert_aliases(args, alias_map): converted_args[base_key] = value return converted_args + def filter_explicitly_set_params(params, module_args): """ Filters out parameters that are not explicitly set by the user. @@ -588,412 +591,361 @@ def filter_explicitly_set_params(params, module_args): """ explicitly_set_params = {} for key, value in params.items(): - if key in module_args and params[key] != module_args[key].get('default', None): + if key in module_args and params[key] != module_args[key].get("default", None): explicitly_set_params[key] = value return explicitly_set_params + def main(): """ Main function of the interfaces_configuration module """ module_args = { - "identifier": { - "type": "str", - "description": "Technical identifier of the interface, used by hasync for example", - }, - "adv_dhcp6_authentication_statement_algorithm": { - "type": "str", - "required": False, - "aliases": ["dhcp6_authentication_algorithm"] - }, - "adv_dhcp6_authentication_statement_authname": { - "type": "str", - "required": False, - "aliases": ["dhcp6_authentication_authname"] - }, - "adv_dhcp6_authentication_statement_protocol": { - "type": "str", - "required": False, - "aliases": ["dhcp6_authentication_protocol"] - }, - "adv_dhcp6_authentication_statement_rdm": { - "type": "str", - "required": False, - "aliases": ["dhcp6_authentication_rdm"] - }, - "adv_dhcp6_config_advanced": { - "type": "bool", - "required": False, - "aliases": ["dhcp6_config_advanced"] - }, - "adv_dhcp6_config_file_override": { - "type": "bool", - "required": False, - "aliases": ["dhcp6_config_file_override"] - }, - "adv_dhcp6_config_file_override_path": { - "type": "str", - "required": False, - "aliases": ["dhcp6_config_file_override_path"] - }, - "adv_dhcp6_id_assoc_statement_address": { - "type": "str", - "required": False, - "aliases": ["dhcp6_id_assoc_address"] - }, - "adv_dhcp6_id_assoc_statement_address_enable": { - "type": "bool", - "required": False, - "aliases": ["dhcp6_id_assoc_address_enable"] - }, - "adv_dhcp6_id_assoc_statement_address_id": { - "type": "int", - "required": False, - "aliases": ["dhcp6_id_assoc_address_id"] - }, - "adv_dhcp6_id_assoc_statement_address_pltime": { - "type": "int", - "required": False, - "aliases": ["dhcp6_id_assoc_address_pltime"] - }, - "adv_dhcp6_id_assoc_statement_address_vltime": { - "type": "int", - "required": False, - "aliases": ["dhcp6_id_assoc_address_vltime"] - }, - "adv_dhcp6_id_assoc_statement_prefix": { - "type": "str", - "required": False, - "aliases": ["dhcp6_id_assoc_prefix"] - }, - "adv_dhcp6_id_assoc_statement_prefix_enable": { - "type": "bool", - "required": False, - "aliases": ["dhcp6_id_assoc_prefix_enable"] - }, - "adv_dhcp6_id_assoc_statement_prefix_id": { - "type": "int", - "required": False, - "aliases": ["dhcp6_id_assoc_prefix_id"] - }, - "adv_dhcp6_id_assoc_statement_prefix_pltime": { - "type": "int", - "required": False, - "aliases": ["dhcp6_id_assoc_prefix_pltime"] - }, - "adv_dhcp6_id_assoc_statement_prefix_vltime": { - "type": "int", - "required": False, - "aliases": ["dhcp6_id_assoc_prefix_vltime"] - }, - "adv_dhcp6_interface_statement_information_only_enable": { - "type": "bool", - "required": False, - "aliases": ["dhcp6_interface_info_only_enable"] - }, - "adv_dhcp6_interface_statement_request_options": { - "type": "str", - "required": False, - "aliases": ["dhcp6_interface_request_options"] - }, - "adv_dhcp6_interface_statement_script": { - "type": "str", - "required": False, - "aliases": ["dhcp6_interface_script"] - }, - "adv_dhcp6_interface_statement_send_options": { - "type": "str", - "required": False, - "aliases": ["dhcp6_interface_send_options"] - }, - "adv_dhcp6_key_info_statement_expire": { - "type": "str", - "required": False, - "aliases": ["dhcp6_key_info_expire"] - }, - "adv_dhcp6_key_info_statement_keyid": { - "type": "int", - "required": False, - "aliases": ["dhcp6_key_info_keyid"] - }, - "adv_dhcp6_key_info_statement_keyname": { - "type": "str", - "required": False, - "aliases": ["dhcp6_key_info_keyname"] - }, - "adv_dhcp6_key_info_statement_realm": { - "type": "str", - "required": False, - "aliases": ["dhcp6_key_info_realm"] - }, - "adv_dhcp6_key_info_statement_secret": { - "type": "str", - "required": False, - "aliases": ["dhcp6_key_info_secret"] - }, - "adv_dhcp6_prefix_interface_statement_sla_len": { - "type": "int", - "required": False, - "aliases": ["dhcp6_prefix_sla_len"] - }, - "adv_dhcp_config_advanced": { - "type": "bool", - "required": False, - "aliases": ["dhcp_config_advanced"] - }, - "adv_dhcp_config_file_override": { - "type": "bool", - "required": False, - "aliases": ["dhcp_config_file_override"] - }, - "adv_dhcp_config_file_override_path": { - "type": "str", - "required": False, - "aliases": ["dhcp_config_file_override_path"] - }, - "adv_dhcp_option_modifiers": { - "type": "str", - "required": False, - "aliases": ["dhcp_option_modifiers"] - }, - "adv_dhcp_pt_backoff_cutoff": { - "type": "int", - "required": False, - "aliases": ["dhcp_pt_backoff_cutoff"] - }, - "adv_dhcp_pt_initial_interval": { - "type": "int", - "required": False, - "aliases": ["dhcp_pt_initial_interval"] - }, - "adv_dhcp_pt_reboot": { - "type": "int", - "required": False, - "aliases": ["dhcp_pt_reboot"] - }, - "adv_dhcp_pt_retry": { - "type": "int", - "required": False, - "aliases": ["dhcp_pt_retry"] - }, - "adv_dhcp_pt_select_timeout": { - "type": "int", - "required": False, - "aliases": ["dhcp_pt_select_timeout"] - }, - "adv_dhcp_pt_timeout": { - "type": "int", - "required": False, - "aliases": ["dhcp_pt_timeout"] - }, - "adv_dhcp_pt_values": { - "type": "str", - "required": False, - "aliases": ["dhcp_pt_values"] - }, - "adv_dhcp_request_options": { - "type": "str", - "required": False, - "aliases": ["dhcp_request_options"] - }, - "adv_dhcp_required_options": { - "type": "str", - "required": False, - "aliases": ["dhcp_required_options"] - }, - "adv_dhcp_send_options": { - "type": "str", - "required": False, - "aliases": ["dhcp_send_options"] - }, - "alias_address": { - "type": "str", - "required": False, - "aliases": ["alias_address"] - }, - "alias_subnet": { - "type": "int", - "required": False, - "aliases": ["alias_subnet"] - }, - "blockprivate": { - "type": "bool", - "required": False, - "aliases": ["block_private"] - }, - "blockbogons": { + "identifier": { + "type": "str", + "description": "Technical identifier of the interface, used by hasync for example", + }, + "adv_dhcp6_authentication_statement_algorithm": { + "type": "str", + "required": False, + "aliases": ["dhcp6_authentication_algorithm"], + }, + "adv_dhcp6_authentication_statement_authname": { + "type": "str", + "required": False, + "aliases": ["dhcp6_authentication_authname"], + }, + "adv_dhcp6_authentication_statement_protocol": { + "type": "str", + "required": False, + "aliases": ["dhcp6_authentication_protocol"], + }, + "adv_dhcp6_authentication_statement_rdm": { + "type": "str", + "required": False, + "aliases": ["dhcp6_authentication_rdm"], + }, + "adv_dhcp6_config_advanced": { + "type": "bool", + "required": False, + "aliases": ["dhcp6_config_advanced"], + }, + "adv_dhcp6_config_file_override": { + "type": "bool", + "required": False, + "aliases": ["dhcp6_config_file_override"], + }, + "adv_dhcp6_config_file_override_path": { + "type": "str", + "required": False, + "aliases": ["dhcp6_config_file_override_path"], + }, + "adv_dhcp6_id_assoc_statement_address": { + "type": "str", + "required": False, + "aliases": ["dhcp6_id_assoc_address"], + }, + "adv_dhcp6_id_assoc_statement_address_enable": { + "type": "bool", + "required": False, + "aliases": ["dhcp6_id_assoc_address_enable"], + }, + "adv_dhcp6_id_assoc_statement_address_id": { + "type": "int", + "required": False, + "aliases": ["dhcp6_id_assoc_address_id"], + }, + "adv_dhcp6_id_assoc_statement_address_pltime": { + "type": "int", + "required": False, + "aliases": ["dhcp6_id_assoc_address_pltime"], + }, + "adv_dhcp6_id_assoc_statement_address_vltime": { + "type": "int", + "required": False, + "aliases": ["dhcp6_id_assoc_address_vltime"], + }, + "adv_dhcp6_id_assoc_statement_prefix": { + "type": "str", + "required": False, + "aliases": ["dhcp6_id_assoc_prefix"], + }, + "adv_dhcp6_id_assoc_statement_prefix_enable": { + "type": "bool", + "required": False, + "aliases": ["dhcp6_id_assoc_prefix_enable"], + }, + "adv_dhcp6_id_assoc_statement_prefix_id": { + "type": "int", + "required": False, + "aliases": ["dhcp6_id_assoc_prefix_id"], + }, + "adv_dhcp6_id_assoc_statement_prefix_pltime": { + "type": "int", + "required": False, + "aliases": ["dhcp6_id_assoc_prefix_pltime"], + }, + "adv_dhcp6_id_assoc_statement_prefix_vltime": { + "type": "int", + "required": False, + "aliases": ["dhcp6_id_assoc_prefix_vltime"], + }, + "adv_dhcp6_interface_statement_information_only_enable": { + "type": "bool", + "required": False, + "aliases": ["dhcp6_interface_info_only_enable"], + }, + "adv_dhcp6_interface_statement_request_options": { + "type": "str", + "required": False, + "aliases": ["dhcp6_interface_request_options"], + }, + "adv_dhcp6_interface_statement_script": { + "type": "str", + "required": False, + "aliases": ["dhcp6_interface_script"], + }, + "adv_dhcp6_interface_statement_send_options": { + "type": "str", + "required": False, + "aliases": ["dhcp6_interface_send_options"], + }, + "adv_dhcp6_key_info_statement_expire": { + "type": "str", + "required": False, + "aliases": ["dhcp6_key_info_expire"], + }, + "adv_dhcp6_key_info_statement_keyid": { + "type": "int", + "required": False, + "aliases": ["dhcp6_key_info_keyid"], + }, + "adv_dhcp6_key_info_statement_keyname": { + "type": "str", + "required": False, + "aliases": ["dhcp6_key_info_keyname"], + }, + "adv_dhcp6_key_info_statement_realm": { + "type": "str", + "required": False, + "aliases": ["dhcp6_key_info_realm"], + }, + "adv_dhcp6_key_info_statement_secret": { + "type": "str", + "required": False, + "aliases": ["dhcp6_key_info_secret"], + }, + "adv_dhcp6_prefix_interface_statement_sla_len": { + "type": "int", + "required": False, + "aliases": ["dhcp6_prefix_sla_len"], + }, + "adv_dhcp_config_advanced": { + "type": "bool", + "required": False, + "aliases": ["dhcp_config_advanced"], + }, + "adv_dhcp_config_file_override": { "type": "bool", "required": False, - "aliases": ["block_bogons"] - }, - "descr": { - "type": "str", - "required": False, - "aliases": ["description"] - }, - "dhcp6_ia_pd_len": { - "type": "int", - "required": False, - "aliases": ["dhcp6_ia_pd_len"] - }, - "dhcp6_prefix_id": { - "type": "int", - "required": False, - "aliases": ["dhcp6_prefix_id"] - }, - "dhcp6_ifid": { - "type": "str", - "required": False, - "aliases": ["dhcp6_ifid"] - }, - "dhcp6vlanprio": { - "type": "int", - "required": False, - "aliases": ["dhcp6_vlan_prio"] - }, - "dhcphostname": { - "type": "str", - "required": False, - "aliases": ["dhcp_hostname"] - }, - "dhcprejectfrom": { - "type": "str", - "required": False, - "aliases": ["dhcp_reject_from"] - }, - "dhcpvlanprio": { - "type": "int", - "required": False, - "aliases": ["dhcp_vlan_prio"] - }, - "disablechecksumoffloading": { - "type": "bool", - "required": False, - "aliases": ["disable_checksum_offloading"] - }, - "disablelargereceiveoffloading": { - "type": "bool", - "required": False, - "aliases": ["disable_large_receive_offloading"] - }, - "disablesegmentationoffloading": { - "type": "bool", - "required": False, - "aliases": ["disable_segmentation_offloading"] - }, - "disablevlanhwfilter": { - "type": "bool", - "required": False, - "aliases": ["disable_vlan_hw_filter"] - }, - "enable": { - "type": "bool", - "required": False, - "aliases": ["enabled"] - }, - "gateway": { - "type": "str", - "required": False, - "aliases": ["ipv4_gateway"] - }, - "gateway_6rd": { - "type": "str", - "required": False, - }, - "gatewayv6": { - "type": "str", - "required": False, - "aliases": ["ipv6_gateway"] - }, - "hw_settings_overwrite": { - "type": "bool", - "required": False, - }, - "if": { - "type": "str", - "required": False, - "aliases": ["device"] - }, - "ipaddr": { - "type": "str", - "required": False, - "aliases": ["ipv4_address"] - }, - "ipaddr6": { - "type": "str", - "required": False, - "aliases": ["ipv6_address"] - }, - "lock": { - "type": "bool", - "required": False, - "aliases": ["locked"] - }, - "media": { - "type": "str", - "required": False, - }, - "mediaopt": { - "type": "str", - "required": False, - "aliases": ["media_option"] - }, - "mss": { - "type": "int", - "required": False, - }, - "mtu": { - "type": "int", - "required": False, - }, - "prefix_6rd": { - "type": "str", - "required": False, - }, - "prefix_6rd_v4addr": { - "type": "str", - "required": False, - }, - "prefix_6rd_v4plen": { - "type": "int", - "required": False, - }, - "spoofmac": { - "type": "str", - "required": False, - "aliases": ["mac_address"] - }, - "track6_interface": { - "type": "str", - "required": False, - }, - "track6_prefix_id": { - "type": "int", - "required": False, - }, - "track6_ifid": { - "type": "str", - "required": False, - }, - "subnet": { - "type": "int", - "required": False, - "when": "ipaddr", - "aliases": ["ipv4_subnet"] - }, - "subnet6": { - "type": "int", - "required": False, - "when": "ipaddr6", - "aliases": ["ipv6_subnet"] - }, - "state": { - "type": "str", - "required": False, - "choices": ["present", "absent"], - "default": "present" - }, + "aliases": ["dhcp_config_file_override"], + }, + "adv_dhcp_config_file_override_path": { + "type": "str", + "required": False, + "aliases": ["dhcp_config_file_override_path"], + }, + "adv_dhcp_option_modifiers": { + "type": "str", + "required": False, + "aliases": ["dhcp_option_modifiers"], + }, + "adv_dhcp_pt_backoff_cutoff": { + "type": "int", + "required": False, + "aliases": ["dhcp_pt_backoff_cutoff"], + }, + "adv_dhcp_pt_initial_interval": { + "type": "int", + "required": False, + "aliases": ["dhcp_pt_initial_interval"], + }, + "adv_dhcp_pt_reboot": { + "type": "int", + "required": False, + "aliases": ["dhcp_pt_reboot"], + }, + "adv_dhcp_pt_retry": { + "type": "int", + "required": False, + "aliases": ["dhcp_pt_retry"], + }, + "adv_dhcp_pt_select_timeout": { + "type": "int", + "required": False, + "aliases": ["dhcp_pt_select_timeout"], + }, + "adv_dhcp_pt_timeout": { + "type": "int", + "required": False, + "aliases": ["dhcp_pt_timeout"], + }, + "adv_dhcp_pt_values": { + "type": "str", + "required": False, + "aliases": ["dhcp_pt_values"], + }, + "adv_dhcp_request_options": { + "type": "str", + "required": False, + "aliases": ["dhcp_request_options"], + }, + "adv_dhcp_required_options": { + "type": "str", + "required": False, + "aliases": ["dhcp_required_options"], + }, + "adv_dhcp_send_options": { + "type": "str", + "required": False, + "aliases": ["dhcp_send_options"], + }, + "alias_address": { + "type": "str", + "required": False, + "aliases": ["alias_address"], + }, + "alias_subnet": {"type": "int", "required": False, "aliases": ["alias_subnet"]}, + "blockprivate": { + "type": "bool", + "required": False, + "aliases": ["block_private"], + }, + "blockbogons": {"type": "bool", "required": False, "aliases": ["block_bogons"]}, + "descr": {"type": "str", "required": False, "aliases": ["description"]}, + "dhcp6_ia_pd_len": { + "type": "int", + "required": False, + "aliases": ["dhcp6_ia_pd_len"], + }, + "dhcp6_prefix_id": { + "type": "int", + "required": False, + "aliases": ["dhcp6_prefix_id"], + }, + "dhcp6_ifid": {"type": "str", "required": False, "aliases": ["dhcp6_ifid"]}, + "dhcp6vlanprio": { + "type": "int", + "required": False, + "aliases": ["dhcp6_vlan_prio"], + }, + "dhcphostname": { + "type": "str", + "required": False, + "aliases": ["dhcp_hostname"], + }, + "dhcprejectfrom": { + "type": "str", + "required": False, + "aliases": ["dhcp_reject_from"], + }, + "dhcpvlanprio": { + "type": "int", + "required": False, + "aliases": ["dhcp_vlan_prio"], + }, + "disablechecksumoffloading": { + "type": "bool", + "required": False, + "aliases": ["disable_checksum_offloading"], + }, + "disablelargereceiveoffloading": { + "type": "bool", + "required": False, + "aliases": ["disable_large_receive_offloading"], + }, + "disablesegmentationoffloading": { + "type": "bool", + "required": False, + "aliases": ["disable_segmentation_offloading"], + }, + "disablevlanhwfilter": { + "type": "bool", + "required": False, + "aliases": ["disable_vlan_hw_filter"], + }, + "enable": {"type": "bool", "required": False, "aliases": ["enabled"]}, + "gateway": {"type": "str", "required": False, "aliases": ["ipv4_gateway"]}, + "gateway_6rd": { + "type": "str", + "required": False, + }, + "gatewayv6": {"type": "str", "required": False, "aliases": ["ipv6_gateway"]}, + "hw_settings_overwrite": { + "type": "bool", + "required": False, + }, + "if": {"type": "str", "required": False, "aliases": ["device"]}, + "ipaddr": {"type": "str", "required": False, "aliases": ["ipv4_address"]}, + "ipaddr6": {"type": "str", "required": False, "aliases": ["ipv6_address"]}, + "lock": {"type": "bool", "required": False, "aliases": ["locked"]}, + "media": { + "type": "str", + "required": False, + }, + "mediaopt": {"type": "str", "required": False, "aliases": ["media_option"]}, + "mss": { + "type": "int", + "required": False, + }, + "mtu": { + "type": "int", + "required": False, + }, + "prefix_6rd": { + "type": "str", + "required": False, + }, + "prefix_6rd_v4addr": { + "type": "str", + "required": False, + }, + "prefix_6rd_v4plen": { + "type": "int", + "required": False, + }, + "spoofmac": {"type": "str", "required": False, "aliases": ["mac_address"]}, + "track6_interface": { + "type": "str", + "required": False, + }, + "track6_prefix_id": { + "type": "int", + "required": False, + }, + "track6_ifid": { + "type": "str", + "required": False, + }, + "subnet": { + "type": "int", + "required": False, + "when": "ipaddr", + "aliases": ["ipv4_subnet"], + }, + "subnet6": { + "type": "int", + "required": False, + "when": "ipaddr6", + "aliases": ["ipv6_subnet"], + }, + "state": { + "type": "str", + "required": False, + "choices": ["present", "absent"], + "default": "present", + }, } # Create the alias map @@ -1013,21 +965,25 @@ def main(): params = filter_explicitly_set_params(params, module_args) # ensure state is present by default - params['state'] = params.get('state', 'present') + params["state"] = params.get("state", "present") # Process the converted arguments result = {} if params.get("ipaddr"): # Validate ipaddr and subnet parameters try: - params["ipaddr"], params["subnet"] = validate_ipaddr_and_subnet(params["ipaddr6"], params["subnet6"]) # pylint: disable=C0301 + params["ipaddr"], params["subnet"] = validate_ipaddr_and_subnet( + params["ipaddr6"], params["subnet6"] + ) # pylint: disable=C0301 except ValueError as e: module.fail_json(msg=str(e)) if params.get("ipaddr6"): # Validate ipaddr and subnet parameters try: - params["ipaddr6"], params["subnet6"] = validate_ipaddr_and_subnet(params["ipaddr6"], params["subnet6"]) # pylint: disable=C0301 + params["ipaddr6"], params["subnet6"] = validate_ipaddr_and_subnet( + params["ipaddr6"], params["subnet6"] + ) # pylint: disable=C0301 except ValueError as e: module.fail_json(msg=str(e)) @@ -1067,5 +1023,6 @@ def main(): module.exit_json(**result) + if __name__ == "__main__": main() diff --git a/plugins/modules/system_high_availability_settings.py b/plugins/modules/system_high_availability_settings.py index 54473503..a4317e21 100644 --- a/plugins/modules/system_high_availability_settings.py +++ b/plugins/modules/system_high_availability_settings.py @@ -121,7 +121,7 @@ UnsupportedVersionForModule, ) -from ansible_collections.puzzle.opnsense.plugins.module_utils.interfaces_configuration_utils import ( # pylint: disable=C0301 +from ansible_collections.puzzle.opnsense.plugins.module_utils.interfaces_configuration_utils import ( # pylint: disable=C0301 OPNSenseGetInterfacesError, ) diff --git a/tests/unit/plugins/module_utils/test_firewall_alias_utils.py b/tests/unit/plugins/module_utils/test_firewall_alias_utils.py index 1dff5141..b7f9cc8e 100644 --- a/tests/unit/plugins/module_utils/test_firewall_alias_utils.py +++ b/tests/unit/plugins/module_utils/test_firewall_alias_utils.py @@ -947,7 +947,6 @@ def test_firewall_alias_from_ansible_module_params_with_OPNsenseMaximumTableEntr with pytest.raises(OPNsenseMaximumTableEntriesExceededError) as excinfo: with FirewallAliasSet(sample_config_path) as alias_set: - alias_set.maximumtableentries = 0 new_alias: FirewallAlias = FirewallAlias.from_ansible_module_params( test_params diff --git a/tests/unit/plugins/module_utils/test_interfaces_configuration_utils.py b/tests/unit/plugins/module_utils/test_interfaces_configuration_utils.py index 0397e22a..c552c425 100644 --- a/tests/unit/plugins/module_utils/test_interfaces_configuration_utils.py +++ b/tests/unit/plugins/module_utils/test_interfaces_configuration_utils.py @@ -1300,7 +1300,6 @@ def test_interface_assignment_from_ansible_module_params_with_description_update "description": "test_interface", } with InterfacesSet(sample_config_path) as interfaces_set: - test_interface_assignment: InterfaceAssignment = ( InterfaceAssignment.from_ansible_module_params(test_params) ) @@ -1482,7 +1481,6 @@ def test_interface_assignment_from_ansible_module_params_with_duplicate_device( def test_get_interfaces_success( mock_get_version, mock_get_interfaces, sample_config_path ): - # Assuming InterfacesSet needs a configuration path and we have sample_config_path defined with InterfacesSet(sample_config_path) as interfaces_set: result = interfaces_set.get_interfaces() @@ -1502,7 +1500,6 @@ def test_get_interfaces_success( def test_get_interfaces_success( mock_get_version, mock_get_interfaces, sample_config_path ): - # Assuming InterfacesSet needs a configuration path and we have sample_config_path defined with InterfacesSet(sample_config_path) as interfaces_set: with pytest.raises(OPNSenseGetInterfacesError) as excinfo: @@ -1525,7 +1522,6 @@ def test_get_interfaces_success( def test_get_interfaces_success( mock_get_version, mock_get_interfaces, sample_config_path ): - # Assuming InterfacesSet needs a configuration path and we have sample_config_path defined with InterfacesSet(sample_config_path) as interfaces_set: with pytest.raises(OPNSenseGetInterfacesError) as excinfo: