Esempio n. 1
0
 def create_env_var(self,
                    service,
                    container_port,
                    name,
                    attr_name,
                    attr_value,
                    is_change=False,
                    scope="outer"):
     """
     raise: EnvAlreadyExist
     raise: InvalidEnvName
     """
     if env_var_repo.get_service_env_by_attr_name(service.tenant_id,
                                                  service.service_id,
                                                  attr_name):
         raise EnvAlreadyExist()
     attr_name = str(attr_name).strip()
     attr_value = str(attr_value).strip()
     is_pass, msg = self.check_env_attr_name(attr_name)
     if not is_pass:
         raise InvalidEnvName(msg)
     if len(str(attr_value)) > 512:
         attr_value = str(attr_value)[:512]
     tenantServiceEnvVar = {}
     tenantServiceEnvVar["tenant_id"] = service.tenant_id
     tenantServiceEnvVar["service_id"] = service.service_id
     tenantServiceEnvVar['container_port'] = container_port
     tenantServiceEnvVar["name"] = name
     tenantServiceEnvVar["attr_name"] = attr_name
     tenantServiceEnvVar["attr_value"] = attr_value
     tenantServiceEnvVar["is_change"] = is_change
     tenantServiceEnvVar["scope"] = scope
     return env_var_repo.add_service_env(**tenantServiceEnvVar)
Esempio n. 2
0
 def update_env_by_attr_name(self, tenant, service, attr_name, name,
                             attr_value):
     attr_name = attr_name.strip()
     attr_value = attr_value.strip()
     env = env_var_repo.get_service_env_by_attr_name(
         tenant.tenant_id, service.service_id, attr_name)
     if not env:
         return 404, "环境变量不存在", None
     if not env.is_change:
         return 409, "环境变量不允许被修改", None
     update_params = {"name": name, "attr_value": attr_value}
     if service.create_status == "complete":
         body = {
             "env_name": attr_name,
             "env_value": attr_value,
             "scope": env.scope
         }
         region_api.update_service_env(service.service_region,
                                       tenant.tenant_name,
                                       service.service_alias, body)
     env_var_repo.update_env_var(tenant.tenant_id, service.service_id,
                                 attr_name, **update_params)
     env.name = name
     env.attr_value = attr_value
     return 200, "success", env
Esempio n. 3
0
    def add_service_env_var(self, tenant, service, container_port, name, attr_name, attr_value, isChange,
                            scope="outer"):

        is_pass, msg = self.check_env_attr_name(attr_name)
        if not is_pass:
            return 400, msg, None
        if len(str(attr_value)) > 512:
            attr_value = str(attr_value)[:512]
        tenantServiceEnvVar = {}
        tenantServiceEnvVar["tenant_id"] = service.tenant_id
        tenantServiceEnvVar["service_id"] = service.service_id
        tenantServiceEnvVar['container_port'] = container_port
        tenantServiceEnvVar["name"] = name
        tenantServiceEnvVar["attr_name"] = attr_name
        tenantServiceEnvVar["attr_value"] = attr_value
        tenantServiceEnvVar["is_change"] = isChange
        tenantServiceEnvVar["scope"] = scope
        env = env_var_repo.get_service_env_by_attr_name(service.tenant_id, service.service_id, attr_name)
        if env:
            return 412, u"环境变量{0}已存在".format(attr_name), None
        # 判断是否需要再region端添加
        if service.create_status == "complete":
            attr = {"container_port": container_port,
                    "tenant_id": service.tenant_id, "service_id": service.service_id, "name": name,
                    "attr_name": attr_name, "attr_value": str(attr_value), "is_change": True, "scope": scope,
                    "env_name": attr_name, "env_value": str(attr_value), "enterprise_id": tenant.enterprise_id
                    }

            region_api.add_service_env(service.service_region, tenant.tenant_name,
                                       service.service_alias, attr)
        new_env = env_var_repo.add_service_env(**tenantServiceEnvVar)
        return 200, 'success', new_env
Esempio n. 4
0
 def check_env(self, component, attr_name, attr_value):
     if env_var_repo.get_service_env_by_attr_name(component.tenant_id,
                                                  component.service_id,
                                                  attr_name):
         raise EnvAlreadyExist()
     attr_name = str(attr_name).strip()
     attr_value = str(attr_value).strip()
     is_pass, msg = self.check_env_attr_name(attr_name)
     if not is_pass:
         raise InvalidEnvName(msg)
Esempio n. 5
0
 def get_env_by_attr_name(self, tenant, service, attr_name):
     return env_var_repo.get_service_env_by_attr_name(
         tenant.tenant_id, service.service_id, attr_name)