Ejemplo n.º 1
0
class KubernetesHost(HostBase):
    """ Main handler to operate the K8s hosts
    """
    def __init__(self):
        self.operation = KubernetesOperation()

    def create(self, k8s_params):
        """ Create a new Kubernetes host
        :param k8s_params : params to connect to Kubernetes Master node
        :return:
        """
        # Init connection
        return self.operation.check_host(k8s_params)

    def refresh_status(self, k8s_params):
        """ Refresh the status of the host
        :param k8s_params: params to connect to Kubernetes Master node
        :return: the status of the host
        """
        return self.operation.refresh_status(k8s_params)

    def delete(self, k8s_params):
        """ Delete a host instance and the cluster on it
        :param k8s_params: params to connect to Kubernetes Master node
        :return:
        """
        pass

    def reset(self, k8s_params):
        """ Clean the free clusters on the host.
        :param k8s_params: params to connect to Kubernetes Master node
        :return:
        """
        pass
Ejemplo n.º 2
0
    def get_services_urls(self, cid):
        try:
            cluster = ClusterModel.objects.get(id=cid)

            cluster_name = cluster.name
            kube_config = KubernetesOperation()._get_from_params(
                cluster.host.k8s_param)

            operation = K8sClusterOperation(kube_config)
            services_urls = operation.get_services_urls(cluster_name)
        except Exception as e:
            logger.error(
                "Failed to get Kubernetes services's urls: {}".format(e))
            return None
        return services_urls
Ejemplo n.º 3
0
    def _get_cluster_info(self, cid, config):
        cluster = ClusterModel.objects.get(id=cid)

        cluster_name = cluster.name
        kube_config = KubernetesOperation()._get_config_from_params(cluster
                                                                    .host
                                                                    .k8s_param)

        clusters_exists = ClusterModel.objects(host=cluster.host)
        ports_index = [service.port for service in ServicePort
                       .objects(cluster__in=clusters_exists)]

        nfsServer_ip = cluster.host.k8s_param.get('K8SNfsServer')
        consensus = config['consensus_plugin']

        return cluster, cluster_name, kube_config, ports_index, \
            nfsServer_ip, consensus
Ejemplo n.º 4
0
 def __init__(self):
     self.operation = KubernetesOperation()