def can_delete_resource(ventity, resource_name, resource_id): # 验证 pod 资源是否被 Service 关联 if resource_name in models.POD_RES_LIST: pod_res_name, related_svc_names = models.get_pod_related_service( ventity, resource_name, resource_id) if related_svc_names: raise ValidationError( f"{resource_name}[{pod_res_name}] 被以下资源关联,不能被删除: " f"{','.join(related_svc_names)}") # 验证 Service 是否被 statefulset 关联 if resource_name in [ K8sResourceName.K8sService.value, ]: svc_name, related_ss_names = models.get_service_related_statefulset( ventity, resource_id) if related_ss_names: raise ValidationError( f"{resource_name}[{svc_name}] 被以下资源关联,不能被删除: " f"{','.join(related_ss_names)}") # 删除 Application 时,需要先判断 Deployment 和 service 的依赖关系 if resource_name == MesosResourceName.application.value: app_name, related_resource_names = models.get_application_related_resource( ventity, resource_id) if related_resource_names: raise ValidationError(f"{resource_name}[app_name] 被以下资源关联,不能删除: " f"{','.join(related_resource_names)}")
def can_delete_resource(ventity, resource_name, resource_id): # 验证 pod 资源是否被 Service 关联 if resource_name in models.POD_RES_LIST: pod_res_name, related_svc_names = models.get_pod_related_service(ventity, resource_name, resource_id) if related_svc_names: raise ValidationError( '{resource_name}[{pod_res_name}]{msg}:{svc_names}'.format( resource_name=resource_name, pod_res_name=pod_res_name, msg=_("被以下资源关联,不能删除"), svc_names=','.join(related_svc_names), ) ) # 删除 Application 时,需要先判断 Deployment 和 service 的依赖关系 if resource_name == MesosResourceName.application.value: app_name, related_resource_names = models.get_application_related_resource(ventity, resource_id) if related_resource_names: raise ValidationError( '{resource_name}[{app_name}]{msg}:{related_names}'.format( resource_name=resource_name, app_name=app_name, msg=_("被以下资源关联,不能删除"), related_names=','.join(related_resource_names), ) )