示例#1
0
 def _update_ports(self, ports):
     if ports is None:
         return
     add = ports.get("add", [])
     for port in add:
         container_port = int(port["container_port"])
         port_alias = self.service.service_key.upper()[:8]
         port["tenant_id"] = self.tenant.tenant_id
         port["service_id"] = self.service.service_id
         port["mapping_port"] = container_port
         port["port_alias"] = port_alias
         port_repo.add_service_port(**port)
         if not port["is_inner_service"]:
             continue
         try:
             # TODO create these envs in region
             env_var_service.create_env_var(self.service, container_port,
                                            u"连接地址", port_alias + "_HOST",
                                            "127.0.0.1")
             env_var_service.create_env_var(self.service, container_port,
                                            u"端口", port_alias + "_PORT",
                                            container_port)
         except (EnvAlreadyExist, InvalidEnvName) as e:
             logger.warning(
                 "failed to create env: {}; will ignore this env".format(e))
示例#2
0
 def _update_envs(self, envs, scope):
     if envs is None:
         return
     logger.debug("service id: {}; update envs; data: {}".format(
         self.service.service_id, envs))
     # create envs
     add = envs.get("add", [])
     for env in add:
         container_port = env.get("container_port", 0)
         if container_port == 0 and env["attr_value"] == "**None**":
             env["attr_value"] = self.service.service_id[:8]
         try:
             env_var_service.create_env_var(self.service, container_port,
                                            env["name"], env["attr_name"],
                                            env["attr_value"], env["is_change"],
                                            scope)
         except (EnvAlreadyExist, InvalidEnvName) as e:
             logger.warning("failed to create env: {}; will ignore this env".format(e))