def validate_arguments(arguments):
    """
    Validate argument values:
        <IP>

    Arguments not validated:
        <CONTAINER>
        <INTERFACE>

    :param arguments: Docopt processed arguments
    """
    # Validate IP
    requested_ip = arguments.get("<IP>")
    if not (requested_ip is None or validate_ip(requested_ip, 4)
            or validate_ip(requested_ip, 6) or validate_cidr(requested_ip)
            or requested_ip.lower() in ('ipv4', 'ipv6')):
        print_paragraph("Invalid IP address specified.  Argument must be a "
                        "valid IP or CIDR.")
        sys.exit(1)

    # Validate POOL
    if requested_ip is not None and '/' in requested_ip:
        requested_pool = IPNetwork(requested_ip)

        try:
            client.get_ip_pool_config(requested_pool.version, requested_pool)
        except KeyError:
            print_paragraph("Invalid CIDR specified for desired pool. "
                            "No pool found for {0}.".format(requested_pool))
            sys.exit(1)

    # Validate PROFILE
    endpoint.validate_arguments(arguments)
    def test_validate_arguments(self, case, sys_exit_called):
        """
        Test validate_arguments for calicoctl endpoint command
        """
        with patch('sys.exit', autospec=True) as m_sys_exit:
            # Call method under test
            endpoint.validate_arguments(case)

            # Assert method exits if bad input
            self.assertEqual(m_sys_exit.called, sys_exit_called)
def validate_arguments(arguments):
    """
    Validate argument values:
        <IP>

    Arguments not validated:
        <CONTAINER>
        <INTERFACE>

    :param arguments: Docopt processed arguments
    """
    # Validate IP
    requested_ip = arguments.get("<IP>")
    if not (requested_ip is None or
            validate_ip(requested_ip, 4) or
            validate_ip(requested_ip, 6) or
            validate_cidr(requested_ip) or
            requested_ip.lower() in ('ipv4', 'ipv6')):
        sys.exit('Invalid IP address specified. Argument must be an IP, '
                 'a cidr, "ipv4" or "ipv6". '
                 '"{0}" was given'.format(requested_ip))

    # Validate POOL
    if requested_ip is not None and '/' in requested_ip:
        try:
            requested_pool = IPNetwork(requested_ip)
        except TypeError:
            sys.exit('Invalid cidr specified for desired pool. '
                     '"{0}" was given."'.format(pool))

        try:
            pool = client.get_ip_pool_config(requested_pool.version,
                                             requested_pool)
        except KeyError:
            sys.exit('Invalid cidr specified for desired pool. '
                     'No pool found for "{0}"'.format(requested_pool))


    # Validate PROFILE
    endpoint.validate_arguments(arguments)
def validate_arguments(arguments):
    """
    Validate argument values:
        <IP>

    Arguments not validated:
        <CONTAINER>
        <INTERFACE>

    :param arguments: Docopt processed arguments
    """
    # Validate IP
    container_ip_ok = arguments.get("<IP>") is None or \
                        validate_ip(arguments["<IP>"], 4) or \
                        validate_ip(arguments["<IP>"], 6)

    # Print error message and exit if not valid argument
    if not container_ip_ok:
        print "Invalid IP address specified."
        sys.exit(1)

    endpoint.validate_arguments(arguments)
Exemple #5
0
def validate_arguments(arguments):
    """
    Validate argument values:
        <IP>

    Arguments not validated:
        <CONTAINER>
        <INTERFACE>

    :param arguments: Docopt processed arguments
    """
    # Validate IP
    container_ip_ok = arguments.get("<IP>") is None or \
                        validate_ip(arguments["<IP>"], 4) or \
                        validate_ip(arguments["<IP>"], 6)

    # Print error message and exit if not valid argument
    if not container_ip_ok:
        print "Invalid IP address specified."
        sys.exit(1)

    endpoint.validate_arguments(arguments)
Exemple #6
0
def validate_arguments(arguments):
    """
    Validate argument values:
        <IP>

    Arguments not validated:
        <CONTAINER>
        <INTERFACE>

    :param arguments: Docopt processed arguments
    """
    # Validate IP
    requested_ip = arguments.get("<IP>")
    if not (requested_ip is None or validate_ip(requested_ip, 4)
            or validate_ip(requested_ip, 6) or validate_cidr(requested_ip)
            or requested_ip.lower() in ('ipv4', 'ipv6')):
        sys.exit('Invalid IP address specified. Argument must be an IP, '
                 'a cidr, "ipv4" or "ipv6". '
                 '"{0}" was given'.format(requested_ip))

    # Validate POOL
    if requested_ip is not None and '/' in requested_ip:
        try:
            requested_pool = IPNetwork(requested_ip)
        except TypeError:
            sys.exit('Invalid cidr specified for desired pool. '
                     '"{0}" was given."'.format(pool))

        try:
            pool = client.get_ip_pool_config(requested_pool.version,
                                             requested_pool)
        except KeyError:
            sys.exit('Invalid cidr specified for desired pool. '
                     'No pool found for "{0}"'.format(requested_pool))

    # Validate PROFILE
    endpoint.validate_arguments(arguments)
Exemple #7
0
def validate_arguments(arguments):
    """
    Validate argument values:
        <IP>

    Arguments not validated:
        <CONTAINER>
        <INTERFACE>

    :param arguments: Docopt processed arguments
    """
    # Validate IP
    requested_ip = arguments.get("<IP>")
    if not (requested_ip is None or
            validate_ip(requested_ip, 4) or
            validate_ip(requested_ip, 6) or
            validate_cidr(requested_ip) or
            requested_ip.lower() in ('ipv4', 'ipv6')):
        print_paragraph("Invalid IP address specified.  Argument must be a "
                        "valid IP or CIDR.")
        sys.exit(1)

    # Validate POOL
    if requested_ip is not None and '/' in requested_ip:
        requested_pool = IPNetwork(requested_ip)

        try:
            client.get_ip_pool_config(requested_pool.version, requested_pool)
        except KeyError:
            print_paragraph("Invalid CIDR specified for desired pool. "
                            "No pool found for {0}.".format(requested_pool))
            sys.exit(1)


    # Validate PROFILE
    endpoint.validate_arguments(arguments)