Skip to content

feat(admin-cli): manage tenant SitePrefixes - #4745

Open
chet wants to merge 1 commit into
NVIDIA:mainfrom
chet:gh-issue-4226
Open

feat(admin-cli): manage tenant SitePrefixes#4745
chet wants to merge 1 commit into
NVIDIA:mainfrom
chet:gh-issue-4226

Conversation

@chet

@chet chet commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

This adds nico-admin-cli site-prefix commands to list or show SitePrefixes, create tenant-managed prefixes, replace their metadata, retire them, and inspect lifecycle history.

SitePrefix IDs remain the identity because multiple tenants can own the same CIDR. Exact-CIDR searches therefore return collections, with optional tenant scoping. delete records retirement intent and returns the retained Deleting resource; it does not force-delete address space that may still have child resources or dataplane state.

Related issues

This supports #4226

Type of Change

  • Add - New feature or capability
  • Change - Changes in existing functionality
  • Fix - Bug fixes
  • Remove - Removed features or deprecated functionality
  • Internal - Internal changes (refactoring, tests, docs, etc.)

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • No testing required (docs, internal refactor, etc.)

Additional Notes

Verified the top-level command and the show, create, update, delete, and state-history help output directly. The generated CLI reference belongs in the repository workflow's companion documentation Task and PR.

@chet
chet requested a review from a team as a code owner August 8, 2026 06:41
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Summary by CodeRabbit

  • New Features
    • Added admin CLI support for managing site prefixes.
    • Create, update, retire, delete, and view site prefixes by ID or search criteria.
    • Added filters for tenant, CIDR ranges, authority, routing scope, and lifecycle state.
    • Added state-history viewing for individual site prefixes.
    • Added JSON, YAML, CSV, and table output formats.
    • Supports descriptions, labels, quotas, and version constraints.
  • Error Handling
    • Improved reporting for missing site prefixes and invalid command usage.

Walkthrough

The admin CLI adds SitePrefix commands for creation, update, deletion, search, display, and state-history retrieval. It adds RPC helpers, structured output formats, command dispatch, validation, and parsing tests.

Changes

SitePrefix CLI

Layer / File(s) Summary
Command registration and dispatch
crates/admin-cli/cli_domains.yaml, crates/admin-cli/src/cfg/cli_options.rs, crates/admin-cli/src/main.rs, crates/admin-cli/src/errors.rs, crates/admin-cli/src/site_prefix/mod.rs
Registers the site-prefix command tree, dispatches commands, and defines missing-resource errors.
RPC helpers and output models
crates/admin-cli/src/rpc.rs, crates/admin-cli/src/site_prefix/common.rs, crates/admin-cli/src/site_prefix/output.rs
Adds chunked lookup, single-ID validation, state-history access, and JSON, YAML, ASCII, and CSV output.
Create, update, and delete commands
crates/admin-cli/src/site_prefix/create.rs, crates/admin-cli/src/site_prefix/update.rs, crates/admin-cli/src/site_prefix/delete.rs, crates/admin-cli/src/site_prefix/tests.rs
Adds request parsing, metadata conversion, API execution, formatted responses, version matching, and delete/retire tests.
Search and state-history commands
crates/admin-cli/src/site_prefix/show.rs, crates/admin-cli/src/site_prefix/state_history.rs, crates/admin-cli/src/site_prefix/tests.rs
Adds direct lookup, CIDR and lifecycle filters, state-history conversion, output writing, and invalid-argument tests.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SitePrefixArgs
  participant RuntimeContext
  participant ApiClient
  participant SitePrefixOutput
  SitePrefixArgs->>RuntimeContext: Run SitePrefix command
  RuntimeContext->>ApiClient: Search or fetch SitePrefix data
  ApiClient-->>RuntimeContext: Return SitePrefix records
  RuntimeContext->>SitePrefixOutput: Write configured output format
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.17% 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
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.
Description check ✅ Passed The description clearly explains the new SitePrefix CLI commands, lifecycle behavior, testing, and related issue.
Title check ✅ Passed The title clearly and concisely identifies the new admin CLI capability for managing tenant SitePrefixes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@chet

chet commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full_review, thanks!

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

@chet, I will perform a full review of PR #4745.

🐇

✅ Action performed

Full review finished.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

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

Inline comments:
In `@crates/admin-cli/src/site_prefix/create.rs`:
- Around line 57-62: The prefix argument in the create command currently parses
any IpNet; add a Clap value parser for prefix that reuses the existing IPv4,
RFC1918, and prefix-length policy, accepting only canonical private IPv4
networks with lengths /8 through /31 and rejecting IPv6, public ranges, /0, and
/32 before RPC submission. Add focused CLI parsing tests covering valid and
invalid boundaries.

In `@crates/admin-cli/src/site_prefix/mod.rs`:
- Around line 34-48: Add the single-resource lookup example to the
`after_long_help` examples for the `site-prefix` command, using a realistic UUID
with `nico-admin-cli site-prefix show <id>`. Keep the existing inventory `show`
example and other examples unchanged.
- Line 49: Update the Clap attribute on the relevant command or argument type by
replacing the invalid rename_all value "kebab_case" with "kebab-case", or remove
the attribute since kebab-case is already the default.

In `@crates/admin-cli/src/site_prefix/show.rs`:
- Line 132: Replace the unsupported "kebab_case" Clap rename style with
"kebab-case" in the derive attributes for both RoutingScopeArg and
LifecycleStateArg at crates/admin-cli/src/site_prefix/show.rs lines 132-132 and
146-146.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 42587f1f-48d7-49db-bc53-a2c6d4a2887b

📥 Commits

Reviewing files that changed from the base of the PR and between d77bf0f and 045afd4.

📒 Files selected for processing (14)
  • crates/admin-cli/cli_domains.yaml
  • crates/admin-cli/src/cfg/cli_options.rs
  • crates/admin-cli/src/errors.rs
  • crates/admin-cli/src/main.rs
  • crates/admin-cli/src/rpc.rs
  • crates/admin-cli/src/site_prefix/common.rs
  • crates/admin-cli/src/site_prefix/create.rs
  • crates/admin-cli/src/site_prefix/delete.rs
  • crates/admin-cli/src/site_prefix/mod.rs
  • crates/admin-cli/src/site_prefix/output.rs
  • crates/admin-cli/src/site_prefix/show.rs
  • crates/admin-cli/src/site_prefix/state_history.rs
  • crates/admin-cli/src/site_prefix/tests.rs
  • crates/admin-cli/src/site_prefix/update.rs

Comment thread crates/admin-cli/src/site_prefix/create.rs
Comment thread crates/admin-cli/src/site_prefix/mod.rs
Comment thread crates/admin-cli/src/site_prefix/mod.rs
Comment thread crates/admin-cli/src/site_prefix/show.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/admin-cli/src/site_prefix/state_history.rs (1)

55-62: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Implement From<StateHistoryRecord> for this conversion.

HistoryRecordView::from_record is a bespoke conversion method. Implement From<StateHistoryRecord> and use .map(HistoryRecordView::from).

Proposed refactor
-impl HistoryRecordView {
-    fn from_record(record: StateHistoryRecord) -> Self {
+impl From<StateHistoryRecord> for HistoryRecordView {
+    fn from(record: StateHistoryRecord) -> Self {
         Self {
             state: display_state(&record.state),
             version: record.version,
             time: record.time.map(|time| time.to_string()),
         }
     }
+}
 
+impl HistoryRecordView {
     fn table(records: &[Self]) -> Table {
-            .map(HistoryRecordView::from_record)
+            .map(HistoryRecordView::from)

As per coding guidelines, “Prefer From/TryFrom and FromStr conversions over bespoke conversion methods.” As per path instructions, prefer “idiomatic From/TryFrom conversions.”

Also applies to: 110-118

🤖 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 `@crates/admin-cli/src/site_prefix/state_history.rs` around lines 55 - 62,
Replace the bespoke HistoryRecordView::from_record conversion with an impl
From<StateHistoryRecord> for HistoryRecordView, preserving the existing state,
version, and time mappings. Update the related collection conversion to use
.map(HistoryRecordView::from) and remove or stop calling from_record.

Sources: Coding guidelines, Path instructions

🤖 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 `@crates/admin-cli/src/site_prefix/state_history.rs`:
- Around line 55-62: Replace the bespoke HistoryRecordView::from_record
conversion with an impl From<StateHistoryRecord> for HistoryRecordView,
preserving the existing state, version, and time mappings. Update the related
collection conversion to use .map(HistoryRecordView::from) and remove or stop
calling from_record.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: bda640ef-9962-4634-a507-c42b644adaaf

📥 Commits

Reviewing files that changed from the base of the PR and between d77bf0f and 045afd4.

📒 Files selected for processing (14)
  • crates/admin-cli/cli_domains.yaml
  • crates/admin-cli/src/cfg/cli_options.rs
  • crates/admin-cli/src/errors.rs
  • crates/admin-cli/src/main.rs
  • crates/admin-cli/src/rpc.rs
  • crates/admin-cli/src/site_prefix/common.rs
  • crates/admin-cli/src/site_prefix/create.rs
  • crates/admin-cli/src/site_prefix/delete.rs
  • crates/admin-cli/src/site_prefix/mod.rs
  • crates/admin-cli/src/site_prefix/output.rs
  • crates/admin-cli/src/site_prefix/show.rs
  • crates/admin-cli/src/site_prefix/state_history.rs
  • crates/admin-cli/src/site_prefix/tests.rs
  • crates/admin-cli/src/site_prefix/update.rs

Add the admin CLI surface for tenant-managed SitePrefixes now that Core owns their lifecycle.

Operators can create, list, update, retire, and inspect state history without relying on CIDR as identity. Exact-CIDR searches stay collection-valued because multiple tenants may own the same address space, while mutations require the SitePrefix ID and owning tenant.

This supports NVIDIA#4226

Signed-off-by: Chet Nichols III <chetn@nvidia.com>
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.

1 participant