def list_compute_profiles(self): """Get the list of compute profiles. :return: List of compute profile details as body of the result :rtype: dict """ result = { 'body': [], 'status_code': requests.codes.ok, } profile_api = ProfileApi(api_client=self.pks_client) self.pks_wire_logger.debug(f"Sending request to PKS:" f" {self.pks_host_uri} to get the" f" list of compute profiles") try: cp_list = profile_api.list_compute_profiles() except ApiException as err: SERVER_LOGGER.debug(f"Listing compute-profiles in PKS failed " f"with error:\n {err}") raise PksServerError(err.status, err.body) list_of_cp_dicts = [cp.to_dict() for cp in cp_list] self.pks_wire_logger.debug(f"Received response from PKS:" f" {self.pks_host_uri} on list of" f" compute profiles: {list_of_cp_dicts}") result['body'] = list_of_cp_dicts return result
def delete_compute_profile(self, cp_name): """Delete the compute profile with a given name. :param str cp_name: Name of the compute profile :return: result :rtype: dict """ result = { 'body': [], 'status_code': requests.codes.ok, } profile_api = ProfileApi(api_client=self.pks_client) self.pks_wire_logger.debug(f"Sending request to PKS:" f"{self.pks_host_uri} to delete" f" the compute profile: {cp_name}") try: profile_api.delete_compute_profile(profile_name=cp_name) except ApiException as err: SERVER_LOGGER.debug(f"Deleting compute-profile {cp_name}" f" in PKS failed with error:\n {err}") raise PksServerError(err.status, err.body) self.pks_wire_logger.debug(f"Received response from PKS:" f" {self.pks_host_uri} that it deleted" f" the compute profile: {cp_name}") return result
def get_compute_profile(self, cp_name): """Get the details of compute profile. :param str cp_name: Name of the compute profile :return: Details of the compute profile as body of the result :rtype: dict """ result = { 'body': [], 'status_code': requests.codes.ok, } profile_api = ProfileApi(api_client=self.pks_client) self.pks_wire_logger.debug(f"Sending request to" f" PKS:{self.pks_host_uri} to get the" f" compute profile: {cp_name}") try: compute_profile = \ profile_api.get_compute_profile(profile_name=cp_name) except ApiException as err: SERVER_LOGGER.debug(f"Creating compute-profile {cp_name}" f" in PKS failed with error:\n {err}") raise PksServerError(err.status, err.body) self.pks_wire_logger.debug(f"Received response from" f" PKS: {self.pks_host_uri} on" f" compute-profile: {cp_name} with" f" details: {compute_profile.to_dict()}") result['body'] = compute_profile.to_dict() return result
def delete_compute_profile(self, cp_name): """Delete the compute profile with a given name. :param str cp_name: Name of the compute profile :return: result :rtype: dict """ result = {} result['body'] = [] result['status_code'] = OK profile_api = ProfileApi(api_client=self.pks_client) LOGGER.debug(f"Sending request to PKS:{self.pks_host_uri} to delete " f"the compute profile: {cp_name}") try: profile_api.delete_compute_profile(profile_name=cp_name) except ApiException as err: LOGGER.debug(f"Deleting compute-profile {cp_name} in PKS failed " f"with error:\n {err}") raise PksServerError(err.status, err.body) LOGGER.debug(f"Received response from PKS: {self.pks_host_uri} that" f" it deleted the compute profile: {cp_name}") return result
def get_compute_profile(self, cp_name): """Get the details of compute profile. :param str cp_name: Name of the compute profile :return: Details of the compute profile as body of the result :rtype: dict """ result = {} result['body'] = [] result['status_code'] = OK profile_api = ProfileApi(api_client=self.pks_client) LOGGER.debug(f"Sending request to PKS:{self.pks_host_uri} to get the " f"compute profile: {cp_name}") try: compute_profile = \ profile_api.get_compute_profile(profile_name=cp_name) except ApiException as err: LOGGER.debug(f"Creating compute-profile {cp_name} in PKS failed " f"with error:\n {err}") raise PksServerError(err.status, err.body) LOGGER.debug(f"Received response from PKS: {self.pks_host_uri} on " f"compute-profile: {cp_name} with details: " f"{compute_profile.to_dict()}") result['body'] = compute_profile.to_dict() return result
def create_compute_profile(self, cp_name, az_name, description, cpi, datacenter_name, cluster_name, ovdc_rp_name): """Create a PKS compute profile that maps to a given oVdc in vCD. :param str cp_name: Name of the compute profile :param str az_name: Name of the PKS availability zone to be defined :param str description: Description of the compute profile :param str cpi: Unique identifier provided by BOSH :param str datacenter_name: Name of the datacenter :param str cluster_name: Name of the cluster :param str ovdc_rp_name: Name of the oVdc resource pool :return: result :rtype: dict """ result = {} result['body'] = [] result['status_code'] = OK profile_api = ProfileApi(api_client=self.pks_client) resource_pool = {'resource_pool': ovdc_rp_name} cloud_properties = { 'datacenters': [{ 'name': datacenter_name, 'clusters': [{ cluster_name: resource_pool }] }] } az_params = { 'azs': [{ 'name': az_name, 'cpi': cpi, 'cloud_properties': cloud_properties }] } cp_params_json_str = json.dumps(az_params) cp_request = ComputeProfileRequest(name=cp_name, description=description, parameters=cp_params_json_str) LOGGER.debug(f"Sending request to PKS:{self.pks_host_uri} to create " f"the compute profile: {cp_name} for ovdc {ovdc_rp_name}") try: profile_api.add_compute_profile(body=cp_request) except ApiException as err: LOGGER.debug(f"Creating compute-profile {cp_name} in PKS failed " f"with error:\n {err}") raise PksServerError(err.status, err.body) LOGGER.debug(f"PKS: {self.pks_host_uri} created the compute profile: " f"{cp_name} for ovdc {ovdc_rp_name}") return result
def create_compute_profile(self, cp_name, az_name, description, cpi, datacenter_name, cluster_name, ovdc_rp_name): """Create a PKS compute profile that maps to a given oVdc in vCD. :param str cp_name: Name of the compute profile :param str az_name: Name of the PKS availability zone to be defined :param str description: Description of the compute profile :param str cpi: Unique identifier provided by BOSH :param str datacenter_name: Name of the datacenter :param str cluster_name: Name of the cluster :param str ovdc_rp_name: Name of the oVdc resource pool :return: result :rtype: dict """ result = { 'body': [], 'status_code': requests.codes.ok, } profile_api = ProfileApi(api_client=self.pks_client) resource_pool = {'resource_pool': ovdc_rp_name} cloud_properties = { 'datacenters': [{ 'name': datacenter_name, 'clusters': [{ cluster_name: resource_pool }] }] } az = AZ(name=az_name, cpi=cpi, cloud_properties=cloud_properties) cp_params = ComputeProfileParameters(azs=[az]) cp_request = ComputeProfileRequest(name=cp_name, description=description, parameters=cp_params) self.pks_wire_logger.debug(f"Sending request to" f" PKS:{self.pks_host_uri} to create the" f" compute profile: {cp_name}" f" for ovdc {ovdc_rp_name}") try: profile_api.add_compute_profile(body=cp_request) except ApiException as err: SERVER_LOGGER.debug(f"Creating compute-profile {cp_name} in PKS" f" failed with error:\n {err}") raise PksServerError(err.status, err.body) self.pks_wire_logger.debug(f"PKS: {self.pks_host_uri} created the" f" compute profile: {cp_name}" f" for ovdc {ovdc_rp_name}") return result