def __enabling_basic_authentication(k8s_conf):
    """Basic Authentication function"""
    basic_authentications = config_utils.get_basic_auth(k8s_conf)
    for basic_authentication in basic_authentications:
        user = basic_authentication[consts.USER_KEY]
        user_name = user[consts.USER_NAME_KEY]
        user_password = user[consts.USER_PASS_KEY]
        user_id = basic_authentication.get(consts.USER_KEY).get(
            consts.USER_ID_KEY)
        pb_vars = {
            'user_name': user_name,
            'user_password': user_password,
            'user_id': user_id,
            'PROJ_ARTIFACT_DIR':
            config_utils.get_project_artifact_dir(k8s_conf),
        }
        ansible_utils.apply_playbook(consts.KUBERNETES_USER_LIST,
                                     variables=pb_vars)

    master_host, ip = config_utils.get_first_master_host(k8s_conf)
    pb_vars = {
        'BASIC_AUTH_FILE': consts.K8S_BASIC_AUTH_CSV,
        'KUBERNETES_PATH': consts.NODE_K8S_PATH,
    }
    ansible_utils.apply_playbook(consts.KUBERNETES_AUTHENTICATION, [ip],
                                 consts.NODE_USER,
                                 variables=pb_vars)
def __install_kubectl(k8s_conf):
    """
    This function is used to install kubectl at bootstrap node
    """
    lb_ip = "127.0.0.1"
    lb_ips = config_utils.get_ha_lb_ips(k8s_conf)
    if len(lb_ips) > 0:
        lb_ip = lb_ips[0]

    logger.info("Load balancer ip %s", lb_ip)

    host_name, ip = config_utils.get_first_master_host(k8s_conf)
    ha_enabled = len(lb_ips) > 0
    pb_vars = {
        'ip': ip,
        'host_name': host_name,
        'ha_enabled': ha_enabled,
        'Project_name': config_utils.get_project_name(k8s_conf),
        'lb_ip': lb_ip,
        'CONFIG_DEMO_FILE': consts.KUBECTL_CONF_TMPLT,
        'PROJ_ARTIFACT_DIR': config_utils.get_project_artifact_dir(
            k8s_conf),
        'KUBERNETES_PATH': consts.NODE_K8S_PATH,
    }
    pb_vars.update(config_utils.get_proxy_dict(k8s_conf))
    ansible_utils.apply_playbook(consts.K8_KUBECTL_INSTALLATION,
                                 variables=pb_vars)
Esempio n. 3
0
def delete_flannel_interfaces(k8s_conf):
    """
    This function is used to delete flannel interfaces
    """
    logger.info('EXECUTING FLANNEL INTERFACE DELETION PLAY')
    multus_flannel_cfgs = config_utils.get_multus_cni_flannel_cfgs(k8s_conf)

    for multus_flannel_cfg in multus_flannel_cfgs:
        hostdetails = multus_flannel_cfg.get(consts.FLANNEL_NET_DTLS_KEY)
        network_name = hostdetails.get(consts.NETWORK_NAME_KEY)

        pb_vars = {
            'node_type': consts.NODE_TYPE_MASTER,
            'networkName': network_name,
            'PROJ_ARTIFACT_DIR':
            config_utils.get_project_artifact_dir(k8s_conf),
        }
        master_host_name, master_ip = config_utils.get_first_master_host(
            k8s_conf)
        logger.info(
            'Executing delete flannel interface play. '
            'Master Host Name - %s', master_host_name)
        if master_ip:
            ansible_utils.apply_playbook(consts.K8_DELETE_FLANNEL_INTERFACE,
                                         [master_ip],
                                         config_utils.get_node_user(k8s_conf),
                                         variables=pb_vars)
def __launch_sriov_network(k8s_conf, sriov_host):
    master_host, ip = config_utils.get_first_master_host(k8s_conf)

    for sriov_net in sriov_host[consts.SRIOV_NETWORKS_KEY]:
        dpdk_enable = config_utils.bool_val(sriov_net.get(
            consts.SRIOV_DPDK_ENABLE_KEY))

        if dpdk_enable:
            logger.info('SRIOV NETWORK CREATION STARTED USING DPDK DRIVER')

            host_type = sriov_net.get(consts.TYPE_KEY)
            sriov_intf = sriov_net.get(consts.SRIOV_INTF_KEY)
            sriov_nw_name = sriov_net.get(consts.NETWORK_NAME_KEY)
            pb_vars = {
                'intf': sriov_intf,
                'network_name': sriov_nw_name,
                'dpdk_driver': consts.DPDK_DRIVER,
                'dpdk_tool': consts.DPDK_TOOL,
                'node_hostname': sriov_host.get(consts.HOSTNAME_KEY),
                'PROJ_ARTIFACT_DIR': config_utils.get_project_artifact_dir(
                    k8s_conf),
            }
            ansible_utils.apply_playbook(
                consts.K8_SRIOV_DPDK_CR_NW, [master_host],
                consts.NODE_USER, variables=pb_vars)

            if host_type == consts.NET_TYPE_LOCAL_TYPE:
                logger.info('SRIOV NETWORK CREATION STARTED USING '
                            'KERNEL DRIVER WITH IPAM host-local')

                pb_vars = {
                    'host_name': master_host,
                    'intf': sriov_intf,
                    'network_name': sriov_nw_name,
                    'rangeStart': sriov_net.get(consts.RANGE_START_KEY),
                    'rangeEnd': sriov_net.get(consts.RANGE_END_KEY),
                    'subnet': sriov_net.get(consts.SUBNET_KEY),
                    'gateway': sriov_net.get(consts.GATEWAY_KEY),
                    'masterPlugin': sriov_net.get(consts.MASTER_PLUGIN_KEY),
                    'PROJ_ARTIFACT_DIR': config_utils.get_project_artifact_dir(
                        k8s_conf),
                }
                ansible_utils.apply_playbook(
                    consts.K8_SRIOV_CR_NW, consts.NODE_USER, variables=pb_vars)

            if host_type == consts.DHCP_TYPE:
                logger.info(
                    'SRIOV NETWORK CREATION STARTED USING '
                    'KERNEL DRIVER WITH IPAM host-dhcp')
                pb_vars = {
                    'intf': sriov_intf,
                    'network_name': sriov_nw_name,
                    'PROJ_ARTIFACT_DIR': config_utils.get_project_artifact_dir(
                        k8s_conf),
                }
                pb_vars.update(config_utils.get_proxy_dict(k8s_conf))
                ansible_utils.apply_playbook(
                    consts.K8_SRIOV_DHCP_CR_NW,
                    consts.NODE_USER, variables=pb_vars)
Esempio n. 5
0
def __modifying_etcd_node(k8s_conf):
    """etcd modification changes"""
    ip = config_utils.get_k8s_api_host(k8s_conf)
    master_host_name, master_ip = config_utils.get_first_master_host(k8s_conf)
    if not ip:
        ip = master_ip
    logger.debug('EXECUTING ETCD modification to ip - %s', ip)
    ansible_utils.apply_playbook(consts.ETCD_CHANGES, [master_ip],
                                 config_utils.get_node_user(k8s_conf),
                                 variables={'ip': ip})
Esempio n. 6
0
 def test_get_first_master_host(self):
     """
     Ensures the hostname and IP of the first master host found in the config are properly parsed
     """
     hostname, ip = config_utils.get_first_master_host(self.config)
     for node in self.node_list:
         if node[consts.HOST_KEY][
                 consts.NODE_TYPE_KEY] == consts.NODE_TYPE_MASTER:
             hostname_cfg, ip_cfg = node[consts.HOST_KEY][
                 consts.HOSTNAME_KEY], node[consts.HOST_KEY][consts.IP_KEY]
             break
     self.assertItemsEqual((hostname_cfg, ip_cfg), (hostname, ip))
Esempio n. 7
0
def launch_crd_network(k8s_conf):
    """
    This function is used to create crd network
    """
    master_host_name, master_ip = config_utils.get_first_master_host(k8s_conf)
    logger.info(
        'EXECUTING CRD NETWORK CREATION PLAY. Master ip - %s, '
        'Master Host Name - %s', master_ip, master_host_name)
    pb_vars = {
        'CRD_NET_YML': consts.K8S_CRD_NET_CONF,
        'PROJ_ARTIFACT_DIR': config_utils.get_project_artifact_dir(k8s_conf),
    }
    ansible_utils.apply_playbook(consts.K8_CREATE_CRD_NETWORK,
                                 variables=pb_vars)
Esempio n. 8
0
def __install_kubectl(k8s_conf):
    """
    This function is used to install kubectl at bootstrap node
    """
    host_name, ip = config_utils.get_first_master_host(k8s_conf)
    api_ip_url = config_utils.get_k8s_api_url(k8s_conf, ip)

    pb_vars = {
        'ip': ip,
        'api_ip_url': api_ip_url,
        'node_user': config_utils.get_node_user(k8s_conf),
        'host_name': host_name,
        'Project_name': config_utils.get_project_name(k8s_conf),
        'CONFIG_DEMO_FILE': consts.KUBECTL_CONF_TMPLT,
        'PROJ_ARTIFACT_DIR': config_utils.get_project_artifact_dir(k8s_conf),
        'KUBERNETES_PATH': consts.NODE_K8S_PATH,
    }
    pb_vars.update(config_utils.get_proxy_dict(k8s_conf))
    ansible_utils.apply_playbook(consts.K8_KUBECTL_INSTALLATION,
                                 variables=pb_vars)
def __modifying_etcd_node(k8s_conf):
    """etcd modification changes"""
    master_host_name, master_ip = config_utils.get_first_master_host(k8s_conf)
    ansible_utils.apply_playbook(consts.ETCD_CHANGES, [master_ip],
                                 consts.NODE_USER,
                                 variables={'ip': master_ip})