-
Notifications
You must be signed in to change notification settings - Fork 7
feat(scripts): add Hyperstack VM debug utility #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Interactive CLI tool for managing Hyperstack VMs with support for: - Listing VMs with formatted table output - Getting detailed VM status by ID - Interactive bulk VM deletion - Setting webhook callback URLs for all VMs Uses httpx for API calls and rich for terminal UI.
WalkthroughA new interactive Python script is introduced to manage Hyperstack virtual machines via REST API. The tool provides VM listing, status checking, deletion, and callback attachment capabilities through a menu-driven CLI interface with authentication and rich formatted output. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant CLI as scripts/hyperstack-debug.py
participant HTTP as httpx.Client
participant API as Hyperstack API
User->>CLI: Start script
CLI->>CLI: Authenticate (env var / prompt)
Note over CLI: Main event loop
rect rgb(200, 220, 240)
Note over CLI,API: Example: List VMs Flow
User->>CLI: Choose "list_vms"
CLI->>HTTP: GET /core/virtual-machines
HTTP->>API: Request
API-->>HTTP: VM list (JSON)
HTTP-->>CLI: Response
CLI->>CLI: Parse & format table
CLI-->>User: Display VMs
end
rect rgb(220, 240, 200)
Note over CLI,API: Example: Delete VM Flow
User->>CLI: Choose "delete_vms"
CLI->>CLI: Prompt for VM ID
User->>CLI: Confirm deletion
CLI->>HTTP: DELETE /core/virtual-machines/{id}
HTTP->>API: Request
API-->>HTTP: 200 OK / error
HTTP-->>CLI: Response
CLI->>CLI: Format result message
CLI-->>User: Display success/failure
end
rect rgb(240, 220, 200)
Note over CLI,API: Example: Attach Callback Flow
User->>CLI: Choose "set_callbacks"
CLI->>HTTP: GET /core/virtual-machines
HTTP->>API: Request
API-->>HTTP: VM list
CLI->>CLI: Display VMs
User->>CLI: Provide callback token
CLI->>CLI: Build callback URL
User->>CLI: Confirm attachment
CLI->>HTTP: POST callback to VM
HTTP->>API: Request
API-->>HTTP: 200 OK / error
HTTP-->>CLI: Response
CLI-->>User: Display result
end
User->>CLI: Choose "quit"
CLI->>User: Exit
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Nitpick comments (2)
scripts/hyperstack-debug.py (2)
42-60: Consider using argparse for command-line arguments.The manual parsing of
sys.argvworks but argparse would provide better help text, validation, and extensibility.🔎 Example using argparse
At the top of the file, add:
import argparseThen refactor the function:
def get_callback_token() -> str: """Get callback token from environment or command-line argument or prompt.""" - # Check command-line argument (--callback-token=xxx) - for arg in sys.argv[1:]: - if arg.startswith("--callback-token="): - return arg.split("=", 1)[1] + # Parse arguments to check for --callback-token + parser = argparse.ArgumentParser(add_help=False) + parser.add_argument("--callback-token", default=None) + parser.add_argument("--debug", action="store_true") + args, _ = parser.parse_known_args() + + if args.callback_token: + return args.callback_token # Check environment variable token = os.environ.get("BASILICA_CALLBACK_TOKEN")
360-363: Consider adding Content-Type header for JSON requests.While httpx may automatically add
Content-Type: application/jsonfor JSON payloads, being explicit improves clarity and prevents potential issues.🔎 Proposed addition
headers = { "api_key": api_key, "accept": "application/json", + "content-type": "application/json", }
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
scripts/hyperstack-debug.py
🧰 Additional context used
🪛 Ruff (0.14.10)
scripts/hyperstack-debug.py
95-95: f-string without any placeholders
Remove extraneous f prefix
(F541)
🔇 Additional comments (10)
scripts/hyperstack-debug.py (10)
1-26: LGTM! Well-structured script setup.The PEP 723 metadata, imports, and constants are properly configured. The hardcoded URLs are appropriate for a debug utility.
28-39: LGTM! Proper credential handling.The function correctly retrieves the API key from environment or user input with appropriate security measures.
68-84: LGTM! Robust API response handling.The function properly handles API errors and accommodates different response structures with fallback keys.
110-146: LGTM! Consistent error handling.Both functions follow a consistent pattern with proper error handling and clear return values.
149-170: LGTM! Flexible display handling.The function handles various API response formats gracefully with fallbacks for nested structures.
173-218: LGTM! Comprehensive detail display.The function provides detailed VM information with proper handling of different data structures.
221-231: LGTM!
234-247: LGTM! Proper input validation.The function validates user input and handles errors appropriately.
337-345: LGTM! Clean menu implementation.
365-390: LGTM! Proper exception handling.The main loop and entry point handle exceptions appropriately with good user experience considerations.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.