def post(self, request, *args, **kwargs): """ 添加应用信息 --- parameters: - name: tenantName description: 租户名 required: true type: string paramType: path - name: group_name description: 应用名称 required: true type: string paramType: form - name: group_note description: 应用备注 required: false type: string paramType: form """ app_name = request.data.get("app_name", None) note = request.data.get("note", "") if len(note) > 2048: return Response(general_message(400, "node too long", "应用备注长度限制2048"), status=400) region_name = self.response_region if request.data.get("region_name", None): region_name = request.data.get("region_name", None) data = group_service.create_app(self.tenant, region_name, app_name, note, self.user.get_username()) result = general_message(200, "success", "创建成功", bean=data) return Response(result, status=result["code"])
def create_new_group(self, tenant, region, old_group_id): old_group = group_repo.get_group_by_id(old_group_id) if old_group: new_group_name = '_'.join([old_group.group_name, make_uuid()[-4:]]) else: new_group_name = make_uuid()[:8] app = group_service.create_app(tenant, region, new_group_name, "备份创建") new_app = group_repo.get_group_by_id(app["ID"]) return new_app
def post(self, request, *args, **kwargs): serializer = AppPostInfoSerializer(data=request.data) serializer.is_valid(raise_exception=True) data = serializer.data group_info = group_service.create_app( self.team, self.region_name, data["app_name"], data.get("app_note"), self.user.get_username(), ) re = AppBaseInfoSerializer(group_info) return Response(re.data, status=status.HTTP_201_CREATED)
def __create_new_group_by_group_name(self, tenant, region, old_group_id): new_group_name = '_'.join(["备份应用", make_uuid()[-4:]]) app = group_service.create_app(tenant, region, new_group_name) new_app = group_repo.get_group_by_id(app["ID"]) return new_app
def post(self, request, *args, **kwargs): """ docker-compose创建组件 --- parameters: - name: tenantName description: 租户名 required: true type: string paramType: path - name: group_name description: 应用名称 required: true type: string paramType: form - name: user_name description: 镜像仓库名称 required: true type: string paramType: form - name: password description: 镜像仓库密码 required: true type: string paramType: form - name: yaml_content description: compose文件内容 required: true type: string paramType: form """ group_name = request.data.get("group_name", None) hub_user = request.data.get("user_name", "") hub_pass = request.data.get("password", "") yaml_content = request.data.get("yaml_content", "") group_note = request.data.get("group_note", "") if group_note and len(group_note) > 2048: return Response(general_message(400, "node too long", "应用备注长度限制2048"), status=400) if not group_name: return Response(general_message(400, 'params error', "请指明需要创建的compose组名"), status=400) if not yaml_content: return Response(general_message(400, "params error", "未指明yaml内容"), status=400) # Parsing yaml determines whether the input is illegal code, msg, json_data = compose_service.yaml_to_json(yaml_content) if code != 200: return Response(general_message(code, "parse yaml error", msg), status=code) # 创建组 group_info = group_service.create_app(self.tenant, self.response_region, group_name, group_note, self.user.get_username()) code, msg, group_compose = compose_service.create_group_compose( self.tenant, self.response_region, group_info["group_id"], yaml_content, hub_user, hub_pass) if code != 200: return Response(general_message(code, "create group compose error", msg), status=code) bean = dict() bean["group_id"] = group_compose.group_id bean["compose_id"] = group_compose.compose_id bean["app_name"] = group_info["app_name"] result = general_message(200, "operation success", "compose组创建成功", bean=bean) return Response(result, status=result["code"])