Skip to content
Merged
Show file tree
Hide file tree
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
64 changes: 34 additions & 30 deletions src/handlers/servers/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,36 +39,40 @@ async def servers_info(callback_query: CallbackQuery, callback_data: BotCB, hetz
price_hourly = f"{hourly:.4f}€"
price_monthly = f"{monthly:.2f}€"

update = await callback_query.message.edit(
text=Dialogs.SERVERS_INFO.format(
name=server.name,
status=server.status,
ipv4=server.public_net.ipv4.ip if server.public_net.ipv4 else "➖",
ipv6=server.public_net.ipv6.ip if server.public_net.ipv6 else "➖",
ram=server.server_type.memory,
cpu=server.server_type.cores,
created=server.created.strftime("%Y-%m-%d"),
country=server.datacenter.location.country,
city=server.datacenter.location.city,
image=server.image.name or server.image.description,
created_day=(datetime.now(tz=timezone.utc) - server.created).days,
disk=server.server_type.disk,
snapshot=len(
[
snapshot
for snapshot in hetzner.images.get_all(type="snapshot")
if snapshot.created_from and snapshot.created_from.id == server.id
]
),
traffic_in=ingoing_gb,
traffic_out=outgoing_gb,
traffic_total=total_gb,
traffic_included=included_gb,
traffic_used_percent=(used_percent if used_percent is not None else "➖"),
traffic_billable=round(max(total_gb - included_gb, 0), 3) if included_gb else 0,
price_hourly=price_hourly,
price_monthly=price_monthly,
text = Dialogs.SERVERS_INFO.format(
name=server.name,
status=server.status,
ipv4=server.public_net.ipv4.ip if server.public_net.ipv4 else "➖",
ipv6=server.public_net.ipv6.ip if server.public_net.ipv6 else "➖",
ram=server.server_type.memory,
cpu=server.server_type.cores,
created=server.created.strftime("%Y-%m-%d"),
country=server.datacenter.location.country,
city=server.datacenter.location.city,
image=server.image.name or server.image.description,
created_day=(datetime.now(tz=timezone.utc) - server.created).days,
disk=server.server_type.disk,
snapshot=len(
[
snapshot
for snapshot in hetzner.images.get_all(type="snapshot")
if snapshot.created_from and snapshot.created_from.id == server.id
]
),
reply_markup=BotKB.servers_update(server=server),
traffic_in=ingoing_gb,
traffic_out=outgoing_gb,
traffic_total=total_gb,
traffic_included=included_gb,
traffic_used_percent=(used_percent if used_percent is not None else "➖"),
traffic_billable=round(max(total_gb - included_gb, 0), 3) if included_gb else 0,
price_hourly=price_hourly,
price_monthly=price_monthly,
)
reply_markup = BotKB.servers_update(server=server)

try:
update = await callback_query.message.edit(text=text, reply_markup=reply_markup)
except Exception:
await callback_query.answer()
return
return await UserMessage.clear(update, keep_current=True)
7 changes: 7 additions & 0 deletions src/keys/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ def servers_update(cls, server: Server) -> InlineKeyboardMarkup:
).pack(),
)
kb.adjust(1, 1, 2, 1, 2, 1, 2, 1, 2, 2)
kb.row(
InlineKeyboardButton(
text=Buttons.SERVERS_REFRESH,
callback_data=BotCB(area=AreaType.SERVER, task=TaskType.INFO, target=server.id).pack(),
),
size=1,
)
cls._back(kb=kb, area=AreaType.SERVER)
return kb.as_markup()

Expand Down
1 change: 1 addition & 0 deletions src/lang/_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Buttons(StrEnum):
SERVERS_UNASSIGN_IPV4 = "❌ Unassign IPv4"
SERVERS_UNASSIGN_IPV6 = "❌ Unassign IPv6"
SERVERS_UPGRADE = "⬆️ Upgrade"
SERVERS_REFRESH = "🔄 Refresh"

### Snapshots
SNAPSHOTS = "📸 Snapshots"
Expand Down