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 """ 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" else: print "calico-node container is running. Status: %s" % \ calico_node_info[0]["Status"] apt_cmd = docker_client.exec_create("calico-node", ["/bin/bash", "-c", "apt-cache policy calico-felix"]) result = re.search(r"Installed: (.*?)\s", docker_client.exec_start(apt_cmd)) if result is not None: print "Running felix version %s" % result.group(1) print "\nIPv4 BGP status" pprint_bird_protocols(4) print "IPv6 BGP status" pprint_bird_protocols(6)
def warn_if_hostname_conflict(ip): """ Prints a warning message if it seems like an existing host is already running calico using this hostname. :param ip: User-provided IP address to start this node with. :return: Nothing """ # If there's already a calico-node container on this host, they're probably # just re-running node to update one of the ip addresses, so skip.. if len(docker_client.containers(filters={'name': 'calico-node'})) == 0: # Otherwise, check if another host with the same hostname # is already configured try: current_ipv4, _ = client.get_host_bgp_ips(hostname) except KeyError: # No other machine has registered configuration under this hostname. # This must be a new host with a unique hostname, which is the # expected behavior. pass else: if current_ipv4 != "" and current_ipv4 != ip: print_paragraph("WARNING: Hostname '%s' is already in use " "with IP address %s. Calico requires each compute host to " "have a unique hostname. If this is your first time " "running 'calicoctl node' on this host, ensure that " \ "another host is not already using the " \ "same hostname." % (hostname, ip))