def validate_port(port): try: p = int(port) except ValueError: if port == "*": # * is allowed for creating wildcard VSs return raise ValidationError('Port must be an integer ({} given)' .format(port)) if not 1 <= p <= 65535: raise ValidationError('Invalid port number ({} given)'.format(p))
def validate_protocol(protocol): if protocol.upper() not in ('TCP', 'UDP'): raise ValidationError('Invalid protocol ({} given)'.format(protocol))
def validate_ip(ip): try: IPAddress(ip) except AddrFormatError: raise ValidationError('Invalid IP address ({} given)'.format(ip))