Skip to content

Commit

Permalink
Added ArmoniK cluster commands
Browse files Browse the repository at this point in the history
  • Loading branch information
AncientPatata committed Jan 22, 2025
1 parent ba4c347 commit 9f0c5a5
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/armonik_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ def cli() -> None:
cli.add_command(commands.sessions)
cli.add_command(commands.tasks)
cli.add_command(commands.partitions)
cli.add_command(commands.cluster)
3 changes: 2 additions & 1 deletion src/armonik_cli/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .sessions import sessions
from .tasks import tasks
from .partitions import partitions
from .cluster import cluster


__all__ = ["sessions", "tasks", "partitions"]
__all__ = ["sessions", "tasks", "partitions", "cluster"]
62 changes: 62 additions & 0 deletions src/armonik_cli/commands/cluster.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import grpc
import rich_click as click

from armonik.client.versions import ArmoniKVersions
from armonik.client.health_checks import ArmoniKHealthChecks
from rich.panel import Panel
from rich.table import Table
from rich.text import Text
from rich import print

from armonik_cli.core import base_command


@click.group(name="cluster")
def cluster() -> None:
"""Manage ArmoniK cluster."""
pass


@cluster.command(name="info")
@base_command
def cluster_info(endpoint: str, output: str, debug: bool) -> None:
"""Get basic information on the ArmoniK cluster (endpoint, versions)"""
with grpc.insecure_channel(endpoint) as channel:
versions_client = ArmoniKVersions(channel)
version_info = versions_client.list_versions()

grid = Table.grid(padding=(0, 1))
grid.add_column("Label", justify="left", style="cyan", no_wrap=True)
grid.add_column("Value", style="green", justify="left")

grid.add_row("Endpoint:", endpoint)
grid.add_row("Core Version:", version_info['core'])
grid.add_row("API Version:", version_info['api'])

panel = Panel(grid, title="Cluster Information", border_style="blue")
print(panel)

@cluster.command(name="health")
@base_command
def cluster_health(endpoint: str, output: str, debug: bool) -> None:
"""Get information on the health of some components of the ArmoniK cluster"""
with grpc.insecure_channel(endpoint) as channel:
health_client = ArmoniKHealthChecks(channel)
health_status = health_client.check_health()

grid = Table.grid(padding=(0, 1))
grid.add_column("Service", style="cyan", justify="left")
grid.add_column("Status", style="green", justify="left")
grid.add_column("Message", style="yellow", justify="left")

for service_name, info in health_status.items():
status_style = "green" if info["status"] else "red"
status_text = "✓ Healthy" if info["status"] else "✗ Unhealthy"
grid.add_row(
" ".join(word.capitalize() for word in service_name.split("_")),
Text(status_text, style=status_style),
info["message"] or "-"
)

panel = Panel(grid, title="Health Status", border_style="blue")
print(panel)

0 comments on commit 9f0c5a5

Please sign in to comment.