def get_tenant_groups_by_region(self, tenant, region_name): return group_repo.list_tenant_group_on_region(tenant, region_name)
def delete_tenant_on_region(self, enterprise_id, team_name, region_name, user): tenant = team_repo.get_team_by_team_name_and_eid( enterprise_id, team_name) tenant_region = region_repo.get_team_region_by_tenant_and_region( tenant.tenant_id, region_name) if not tenant_region: raise ServiceHandleException( msg="team not open cluster, not need close", msg_show="该团队未开通此集群,无需关闭") # start delete region_config = region_repo.get_enterprise_region_by_region_name( enterprise_id, region_name) ignore_cluster_resource = False if not region_config: # cluster spec info not found, cluster side resources are no longer operated on ignore_cluster_resource = True else: info = region_api.check_region_api(enterprise_id, region_name) # check cluster api health if not info or info["rbd_version"] == "": ignore_cluster_resource = True services = service_repo.get_services_by_team_and_region( tenant.tenant_id, region_name) if not ignore_cluster_resource and services and len(services) > 0: # check component status service_ids = [service.service_id for service in services] status_list = base_service.status_multi_service( region=region_name, tenant_name=tenant.tenant_name, service_ids=service_ids, enterprise_id=tenant.enterprise_id) status_list = [ x for x in [x["status"] for x in status_list] if x not in ["closed", "undeploy"] ] if len(status_list) > 0: raise ServiceHandleException( msg= "There are running components under the current application", msg_show="团队在集群{0}下有运行态的组件,请关闭组件后再卸载当前集群".format( region_config.region_alias)) # Components are the key to resource utilization, # and removing the cluster only ensures that the component's resources are freed up. from console.services.app_actions import app_manage_service from console.services.plugin import plugin_service not_delete_from_cluster = False for service in services: not_delete_from_cluster = app_manage_service.really_delete_service( tenant, service, user, ignore_cluster_resource, not_delete_from_cluster) plugins = plugin_repo.get_tenant_plugins(tenant.tenant_id, region_name) if plugins: for plugin in plugins: plugin_service.delete_plugin(region_name, tenant, plugin.plugin_id, ignore_cluster_resource, is_force=True) group_repo.list_tenant_group_on_region(tenant, region_name).delete() # delete tenant if not ignore_cluster_resource: try: region_api.delete_tenant(region_name, team_name) except region_api.CallApiError as e: if e.status != 404: logger.error("delete tenant failure {}".format(e.body)) raise ServiceHandleException( msg="delete tenant from cluster failure", msg_show="从集群删除租户失败") except Exception as e: logger.exception(e) raise ServiceHandleException( msg="delete tenant from cluster failure", msg_show="从集群删除租户失败") tenant_region.delete()