예제 #1
0
 def container_node_id(self):
     query = {
         "cru": self.resources["cpu"],
         "mru": math.ceil(self.resources["memory"] / 1024),
         "sru": math.ceil(self.resources["disk_size"] / 1024),
     }
     self.selected_node = deployer.ask_container_placement(self, self.pool_id, ip_version=self.ip_version, **query)
     if not self.selected_node:
         self.selected_node = deployer.schedule_container(self.pool_id, ip_version=self.ip_version, **query)
예제 #2
0
파일: exposed.py 프로젝트: abdulgig/js-sdk
    def reservation(self):
        metadata = {
            "name": self.domain,
            "form_info": {
                "Solution name": self.domain,
                "chatflow": "exposed"
            }
        }
        self.solution_metadata.update(metadata)
        query = {"mru": 1, "cru": 1, "sru": 1}
        self.selected_node = deployer.schedule_container(self.pool_id, **query)
        self.network_name = self.solution["Network"]

        result = deployer.add_network_node(
            self.network_name,
            self.selected_node,
            self.pool_id,
            bot=self,
            owner=self.solution_metadata.get("owner"))
        if result:
            for wid in result["ids"]:
                success = deployer.wait_workload(
                    wid, self, breaking_node_id=self.selected_node.node_id)
                if not success:
                    raise DeploymentFailed(
                        f"Failed to add node to network {wid}", wid=wid)

        self.network_view = deployer.get_network_view(self.network_name)
        self.tcprouter_ip = self.network_view.get_free_ip(self.selected_node)
        if not self.tcprouter_ip:
            raise StopChatFlow(
                f"No available ips one for network {self.network_view.name} node {self.selected_node.node_id}"
            )

        if self.domain_type != "Custom Domain":
            self.dom_id = deployer.create_subdomain(
                pool_id=self.domain_pool.pool_id,
                gateway_id=self.domain_gateway.node_id,
                subdomain=self.domain,
                **self.solution_metadata,
                solution_uuid=self.solution_id,
            )
            success = deployer.wait_workload(self.dom_id, self)
            if not success:
                raise DeploymentFailed(
                    f"Failed to reserve sub-domain workload {self.dom_id}",
                    solution_uuid=self.solution_id)

        self.proxy_id = deployer.create_proxy(
            pool_id=self.domain_pool.pool_id,
            gateway_id=self.domain_gateway.node_id,
            domain_name=self.domain,
            trc_secret=self.secret,
            **self.solution_metadata,
            solution_uuid=self.solution_id,
        )
        success = deployer.wait_workload(self.proxy_id, self)
        if not success:
            raise DeploymentFailed(
                f"Failed to reserve reverse proxy workload {self.proxy_id}",
                solution_uuid=self.solution_id)

        self.tcprouter_id = deployer.expose_address(
            pool_id=self.pool_id,
            gateway_id=self.domain_gateway.node_id,
            network_name=self.network_name,
            local_ip=self.solution_ip,
            port=self.port,
            tls_port=self.tls_port,
            trc_secret=self.secret,
            bot=self,
            **self.solution_metadata,
            solution_uuid=self.solution_id,
        )
        success = deployer.wait_workload(self.tcprouter_id, self)
        if not success:
            raise DeploymentFailed(
                f"Failed to reserve TCP Router container workload {self.tcprouter_id}",
                solution_uuid=self.solution_id,
                wid=self.tcprouter_id,
            )
예제 #3
0
파일: exposed.py 프로젝트: xmonader/js-sdk
    def reservation(self):
        metadata = {
            "name": self.domain,
            "form_info": {
                "Solution name": self.domain,
                "chatflow": "exposed"
            }
        }
        self.solution_metadata.update(metadata)
        query = {"mru": 1, "cru": 1, "sru": 1}
        self.selected_node = deployer.schedule_container(self.pool_id, **query)
        self.network_name = self.solution["Network"]

        result = deployer.add_network_node(
            self.network_name,
            self.selected_node,
            self.pool_id,
            bot=self,
            owner=self.solution_metadata.get("owner"))
        if result:
            for wid in result["ids"]:
                success = deployer.wait_workload(
                    wid, self, breaking_node_id=self.selected_node.node_id)
                if not success:
                    raise DeploymentFailed(
                        f"Failed to add node to network {wid}", wid=wid)

        self.network_view = deployer.get_network_view(self.network_name)
        self.tcprouter_ip = self.network_view.get_free_ip(self.selected_node)
        if not self.tcprouter_ip:
            raise StopChatFlow(
                f"No available ips one for network {self.network_view.name} node {self.selected_node.node_id}"
            )

        if self.domain_type != "Custom Domain":
            self.dom_id = deployer.create_subdomain(
                pool_id=self.domain_pool.pool_id,
                gateway_id=self.domain_gateway.node_id,
                subdomain=self.domain,
                **self.solution_metadata,
                solution_uuid=self.solution_id,
            )
            success = deployer.wait_workload(self.dom_id, self)
            if not success:
                raise DeploymentFailed(
                    f"Failed to reserve sub-domain workload {self.dom_id}",
                    solution_uuid=self.solution_id)

        if self.proxy_type == "TRC":
            self.proxy_id = deployer.create_proxy(
                pool_id=self.domain_pool.pool_id,
                gateway_id=self.domain_gateway.node_id,
                domain_name=self.domain,
                trc_secret=self.secret,
                **self.solution_metadata,
                solution_uuid=self.solution_id,
            )
            success = deployer.wait_workload(self.proxy_id, self)
            if not success:
                raise DeploymentFailed(
                    f"Failed to reserve reverse proxy workload {self.proxy_id}",
                    solution_uuid=self.solution_id)

        trc_log_config = j.core.config.get("LOGGING_SINK", {})
        if trc_log_config:
            trc_log_config[
                "channel_name"] = f"{self.threebot_name}-{self.solution_name}-trc".lower(
                )

        if self.proxy_type == "NGINX":
            self.tcprouter_id = deployer.expose_and_create_certificate(
                domain=self.domain,
                email=self.email,
                pool_id=self.pool_id,
                gateway_id=self.domain_gateway.node_id,
                network_name=self.network_name,
                solution_ip=self.solution_ip,
                solution_port=self.port,
                trc_secret=self.secret,
                bot=self,
                enforce_https=self.force_https,
                log_config=trc_log_config,
                **self.solution_metadata,
                solution_uuid=self.solution_id,
            )
        else:
            self.tcprouter_id, _ = deployer.expose_address(
                pool_id=self.pool_id,
                gateway_id=self.domain_gateway.node_id,
                network_name=self.network_name,
                local_ip=self.solution_ip,
                port=self.port,
                tls_port=self.tls_port,
                trc_secret=self.secret,
                bot=self,
                log_config=trc_log_config,
                **self.solution_metadata,
                solution_uuid=self.solution_id,
            )
        success = deployer.wait_workload(self.tcprouter_id, self)
        if not success:
            raise DeploymentFailed(
                f"Failed to reserve TCP Router container workload {self.tcprouter_id}",
                solution_uuid=self.solution_id,
                wid=self.tcprouter_id,
            )