def put(self, request, *args, **kwargs):
        """
        修改构建源
        ---
        """
        s_id = transaction.savepoint()
        try:
            image = request.data.get("image", None)
            cmd = request.data.get("cmd", None)
            service_source = request.data.get("service_source")
            git_url = request.data.get("git_url", None)
            code_version = request.data.get("code_version", None)
            user_name = request.data.get("user_name", None)
            password = request.data.get("password", None)

            if not service_source:
                return Response(general_message(400, "param error", "参数错误"), status=400)

            service_source_user = service_source_repo.get_service_source(team_id=self.service.tenant_id,
                                                                         service_id=self.service.service_id)

            if not service_source_user:
                service_source_info = {
                    "service_id": self.service.service_id,
                    "team_id": self.service.tenant_id,
                    "user_name": user_name,
                    "password": password,
                    "create_time": datetime.datetime.now().strftime('%Y%m%d%H%M%S')
                }
                service_source_repo.create_service_source(**service_source_info)
            else:
                service_source_user.user_name = user_name
                service_source_user.password = password
                service_source_user.save()
            if service_source == "source_code":
                if code_version:
                    self.service.code_version = code_version
                else:
                    self.service.code_version = "master"
                if git_url:
                    self.service.git_url = git_url
                self.service.save()
                transaction.savepoint_commit(s_id)
            elif service_source == "docker_run":
                if image:
                    version = image.split(':')[-1]
                    if not version:
                        version = "latest"
                        image = image + ":" + version
                    self.service.image = image
                    self.service.version = version
                self.service.cmd = cmd
                self.service.save()
                transaction.savepoint_commit(s_id)
            result = general_message(200, "success", "修改成功")
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
            transaction.savepoint_rollback(s_id)
        return Response(result, status=result["code"])
 def svc_source(self, service_source):
     if not service_source:
         logger.warning("service id: {}; service source data not found while \
             restoring service source".format(self.service.service_id))
         return
     service_source_repo.delete_service_source(self.tenant.tenant_id, self.service.service_id)
     service_source.pop("ID")
     if "service" in service_source:
         service_source["service_id"] = service_source.pop("service")
     logger.debug("service_source: {}".format(json.dumps(service_source)))
     service_source_repo.create_service_source(**service_source)
Beispiel #3
0
 def create_service_source_info(self, tenant, service, user_name, password):
     params = {
         "team_id": tenant.tenant_id,
         "service_id": service.service_id,
         "user_name": user_name,
         "password": password,
     }
     return service_source_repo.create_service_source(**params)
    def __init_service_source(self, ts, app):
        is_slug = bool(
            ts.image.startswith('goodrain.me/runner')
            and app["language"] not in ("dockerfile", "docker"))
        if is_slug:
            extend_info = app["service_slug"]
            extend_info["slug_path"] = app.get("share_slug_path", "")
        else:
            extend_info = app["service_image"]

        service_source_params = {
            "team_id": ts.tenant_id,
            "service_id": ts.service_id,
            "user_name": "",
            "password": "",
            "extend_info": json.dumps(extend_info)
        }
        service_source_repo.create_service_source(**service_source_params)
Beispiel #5
0
    def update_check_app(self, tenant, service, data):

        service_source = service_source_repo.get_service_source(
            tenant.tenant_id, service.service_id)
        service_cname = data.get("service_cname", service.service_cname)
        image = data.get("image", service.image)
        cmd = data.get("cmd", service.cmd)
        docker_cmd = data.get("docker_cmd", service.docker_cmd)
        git_url = data.get("git_url", service.git_url)
        min_memory = data.get("min_memory", service.min_memory)
        min_memory = int(min_memory)
        min_cpu = baseService.calculate_service_cpu(service.service_region,
                                                    min_memory)

        extend_method = data.get("extend_method", service.extend_method)

        service.service_cname = service_cname
        service.min_memory = min_memory
        service.min_cpu = min_cpu
        service.extend_method = extend_method
        service.image = image
        service.cmd = cmd
        service.git_url = git_url
        service.docker_cmd = docker_cmd
        service.save()

        user_name = data.get("user_name", None)
        password = data.get("password", None)
        if user_name is not None:
            if not service_source:
                params = {
                    "team_id": tenant.tenant_id,
                    "service_id": service.service_id,
                    "user_name": user_name,
                    "password": password,
                }
                service_source_repo.create_service_source(**params)
            else:
                service_source.user_name = user_name
                service_source.password = password
                service_source.save()
        return 200, "success"
Beispiel #6
0
    def put(self, request, *args, **kwargs):
        """
        修改构建源
        ---
        """
        s_id = transaction.savepoint()
        try:
            image = request.data.get("image", None)
            cmd = request.data.get("cmd", None)
            service_source = request.data.get("service_source")
            git_url = request.data.get("git_url", None)
            code_version = request.data.get("code_version", None)
            user_name = request.data.get("user_name", None)
            password = request.data.get("password", None)
            is_oauth = request.data.get("is_oauth", False)
            user_id = request.user.user_id
            oauth_service_id = request.data.get("service_id")
            git_full_name = request.data.get("full_name")

            if not service_source:
                return Response(general_message(400, "param error", "参数错误"),
                                status=400)

            service_source_user = service_source_repo.get_service_source(
                team_id=self.service.tenant_id,
                service_id=self.service.service_id)

            if not service_source_user:
                service_source_info = {
                    "service_id": self.service.service_id,
                    "team_id": self.service.tenant_id,
                    "user_name": user_name,
                    "password": password,
                    "create_time":
                    datetime.datetime.now().strftime('%Y%m%d%H%M%S')
                }
                service_source_repo.create_service_source(
                    **service_source_info)
            else:
                service_source_user.user_name = user_name
                service_source_user.password = password
                service_source_user.save()
            if service_source == "source_code":
                if code_version:
                    self.service.code_version = code_version
                else:
                    self.service.code_version = "master"
                if git_url:
                    if is_oauth:
                        oauth_service = oauth_repo.get_oauth_services_by_service_id(
                            service_id=oauth_service_id)
                        oauth_user = oauth_user_repo.get_user_oauth_by_user_id(
                            service_id=oauth_service_id, user_id=user_id)
                        try:
                            instance = get_oauth_instance(
                                oauth_service.oauth_type, oauth_service,
                                oauth_user)
                        except Exception as e:
                            logger.debug(e)
                            rst = {
                                "data": {
                                    "bean": None
                                },
                                "status": 400,
                                "msg_show": u"未找到OAuth服务"
                            }
                            return Response(rst, status=200)
                        if not instance.is_git_oauth():
                            rst = {
                                "data": {
                                    "bean": None
                                },
                                "status": 400,
                                "msg_show": u"该OAuth服务不是代码仓库类型"
                            }
                            return Response(rst, status=200)
                        service_code_from = "oauth_" + oauth_service.oauth_type
                        self.service.code_from = service_code_from
                        self.service.git_url = git_url
                        self.service.git_full_name = git_full_name
                        self.service.oauth_service_id = oauth_service_id
                    else:
                        self.service.git_url = git_url
                self.service.save()
                transaction.savepoint_commit(s_id)
            elif service_source == "docker_run":
                if image:
                    version = image.split(':')[-1]
                    if not version:
                        version = "latest"
                        image = image + ":" + version
                    self.service.image = image
                    self.service.version = version
                self.service.cmd = cmd
                self.service.save()
                transaction.savepoint_commit(s_id)
            result = general_message(200, "success", "修改成功")
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
            transaction.savepoint_rollback(s_id)
        return Response(result, status=result["code"])