Пример #1
0
def determine_ip_nodes():
    """Attempts to detect and return ip automatically.
    Also set node names, zones, and addresses in a cloud deployment.

    :return:
    """
    from pygluu.kubernetes.kubeapi import Kubernetes
    from .extensions import gluu_settings
    kubernetes = Kubernetes()
    logger.info(
        "Determining OS type and attempting to gather external IP address")

    data = {}
    # detect IP address automatically (if possible)
    try:
        node_ip_list = []
        node_zone_list = []
        node_name_list = []
        node_list = kubernetes.list_nodes().items

        for node in node_list:
            node_name = node.metadata.name
            node_addresses = kubernetes.read_node(
                name=node_name).status.addresses
            if gluu_settings.db.get("global.storageClass.provisioner") in (
                    "microk8s.io/hostpath", "k8s.io/minikube-hostpath"):
                for add in node_addresses:
                    if add.type == "InternalIP":
                        data["ip"] = ip = add.address
                        node_ip_list.append(ip)
            else:
                for add in node_addresses:
                    if add.type == "ExternalIP":
                        data["ip"] = ip = add.address
                        node_ip_list.append(ip)

        data["CN_NODES_NAMES"] = node_name_list
        data["CN_NODES_ZONES"] = node_zone_list
        data["CN_NODES_IPS"] = node_ip_list

        if gluu_settings.db.get("installer-settings.volumeProvisionStrategy"
                                ) in ("eks", "gke", "do", "local", "aks"):
            #  Assign random IP. IP will be changed by either the update ip script, GKE external ip or nlb ip
            data["ip"] = "22.22.22.22"
        return data
    except Exception as e:

        logger.error(e)
        # prompt for user-inputted IP address
        logger.warning("Cannot determine IP address")
        # return a fail safe
        return {
            "ip": "127.0.0.1",
            "CN_NODES_NAMES": [],
            "CN_NODES_ZONES": [],
            "CN_NODES_IPS": []
        }
Пример #2
0
def gather_ip():
    """Attempts to detect and return ip automatically.
    Also set node names, zones, and addresses in a cloud deployment.

    :return:
    """
    from pygluu.kubernetes.kubeapi import Kubernetes
    from pygluu.kubernetes.settings import ValuesHandler
    import ipaddress
    kubernetes = Kubernetes()
    settings = ValuesHandler()
    logger.info(
        "Determining OS type and attempting to gather external IP address")
    ip = ""

    # detect IP address automatically (if possible)
    try:
        node_ip_list = []
        node_zone_list = []
        node_name_list = []
        node_list = kubernetes.list_nodes().items

        for node in node_list:
            node_name = node.metadata.name
            node_addresses = kubernetes.read_node(
                name=node_name).status.addresses
            if settings.get("global.storageClass.provisioner") in (
                    "microk8s.io/hostpath", "k8s.io/minikube-hostpath"):
                for add in node_addresses:
                    if add.type == "InternalIP":
                        ip = add.address
                        node_ip_list.append(ip)
            else:
                for add in node_addresses:
                    if add.type == "ExternalIP":
                        ip = add.address
                        node_ip_list.append(ip)
                # Digital Ocean does not provide zone support yet
                if settings.get("global.storageClass.provisioner") not in (
                        "dobs.csi.digitalocean.com", "openebs.io/local"):
                    node_zone = node.metadata.labels[
                        "failure-domain.beta.kubernetes.io/zone"]
                    node_zone_list.append(node_zone)
                node_name_list.append(node_name)

        settings.set("installer-settings.nodes.names", node_name_list)
        settings.set("installer-settings.nodes.zones", node_zone_list)
        settings.set("installer-settings.nodes.ips", node_ip_list)

        if settings.get("global.storageClass.provisioner") in (
                "kubernetes.io/aws-ebs", "kubernetes.io/gce-pd",
                "kubernetes.io/azure-disk", "dobs.csi.digitalocean.com",
                "openebs.io/local"):
            #  Assign random IP. IP will be changed by either the update ip script, GKE external ip or nlb ip
            return "22.22.22.22"

    except Exception as e:
        logger.error(e)
        # prompt for user-inputted IP address
        logger.warning("Cannot determine IP address")
        ip = click.prompt("Please input the host's external IP address")

    if click.confirm(f"Is this the correct external IP address: {ip}",
                     default=True):
        return ip

    while True:
        ip = click.prompt("Please input the host's external IP address")
        try:
            ipaddress.ip_address(ip)
            return ip
        except ValueError as exc:
            # raised if IP is invalid
            logger.warning(f"Cannot determine IP address; reason={exc}")
Пример #3
0
def determine_ip_nodes():
    """Attempts to detect and return ip automatically.
    Also set node names, zones, and addresses in a cloud deployment.

    :return:
    """
    from pygluu.kubernetes.kubeapi import Kubernetes
    from .extensions import gluu_settings
    kubernetes = Kubernetes()
    logger.info(
        "Determining OS type and attempting to gather external IP address")

    data = {}
    # detect IP address automatically (if possible)
    try:
        node_ip_list = []
        node_zone_list = []
        node_name_list = []
        node_list = kubernetes.list_nodes().items

        for node in node_list:
            node_name = node.metadata.name
            node_addresses = kubernetes.read_node(
                name=node_name).status.addresses
            if gluu_settings.db.get("DEPLOYMENT_ARCH") in ("microk8s",
                                                           "minikube"):
                for add in node_addresses:
                    if add.type == "InternalIP":
                        data["ip"] = ip = add.address
                        node_ip_list.append(ip)
            else:
                for add in node_addresses:
                    if add.type == "ExternalIP":
                        data["ip"] = ip = add.address
                        node_ip_list.append(ip)
                # Digital Ocean does not provide zone support yet
                if gluu_settings.db.get("DEPLOYMENT_ARCH") not in ("do",
                                                                   "local"):
                    node_zone = node.metadata.labels[
                        "failure-domain.beta.kubernetes.io/zone"]
                    node_zone_list.append(node_zone)
                node_name_list.append(node_name)

        data["NODES_NAMES"] = node_name_list
        data["NODES_ZONES"] = node_zone_list
        data["NODES_IPS"] = node_ip_list

        if gluu_settings.db.get("DEPLOYMENT_ARCH") in ("eks", "gke", "do",
                                                       "local", "aks"):
            #  Assign random IP. IP will be changed by either the update ip script, GKE external ip or nlb ip
            data["ip"] = "22.22.22.22"
        return data
    except Exception as e:

        logger.error(e)
        # prompt for user-inputted IP address
        logger.warning("Cannot determine IP address")
        # return a fail safe
        return {
            "ip": "127.0.0.1",
            "NODES_NAMES": [],
            "NODES_ZONES": [],
            "NODES_IPS": []
        }