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)
Example #2
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)