Skip to content

Commit 8766d48

Browse files
committed
Display alerts for unallocated PAYG VMs with active flows and unstarted coco VMs
1 parent e4d2667 commit 8766d48

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

src/aleph_client/commands/instance/__init__.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -808,12 +808,19 @@ async def _show_instances(messages: builtins.list[InstanceMessage]):
808808

809809
await fetch_crn_list() # Precache CRN list
810810
scheduler_responses = dict(await asyncio.gather(*[fetch_vm_info(message) for message in messages]))
811-
uninitialized_confidential_found = False
811+
uninitialized_confidential_found = []
812+
unallocated_payg_found = []
812813
async with AlephHttpClient(api_server=settings.API_HOST) as client:
813814
for message in messages:
814815
info = scheduler_responses[message.item_hash]
816+
817+
is_hold = info["payment"] == PaymentType.hold.value
818+
if not is_hold and info["ipv6_logs"] == help_strings.VM_NOT_READY:
819+
unallocated_payg_found.append(message.item_hash)
815820
if info["confidential"] and info["ipv6_logs"] == help_strings.VM_NOT_READY:
816-
uninitialized_confidential_found = True
821+
uninitialized_confidential_found.append(message.item_hash)
822+
823+
# 1st Column
817824
name = Text(
818825
(
819826
message.content.metadata["name"]
@@ -831,7 +838,7 @@ async def _show_instances(messages: builtins.list[InstanceMessage]):
831838
"Payment: ",
832839
Text(
833840
info["payment"].capitalize().ljust(12),
834-
style="red" if info["payment"] == PaymentType.hold.value else "orange3",
841+
style="red" if is_hold else "orange3",
835842
),
836843
)
837844
confidential = Text.assemble(
@@ -847,7 +854,7 @@ async def _show_instances(messages: builtins.list[InstanceMessage]):
847854
payer = Text.assemble("\nPayer: ", Text(str(message.content.address), style="orange1"))
848855
price: PriceResponse = await client.get_program_price(message.item_hash)
849856
required_tokens = Decimal(price.required_tokens)
850-
if price.payment_type == PaymentType.hold.value:
857+
if is_hold:
851858
aleph_price = Text(f"{displayable_amount(required_tokens, decimals=3)} (fixed)", style="violet")
852859
else:
853860
psec = f"{displayable_amount(required_tokens, decimals=8)}/sec"
@@ -856,6 +863,7 @@ async def _show_instances(messages: builtins.list[InstanceMessage]):
856863
pmonth = f"{displayable_amount(2628000*required_tokens, decimals=3)}/month"
857864
aleph_price = Text.assemble(psec, " | ", phour, " | ", pday, " | ", pmonth, style="violet")
858865
cost = Text.assemble("\n$ALEPH: ", aleph_price)
866+
859867
instance = Text.assemble(
860868
"Item Hash ↓\t Name: ",
861869
name,
@@ -870,6 +878,8 @@ async def _show_instances(messages: builtins.list[InstanceMessage]):
870878
payer,
871879
cost,
872880
)
881+
882+
# 2nd Column
873883
hypervisor = safe_getattr(message, "content.environment.hypervisor")
874884
specs = [
875885
f"vCPU: [magenta3]{message.content.resources.vcpus}[/magenta3]\n",
@@ -884,6 +894,8 @@ async def _show_instances(messages: builtins.list[InstanceMessage]):
884894
specs += [f"• [green]{gpu.vendor}, {gpu.device_name}[green]"]
885895
specs += ["[/bright_yellow]"]
886896
specifications = Text.from_markup("".join(specs))
897+
898+
# 3rd Column
887899
status_column = Text.assemble(
888900
Text.assemble(
889901
Text("Allocation: ", style="blue"),
@@ -936,20 +948,33 @@ async def _show_instances(messages: builtins.list[InstanceMessage]):
936948
console.print(table)
937949

938950
infos = [Text.from_markup(f"[bold]Address:[/bold] [bright_cyan]{messages[0].sender}[/bright_cyan]")]
951+
if unallocated_payg_found:
952+
unallocated_payg_found_str = "\n".join(unallocated_payg_found)
953+
infos += [
954+
Text.assemble(
955+
Text.from_markup("\n\nYou have unallocated/unstarted instance(s) with active flows:\n"),
956+
Text.from_markup(f"[bright_red]{unallocated_payg_found_str}[/bright_red]"),
957+
Text.from_markup(
958+
"\n[italic]↳[/italic] [orange3]Recommended action:[/orange3] allocate + start, or delete them."
959+
),
960+
)
961+
]
939962
if uninitialized_confidential_found:
963+
uninitialized_confidential_found_str = "\n".join(uninitialized_confidential_found)
940964
infos += [
941965
Text.assemble(
942-
"\n\nBoot uninitialized/unstarted confidential instances with:\n",
966+
"\n\nBoot unallocated/unstarted confidential instance(s):\n",
967+
Text.from_markup(f"[grey50]{uninitialized_confidential_found_str}[/grey50]"),
943968
Text.from_markup(
944-
" aleph instance confidential [bright_cyan]<vm-item-hash>[/bright_cyan]", style="italic"
969+
"\n aleph instance confidential [bright_cyan]<vm-item-hash>[/bright_cyan]", style="italic"
945970
),
946971
)
947972
]
948973
infos += [
949974
Text.assemble(
950975
"\n\nConnect to an instance with:\n",
951976
Text.from_markup(
952-
"↳ ssh root@[yellow]<ipv6-address>[/yellow] [-i [orange3]<ssh-private-key-file>[/orange3]]",
977+
"↳ ssh root@[yellow]<ipv6-address>[/yellow] [-i [orange3]<ssh-private-key-file>[/orange3]]",
953978
style="italic",
954979
),
955980
)

0 commit comments

Comments
 (0)