Example #1
0
def status(arguments):
    """
    Main dispatcher for status commands. Calls the corresponding helper
    function.

    :param arguments: A dictionary of arguments already processed through
    this file's docstring with docopt
    :return: None
    """
    # Check runtime.
    runtime = arguments.get("--runtime")
    if not runtime in ["docker", "rkt"]:
        print "Invalid runtime specified: '%s'" % runtime
        sys.exit(1)

    # Check backend
    backend = arguments.get("--backend")
    if not backend in [None, "bird", "gobgp", "none"]:
        print "Invalid backend specified: '%s'" % backend
        sys.exit(1)

    # Start by locating the calico-node container and querying the package
    # summary file.
    if runtime == "rkt":
        enforce_root()
        check_container_status_rkt()
    else:
        check_container_status_docker()

    # Now query the host BGP details.  If the AS number is not specified on the
    # host then it must be inheriting the default.
    try:
        bgp_ipv4, bgp_ipv6 = client.get_host_bgp_ips(hostname)
        bgp_as = client.get_host_as(hostname)
        if bgp_as is None:
            bgp_as = client.get_default_node_as()
            bgp_as += " (inherited)"
    except DataStoreError:
        print "Error connecting to etcd.  Ensure ETCD_ENDPOINTS or ETCD_AUTHORITY is set properly."
        bgp_ipv4 = bgp_ipv6 = "unknown"
        bgp_as = "unknown"

    # TODO: Add additional information to the BIRD section:
    # TODO: - Include AS numbers of peers
    # TODO: - Include host name of peers when the peer is a calico-node
    # TODO: - Include details of peers configured multiple times

    print "\nIPv4 BGP status"
    if bgp_ipv4:
        print "IP: %s    AS Number: %s" % (bgp_ipv4, bgp_as)
        pprint_bgp_protocols(4, backend)
    else:
        print "No IPv4 address configured.\n"

    print "IPv6 BGP status"
    if bgp_ipv6:
        print "IP: %s    AS Number: %s" % (bgp_ipv6, bgp_as)
        pprint_bgp_protocols(6, backend)
    else:
        print "No IPv6 address configured.\n"
Example #2
0
def status(arguments):
    """
    Main dispatcher for status commands. Calls the corresponding helper
    function.

    :param arguments: A dictionary of arguments already processed through
    this file's docstring with docopt
    :return: None
    """
    # Check runtime.
    runtime = arguments.get("--runtime")
    if not runtime in ["docker", "rkt"]:
        print "Invalid runtime specified: '%s'" % runtime
        sys.exit(1)

    # Check backend
    backend = arguments.get("--backend")
    if not backend in [None, "bird", "gobgp", "none"]:
        print "Invalid backend specified: '%s'" % backend
        sys.exit(1)

    # Start by locating the calico-node container and querying the package
    # summary file.
    if runtime == "rkt":
        enforce_root()
        check_container_status_rkt()
    else:
        check_container_status_docker()

    # Now query the host BGP details.  If the AS number is not specified on the
    # host then it must be inheriting the default.
    try:
        bgp_ipv4, bgp_ipv6 = client.get_host_bgp_ips(hostname)
        bgp_as = client.get_host_as(hostname)
        if bgp_as is None:
            bgp_as = client.get_default_node_as()
            bgp_as += " (inherited)"
    except DataStoreError:
        print "Error connecting to etcd.  Ensure ETCD_ENDPOINTS or ETCD_AUTHORITY is set properly."
        bgp_ipv4 = bgp_ipv6 = "unknown"
        bgp_as = "unknown"

    # TODO: Add additional information to the BIRD section:
    # TODO: - Include AS numbers of peers
    # TODO: - Include host name of peers when the peer is a calico-node
    # TODO: - Include details of peers configured multiple times

    print "\nIPv4 BGP status"
    if bgp_ipv4:
        print "IP: %s    AS Number: %s" % (bgp_ipv4, bgp_as)
        pprint_bgp_protocols(4, backend)
    else:
        print "No IPv4 address configured.\n"

    print "IPv6 BGP status"
    if bgp_ipv6:
        print "IP: %s    AS Number: %s" % (bgp_ipv6, bgp_as)
        pprint_bgp_protocols(6, backend)
    else:
        print "No IPv6 address configured.\n"
Example #3
0
def status(arguments):
    """
    Main dispatcher for status commands. Calls the corresponding helper
    function.

    :param arguments: A dictionary of arguments already processed through
    this file's docstring with docopt
    :return: None
    """
    # Start by locating the calico-node container and querying the package
    # summary file.
    try:
        calico_node_info = filter(
            lambda container: "/calico-node" in container["Names"],
            docker_client.containers())
        if len(calico_node_info) == 0:
            print "calico-node container not running"
            sys.exit(1)
        else:
            print "calico-node container is running. Status: %s" % \
                  calico_node_info[0]["Status"]

            libraries_cmd = docker_client.exec_create(
                "calico-node", ["sh", "-c", "cat libraries.txt"])
            libraries_out = docker_client.exec_start(libraries_cmd)
            result = re.search(r"^calico\s*\((.*)\)\s*$", libraries_out,
                               re.MULTILINE)

            if result is not None:
                print "Running felix version %s" % result.group(1)
    except ConnectionError:
        print "Docker is not running"
        # TODO: Perform status checks in platform-independent way.
        sys.exit(1)

    # Now query the host BGP details.  If the AS number is not specified on the
    # host then it must be inheriting the default.
    try:
        bgp_ipv4, bgp_ipv6 = client.get_host_bgp_ips(hostname)
        bgp_as = client.get_host_as(hostname)
        if bgp_as is None:
            bgp_as = client.get_default_node_as()
            bgp_as += " (inherited)"
    except DataStoreError:
        print "Error connecting to etcd."
        bgp_ipv4 = bgp_ipv6 = "unknown"
        bgp_as = "unknown"

    # TODO: Add additional information to the BIRD section:
    # TODO: - Include AS numbers of peers
    # TODO: - Include host name of peers when the peer is a calico-node
    # TODO: - Include details of peers configured multiple times

    print "\nIPv4 BGP status"
    if bgp_ipv4:
        print "IP: %s    AS Number: %s" % (bgp_ipv4, bgp_as)
        pprint_bird_protocols(4)
    else:
        print "No IPv4 address configured.\n"

    print "IPv6 BGP status"
    if bgp_ipv6:
        print "IP: %s    AS Number: %s" % (bgp_ipv6, bgp_as)
        pprint_bird_protocols(6)
    else:
        print "No IPv6 address configured.\n"
Example #4
0
def status(arguments):
    """
    Main dispatcher for status commands. Calls the corresponding helper
    function.

    :param arguments: A dictionary of arguments already processed through
    this file's docstring with docopt
    :return: None
    """
    # Start by locating the calico-node container and querying the package
    # summary file.
    try:
        calico_node_info = filter(lambda container: "/calico-node" in
                                  container["Names"],
                                  docker_client.containers())
        if len(calico_node_info) == 0:
            print "calico-node container not running"
            sys.exit(1)
        else:
            print "calico-node container is running. Status: %s" % \
                  calico_node_info[0]["Status"]

            libraries_cmd = docker_client.exec_create("calico-node",
                                                      ["sh", "-c",
                                                       "cat libraries.txt"])
            libraries_out = docker_client.exec_start(libraries_cmd)
            result = re.search(r"^calico\s*\((.*)\)\s*$", libraries_out,
                               re.MULTILINE)

            if result is not None:
                print "Running felix version %s" % result.group(1)
    except ConnectionError:
        print "Docker is not running"
        # TODO: Perform status checks in platform-independent way.
        sys.exit(1)

    # Now query the host BGP details.  If the AS number is not specified on the
    # host then it must be inheriting the default.
    try:
        bgp_ipv4, bgp_ipv6 = client.get_host_bgp_ips(hostname)
        bgp_as = client.get_host_as(hostname)
        if bgp_as is None:
            bgp_as = client.get_default_node_as()
            bgp_as += " (inherited)"
    except DataStoreError:
        print "Error connecting to etcd."
        bgp_ipv4 = bgp_ipv6 = "unknown"
        bgp_as = "unknown"

    # TODO: Add additional information to the BIRD section:
    # TODO: - Include AS numbers of peers
    # TODO: - Include host name of peers when the peer is a calico-node
    # TODO: - Include details of peers configured multiple times

    print "\nIPv4 BGP status"
    if bgp_ipv4:
        print "IP: %s    AS Number: %s" % (bgp_ipv4, bgp_as)
        pprint_bird_protocols(4)
    else:
        print "No IPv4 address configured.\n"

    print "IPv6 BGP status"
    if bgp_ipv6:
        print "IP: %s    AS Number: %s" % (bgp_ipv6, bgp_as)
        pprint_bird_protocols(6)
    else:
        print "No IPv6 address configured.\n"