Skip to content

Conversation

@itzlambda
Copy link
Collaborator

@itzlambda itzlambda commented Dec 24, 2025

Summary by CodeRabbit

  • New Features
    • Added an interactive CLI tool for managing virtual machines, including listing VMs, viewing status details, deleting instances, and configuring callbacks with rich formatted output and user-friendly prompts.

✏️ Tip: You can customize this high-level summary in your review settings.

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.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 24, 2025

Walkthrough

A 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

Cohort / File(s) Summary
New Hyperstack Management Script
scripts/hyperstack-debug.py
New 300+ line CLI tool with authentication (env var / prompt), VM CRUD operations (list, get, delete), callback URL management, interactive menu loop, rich console output with formatted tables, and comprehensive HTTP error handling via httpx client

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Hops of joy through virtual lands,
Hyperstacks now bend to our commands!
Menus dance, callbacks align,
REST calls flow in perfect design!
Debug and manage with bunny-smooth grace! 🌟

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(scripts): add Hyperstack VM debug utility' directly and clearly describes the main change: introducing a new debug utility script for managing Hyperstack VMs.
Docstring Coverage ✅ Passed Docstring coverage is 93.33% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/hyperstack-debug

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@itzlambda itzlambda marked this pull request as ready for review December 24, 2025 08:36
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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.argv works but argparse would provide better help text, validation, and extensibility.

🔎 Example using argparse

At the top of the file, add:

import argparse

Then 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/json for 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7dbac54 and 83d79c8.

📒 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.

@itzlambda itzlambda merged commit 413babe into main Dec 24, 2025
14 checks passed
@itzlambda itzlambda deleted the feat/hyperstack-debug branch December 24, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants