diff --git a/backend/src/interfaces/agent.py b/backend/src/interfaces/agent.py index 1320691..959c791 100644 --- a/backend/src/interfaces/agent.py +++ b/backend/src/interfaces/agent.py @@ -47,12 +47,13 @@ class GetAgentSecretMessage(BaseModel): class GetAgentResponse(PublicAgentData): - pass + instance_ip: str | None class GetAgentSecretResponse(BaseModel): secret: str + class AgentPythonPackageManager(str, Enum): poetry = "poetry" pip = "pip" diff --git a/backend/src/interfaces/aleph.py b/backend/src/interfaces/aleph.py index 9f3cfb7..f4b4137 100644 --- a/backend/src/interfaces/aleph.py +++ b/backend/src/interfaces/aleph.py @@ -6,12 +6,3 @@ class AlephVolume(BaseModel): mount: str ref: str use_latest: bool - - -class AlephNodeInfo: - def __init__(self, **kwargs): - self.data = kwargs.get("data", {}) - self.nodes = self.data.get("corechannel", {}).get("resource_nodes", []) - self.nodes.sort(key=lambda x: x.get("score", 0), reverse=True) - self.core_node = self.data.get("corechannel", {}).get("nodes", []) - self.core_node.sort(key=lambda x: x.get("score", 0), reverse=True) diff --git a/backend/src/main.py b/backend/src/main.py index da70a7d..405ec41 100644 --- a/backend/src/main.py +++ b/backend/src/main.py @@ -116,9 +116,15 @@ async def get_agent_public_info(agent_id: str) -> GetAgentResponse: ) agent = agents[0] + try: + ip_address = await fetch_instance_ip(agent.instance_hash) + except ValueError: + ip_address = None + return GetAgentResponse( id=agent.id, instance_hash=agent.instance_hash, + instance_ip=ip_address, last_update=agent.last_update, subscription_id=agent.subscription_id, ) @@ -205,11 +211,10 @@ async def update( try: hostname = await fetch_instance_ip(agent.instance_hash) - print(hostname) except ValueError: raise HTTPException( status_code=HTTPStatus.INTERNAL_SERVER_ERROR, - detail="Instance IPv6 not found, it's probably not allocated yet.", + detail="Instance IPv6 address not found, it probably isn't allocated yet. Please try again in a few minutes.", ) # Create a Paramiko SSH client @@ -233,7 +238,7 @@ async def update( # Execute a command _stdin, stdout, stderr = ssh_client.exec_command( - f"wget {deploy_script_url} -O /tmp/deploy-agent.sh -q --no-cached && chmod +x /tmp/deploy-agent.sh && /tmp/deploy-agent.sh {python_version} {package_manager.value}" + f"wget {deploy_script_url} -O /tmp/deploy-agent.sh -q --no-cache && chmod +x /tmp/deploy-agent.sh && /tmp/deploy-agent.sh {python_version} {package_manager.value}" ) output = stdout.read().decode("utf-8") diff --git a/backend/src/utils/aleph.py b/backend/src/utils/aleph.py index c2e2006..c96140f 100644 --- a/backend/src/utils/aleph.py +++ b/backend/src/utils/aleph.py @@ -25,5 +25,9 @@ async def fetch_instance_ip(item_hash) -> str: resp.raise_for_status() allocation = await resp.json() return allocation["vm_ipv6"] - except (aiohttp.ClientResponseError, aiohttp.ClientConnectorError): + except ( + aiohttp.ClientResponseError, + aiohttp.ClientConnectorError, + aiohttp.ConnectionTimeoutError, + ): raise ValueError()