Exemplo n.º 1
0
 def delete(self, request, *args, **kwargs):
     """
     批量删除组件
     ---
     parameters:
         - name: tenantName
           description: 租户名
           required: true
           type: string
           paramType: path
         - name: service_ids
           description: 批量操作的组件ID 多个以英文逗号分隔
           required: true
           type: string
           paramType: form
     """
     service_ids = request.data.get("service_ids", None)
     service_id_list = service_ids.split(",")
     services = service_repo.get_services_by_service_ids(service_id_list)
     msg_list = []
     for service in services:
         code, msg = app_manage_service.batch_delete(self.user,
                                                     self.tenant,
                                                     service,
                                                     is_force=True)
         msg_dict = dict()
         msg_dict['status'] = code
         msg_dict['msg'] = msg
         msg_dict['service_id'] = service.service_id
         msg_dict['service_cname'] = service.service_cname
         msg_list.append(msg_dict)
     code = 200
     result = general_message(code, "success", "操作成功", list=msg_list)
     return Response(result, status=result['code'])
Exemplo n.º 2
0
 def delete(self, req, app_id, *args, **kwargs):
     msg_list = []
     try:
         force = int(req.GET.get("force", 0))
     except ValueError:
         raise ServiceHandleException(msg='force value error',
                                      msg_show=u"参数错误")
     service_ids = app_service.get_group_services_by_id(self.app.ID)
     services = service_repo.get_services_by_service_ids(service_ids)
     if services:
         status_list = base_service.status_multi_service(
             region=self.app.region_name,
             tenant_name=self.team.tenant_name,
             service_ids=service_ids,
             enterprise_id=self.team.enterprise_id)
         status_list = filter(lambda x: x not in ["closed", "undeploy"],
                              map(lambda x: x["status"], status_list))
         if len(status_list) > 0:
             raise ServiceHandleException(
                 msg=
                 "There are running components under the current application",
                 msg_show=u"当前应用下有运行态的组件,不可删除")
         else:
             code_status = 200
             for service in services:
                 code, msg = app_manage_service.batch_delete(self.user,
                                                             self.team,
                                                             service,
                                                             is_force=True)
                 msg_dict = dict()
                 msg_dict['status'] = code
                 msg_dict['msg'] = msg
                 msg_dict['service_id'] = service.service_id
                 msg_dict['service_cname'] = service.service_cname
                 msg_list.append(msg_dict)
                 if code != 200:
                     code_status = code
                     if force:
                         code_status = 200
                         app_manage_service.delete_again(self.user,
                                                         self.team,
                                                         service,
                                                         is_force=True)
             if code_status != 200:
                 raise ServiceHandleException(msg=msg_list,
                                              msg_show=u"请求错误")
             else:
                 code, msg, data = group_service.delete_group_no_service(
                     self.app.ID)
                 if code != 200:
                     raise ServiceHandleException(msg=msg, msg_show=u"请求错误")
                 return Response(None, status=code)
     code, msg, data = group_service.delete_group_no_service(self.app.ID)
     if code != 200:
         raise ServiceHandleException(msg=msg, msg_show=u"请求错误")
     return Response(None, status=code)
Exemplo n.º 3
0
 def delete(self, request, *args, **kwargs):
     """
     批量删除应用
     ---
     parameters:
         - name: tenantName
           description: 租户名
           required: true
           type: string
           paramType: path
         - name: service_ids
           description: 批量操作的服务ID 多个以英文逗号分隔
           required: true
           type: string
           paramType: form
     """
     try:
         service_ids = request.data.get("service_ids", None)
         identitys = team_services.get_user_perm_identitys_in_permtenant(
             user_id=self.user.user_id, tenant_name=self.tenant_name)
         perm_tuple = team_services.get_user_perm_in_tenant(
             user_id=self.user.user_id, tenant_name=self.tenant_name)
         if "delete_service" not in perm_tuple and "owner" not in identitys and "admin" \
                 not in identitys and "developer" not in identitys:
             return Response(general_message(400, "Permission denied",
                                             "没有删除应用权限"),
                             status=400)
         service_id_list = service_ids.split(",")
         services = service_repo.get_services_by_service_ids(
             service_id_list)
         msg_list = []
         for service in services:
             code, msg = app_manage_service.batch_delete(self.user,
                                                         self.tenant,
                                                         service,
                                                         is_force=True)
             msg_dict = dict()
             msg_dict['status'] = code
             msg_dict['msg'] = msg
             msg_dict['service_id'] = service.service_id
             msg_dict['service_cname'] = service.service_cname
             msg_list.append(msg_dict)
         code = 200
         result = general_message(code, "success", "操作成功", list=msg_list)
         return Response(result, status=result['code'])
     except Exception as e:
         logger.exception(e)