def disable_ovdc_for_k8s(self, ovdc_name, org_name=None):
        """Disable ovdc for k8s for the given container provider.

        :param str ovdc_name: Name of the ovdc to be enabled
        :param str org_name: Name of organization that belongs to ovdc_name

        :return: response object

        :rtype: dict
        """
        method = 'PUT'
        ovdc = get_vdc(self.client,
                       ovdc_name,
                       org_name=org_name,
                       is_admin_operation=True)
        ovdc_id = utils.extract_id(ovdc.resource.get('id'))
        uri = f'{self._uri}/ovdc/{ovdc_id}/info'
        data = {
            'ovdc_id': ovdc_id,
            'ovdc_name': ovdc_name,
            K8S_PROVIDER_KEY: K8sProviders.NONE,
            'pks_plans': None,
            'org_name': org_name,
            'disable': True
        }

        response = self.client._do_request_prim(
            method,
            uri,
            self.client._session,
            contents=data,
            media_type='application/json',
            accept_type='application/*+json')
        return process_response(response)
    def info_ovdc_for_k8s(self, ovdc_name, org_name=None):
        """Disable ovdc for k8s for the given container provider.

        :param str ovdc_name: Name of the ovdc to be enabled
        :param str org_name: Name of organization that belongs to ovdc_name

        :return: response object

        :rtype: dict
        """
        method = 'GET'
        ovdc = get_vdc(self.client,
                       ovdc_name,
                       org_name=org_name,
                       is_admin_operation=True)
        ovdc_id = utils.extract_id(ovdc.resource.get('id'))
        uri = f'{self._uri}/ovdc/{ovdc_id}/info'

        response = self.client._do_request_prim(
            method,
            uri,
            self.client._session,
            contents=None,
            media_type=None,
            accept_type='application/*+json')
        return process_response(response)
Exemple #3
0
    def add_node(self,
                 vdc,
                 network_name,
                 name,
                 node_count=1,
                 cpu=None,
                 memory=None,
                 storage_profile=None,
                 ssh_key=None,
                 template=None,
                 node_type=TYPE_NODE,
                 disable_rollback=True):
        """Add nodes to a Kubernetes cluster.

        :param vdc: (str): The name of the vdc that contains the cluster
        :param network_name: (str): The name of the network to which the
            node VMs will connect to
        :param name: (str): The name of the cluster
        :param node_count: (str): The number of nodes
        :param cpu: (str): The number of virtual cpus on each of the
            new nodes in the cluster
        :param memory: (str): The amount of memory (in MB) on each of the new
            nodes in the cluster
        :param storage_profile: (str): The name of the storage profile which
            will back the new nodes
        :param ssh_key: (str): The ssh key that clients can use to log into the
            node vms without explicitly providing passwords
        :param template: (str): The name of the catalog template to use to
            instantiate the nodes
        :param disable_rollback: (bool): Flag to control weather rollback
            should be performed or not in case of errors. True to rollback,
            False to not rollback

        :return: (json) A parsed json object describing the requested cluster.
        """
        method = 'POST'
        uri = '%s/%s/node' % (self._uri, name)
        data = {
            'name': name,
            'node_count': node_count,
            'vdc': vdc,
            'cpu': cpu,
            'memory': memory,
            'network': network_name,
            'storage_profile': storage_profile,
            'ssh_key': ssh_key,
            'template': template,
            'node_type': node_type,
            'disable_rollback': disable_rollback
        }
        response = self.client._do_request_prim(
            method,
            uri,
            self.client._session,
            contents=data,
            media_type='application/json',
            accept_type='application/*+json')
        return process_response(response)
 def list(self):
     method = 'GET'
     uri = f'{self._uri}/ovdc'
     response = self.client._do_request_prim(method,
                                             uri,
                                             self.client._session,
                                             contents=None,
                                             media_type=None,
                                             accept_type='application/json')
     return process_response(response)
Exemple #5
0
 def enable_service(self, enabled=True):
     method = 'PUT'
     uri = '%s/system' % (self._uri)
     response = self.client._do_request_prim(
         method,
         uri,
         self.client._session,
         contents={'enabled': enabled},
         media_type=None,
         accept_type='application/*+json',
         auth=None)
     return process_response(response)
Exemple #6
0
 def stop(self):
     method = 'PUT'
     uri = '%s/system' % (self._uri)
     response = self.client._do_request_prim(
         method,
         uri,
         self.client._session,
         contents={'stopped': True},
         media_type=None,
         accept_type='application/*+json',
         auth=None)
     return process_response(response)
Exemple #7
0
 def get_info(self):
     method = 'GET'
     uri = '%s/system' % (self._uri)
     response = self.client._do_request_prim(
         method,
         uri,
         self.client._session,
         contents=None,
         media_type=None,
         accept_type='application/*+json',
         auth=None)
     return process_response(response)
 def list(self, list_pks_plans=False):
     method = 'GET'
     uri = f'{self._uri}/ovdc'
     contents = {
         'list_pks_plans': list_pks_plans,
     }
     response = self.client._do_request_prim(
         method,
         uri,
         self.client._session,
         contents=contents,
         media_type=None,
         accept_type='application/json')
     return process_response(response)
 def delete_cluster(self, cluster_name):
     method = 'DELETE'
     uri = '%s/%s' % (self._uri, cluster_name)
     response = self.client._do_request_prim(
         method,
         uri,
         self.client._session,
         accept_type='application/*+json')
     try:
         result = process_response(response)
     except VcdResponseError as e:
         if e.error_message == ERROR_UNKNOWN:
             raise CseClientError("Invalid cluster/node name")
         else:
             raise e
     return result
    def enable_ovdc_for_k8s(self,
                            ovdc_name,
                            k8s_provider=None,
                            pks_plan=None,
                            pks_cluster_domain=None,
                            org_name=None):
        """Enable ovdc for k8s for the given container provider.

        :param str ovdc_name: Name of the ovdc to be enabled
        :param str k8s_provider: Name of the container provider
        :param str pks_plan: PKS plan
        :param str pks_cluster_domain: Suffix of the domain name, which will be
         used to construct FQDN of the clusters.
        :param str org_name: Name of organization that belongs to ovdc_name

        :return: response object

        :rtype: dict
        """
        method = 'PUT'
        ovdc = get_vdc(self.client,
                       ovdc_name,
                       org_name=org_name,
                       is_admin_operation=True)
        ovdc_id = utils.extract_id(ovdc.resource.get('id'))
        uri = f'{self._uri}/ovdc/{ovdc_id}/info'

        data = {
            'ovdc_id': ovdc_id,
            'ovdc_name': ovdc_name,
            K8S_PROVIDER_KEY: k8s_provider,
            'pks_plans': pks_plan,
            'pks_cluster_domain': pks_cluster_domain,
            'org_name': org_name,
            'enable': True
        }

        response = self.client._do_request_prim(
            method,
            uri,
            self.client._session,
            contents=data,
            media_type='application/json',
            accept_type='application/*+json')
        return process_response(response)
Exemple #11
0
 def get_clusters(self, vdc=None, org=None):
     method = 'GET'
     uri = self._uri
     params = {}
     if vdc:
         params['vdc'] = vdc
     if org:
         params['org'] = org
     response = self.client._do_request_prim(
         method,
         uri,
         self.client._session,
         contents=None,
         media_type=None,
         accept_type='application/*+json',
         auth=None,
         params=params)
     return process_response(response)
Exemple #12
0
 def get_node_info(self, cluster_name, node_name):
     method = 'GET'
     uri = '%s/%s/%s/info' % (self._uri, cluster_name, node_name)
     response = self.client._do_request_prim(
         method,
         uri,
         self.client._session,
         contents=None,
         media_type=None,
         accept_type='application/*+json',
         auth=None)
     try:
         result = process_response(response)
     except VcdResponseError as e:
         if e.error_message == ERROR_UNKNOWN:
             raise CseClientError("Invalid cluster/node name")
         else:
             raise e
     return result
Exemple #13
0
    def delete_nodes(self, vdc, name, nodes, force=False):
        """Delete nodes from a Kubernetes cluster.

        :param vdc: (str): The name of the vdc that contains the cluster
        :param name: (str): The name of the cluster
        :param nodes: (list(str)): The list of nodes to delete
        :param force: (bool): Force delete the node VM even if kubernetes fails
        :return: (json) A parsed json object describing the requested cluster
            operation.
        """
        method = 'DELETE'
        uri = '%s/%s/node' % (self._uri, name)
        data = {'name': name, 'vdc': vdc, 'nodes': nodes, 'force': force}
        response = self.client._do_request_prim(
            method,
            uri,
            self.client._session,
            contents=data,
            media_type=None,
            accept_type='application/*+json')
        return process_response(response)
Exemple #14
0
 def resize_cluster(self,
                    network_name,
                    cluster_name,
                    node_count=1,
                    vdc=None,
                    disable_rollback=True):
     method = 'PUT'
     uri = f"{self._uri}/{cluster_name}"
     data = {
         'name': cluster_name,
         'node_count': node_count,
         'node_type': TYPE_NODE,
         'vdc': vdc,
         'network': network_name,
         'disable_rollback': disable_rollback
     }
     response = self.client._do_request_prim(method,
                                             uri,
                                             self.client._session,
                                             contents=data,
                                             media_type='application/json',
                                             accept_type='application/json')
     return process_response(response)
Exemple #15
0
    def create_cluster(self,
                       vdc,
                       network_name,
                       name,
                       node_count=2,
                       cpu=None,
                       memory=None,
                       storage_profile=None,
                       ssh_key=None,
                       template=None,
                       enable_nfs=False,
                       disable_rollback=True,
                       org=None):
        """Create a new Kubernetes cluster.

        :param vdc: (str): The name of the vdc in which the cluster will be
            created
        :param network_name: (str): The name of the network to which the
            cluster vApp will connect to
        :param name: (str): The name of the cluster
        :param node_count: (str): The number ofs nodes
        :param cpu: (str): The number of virtual cpus on each of the
            nodes in the cluster
        :param memory: (str): The amount of memory (in MB) on each of the nodes
            in the cluster
        :param storage_profile: (str): The name of the storage profile which
            will back the cluster
        :param ssh_key: (str): The ssh key that clients can use to log into the
            node vms without explicitly providing passwords
        :param template: (str): The name of the template to use to
            instantiate the nodes
        :param enable_nfs: (bool): bool value to indicate if NFS node is to be
            created
        :param disable_rollback: (bool): Flag to control weather rollback
            should be performed or not in case of errors. True to rollback,
            False to not rollback
        :param pks_ext_host: (str): Address from which to access the Kubernetes
        API for PKS.
        :param pks_plan: (str): Preconfigured PKS plan to use for deploying the
        cluster.
        :param org: (str): name of the organization in which the vdc to be
        used for cluster creation.

        :return: (json) A parsed json object describing the requested cluster.
        """
        method = 'POST'
        uri = self._uri
        data = {
            'cluster_name': name,
            'node_count': node_count,
            'vdc': vdc,
            'cpu': cpu,
            'memory': memory,
            'network': network_name,
            'storage_profile': storage_profile,
            'ssh_key': ssh_key,
            'template': template,
            'enable_nfs': enable_nfs,
            'disable_rollback': disable_rollback,
            'org': org
        }
        response = self.client._do_request_prim(
            method,
            uri,
            self.client._session,
            contents=data,
            media_type='application/json',
            accept_type='application/*+json')
        return process_response(response)