Ejemplo n.º 1
0
def get_node_ips_from_module(module):
    """
    Fetches the node IP's in cluster from terraform state file

    Args:
        module (str): Module name in terraform.tfstate file
            e.g: constants.COMPUTE_MODULE

    Returns:
        list: List of module node IP's

    """
    terraform_state_file = os.path.join(
        config.ENV_DATA['cluster_path'],
        "terraform_data",
        "terraform.tfstate"
    )

    if not os.path.isfile(terraform_state_file):
        raise FileNotFoundError(
            errno.ENOENT,
            os.strerror(errno.ENOENT),
            terraform_state_file
        )
    ip_address = get_module_ip(
        terraform_state_file,
        module
    )
    return ip_address
Ejemplo n.º 2
0
    def create_inventory_for_haproxy(self):
        """
        Creates the inventory file for haproxy

        Returns:
            str: Path to inventory file for haproxy

        """
        inventory_data_haproxy = {}
        inventory_data_haproxy['ssh_key_private'] = self.ssh_key_pem
        inventory_data_haproxy['platform'] = config.ENV_DATA['platform']
        inventory_data_haproxy['rhel_worker_nodes'] = self.rhel_worker_nodes
        lb_address = get_module_ip(
            self.terraform_state_file,
            constants.LOAD_BALANCER_MODULE
        )
        control_plane_address = get_module_ip(
            self.terraform_state_file,
            constants.CONTROL_PLANE
        )
        compute_address = get_module_ip(
            self.terraform_state_file,
            constants.COMPUTE_MODULE
        )
        inventory_data_haproxy['lb'] = lb_address
        inventory_data_haproxy['masters'] = control_plane_address
        inventory_data_haproxy['workers'] = compute_address

        logger.info("Generating inventory file for haproxy")
        _templating = Templating()
        inventory_template_path_haproxy = os.path.join(
            "ocp-deployment", constants.INVENTORY_TEMPLATE_HAPROXY
        )
        inventory_config_haproxy_str = _templating.render_template(
            inventory_template_path_haproxy, inventory_data_haproxy
        )
        inventory_yaml_haproxy = os.path.join(
            self.cluster_path,
            constants.TERRAFORM_DATA_DIR,
            constants.INVENTORY_FILE_HAPROXY
        )
        logger.debug(f"inventory contents for haproxy: {inventory_config_haproxy_str}")
        logger.debug(f"inventory yaml: {inventory_yaml_haproxy}")
        with open(inventory_yaml_haproxy, "w") as f:
            f.write(inventory_config_haproxy_str)

        return inventory_yaml_haproxy
Ejemplo n.º 3
0
    def remove_boostrap_in_proxy(self):
        """
        Removes bootstrap IP from haproxy.conf
        """
        bootstrap_ip = get_module_ip(self.terraform_state_file,
                                     constants.BOOTSTRAP_MODULE)[0]
        # backup the conf file
        cmd = (f"sudo cp {constants.HAPROXY_LOCATION}"
               f" {constants.HAPROXY_LOCATION}_backup")
        self.lb.exec_cmd(cmd)

        # remove bootstrap IP
        cmd = f"sudo sed -i '/{bootstrap_ip}/d' {constants.HAPROXY_LOCATION}"
        self.lb.exec_cmd(cmd)
Ejemplo n.º 4
0
    def _get_host(self):
        """
        Fetches the Host/IP address from terraform.tfstate file

        Returns:
             str: IP Address of load balancer

        """
        self.terraform_state_file = os.path.join(
            config.ENV_DATA["cluster_path"], "terraform_data",
            "terraform.tfstate")

        if not os.path.isfile(self.terraform_state_file):
            raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT),
                                    self.terraform_state_file)
        ip_address = get_module_ip(self.terraform_state_file,
                                   constants.LOAD_BALANCER_MODULE)
        return ip_address[0]