def validate_ntp_servers(ntp_servers): if ntp_servers is None: return for server in ntp_servers: if not validate_dns_name_ip_address(server): raise ValidationError( 'Invalid ntp-server %s specified. ' 'Should be either a host name or an IPv4 address' % server)
def _parse_endpoint(endpoint): host_port_pattern = r'([^:]+):(\d+)$' m = re.match(host_port_pattern, endpoint) if not m: raise ValidationError(error_msg) host = m.group(1) port = int(m.group(2)) if not util.validate_dns_name_ip_address(host): raise ValidationError('Invalid hostname: ' + host) return host, port
def _parse_proxies(*proxy_host_ports): """ Parse proxies specified on the command line. :param proxy_host_ports: a list of strings in "host:port" format :return: a list of Proxy objects :raise: ValidationError if any of the items are malformed """ proxies = [] for s in proxy_host_ports: m = re.match(r'([^:]+):(\d+)$', s) if not m: raise ValidationError('%s is not in host:port format' % s) host = m.group(1) port = int(m.group(2)) if not util.validate_dns_name_ip_address(host): raise ValidationError('%s is not a valid hostname' % host) proxy = Proxy(host, port) proxies.append(proxy) return proxies