Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/aleph/sdk/client/services/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from aleph_message.models import InstanceMessage, ItemHash, MessageType, PaymentType
from aleph_message.status import MessageStatus

from aleph.sdk.client.services.crn import CrnList
from aleph.sdk.query.filters import MessageFilter
from aleph.sdk.query.responses import MessagesResponse

Expand Down Expand Up @@ -47,7 +48,7 @@ async def get_name_of_executable(self, item_hash: ItemHash) -> Optional[str]:
return None

async def get_instance_allocation_info(
self, msg: InstanceMessage, crn_list: dict
self, msg: InstanceMessage, crn_list: CrnList
) -> Tuple[InstanceMessage, Union[InstanceManual, InstanceWithScheduler]]:
vm_hash = msg.item_hash
payment_type = safe_getattr(msg, "content.payment.type.value")
Expand All @@ -62,12 +63,8 @@ async def get_instance_allocation_info(
info = InstanceWithScheduler(source="scheduler", allocations=alloc)
else:
crn_hash = safe_getattr(msg, "content.requirements.node.node_hash")
if isinstance(crn_list, list):
node = next((n for n in crn_list if n.get("hash") == crn_hash), None)
url = sanitize_url(node.get("address")) if node else ""
else:
node = crn_list.get(crn_hash)
url = sanitize_url(node.get("address")) if node else ""
node = crn_list.find_crn_by_hash(crn_hash)
url = sanitize_url(node.address) if node else ""

info = InstanceManual(source="manual", crn_url=url)
return msg, info
Expand All @@ -84,8 +81,7 @@ async def get_instances(self, address: str) -> List[InstanceMessage]:
return resp.messages

async def get_instances_allocations(self, messages_list, only_processed=True):
crn_list_response = await self._client.crn.get_crns_list()
crn_list = crn_list_response.get("crns", {})
crn_list = await self._client.crn.get_crns_list(only_active=False)

tasks = []
for msg in messages_list:
Expand Down
Loading