def ip_addresses(self, values): for value in values: try: CheckedIPAddress(value) except Exception as e: raise ValueError("invalid IP address {0}: {1}".format( value, e))
def check_ip_option(option, opt, value): from ipapython.ipautil import CheckedIPAddress try: return CheckedIPAddress(value) except Exception as e: raise OptionValueError("option %s: invalid IP address %s: %s" % (opt, value, e))
def _validate_ipmask(ugettext, ipmask): if not ipmask: return try: ip = CheckedIPAddress(ipmask, parse_netmask=True, allow_network=True) except (netaddr.AddrFormatError, ValueError), e: return unicode(e)
def validate_ipaddr(ugettext, ipaddr): """ Verify that we have either an IPv4 or IPv6 address. """ try: ip = CheckedIPAddress(ipaddr, match_local=False) except Exception, e: return unicode(e)
def check_ip_option(option, opt, value, allow_loopback=False): try: if allow_loopback: return CheckedIPAddressLoopback(value) else: return CheckedIPAddress(value) except Exception as e: raise OptionValueError("option {}: invalid IP address {}: {}".format( opt, value, e))
def check_ip_option(option, opt, value): from ipapython.ipautil import CheckedIPAddress ip_local = option.ip_local is True ip_netmask = option.ip_netmask is True try: return CheckedIPAddress(value, parse_netmask=ip_netmask, match_local=ip_local) except Exception as e: raise OptionValueError("option %s: invalid IP address %s: %s" % (opt, value, e))
def validate_ipaddr(ugettext, ipaddr): try: CheckedIPAddress(ipaddr, parse_netmask=False, allow_loopback=True, allow_broadcast=True, allow_multicast=True) except Exception, e: return unicode(e)
def validate_ipnet(ugettext, ipaddr): m = re.match(r'^(?:\+=\s+)(?P<addr>.*)$', ipaddr) if m is not None: if m.group('addr'): ipaddr = m.group('addr') # for some reason, +addr pass as valid in built-in CheckedIPAddress m = re.match(r'^[0-9].*', ipaddr) if m is None: return _("Invalid IP network address: <%s>" % ipaddr) try: CheckedIPAddress(ipaddr, allow_network=True, allow_loopback=True, allow_broadcast=True, allow_multicast=True) except Exception, e: return unicode(e)
def parse(value): try: return CheckedIPAddress(value, match_local=True) except Exception as e: raise ValueError("invalid IP address {0}: {1}".format( value, e))