def create_pks_compute_profile(request_data, request_context: ctx.RequestContext, pks_context): ovdc_id = request_data.get(RequestKey.OVDC_ID) org_name = request_data.get(RequestKey.ORG_NAME) ovdc_name = request_data.get(RequestKey.OVDC_NAME) # Compute profile creation pks_compute_profile_name = _construct_pks_compute_profile_name( request_context.sysadmin_client, ovdc_id) pks_compute_profile_description = f"{org_name}--{ovdc_name}--{ovdc_id}" pks_az_name = f"az-{ovdc_name}" ovdc_rp_name = f"{ovdc_name} ({ovdc_id})" compute_profile_params = PksComputeProfileParams( pks_compute_profile_name, pks_az_name, pks_compute_profile_description, pks_context.get('cpi'), pks_context.get('datacenter'), pks_context.get('cluster'), ovdc_rp_name).to_dict() LOGGER.debug(f"Creating PKS Compute Profile with name:" f"{pks_compute_profile_name}") pksbroker = PksBroker(pks_context, request_context) try: pksbroker.create_compute_profile(**compute_profile_params) except e.PksServerError as err: if err.status == requests.codes.conflict: LOGGER.debug(f"Compute profile name {pks_compute_profile_name}" f" already exists\n{str(err)}") else: raise
def create_pks_compute_profile(pks_ctx, tenant_auth_token, is_jwt_token, request_data): ovdc_id = request_data.get(RequestKey.OVDC_ID) org_name = request_data.get(RequestKey.ORG_NAME) ovdc_name = request_data.get(RequestKey.OVDC_NAME) # Compute profile creation pks_compute_profile_name = \ _construct_pks_compute_profile_name(ovdc_id) pks_compute_profile_description = f"{org_name}--{ovdc_name}" \ f"--{ovdc_id}" pks_az_name = f"az-{ovdc_name}" ovdc_rp_name = f"{ovdc_name} ({ovdc_id})" compute_profile_params = PksComputeProfileParams( pks_compute_profile_name, pks_az_name, pks_compute_profile_description, pks_ctx.get('cpi'), pks_ctx.get('datacenter'), pks_ctx.get('cluster'), ovdc_rp_name).to_dict() LOGGER.debug(f"Creating PKS Compute Profile with name:" f"{pks_compute_profile_name}") pksbroker = PksBroker(pks_ctx, tenant_auth_token, is_jwt_token) try: pksbroker.create_compute_profile(**compute_profile_params) except PksServerError as ex: if ex.status == requests.codes.conflict: LOGGER.debug(f"Compute profile name {pks_compute_profile_name}" f" already exists\n{str(ex)}") else: raise
def list_clusters(request_data, request_context: ctx.RequestContext): request_data['is_admin_request'] = True pks_clusters = [] pks_contexts = create_pks_context_for_all_accounts_in_org(request_context) for pks_context in pks_contexts: pks_broker = PksBroker(pks_context, request_context) # Get all cluster information to get vdc name from compute-profile-name pks_clusters.extend(pks_broker.list_clusters(data=request_data)) return pks_clusters
def list_clusters(request_data, tenant_auth_token, is_jwt_token): request_data['is_admin_request'] = True pks_clusters = [] pks_ctx_list = create_pks_context_for_all_accounts_in_org( tenant_auth_token, is_jwt_token) for pks_ctx in pks_ctx_list: pks_broker = PksBroker(pks_ctx, tenant_auth_token, is_jwt_token) # Get all cluster information to get vdc name from compute-profile-name pks_clusters.extend(pks_broker.list_clusters(request_data)) return pks_clusters
def _get_vc_to_pks_plans_map(tenant_auth_token, is_jwt_token): pks_vc_plans_map = {} pks_ctx_list = pks_broker_manager.create_pks_context_for_all_accounts_in_org(tenant_auth_token, is_jwt_token) # noqa: E501 for pks_ctx in pks_ctx_list: if pks_ctx['vc'] in pks_vc_plans_map: continue pks_broker = PksBroker(pks_ctx, tenant_auth_token, is_jwt_token) plans = pks_broker.list_plans() plan_names = [plan.get('name') for plan in plans] pks_vc_plans_map[pks_ctx['vc']] = [plan_names, pks_ctx['host']] return pks_vc_plans_map
def list_clusters(request_data, tenant_auth_token): request_data['is_admin_request'] = True pks_clusters = [] pks_ctx_list = \ create_pks_context_for_all_accounts_in_org(tenant_auth_token) for pks_ctx in pks_ctx_list: pks_broker = PksBroker(pks_ctx, tenant_auth_token) # Get all cluster information to get vdc name from compute-profile-name for cluster in pks_broker.list_clusters(request_data): pks_cluster = \ pks_broker.generate_cluster_subset_with_given_keys(cluster) pks_clusters.append(pks_cluster) return pks_clusters
def get_cluster_and_broker(request_data, tenant_auth_token, is_jwt_token): cluster_name = request_data[RequestKey.CLUSTER_NAME] vcd_broker = VcdBroker(tenant_auth_token, is_jwt_token) try: return vcd_broker.get_cluster_info(request_data), vcd_broker except ClusterNotFoundError as err: # continue searching using PksBrokers LOGGER.debug(f"{err}") except CseDuplicateClusterError as err: # fail because multiple clusters with same name exist # only case is when multiple same-name clusters exist across orgs # and sys admin tries to do a cluster operation LOGGER.debug(f"{err}") raise except Exception as err: LOGGER.error(f"Unknown error: {err}", exc_info=True) raise pks_ctx_list = create_pks_context_for_all_accounts_in_org( tenant_auth_token, is_jwt_token) for pks_ctx in pks_ctx_list: debug_msg = f"Get cluster info for cluster '{cluster_name}' " \ f"failed on host '{pks_ctx['host']}' with error: " pks_broker = PksBroker(pks_ctx, tenant_auth_token, is_jwt_token) try: return pks_broker.get_cluster_info(request_data), pks_broker except (PksClusterNotFoundError, PksServerError) as err: # continue searching using other PksBrokers LOGGER.debug(f"{debug_msg}{err}") except PksDuplicateClusterError as err: # fail because multiple clusters with same name exist LOGGER.debug(f"{debug_msg}{err}") raise except Exception as err: LOGGER.error(f"Unknown error: {err}", exc_info=True) raise # only raised if cluster was not found in VcdBroker or PksBrokers raise ClusterNotFoundError(f"Cluster '{cluster_name}' not found.")
def _get_broker_from_k8s_metadata(k8s_metadata, op_ctx: ctx.OperationContext): """Get broker from ovdc k8s metadata. If PKS is not enabled, raise CseServerError If PKS is enabled if no ovdc metadata exists or k8s provider is None, raise server error else return the broker according to ovdc k8s provider """ _raise_error_if_pks_not_enabled() if not k8s_metadata or k8s_metadata.get( K8S_PROVIDER_KEY) != K8sProvider.PKS: # noqa: E501 raise CseServerError("Org VDC is not enabled for Kubernetes " "cluster deployment") return PksBroker(k8s_metadata, op_ctx)
def _get_cluster_and_broker(request_data, request_context, **kwargs): cluster_name = request_data[RequestKey.CLUSTER_NAME] pks_ctx_list = create_pks_context_for_all_accounts_in_org(request_context) for pks_ctx in pks_ctx_list: debug_msg = f"Get cluster info for cluster '{cluster_name}' " \ f"failed on host '{pks_ctx['host']}' with error: " pks_broker = PksBroker(pks_ctx, request_context) try: return pks_broker.get_cluster_info( data=request_data, **kwargs), pks_broker # noqa: E501 except (PksClusterNotFoundError, PksServerError) as err: # continue searching using other PksBrokers LOGGER.debug(f"{debug_msg}{err}") except PksDuplicateClusterError as err: # fail because multiple clusters with same name exist LOGGER.debug(f"{debug_msg}{err}") raise except Exception as err: LOGGER.error(f"Unknown error: {err}", exc_info=True) raise # raised if cluster was not found in PksBrokers raise ClusterNotFoundError(f"Cluster '{cluster_name}' not found.")
def get_broker_from_k8s_metadata(k8s_metadata, tenant_auth_token, is_jwt_token): """Get broker from ovdc k8s metadata. If PKS is not enabled, always return VcdBroker If PKS is enabled if no ovdc metadata exists or k8s provider is None, raise server error else return the broker according to ovdc k8s provider """ if utils.is_pks_enabled(): if not k8s_metadata or k8s_metadata.get(K8S_PROVIDER_KEY) == K8sProvider.NONE: # noqa: E501 raise CseServerError("Org VDC is not enabled for Kubernetes " "cluster deployment") if k8s_metadata.get(K8S_PROVIDER_KEY) == K8sProvider.PKS: return PksBroker(k8s_metadata, tenant_auth_token, is_jwt_token) return VcdBroker(tenant_auth_token, is_jwt_token)