def validate_ips(self, ips, error_msg): invalid_ips = [ ip for ip in ips if not any([ is_ip_address(ip), is_ip_network_address(ip), ip == "any", ip == "none" ]) ] if any(invalid_ips): self.fail_json(msg=error_msg % invalid_ips)
def get_ipa_idnsforwarders(self, **_kwargs): # pylint: disable=R1710 if self.ipa_params.forwarders is not None: forwarders = [] for forwarder in self.ipa_params.forwarders: ip_address = forwarder.get("ip_address") if not is_ip_address(ip_address): self.fail_json(msg="Invalid IP for DNS forwarder: %s" % ip_address) port = forwarder.get("port", None) if port and not is_valid_port(port): self.fail_json( msg="Invalid port number for DNS forwarder: %s %s" % (ip_address, port)) formatted_forwarder = ip_address port = forwarder.get("port") if port: formatted_forwarder += " port %d" % port forwarders.append(formatted_forwarder) return forwarders