-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(deployment/backend): Instance message posted
- Loading branch information
1 parent
c9a774e
commit 1d14dd1
Showing
4 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import aiohttp | ||
from aleph.sdk import AlephHttpClient | ||
from aleph_message.models import InstanceMessage | ||
|
||
from src.config import config | ||
|
||
|
||
async def fetch_instance_ip(item_hash) -> str: | ||
""" | ||
Fetches IPv6 of an allocated instance given a message hash. | ||
Args: | ||
item_hash: Instance message hash. | ||
Returns: | ||
IPv6 address | ||
""" | ||
async with AlephHttpClient(api_server=config.ALEPH_API_URL) as client: | ||
message = await client.get_message(item_hash, InstanceMessage) | ||
|
||
async with aiohttp.ClientSession() as session: | ||
try: | ||
async with session.get( | ||
f"https://scheduler.api.aleph.cloud/api/v0/allocation/{message.item_hash}" | ||
) as resp: | ||
resp.raise_for_status() | ||
allocation = await resp.json() | ||
return allocation["vm_ipv6"] | ||
except (aiohttp.ClientResponseError, aiohttp.ClientConnectorError): | ||
raise ValueError() |