Skip to content

feat: Add rack and tray lifecycle and task commands to TUI#535

Merged
kfelternv merged 4 commits into
NVIDIA:mainfrom
kfelternv:nico-cli-lifecycle-task-524
May 21, 2026
Merged

feat: Add rack and tray lifecycle and task commands to TUI#535
kfelternv merged 4 commits into
NVIDIA:mainfrom
kfelternv:nico-cli-lifecycle-task-524

Conversation

@kfelternv
Copy link
Copy Markdown
Contributor

@kfelternv kfelternv commented May 15, 2026

Rack and tray lifecycle commands are useful to have in the tui, so that users dont have to know uuids of resources before running the command. This PR adds various commands to the interactive mode of the cli for rack and tray lifecycle commands like rack bringup.

Signed-off-by: Kyle Felter <kfelter@nvidia.com>
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 15, 2026

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

Review Change Stack

Summary by CodeRabbit

  • New Features

    • Added rack lifecycle commands: bringup, power state, firmware, and validation operations.
    • Added tray management commands: list, retrieve details, power state, firmware, and validation.
    • Introduced rack task commands: get and cancel task operations.
    • Implemented site scope enforcement for rack and tray operations.
    • Enhanced REPL autocomplete support for new rack and tray command prefixes.
  • Tests

    • Added comprehensive test coverage for new lifecycle, task, and scope-handling functionality.

Walkthrough

This PR extends the CLI TUI with complete tray resource management, adding tray data fetching with site scoping, user commands for listing and managing tray/rack lifecycle operations, shared infrastructure for scope enforcement and task handling, command registration, REPL autocomplete support, and comprehensive test coverage.

Changes

Tray Resource Management and Lifecycle Operations

Layer / File(s) Summary
Tray Data Fetching and Session Integration
cli/tui/session.go, cli/tui/cache.go, cli/tui/commands.go
Registers tray as a fetchable resource type with fetchTrays implementation supporting org-scoped queries with optional siteId filtering; maps each item to NamedItem with fallback name resolution, power state status, and comprehensive extra fields. Cache invalidation extended to include tray entries. Scope flag handling recognizes tray commands as site-scoped.
Shared Lifecycle Command Infrastructure
cli/tui/commands.go
requireSiteScope enforces and persists site scoping (prompting if needed), powerStateChoices defines canonical power state enum, printTaskIDs renders task IDs from lifecycle responses before full JSON, and taskIDFromArgsOrPrompt accepts positional or interactive task ID input.
Tray Listing and Detail Commands
cli/tui/commands.go
cmdTrayList renders table of trays with rack name and firmware metadata; cmdTrayGet fetches and displays tray detail JSON with site scope enforcement in request parameters and logging.
Rack Lifecycle Commands
cli/tui/commands.go
cmdRackBringup, cmdRackPower, cmdRackFirmware, cmdRackValidate execute rack operations, each enforcing site scope, collecting interactive inputs where needed, invoking the corresponding API endpoint with siteId, and rendering task IDs or validation JSON via shared helpers.
Tray Lifecycle Commands
cli/tui/commands.go
cmdTrayPower, cmdTrayFirmware, cmdTrayValidate execute tray operations, each enforcing site scope, collecting interactive inputs where needed, invoking the corresponding API endpoint with siteId, and rendering task IDs or validation JSON via shared helpers.
Rack Task Commands and Interactive Task ID Resolution
cli/tui/commands.go
cmdRackTaskGet and cmdRackTaskCancel manage task lifecycle with site scope enforcement; taskIDFromArgsOrPrompt accepts positional task ID or prompts interactively; task operations invoke endpoints with siteId and render task details or cancellation response JSON.
Command Registration and REPL Autocomplete
cli/tui/commands.go, cli/tui/repl.go
AllCommands() registers all rack and tray operational/task commands, wiring command names and handler functions. REPL argResourceMap extended with new rack and tray subcommands to enable argument name completion.
Test Coverage for Lifecycle and Scope Integration
cli/tui/commands_test.go
Adds tests for lifecycle infrastructure (taskIDFromArgsOrPrompt argument/prompt/validation, printTaskIDs output, powerStateChoices enum, requireSiteScope scope persistence). Extends existing scope-flag and cache-invalidation tests to verify tray resource type inclusion. Verifies AllCommands() registers expected tray/rack lifecycle/task commands.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • NVIDIA/infra-controller-rest#534: Updates cli/tui/cache.go's InvalidateFiltered to include additional resource types (expected-rack, expected-switch, expected-power-shelf), following the same pattern as this PR's tray integration.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.62% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the primary change: adding rack and tray lifecycle and task commands to the TUI component.
Description check ✅ Passed The description is directly related to the changeset, explaining the motivation for adding rack and tray lifecycle commands to the interactive CLI mode.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@kfelternv kfelternv marked this pull request as ready for review May 15, 2026 19:28
@kfelternv kfelternv requested a review from a team as a code owner May 15, 2026 19:28
@github-actions
Copy link
Copy Markdown

🔐 TruffleHog Secret Scan

No secrets or credentials found!

Your code has been scanned for 700+ types of secrets and credentials. All clear! 🎉

🔗 View scan details

🕐 Last updated: 2026-05-15 19:29:50 UTC | Commit: ccf1e4f

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 15, 2026

🔍 Container Scan Summary

Service Total Critical High Medium Low Other
nico-flow 66 4 34 18 2 8
nico-nsm 82 2 28 43 9 0
nico-psm 67 4 35 18 2 8
nico-rest-api 100 6 53 30 3 8
nico-rest-cert-manager 65 4 34 18 1 8
nico-rest-db 66 4 34 18 2 8
nico-rest-site-agent 65 4 34 18 1 8
nico-rest-site-manager 65 4 34 18 1 8
nico-rest-workflow 67 4 35 18 2 8
TOTAL 643 36 321 199 23 64

Per-CVE detail lives in the per-service grype-* artifacts (JSON + SARIF). Severity counts only — no CVE IDs published here.

@kfelternv
Copy link
Copy Markdown
Contributor Author

Resolves #524

Copy link
Copy Markdown
Contributor

@thossain-nv thossain-nv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks @kfelternv

Copy link
Copy Markdown
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.

🧹 Nitpick comments (2)
cli/tui/cache.go (1)

70-76: ⚡ Quick win

Centralize the filtered resource registry.

This roster now has to stay in sync with appendScopeFlags and the other resource registries, and the tray / expected-* additions already touched multiple copies in this PR. A shared constant or helper would make the next scoped resource much harder to partially wire.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cli/tui/cache.go` around lines 70 - 76, The hardcoded resource list inside
Cache.InvalidateFiltered must be centralized so it stays in sync with other
registries (e.g., appendScopeFlags); extract the literal slice into a single
shared symbol (for example a package-level constant or a small accessor function
like filteredResources() or FilteredResourceRegistry) and replace the inline
list in InvalidateFiltered with a reference to that shared symbol; update other
callers (appendScopeFlags and any other registry usages) to use the same shared
symbol so additions/removals only happen in one place.
cli/tui/commands.go (1)

3179-3184: ⚡ Quick win

Split the inline unmarshal from the condition.

This is the one new place in the file that diverges from the repo’s preferred Go style. Pulling the unmarshal into its own statement keeps the parse path explicit and consistent with the rest of the TUI command code.

♻️ Suggested change
 func printTaskIDs(body []byte, action string) error {
 	var resp struct {
 		TaskIDs []string `json:"taskIds"`
 	}
-	if err := json.Unmarshal(body, &resp); err == nil && len(resp.TaskIDs) > 0 {
+	err := json.Unmarshal(body, &resp)
+	if err == nil && len(resp.TaskIDs) > 0 {
 		fmt.Printf("%s %s started; %d task(s):\n", Green("OK"), action, len(resp.TaskIDs))
 		for _, id := range resp.TaskIDs {
 			fmt.Printf("  %s\n", id)
 		}
 		fmt.Println()

As per coding guidelines, "Prefer split assign-and-condition into two statements: derr := action(); if derr != nil { ... } instead of inline if derr := action(); derr != nil { ... }".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cli/tui/commands.go` around lines 3179 - 3184, The json.Unmarshal call inside
the if statement in printTaskIDs should be split into two statements for clarity
and style: first call json.Unmarshal(body, &resp) and assign its error to a
variable (e.g., err), then use if err == nil && len(resp.TaskIDs) > 0 { ... }
(or handle the error case explicitly) so the parse path is explicit and
consistent with other TUI command code; update the function printTaskIDs to
perform the unmarshal before the conditional that checks len(resp.TaskIDs).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cli/tui/cache.go`:
- Around line 70-76: The hardcoded resource list inside Cache.InvalidateFiltered
must be centralized so it stays in sync with other registries (e.g.,
appendScopeFlags); extract the literal slice into a single shared symbol (for
example a package-level constant or a small accessor function like
filteredResources() or FilteredResourceRegistry) and replace the inline list in
InvalidateFiltered with a reference to that shared symbol; update other callers
(appendScopeFlags and any other registry usages) to use the same shared symbol
so additions/removals only happen in one place.

In `@cli/tui/commands.go`:
- Around line 3179-3184: The json.Unmarshal call inside the if statement in
printTaskIDs should be split into two statements for clarity and style: first
call json.Unmarshal(body, &resp) and assign its error to a variable (e.g., err),
then use if err == nil && len(resp.TaskIDs) > 0 { ... } (or handle the error
case explicitly) so the parse path is explicit and consistent with other TUI
command code; update the function printTaskIDs to perform the unmarshal before
the conditional that checks len(resp.TaskIDs).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 87136334-6e1f-457a-b3cb-094b9963b00d

📥 Commits

Reviewing files that changed from the base of the PR and between 9f448bb and 416fc96.

📒 Files selected for processing (5)
  • cli/tui/cache.go
  • cli/tui/commands.go
  • cli/tui/commands_test.go
  • cli/tui/repl.go
  • cli/tui/session.go
✅ Files skipped from review due to trivial changes (1)
  • cli/tui/repl.go

@kfelternv kfelternv enabled auto-merge (squash) May 21, 2026 17:25
@kfelternv kfelternv merged commit c9a164f into NVIDIA:main May 21, 2026
50 checks passed
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.

3 participants