Skip to content

Commit

Permalink
Add Rack Resiliency Module
Browse files Browse the repository at this point in the history
  • Loading branch information
arka-pramanik-hpe committed Jan 28, 2025
1 parent 27cc433 commit 9fbdf3a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cray/modules/rr/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# cray/modules/rr/__init__.py
from .cli import cli # <-- Explicitly import the CLI group

def setup(main_cli):
main_cli.add_command(cli) # <-- Add the renamed group to the main CLI
40 changes: 40 additions & 0 deletions cray/modules/rr/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import click
import requests

@click.group(name="rr", help="Rack Resiliency commands")
def cli():
pass

# Existing list command
@cli.command(name="list", help="List rack resiliency information")
def list_command():
click.echo("Hello World in the terminal")

@cli.command(name="hello", help="Fetch greeting from HelloWorld API")
@click.option('--name', '-n', default=None, help="Name for personalized greeting")
@click.option('--external-ip', '-e', required=True,
help="External IP of HelloWorld service (port 8080)")
def hello_command(name, external_ip):
"""Fetch greeting from /hello endpoint"""
base_url = f"http://{external_ip}:8080"
endpoint = f"{base_url}/hello"

try:
response = requests.get(
endpoint,
params={'name': name} if name else None,
timeout=5 # Add timeout
)
response.raise_for_status()

# Add JSON parsing validation
try:
data = response.json()
click.echo(f"Response: {data['message']}")
except ValueError:
click.echo(f"Invalid JSON response. Raw response: {response.text}", err=True)

except requests.exceptions.HTTPError as e:
click.echo(f"HTTP Error {e.response.status_code}: {e.response.text}", err=True)
except requests.exceptions.RequestException as e:
click.echo(f"Connection Error: {str(e)}", err=True)

0 comments on commit 9fbdf3a

Please sign in to comment.