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"
def show_default_node_as(): """ Display the default node BGP AS Number. :return: None. """ value = client.get_default_node_as() print value
def node_show(): """ Show hostname and node information for each node in the Calico cluster. """ # Set up output table headings = [ "Hostname", "Bird IPv4", "Bird IPv6", "AS Num", "BGP Peers v4", "BGP Peers v6" ] x = PrettyTable(headings, sortby="Hostname") try: # Get dictionary of host data, indexed by hostname hosts = client.get_hosts_data_dict() for (host, data) in hosts.iteritems(): # Combine BGP peer IP and AS numbers into single values peer_v4_list = [ peer["ip"] + " as " + peer["as_num"] for peer in data["peer_v4"] ] peer_v6_list = [ peer["ip"] + " as " + peer["as_num"] for peer in data["peer_v6"] ] if data["as_num"]: bgp_as = data["as_num"] else: bgp_as = client.get_default_node_as() bgp_as += " (inherited)" x.add_row([ host, data["ip_addr_v4"], data["ip_addr_v6"], bgp_as, "\n".join(peer_v4_list), "\n".join(peer_v6_list) ]) except DataStoreError: print "Error connecting to etcd." sys.exit(1) print str(x) + "\n"
def node_show(): """ Show hostname and node information for each node in the Calico cluster. """ # Set up output table headings = ["Hostname", "Bird IPv4", "Bird IPv6", "AS Num", "BGP Peers v4", "BGP Peers v6"] x = PrettyTable(headings, sortby="Hostname") try: # Get dictionary of host data, indexed by hostname hosts = client.get_hosts_data_dict() for (host, data) in hosts.iteritems(): # Combine BGP peer IP and AS numbers into single values peer_v4_list = [peer["ip"] + " as " + peer["as_num"] for peer in data["peer_v4"]] peer_v6_list = [peer["ip"] + " as " + peer["as_num"] for peer in data["peer_v6"]] if data["as_num"]: bgp_as = data["as_num"] else: bgp_as = client.get_default_node_as() bgp_as += " (inherited)" x.add_row([host, data["ip_addr_v4"], data["ip_addr_v6"], bgp_as, "\n".join(peer_v4_list), "\n".join(peer_v6_list)]) except DataStoreError: print "Error connecting to etcd." sys.exit(1) print str(x) + "\n"
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"
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"