-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27cc433
commit 9fbdf3a
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |