Exemple #1
0
 def put_cluster_acl(self, cluster_id: str, acl_entries: List[Dict]):
     uri = f'{self._cluster_uri}/{cluster_id}/acl'
     put_content = {
         shared_constants.ClusterAclKey.ACCESS_SETTING: acl_entries
     }
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.PUT,
         uri,
         self._client._session,
         contents=put_content,
         media_type='application/json',
         accept_type='application/json')
     response_processor.process_response(response)
 def resize_cluster(self,
                    network_name,
                    cluster_name,
                    node_count,
                    org=None,
                    vdc=None,
                    rollback=True):
     method = RequestMethod.PUT
     uri = f"{self._uri}/cluster/{cluster_name}"
     data = {
         RequestKey.CLUSTER_NAME: cluster_name,
         RequestKey.NUM_WORKERS: node_count,
         RequestKey.ENABLE_NFS: False,
         RequestKey.ORG_NAME: org,
         RequestKey.OVDC_NAME: vdc,
         RequestKey.NETWORK_NAME: network_name,
         RequestKey.ROLLBACK: 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 update_ovdc_compute_policies(self, ovdc_name, org_name,
                                     compute_policy_name, action):
        """Update an ovdc's compute policies.

        :param str ovdc_name: Name of org VDC to update
        :param str org_name: Name of org that @ovdc_name belongs to
        :param str compute_policy_name: Name of compute policy to add or remove
        :param ComputePolicyAction action:

        :rtype: dict
        """
        method = RequestMethod.PUT
        ovdc = get_vdc(self.client,
                       vdc_name=ovdc_name,
                       org_name=org_name,
                       is_admin_operation=True)
        ovdc_id = utils.extract_id(ovdc.get_resource().get('id'))
        uri = f'{self._uri}/ovdc/{ovdc_id}/compute-policies'

        data = {
            RequestKey.OVDC_ID: ovdc_id,  # also exists in url
            RequestKey.COMPUTE_POLICY_NAME: compute_policy_name,
            RequestKey.COMPUTE_POLICY_ACTION: action
        }

        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 add_node(self,
                 network_name,
                 cluster_name,
                 node_count=1,
                 org=None,
                 vdc=None,
                 cpu=None,
                 memory=None,
                 storage_profile=None,
                 ssh_key=None,
                 template=None,
                 enable_nfs=False,
                 rollback=True):
        """Add nodes to a Kubernetes cluster.

        :param org: (str): The name of the org that contains the 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 cluster_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 enable_nfs: (bool): Flag to enable NFS software on worker nodes
        :param rollback: (bool): Flag to control whether rollback
            should be performed or not in case of errors.

        :return: (json) A parsed json object describing the requested cluster.
        """
        method = RequestMethod.POST
        uri = f'{self._uri}/nodes'
        data = {
            RequestKey.CLUSTER_NAME: cluster_name,
            RequestKey.NUM_WORKERS: node_count,
            RequestKey.ORG_NAME: org,
            RequestKey.OVDC_NAME: vdc,
            RequestKey.NUM_CPU: cpu,
            RequestKey.MB_MEMORY: memory,
            RequestKey.NETWORK_NAME: network_name,
            RequestKey.STORAGE_PROFILE_NAME: storage_profile,
            RequestKey.SSH_KEY_FILEPATH: ssh_key,
            RequestKey.TEMPLATE_NAME: template,
            RequestKey.ENABLE_NFS: enable_nfs,
            RequestKey.ROLLBACK: 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 delete_nodes(self,
                     cluster_name,
                     nodes,
                     org=None,
                     vdc=None,
                     force=False):
        """Delete nodes from a Kubernetes cluster.

        :param org: (str): Name of the organization that contains the 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 = RequestMethod.DELETE
        uri = f"{self._uri}/nodes"
        data = {
            RequestKey.CLUSTER_NAME: cluster_name,
            RequestKey.ORG_NAME: org,
            RequestKey.OVDC_NAME: vdc,
            RequestKey.NODE_NAMES_LIST: nodes,
            RequestKey.FORCE_DELETE: force
        }
        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_ovdcs(self):
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.GET,
         self._ovdcs_uri,
         self._client._session,
         accept_type='application/json')
     return process_response(response)
Exemple #7
0
 def resize_cluster(self,
                    network_name,
                    cluster_name,
                    node_count,
                    org=None,
                    vdc=None,
                    rollback=True,
                    template_name=None,
                    template_revision=None,
                    cpu=None,
                    memory=None,
                    ssh_key=None):
     method = RequestMethod.PUT
     uri = f"{self._uri}/cluster/{cluster_name}"
     data = {
         RequestKey.CLUSTER_NAME: cluster_name,
         RequestKey.NUM_WORKERS: node_count,
         RequestKey.ORG_NAME: org,
         RequestKey.OVDC_NAME: vdc,
         RequestKey.NETWORK_NAME: network_name,
         RequestKey.ROLLBACK: rollback,
         RequestKey.TEMPLATE_NAME: template_name,
         RequestKey.TEMPLATE_REVISION: template_revision,
         RequestKey.NUM_CPU: cpu,
         RequestKey.MB_MEMORY: memory,
         RequestKey.SSH_KEY: ssh_key
     }
     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 #8
0
    def create_cluster(self, vdc, name, node_count=None, org=None):
        """Create a new Kubernetes cluster.

        :param vdc: (str): The name of the vdc in which the cluster will be
            created
        :param name: (str): The name of the cluster
        :param node_count: (str): Number of nodes
        :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 = RequestMethod.POST
        uri = f"{self._uri}/clusters"
        data = {
            RequestKey.CLUSTER_NAME: name,
            RequestKey.NUM_WORKERS: node_count,
            RequestKey.OVDC_NAME: vdc,
            RequestKey.ORG_NAME: 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)
Exemple #9
0
 def update_cluster(self,
                    cluster_name,
                    network_name,
                    node_count,
                    org_name=None,
                    ovdc_name=None,
                    template_name=None,
                    template_revision=None,
                    cpu=None,
                    memory=None,
                    ssh_key=None,
                    rollback=True):
     uri = f"{self._cluster_uri}/{cluster_name}"
     payload = {
         shared_constants.RequestKey.CLUSTER_NAME: cluster_name,
         shared_constants.RequestKey.NUM_WORKERS: node_count,
         shared_constants.RequestKey.ORG_NAME: org_name,
         shared_constants.RequestKey.OVDC_NAME: ovdc_name,
         shared_constants.RequestKey.NETWORK_NAME: network_name,
         shared_constants.RequestKey.ROLLBACK: rollback,
         shared_constants.RequestKey.TEMPLATE_NAME: template_name,
         shared_constants.RequestKey.TEMPLATE_REVISION: template_revision,
         shared_constants.RequestKey.NUM_CPU: cpu,
         shared_constants.RequestKey.MB_MEMORY: memory,
         shared_constants.RequestKey.SSH_KEY: ssh_key
     }
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.PUT,
         uri,
         self._client._session,
         contents=payload,
         media_type='application/json',
         accept_type='application/json')
     return process_response(response)
 def list_clusters(self, filters={}):
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.GET,
         self._clusters_uri,
         self._client._session,
         accept_type='application/json',
         params=filters)
     return response_processor.process_response(response)
 def get_templates(self):
     method = RequestMethod.GET
     uri = f"{self._uri}/templates"
     response = self.client._do_request_prim(method,
                                             uri,
                                             self.client._session,
                                             accept_type='application/json')
     return process_response(response)
 def list_ovdc_compute_policies(self, ovdc_id):
     uri = f'{self._ovdc_uri}/{ovdc_id}/compute-policies'
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.GET,
         uri,
         self._client._session,
         accept_type='application/json')
     return process_response(response)
 def get_ovdc(self, ovdc_id):
     uri = f"{self._ovdc_uri}/{ovdc_id}"
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.GET,
         uri,
         self._client._session,
         accept_type='application/json')
     return def_models.Ovdc(**process_response(response))
Exemple #14
0
 def get_upgrade_plan_by_cluster_id(self, cluster_id: str):
     uri = f'{self._cluster_uri}/{cluster_id}/upgrade-plan'
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.GET,
         uri,
         self._client._session,
         accept_type='application/json')
     return response_processor.process_response(response)
 def get_cluster_config(self, cluster_name, org_name=None, ovdc_name=None):
     uri = f"{self._cluster_uri}/{cluster_name}/config"
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.GET,
         uri,
         self._client._session,
         media_type='application/json',
         accept_type='application/json')
     return response_processor.process_response(response)
 def get_cluster(self, cluster_name, filters={}):
     uri = f'{self._cluster_uri}/{cluster_name}'
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.GET,
         uri,
         self._client._session,
         accept_type='application/json',
         params=filters)
     return response_processor.process_response(response)
 def delete_cluster(self, cluster_name, filters={}):
     uri = f"{self._cluster_uri}/{cluster_name}"
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.DELETE,
         uri,
         self._client._session,
         accept_type='application/json',
         params=filters)
     return process_response(response)
Exemple #18
0
 def get_cluster_config_by_cluster_id(self, cluster_id: str) -> dict:
     uri = f"{self._cluster_uri}/{cluster_id}/config"
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.GET,
         uri,
         self._client._session,
         media_type='application/json',
         accept_type='application/json')
     return response_processor.process_response(response)
Exemple #19
0
 def delete_cluster_by_cluster_id(self, cluster_id):
     uri = f"{self._cluster_uri}/{cluster_id}"
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.DELETE,
         uri,
         self._client._session,
         media_type='application/json',
         accept_type='application/json')
     return def_models.DefEntity(**response_processor.process_response(response))  # noqa: E501
 def update_ovdc(self, ovdc_id, ovdc_obj: def_models.Ovdc):
     uri = f"{self._ovdc_uri}/{ovdc_id}"
     resp = self._client._do_request_prim(
         shared_constants.RequestMethod.PUT,
         uri,
         self._client._session,
         contents=asdict(ovdc_obj),
         media_type='application/json',
         accept_type='application/json')
     return process_response(resp)
Exemple #21
0
 def delete_cluster(self, cluster_name, org=None, vdc=None):
     method = RequestMethod.DELETE
     uri = f"{self._uri}/cluster/{cluster_name}"
     response = self.client._do_request_prim(
         method,
         uri,
         self.client._session,
         accept_type='application/json',
         params={RequestKey.ORG_NAME: org, RequestKey.OVDC_NAME: vdc})
     return process_response(response)
 def update_system(self, action):
     payload = {shared_constants.RequestKey.SERVER_ACTION: action}
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.PUT,
         self._system_uri,
         self._client._session,
         contents=payload,
         media_type='application/json',
         accept_type='application/json')
     return process_response(response)
Exemple #23
0
 def get_clusters(self, vdc=None, org=None):
     method = RequestMethod.GET
     uri = f"{self._uri}/clusters"
     response = self.client._do_request_prim(
         method,
         uri,
         self.client._session,
         accept_type='application/json',
         params={RequestKey.ORG_NAME: org, RequestKey.OVDC_NAME: vdc})
     return process_response(response)
Exemple #24
0
 def get_upgrade_plan(self, cluster_name, org=None, vdc=None):
     method = RequestMethod.GET
     uri = f'{self._uri}/cluster/{cluster_name}/upgrade-plan'
     response = self.client._do_request_prim(
         method,
         uri,
         self.client._session,
         accept_type='application/json',
         params={RequestKey.ORG_NAME: org, RequestKey.OVDC_NAME: vdc})
     return process_response(response)
 def list_ovdc_for_k8s(self, list_pks_plans=False):
     method = RequestMethod.GET
     uri = f'{self._uri}/ovdcs'
     response = self.client._do_request_prim(
         method,
         uri,
         self.client._session,
         accept_type='application/json',
         params={RequestKey.LIST_PKS_PLANS: list_pks_plans})
     return process_response(response)
Exemple #26
0
 def delete_nfs_node_by_node_name(self, cluster_id: str, node_name: str):
     uri = f"{self._cluster_uri}/{cluster_id}/nfs/{node_name}"
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.DELETE,
         uri,
         self._client._session,
         media_type='application/json',
         accept_type='application/json')
     return def_models.DefEntity(
         **response_processor.process_response(response))
 def update_service_status(self, action):
     method = RequestMethod.PUT
     uri = f"{self._uri}/system"
     response = self.client._do_request_prim(
         method,
         uri,
         self.client._session,
         contents={RequestKey.SERVER_ACTION: action},
         media_type='application/json',
         accept_type='application/json')
     return process_response(response)
 def get_node_info(self, cluster_name, node_name, filters={}):
     uri = f"{self._node_uri}/{node_name}"
     filters.update(
         {shared_constants.RequestKey.CLUSTER_NAME: cluster_name})
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.GET,
         uri,
         self._client._session,
         accept_type='application/json',
         params=filters)
     return process_response(response)
Exemple #29
0
 def get_cluster_upgrade_plan(self, cluster_name, filters=None):
     if filters is None:
         filters = {}
     uri = f'{self._cluster_uri}/{cluster_name}/upgrade-plan'
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.GET,
         uri,
         self._client._session,
         accept_type='application/json',
         params=filters)
     return process_response(response)
Exemple #30
0
 def update_cluster_by_cluster_id(self, cluster_id, cluster_entity_definition: def_models.ClusterEntity):  # noqa: E501
     cluster_entity_dict = asdict(cluster_entity_definition)
     uri = f"{self._cluster_uri}/{cluster_id}"
     response = self._client._do_request_prim(
         shared_constants.RequestMethod.PUT,
         uri,
         self._client._session,
         contents=cluster_entity_dict,
         media_type='application/json',
         accept_type='application/json')
     return def_models.DefEntity(
         **response_processor.process_response(response))