def _validate(addr, netmask, gateway, nameservers): """Validate Static IP form parameters. Returns an empty array on success, an array of strings describing errors otherwise""" errors = [] if not addr: errors.append("No IP address provided") elif not ipaddr.is_legal_ip(addr): errors.append("Invalid IP address: %s" % addr) if not netmask: errors.append("No netmask provided") elif not ipaddr.is_legal_ip(netmask): errors.append("Invalid netmask: %s" % netmask) for nameserver in nameservers: if nameserver and not ipaddr.is_legal_ip(nameserver): errors.append("Invalid nameserver: %s" % nameserver) if len(nameservers) != len(set(nameservers)): errors.append("Duplicate nameservers specified") if errors: return errors if gateway: if not ipaddr.is_legal_ip(gateway): return [ "Invalid gateway: %s" % gateway ] else: iprange = ipaddr.IPRange(addr, netmask) if gateway not in iprange: return [ "Gateway (%s) not in IP range (%s)" % (gateway, iprange) ] return []