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))
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 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.. 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: hostname_warning = "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) try: if not docker_client.containers(filters={'name': 'calico-node'}): # Calico-node isn't running on this host. # There may be another host using this hostname. print_paragraph(hostname_warning) except IOError: # Couldn't connect to docker to confirm calico-node is running. print_paragraph(hostname_warning)
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.. 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: hostname_warning = "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) try: if not docker_client.containers( filters={'name': 'calico-node'}): # Calico-node isn't running on this host. # There may be another host using this hostname. print_paragraph(hostname_warning) except IOError: # Couldn't connect to docker to confirm calico-node is running. print_paragraph(hostname_warning)
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"