def _find_cluster_in_org(self, cluster_name): """Invoke set of all (vCD/PKS)brokers in the org to find the cluster. If cluster found: Return a tuple of (cluster and the broker instance used to find the cluster) Else: (None, None) if cluster not found. """ vcd_broker = VcdBroker(self.req_headers, self.req_spec) try: return vcd_broker.get_cluster_info(cluster_name), vcd_broker except Exception as err: LOGGER.debug(f"Get cluster info on {cluster_name} failed " f"on vCD with error: {err}") pks_ctx_list = self._create_pks_context_for_all_accounts_in_org() for pks_ctx in pks_ctx_list: pksbroker = PKSBroker(self.req_headers, self.req_spec, pks_ctx) try: return pksbroker.get_cluster_info(cluster_name=cluster_name),\ pksbroker except Exception as err: LOGGER.debug(f"Get cluster info on {cluster_name} failed " f"on {pks_ctx['host']} with error: {err}") return None, None
def _find_cluster_in_org(self, cluster_name, is_org_admin_search=False): """Invoke set of all (vCD/PKS)brokers in the org to find the cluster. 'is_org_admin_search' is used here to prevent cluster creation with same cluster-name by users within org. If it is true, cluster list is filtered by the org name of the logged-in user. If cluster found: Return a tuple of (cluster and the broker instance used to find the cluster) Else: (None, None) if cluster not found. """ vcd_broker = VcdBroker(self.req_headers, self.req_spec) try: return vcd_broker.get_cluster_info(cluster_name), vcd_broker except Exception as err: LOGGER.debug(f"Get cluster info on {cluster_name} failed " f"on vCD with error: {err}") pks_ctx_list = self._create_pks_context_for_all_accounts_in_org() for pks_ctx in pks_ctx_list: pksbroker = PKSBroker(self.req_headers, self.req_spec, pks_ctx) try: return pksbroker.get_cluster_info( cluster_name=cluster_name, is_org_admin_search=is_org_admin_search), pksbroker except PksServerError as err: LOGGER.debug(f"Get cluster info on {cluster_name} failed " f"on {pks_ctx['host']} with error: {err}") return None, None
def find_cluster_in_org(self, cluster_name, is_org_admin_search=False): """Invoke vCD broker to find the cluster in the org. 'is_org_admin_search' is used here to prevent cluster creation with same cluster-name by users within org. If it is true, cluster list is filtered by the org name of the logged-in user. If cluster found: Return a tuple of (cluster and the broker instance used to find the cluster) Else: (None, None) if cluster not found. """ vcd_broker = VcdBroker(self.tenant_auth_token, self.req_spec) try: return vcd_broker.get_cluster_info(cluster_name), vcd_broker except ClusterNotFoundError as err: # If a cluster is not found, then broker_manager will # decide if it wants to raise an error or ignore it if was it just # scanning the broker to check if it can handle the cluster request # or not. LOGGER.debug(f"Get cluster info on {cluster_name}" f"on vCD failed with error: {err}") except CseDuplicateClusterError as err: LOGGER.debug(f"Get cluster info on {cluster_name}" f"on vCD failed with error: {err}") raise except Exception as err: LOGGER.debug(f"Get cluster info on {cluster_name} failed " f"on vCD with error: {err}") return None, None
def cluster_info(request_data, op_ctx: ctx.OperationContext): """Request handler for cluster info operation. Required data: cluster_name Optional data and default values: org_name=None, ovdc_name=None (data validation handled in broker) :return: Dict """ vcd_broker = VcdBroker(op_ctx) return vcd_broker.get_cluster_info(data=request_data)
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.")