def list_clusters(self, data): """List all native clusters and their relevant metadata. Common broker function that validates data for the 'list clusters' operation and returns a list of cluster data. Optional data and default values: org_name=None, ovdc_name=None """ defaults = { RequestKey.ORG_NAME: None, RequestKey.OVDC_NAME: None } validated_data = {**defaults, **data} raw_clusters = get_all_clusters( self.tenant_client, org_name=validated_data[RequestKey.ORG_NAME], ovdc_name=validated_data[RequestKey.OVDC_NAME]) clusters = [] for c in raw_clusters: clusters.append({ 'name': c['name'], 'IP master': c['leader_endpoint'], 'template_name': c.get('template_name'), 'template_revision': c.get('template_revision'), 'k8s_version': c.get('k8s_version'), 'VMs': c['number_of_vms'], 'vdc': c['vdc_name'], 'status': c['status'], 'vdc_id': c['vdc_id'], 'org_name': vcd_utils.get_org_name_from_ovdc_id(c['vdc_id']), K8S_PROVIDER_KEY: K8sProvider.NATIVE }) return clusters
def _does_cluster_belong_to_org(self, cluster_info, org_name): # Returns True if the cluster belongs to the given org # Else False (this also includes missing compute profile name) compute_profile_name = cluster_info.get('compute_profile_name') if compute_profile_name is None: LOGGER.debug(f"compute-profile-name of {cluster_info.get('name')}" f" is not found") return False vdc_id = self._extract_vdc_id_from_pks_compute_profile_name( compute_profile_name) return org_name == get_org_name_from_ovdc_id(vdc_id)
def update_cluster_with_vcd_info(self, pks_cluster): compute_profile_name = pks_cluster.get('compute_profile_name', '') pks_cluster['vdc'] = '' if compute_profile_name: vdc_id = self._extract_vdc_id_from_pks_compute_profile_name( compute_profile_name) # noqa: E501 pks_cluster['org_name'] = get_org_name_from_ovdc_id(vdc_id) pks_cluster[ 'vdc'] = self._extract_vdc_name_from_pks_compute_profile_name( compute_profile_name) # noqa: E501 pks_cluster['status'] = \ pks_cluster.get('last_action', '').lower() + ' ' + \ pks_cluster.get('last_action_state', '').lower() return pks_cluster
def generate_cluster_subset_with_given_keys(self, cluster): pks_cluster = cluster compute_profile_name = cluster.get('compute_profile_name', '') if compute_profile_name: vdc_id = self._extract_vdc_id_from_pks_compute_profile_name( compute_profile_name) # noqa pks_cluster['org_name'] = get_org_name_from_ovdc_id(vdc_id) pks_cluster[ 'vdc'] = self._extract_vdc_name_from_pks_compute_profile_name( compute_profile_name) # noqa else: vdc_id = '' pks_cluster['vdc'] = '' pks_cluster['status'] = \ cluster.get('last_action', '').lower() + ' ' + \ cluster.get('last_action_state', '').lower() return pks_cluster
def list_clusters(self): self._connect_tenant() clusters = [] raw_clusters = load_from_metadata( self.tenant_client, org_name=self.req_spec.get(RequestKey.ORG_NAME), vdc_name=self.req_spec.get(RequestKey.OVDC_NAME)) for c in raw_clusters: clusters.append({ 'name': c['name'], 'IP master': c['leader_endpoint'], 'template': c['template'], 'VMs': c['number_of_vms'], 'vdc': c['vdc_name'], 'status': c['status'], 'vdc_id': c['vdc_id'], 'org_name': get_org_name_from_ovdc_id(c['vdc_id']), K8S_PROVIDER_KEY: K8sProviders.NATIVE }) return clusters