def again_delete_service(self, tenant, service, user=None): """二次删除应用""" try: region_api.delete_service(service.service_region, tenant.tenant_name, service.service_alias, tenant.enterprise_id) except region_api.CallApiError as e: if int(e.status) != 404: logger.exception(e) return 500, "删除应用失败 {0}".format(e.message) if service.create_status == "complete": data = service.toJSON() data.pop("ID") delete_service_repo.create_delete_service(**data) env_var_repo.delete_service_env(tenant.tenant_id, service.service_id) auth_repo.delete_service_auth(service.service_id) domain_repo.delete_service_domain(service.service_id) tcp_domain.delete_service_tcp_domain(service.service_id) dep_relation_repo.delete_service_relation(tenant.tenant_id, service.service_id) mnt_repo.delete_mnt(service.service_id) port_repo.delete_service_port(tenant.tenant_id, service.service_id) volume_repo.delete_service_volumes(service.service_id) group_service_relation_repo.delete_relation_by_service_id( service.service_id) service_attach_repo.delete_service_attach(service.service_id) create_step_repo.delete_create_step(service.service_id) event_service.delete_service_events(service) probe_repo.delete_service_probe(service.service_id) service_payment_repo.delete_service_payment(service.service_id) service_source_repo.delete_service_source(tenant.tenant_id, service.service_id) service_perm_repo.delete_service_perm(service.ID) compose_relation_repo.delete_relation_by_service_id(service.service_id) service_label_repo.delete_service_all_labels(service.service_id) # 删除应用和插件的关系 share_repo.delete_tenant_service_plugin_relation(service.service_id) # 如果这个应用属于应用组, 则删除应用组最后一个应用后同时删除应用组 if service.tenant_service_group_id > 0: count = service_repo.get_services_by_service_group_id( service.tenant_service_group_id).count() if count <= 1: tenant_service_group_repo.delete_tenant_service_group_by_pk( service.tenant_service_group_id) self.__create_service_delete_event(tenant, service, user) service.delete() return 200, "success"
def truncate_service(self, tenant, service): """彻底删除应用""" if service.create_status == "complete": data = service.toJSON() delete_service_repo.create_delete_service(**data) try: region_api.delete_service(service.service_region, tenant.tenant_name, service.service_alias, tenant.enterprise_id) except region_api.CallApiError as e: if int(e.status) != 404: return 500, "删除应用失败 {0}".format(e.message) env_var_repo.delete_service_env(tenant.tenant_id, service.service_id) auth_repo.delete_service_auth(service.service_id) domain_repo.delete_service_domain(service.service_id) dep_relation_repo.delete_service_relation(tenant.tenant_id, service.service_id) env_var_repo.delete_service_env(tenant.tenant_id, service.service_id) mnt_repo.delete_mnt(service.service_id) port_repo.delete_service_port(tenant.tenant_id, service.service_id) volume_repo.delete_service_volumes(service.service_id) group_service_relation_repo.delete_relation_by_service_id( service.service_id) service_attach_repo.delete_service_attach(service.service_id) create_step_repo.delete_create_step(service.service_id) event_service.delete_service_events(service) probe_repo.delete_service_probe(service.service_id) service_payment_repo.delete_service_payment(service.service_id) # 如果这个应用属于应用组, 则删除应用组最后一个应用后同时删除应用组 if service.tenant_service_group_id > 0: count = service_repo.get_services_by_service_group_id( service.tenant_service_group_id).count() if count <= 1: tenant_service_group_repo.delete_tenant_service_group_by_pk( service.tenant_service_group_id) service.delete() return 200, "success"