示例#1
0
 def set_base_dns_domain(self, base_dns_domain: str):
     log.info(
         f"Setting base DNS domain:{base_dns_domain} for cluster: {self.id}"
     )
     self.update_config(base_dns_domain=base_dns_domain)
     self.api_client.update_cluster(self.id,
                                    {"base_dns_domain": base_dns_domain})
示例#2
0
 def wait_for_host_validation(self,
                              host_id,
                              validation_section,
                              validation_id,
                              statuses,
                              timeout=consts.VALIDATION_TIMEOUT,
                              interval=2):
     log.info("Wait until host %s validation %s is in status %s", host_id,
              validation_id, statuses)
     try:
         waiting.wait(
             lambda: self.is_host_validation_in_status(
                 host_id=host_id,
                 validation_section=validation_section,
                 validation_id=validation_id,
                 statuses=statuses),
             timeout_seconds=timeout,
             sleep_seconds=interval,
             waiting_for="Host validation to be in status %s" % statuses,
         )
     except BaseException:
         log.error(
             "Host validation status is: %s",
             utils.get_host_validation_value(
                 self.api_client.cluster_get(self.id), host_id,
                 validation_section, validation_id),
         )
         raise
示例#3
0
 def set_advanced_cluster_host_prefix(self, cluster_host_prefix: int):
     log.info(
         f"Setting Cluster Host Prefix: {cluster_host_prefix} for cluster: {self.id}"
     )
     self.update_config(cluster_network_host_prefix=cluster_host_prefix)
     self.api_client.update_cluster(
         self.id, {"cluster_network_host_prefix": cluster_host_prefix})
示例#4
0
    def prepare_for_installation(self, static_network_config=None, **kwargs):
        self.update_config(**kwargs)
        log.info(
            f"Preparing for installation with clsuter configurations: cluster_config={self._config}"
        )
        log.info(
            f"Preparing for installation with nodes configurations: nodes_config={self.nodes.config}"
        )

        if self._config.download_image:
            if static_network_config:
                static_network_config = static_network.\
                    generate_static_network_data_from_tf(self.nodes.controller.tf_folder)
            else:
                static_network_config = None

            self.generate_and_download_image(
                iso_download_path=self._config.iso_download_path,
                iso_image_type=self._config.iso_image_type,
                static_network_config=static_network_config,
            )
        self.nodes.start_all(self._config.is_static_ip)
        self.wait_until_hosts_are_discovered(allow_insufficient=True)
        self.nodes.set_hostnames(self, self._config.nodes_count,
                                 self._config.is_ipv6,
                                 self._config.is_static_ip)
        if self._high_availability_mode != consts.HighAvailabilityMode.NONE:
            self.set_host_roles(len(self.nodes.get_masters()),
                                len(self.nodes.get_workers()))
        else:
            self.nodes.set_single_node_ip(self)
        self.set_network_params(
            controller=self.nodes.controller,
            vip_dhcp_allocation=self._config.vip_dhcp_allocation,
            service_network_cidr=self._config.service_network_cidr,
            cluster_network_cidr=self._config.cluster_network_cidr,
            cluster_network_host_prefix=self._config.
            cluster_network_host_prefix,
        )
        self.wait_for_ready_to_install()

        if self._config.platform == consts.Platforms.NONE:
            self._configure_load_balancer()
            self._set_none_platform_dns()
        if self._config.vip_dhcp_allocation:
            vips_info = self.__class__.get_vips_from_cluster(
                self.api_client, self.id)
            self._set_dns(api_vip=vips_info["api_vip"],
                          ingress_vip=vips_info["ingress_vip"])
        elif self._config.masters_count == 1:
            main_cidr = self.nodes.controller.get_machine_cidr()
            master_ips = self.get_master_ips(self.api_client, self.id,
                                             main_cidr)
            if len(master_ips) != 1:
                raise Exception(
                    f"Unexpected master count {len(master_ips)} for single node"
                )
            node_ip = master_ips[0]
            self._set_dns(api_vip=node_ip, ingress_vip=node_ip)
示例#5
0
 def get_hosts_by_role(self, role, hosts=None):
     hosts = hosts or self.api_client.get_cluster_hosts(self.id)
     nodes_by_role = []
     for host in hosts:
         if host["role"] == role:
             nodes_by_role.append(host)
     log.info(f"Found hosts: {nodes_by_role}, that has the role: {role}")
     return nodes_by_role
示例#6
0
 def is_host_validation_in_status(self, host_id, validation_section,
                                  validation_id, statuses):
     log.info("Is host %s validation %s in status %s", host_id,
              validation_id, statuses)
     try:
         return (utils.get_host_validation_value(
             self.api_client.cluster_get(self.id), host_id,
             validation_section, validation_id) in statuses)
     except BaseException:
         log.exception("Failed to get cluster %s validation info", self.id)
示例#7
0
    def unset_olm_operator(self, operator_name):
        log.info(f"Unsetting {operator_name} for cluster: {self.id}")
        cluster = self.api_client.cluster_get(self.id)

        olm_operators = []
        for operator in cluster.monitored_operators:
            if operator.name == operator_name or operator.operator_type == OperatorType.BUILTIN:
                continue
            olm_operators.append({"name": operator.name, "properties": operator.properties})

        self.api_client.update_cluster(self.id, {"olm_operators": olm_operators})
示例#8
0
    def get_api_vip(self, cluster):
        cluster = cluster or self.get_details()
        api_vip = cluster.api_vip

        if not api_vip and cluster.user_managed_networking:
            log.info("API VIP is not set, searching for api ip on masters")
            masters = self.get_hosts_by_role(consts.NodeRoles.MASTER, hosts=cluster.to_dict()["hosts"])
            api_vip = self._wait_for_api_vip(masters)

        log.info("api vip is %s", api_vip)
        return api_vip
示例#9
0
 def set_host_name(self, host_id, requested_name):
     log.info(
         f"Setting Required Host Name:{requested_name}, for Host ID: {host_id}"
     )
     host_data = {
         "hosts_names": [{
             "id": host_id,
             "hostname": requested_name
         }]
     }
     self.api_client.update_cluster(self.id, host_data)
示例#10
0
 def set_additional_ntp_source(self, ntp_source: List[str]):
     log.info(f"Setting Additional NTP source:{ntp_source}")
     if isinstance(ntp_source, List):
         ntp_source_string = ",".join(ntp_source)
     elif isinstance(ntp_source, str):
         ntp_source_string = ntp_source
     else:
         raise TypeError(
             f"ntp_source must be a string or a list of strings, got: {ntp_source}," f" type: {type(ntp_source)}"
         )
     self.update_config(additional_ntp_source=ntp_source_string)
     self.api_client.update_cluster(self.id, {"additional_ntp_source": ntp_source_string})
示例#11
0
 def _find_event(self, event_to_find, reference_time, params_list, host_id):
     events_list = self.get_events(host_id=host_id)
     for event in events_list:
         if event_to_find in event["message"]:
             # Adding a 2 sec buffer to account for a small time diff between the machine and the time on staging
             if utils.to_utc(event["event_time"]) >= reference_time - 2:
                 if all(param in event["message"] for param in params_list):
                     # event_exist = True
                     log.info(f"Event to find: {event_to_find} exists with its params")
                     return True
     else:
         return False
示例#12
0
    def update_config(self, **kwargs):
        """
        Note that kwargs can contain values for overriding BaseClusterConfig arguments.
        The name (key) of each argument must match to one of the BaseClusterConfig arguments.
        If key doesn't exists in config - KeyError exception is raised
        """
        log.info(f"Updating cluster {self.id} configurations to {kwargs}")

        for k, v in kwargs.items():
            if not hasattr(self._config, k):
                raise KeyError(f"The key {k} is not present in {self._config.__class__.__name__}")
            setattr(self._config, k, v)
示例#13
0
 def wait_for_event(self, event_to_find, reference_time, params_list=None, host_id="", timeout=10):
     log.info(f"Searching for event: {event_to_find}")
     if params_list is None:
         params_list = list()
     try:
         waiting.wait(
             lambda: self._find_event(event_to_find, reference_time, params_list, host_id),
             timeout_seconds=timeout,
             sleep_seconds=2,
             waiting_for="Event: %s" % event_to_find,
         )
     except waiting.exceptions.TimeoutExpired:
         log.error(f"Event: {event_to_find} did't found")
         raise
示例#14
0
    def set_olm_operator(self, operator_name, properties=None):
        log.info(f"Setting {operator_name} for cluster: {self.id}")
        cluster = self.api_client.cluster_get(self.id)

        if operator_name in [o.name for o in cluster.monitored_operators]:
            return

        olm_operators = []
        for operator in cluster.monitored_operators:
            if operator.operator_type == OperatorType.BUILTIN:
                continue
            olm_operators.append({"name": operator.name, "properties": operator.properties})
        olm_operators.append({"name": operator_name, "properties": properties})

        self._config.olm_operators = olm_operators
        self.api_client.update_cluster(self.id, {"olm_operators": olm_operators})
示例#15
0
    def set_advanced_networking(self, cluster_cidr: str, service_cidr: str, cluster_host_prefix: int):
        log.info(
            f"Setting Cluster CIDR: {cluster_cidr}, Service CIDR: {service_cidr}, "
            f"Cluster Host Prefix: {cluster_host_prefix} for cluster: {self.id}"
        )

        self.update_config(
            service_network_cidr=service_cidr,
            cluster_network_cidr=cluster_cidr,
            cluster_network_host_prefix=cluster_host_prefix,
        )
        self.api_client.update_cluster(
            self.id,
            {
                "cluster_network_cidr": cluster_cidr,
                "service_network_cidr": service_cidr,
                "cluster_network_host_prefix": cluster_host_prefix,
            },
        )
示例#16
0
 def set_ingress_and_api_vips(self, vips):
     log.info(f"Setting API VIP:{vips['api_vip']} and ingres VIP:{vips['ingress_vip']} for cluster: {self.id}")
     self.api_client.update_cluster(self.id, vips)
示例#17
0
 def set_cluster_name(self, cluster_name: str):
     log.info(f"Setting Cluster Name:{cluster_name} for cluster: {self.id}")
     self.update_config(cluster_name=cluster_name)
     self.api_client.update_cluster(self.id, {"name": cluster_name})
示例#18
0
 def get_bootstrap_hostname(self):
     hosts = self.get_hosts_by_role(consts.NodeRoles.MASTER)
     for host in hosts:
         if host.get("bootstrap"):
             log.info("Bootstrap node is: %s", host["requested_hostname"])
             return host["requested_hostname"]
示例#19
0
 def delete_host(self, host):
     host_id = host["id"]
     log.info(f"Going to delete host: {host_id} in cluster: {self.id}")
     self.api_client.deregister_host(cluster_id=self.id, host_id=host_id)
示例#20
0
 def enable_host(self, host):
     host_name = host["requested_hostname"]
     log.info(f"Going to enable host: {host_name} in cluster: {self.id}")
     self.api_client.enable_host(cluster_id=self.id, host_id=host["id"])
示例#21
0
 def set_proxy_values(self, http_proxy, https_proxy="", no_proxy=""):
     log.info(
         f"Setting http_proxy:{http_proxy}, https_proxy:{https_proxy} and no_proxy:{no_proxy} "
         f"for cluster: {self.id}"
     )
     self.api_client.set_cluster_proxy(self.id, http_proxy, https_proxy, no_proxy)
示例#22
0
 def set_pull_secret(self, pull_secret: str):
     log.info(f"Setting pull secret:{pull_secret} for cluster: {self.id}")
     self.update_config(pull_secret=pull_secret)
     self.api_client.update_cluster(self.id, {"pull_secret": pull_secret})
示例#23
0
 def set_advanced_service_cidr(self, service_cidr: str):
     log.info(f"Setting Service CIDR: {service_cidr} for cluster: {self.id}")
     self.update_config(service_network_cidr=service_cidr)
     self.api_client.update_cluster(self.id, {"service_network_cidr": service_cidr})
示例#24
0
 def set_advanced_cluster_cidr(self, cluster_cidr: str):
     log.info(f"Setting Cluster CIDR: {cluster_cidr} for cluster: {self.id}")
     self.update_config(cluster_network_cidr=cluster_cidr)
     self.api_client.update_cluster(self.id, {"cluster_network_cidr": cluster_cidr})
示例#25
0
 def set_machine_cidr(self, machine_cidr):
     log.info(f"Setting Machine Network CIDR:{machine_cidr} for cluster: {self.id}")
     self.api_client.update_cluster(self.id, {"machine_network_cidr": machine_cidr})
示例#26
0
 def set_ssh_key(self, ssh_key: str):
     log.info(f"Setting SSH key:{ssh_key} for cluster: {self.id}")
     self.update_config(ssh_public_key=ssh_key)
     self.api_client.update_cluster(self.id, {"ssh_public_key": ssh_key})
示例#27
0
 def log_configuration(self):
     log.info(f"controller configuration={self._config}")