def get_node_ips(node_type="worker"): """ Gets the node public IP Args: node_type (str): The node type (e.g. worker, master) Returns: list: Node IP's """ ocp = OCP(kind=constants.NODE) if node_type == "worker": nodes = ocp.get(selector=constants.WORKER_LABEL).get("items") if node_type == "master:": nodes = ocp.get(selector=constants.MASTER_LABEL).get("items") if config.ENV_DATA["platform"].lower() == constants.AWS_PLATFORM: raise NotImplementedError elif config.ENV_DATA["platform"].lower() == constants.VSPHERE_PLATFORM: return [ each["address"] for node in nodes for each in node["status"]["addresses"] if each["type"] == "ExternalIP" ] else: raise NotImplementedError
def get_node_ips(node_type='worker'): """ Gets the node public IP Args: node_type (str): The node type (e.g. worker, master) Returns: list: Node IP's """ ocp = OCP(kind=constants.NODE) if node_type == 'worker': nodes = ocp.get(selector=constants.WORKER_LABEL).get('items') if node_type == 'master:': nodes = ocp.get(selector=constants.MASTER_LABEL).get('items') if config.ENV_DATA['platform'].lower() == constants.AWS_PLATFORM: raise NotImplementedError elif config.ENV_DATA['platform'].lower() == constants.VSPHERE_PLATFORM: return [ each['address'] for node in nodes for each in node['status']['addresses'] if each['type'] == "ExternalIP" ] else: raise NotImplementedError
def get_node_ip_addresses(ipkind): """ Gets a dictionary of required IP addresses for all nodes Args: ipkind: ExternalIP or InternalIP or Hostname Returns: dict: Internal or Exteranl IP addresses keyed off of node name """ ocp = OCP(kind=constants.NODE) masternodes = ocp.get(selector=constants.MASTER_LABEL).get("items") workernodes = ocp.get(selector=constants.WORKER_LABEL).get("items") nodes = masternodes + workernodes return { node["metadata"]["name"]: each["address"] for node in nodes for each in node["status"]["addresses"] if each["type"] == ipkind }
def get_ocp_version_dict(): """ Query OCP to get all information about OCP version. Returns: dict: ClusterVersion k8s object """ logger.info("collecting ocp version") # We use ClusterVersion resource (which is acted upon by openshift # cluster-version operator, aka CVO) to get the version of our OCP # instance. See also: # https://github.com/openshift/cluster-version-operator/blob/master/docs/dev/clusterversion.md ocp = OCP(kind="clusterversion") version_dict = ocp.get("version") return version_dict
def get_ocs_version(): """ Query OCP to get all information about OCS version. Returns: dict: ClusterVersion k8s object dict: image_dict with information about images IDs """ logger.info("collecting ocs version") # We use ClusterVersion resource (which is acted upon by openshift # cluster-version operator, aka CVO) to get the version of our OCP # instance. See also: # https://github.com/openshift/cluster-version-operator/blob/master/docs/dev/clusterversion.md ocp = OCP(kind="clusterversion") cluster_version = ocp.get("version") # TODO: When OLM (operator-lifecycle-manager) maintains OCS, it will be # possible to add a check via CSV (cluster service version) to get OCS # version in a similar way as it's done for OCP itself above. # Reference: Jose A. Rivera on ocs-qe list. # Get all openshift storage related namespaces. Eg. at the time of writing # this code (July 2019), there were these storage namespaces: # * openshift-cluster-storage-operator # * openshift-storage # TODO: how to do this in upstream where namespace is rook-ceph? # TODO: should we use defaults.ROOK_CLUSTER_NAMESPACE somehow here? storage_namespaces = [] all_namespaces = OCP(kind="namespace").get()["items"] ns_re = re.compile("^openshift.*storage") for ns in all_namespaces: if ns_re.match(ns["metadata"]["name"]): storage_namespaces.append(ns["metadata"]["name"]) logger.info("found storage namespaces %s", storage_namespaces) # Now get the OCS version by asking for version of all container images of # all pods in openshift-storage namespace. image_dict = {} for ns in storage_namespaces: ocs = OCP(kind="pod", namespace=ns) ocs_pods = ocs.get() ns_dict = {} for pod in ocs_pods["items"]: for container in pod["spec"]["containers"]: logger.debug( "container %s (in pod %s) uses image %s", container["name"], pod["metadata"]["name"], container["image"], ) cs_items = pod["status"].get("containerStatuses") if cs_items is None: pod_name = pod["metadata"]["name"] logger.warning(f"pod {pod_name} has no containerStatuses") continue for cs in cs_items: ns_dict.setdefault(cs["image"], set()).add(cs["imageID"]) image_dict.setdefault(ns, ns_dict) logger.debug("ocs version collected") return cluster_version, image_dict