Exemple #1
0
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))
Exemple #2
0
def validate_protocol(protocol):
    if protocol.upper() not in ('TCP', 'UDP'):
        raise ValidationError('Invalid protocol ({} given)'.format(protocol))
Exemple #3
0
def validate_ip(ip):
    try:
        IPAddress(ip)
    except AddrFormatError:
        raise ValidationError('Invalid IP address ({} given)'.format(ip))