def network_reservation(self): if self.action == "Create": try: self.config = deployer.deploy_network( self.solution_name, self.access_node, self.ip_range, self.ipversion, self.pool, **self.solution_metadata, ) except Exception as e: raise StopChatFlow(f"Failed to register workload due to error {str(e)}") else: self.config = deployer.add_access( self.network_view.name, self.network_view, self.access_node.node_id, self.pool, self.ipversion == "IPv4", bot=self, **self.solution_metadata, ) for wid in self.config["ids"]: try: success = deployer.wait_workload(wid, self, breaking_node_id=self.access_node.node_id) except StopChatFlow as e: if self.action == "Create": solutions.cancel_solution(self.config["ids"]) raise e if not success: raise DeploymentFailed(f"Failed to deploy workload {wid}", wid=wid)
def network_reservation(self): # create config first for wid in self.config["ids"]: try: success = deployer.wait_workload( wid, self, breaking_node_id=self.access_node.node_id) except StopChatFlow as e: solutions.cancel_solution(self.config["ids"]) raise e if not success: raise DeploymentFailed(f"Failed to deploy workload {wid}", wid=wid)
def cancel_solution(self, wids) -> bool: solutions.cancel_solution(wids) return True
def reservation(self): self.workload_ids = [] metadata = { "name": self.solution_name, "form_info": { "chatflow": "gollum", "Solution name": self.solution_name }, } self.solution_metadata.update(metadata) # reserve subdomain self.workload_ids.append( deployer.create_subdomain( pool_id=self.pool_id, gateway_id=self.gateway.node_id, subdomain=self.domain, addresses=self.addresses, solution_uuid=self.solution_id, **self.solution_metadata, )) success = deployer.wait_workload(self.workload_ids[0], self) if not success: raise StopChatFlow( f"Failed to create subdomain {self.domain} on gateway {self.gateway.node_id} {self.workload_ids[0]}" ) # expose container domain wid, _ = deployer.expose_address( pool_id=self.pool_id, gateway_id=self.gateway.node_id, network_name=self.network_view.name, local_ip=self.ip_address, port=80, tls_port=443, trc_secret=self.secret, node_id=self.selected_node.node_id, reserve_proxy=True, domain_name=self.domain, proxy_pool_id=self.gateway_pool.pool_id, solution_uuid=self.solution_id, **self.solution_metadata, ) self.workload_ids.append(wid) success = deployer.wait_workload(self.workload_ids[1], self) if not success: solutions.cancel_solution(self.workload_ids) raise StopChatFlow( f"Failed to create TRC container on node {self.selected_node.node_id} {self.workload_ids[1]}" ) self.container_url = f"https://{self.domain}/" # deploy container var_dict = { "pub_key": self.public_key, "GITHUB_USER": self.github_user.value, "GITHUB_EMAIL": self.github_email.value, "GITHUB_REPO": self.github_repo.value, "GITHUB_TOKEN": self.github_token.value, } entrypoint = f'/bin/bash /start.sh "{self.domain}" "{self.email}"' self.workload_ids.append( deployer.deploy_container( pool_id=self.pool_id, node_id=self.selected_node.node_id, network_name=self.network_view.name, ip_address=self.ip_address, flist=self.flist_url, cpu=self.resources["cpu"], memory=self.resources["memory"], disk_size=self.resources["disk_size"], env=var_dict, interactive=False, entrypoint=entrypoint, solution_uuid=self.solution_id, **self.solution_metadata, )) success = deployer.wait_workload(self.workload_ids[2], self) if not success: raise StopChatFlow( f"Failed to create container on node {self.selected_node.node_id} {self.workload_ids[2]}" )