Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions crates/admin-cli/src/managed_host/erase_metadata/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use clap::Parser;
use rpc::forge::EraseHostMetadataByBmcMacRequest;

/// Erase all NICo-owned site records for a server BMC MAC address.
#[derive(Parser, Debug)]
#[command(after_long_help = "\
EXAMPLES:

Preview which records exist for a BMC MAC (nothing is deleted):
$ nico-admin-cli managed-host erase-metadata --bmc-mac 00:11:22:33:44:55 --dry-run

Erase all lingering records for a BMC MAC to prepare for re-ingestion:
$ nico-admin-cli managed-host erase-metadata --bmc-mac 00:11:22:33:44:55 --confirm

Comment thread
coderabbitai[bot] marked this conversation as resolved.
")]
pub struct Args {
#[clap(
long,
required(true),
help = "Server BMC MAC address whose lingering site records should be erased"
)]
pub bmc_mac: String,

#[clap(
long,
action,
help = "Report the records that would be erased without deleting anything"
)]
pub dry_run: bool,

#[clap(
long,
action,
help = "Confirm you want to erase these records. Required for a real run (ignored with --dry-run)."
)]
pub confirm: bool,
}

impl From<&Args> for EraseHostMetadataByBmcMacRequest {
fn from(args: &Args) -> Self {
Self {
bmc_mac: args.bmc_mac.clone(),
dry_run: args.dry_run,
}
}
}
47 changes: 47 additions & 0 deletions crates/admin-cli/src/managed_host/erase_metadata/cmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use ::rpc::forge::EraseHostMetadataByBmcMacRequest;

use super::args::Args;
use crate::errors::{CarbideCliError, CarbideCliResult};
use crate::rpc::ApiClient;

pub async fn erase_metadata(api_client: &ApiClient, args: Args) -> CarbideCliResult<()> {
// Guard the destructive path: a real run must be explicitly confirmed. --dry-run
// is always safe, so it does not require --confirm. Return an error (non-zero
// exit) so scripts can distinguish a refused run from a completed one.
if !args.dry_run && !args.confirm {
return Err(CarbideCliError::GenericError(format!(
"Refusing to erase records for BMC MAC {} without confirmation. \
Re-run with --dry-run to preview, or add --confirm to proceed.",
args.bmc_mac
)));
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

let req: EraseHostMetadataByBmcMacRequest = (&args).into();
let response = api_client.0.erase_host_metadata_by_bmc_mac(req).await?;

if response.dry_run {
println!("DRY RUN -- no records were deleted. The following would be erased:");
} else {
println!("Erased the following records for BMC MAC {}:", args.bmc_mac);
}
println!("{}", serde_json::to_string_pretty(&response)?);

Ok(())
}
32 changes: 32 additions & 0 deletions crates/admin-cli/src/managed_host/erase_metadata/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

pub mod args;
pub mod cmd;

pub use args::Args;

use crate::cfg::run::Run;
use crate::cfg::runtime::RuntimeContext;
use crate::errors::CarbideCliResult;

impl Run for Args {
async fn run(self, ctx: &mut RuntimeContext) -> CarbideCliResult<()> {
cmd::erase_metadata(&ctx.api_client, self).await?;
Ok(())
}
}
5 changes: 5 additions & 0 deletions crates/admin-cli/src/managed_host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

mod debug_bundle;
mod erase_metadata;
mod maintenance;
mod power_options;
mod quarantine;
Expand Down Expand Up @@ -64,4 +65,8 @@ pub enum Cmd {
SetPrimaryDpu(set_primary_dpu::Args),
#[clap(about = "Download debug bundle with logs for a specific host")]
DebugBundle(debug_bundle::Args),
#[clap(
about = "Erase all NICo-owned site records for a server BMC MAC address (does not touch expected machines)"
)]
EraseMetadata(erase_metadata::Args),
}
48 changes: 48 additions & 0 deletions crates/admin-cli/src/managed_host/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,51 @@ fn desired_power_state_value_enum() {
}
);
}

// erase-metadata routes to the EraseMetadata variant. Each row yields
// (bmc_mac, dry_run, confirm); the required --bmc-mac is missing in the failing row.
#[test]
fn parse_erase_metadata_routes_to_erase_metadata() {
scenarios!(
run = |argv| {
Cmd::try_parse_from(argv.iter().copied())
.map(|cmd| match cmd {
Cmd::EraseMetadata(args) => (args.bmc_mac, args.dry_run, args.confirm),
_ => panic!("expected EraseMetadata variant"),
})
.map_err(drop)
};
"with bmc mac" {
&[
"managed-host",
"erase-metadata",
"--bmc-mac",
"aa:bb:cc:dd:ee:ff",
][..] => Yields(("aa:bb:cc:dd:ee:ff".to_string(), false, false)),
}

"with bmc mac and dry-run" {
&[
"managed-host",
"erase-metadata",
"--bmc-mac",
"aa:bb:cc:dd:ee:ff",
"--dry-run",
][..] => Yields(("aa:bb:cc:dd:ee:ff".to_string(), true, false)),
}

"with bmc mac and confirm" {
&[
"managed-host",
"erase-metadata",
"--bmc-mac",
"aa:bb:cc:dd:ee:ff",
"--confirm",
][..] => Yields(("aa:bb:cc:dd:ee:ff".to_string(), false, true)),
}

"missing required bmc mac" {
&["managed-host", "erase-metadata"][..] => Fails,
}
);
}
Comment on lines +349 to +396

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Include regenerated admin-cli reference documentation before merge.

This adds the managed-host erase-metadata command surface, but the PR still leaves generated CLI documentation pending. Without the regenerated reference, operator-facing help remains stale.

As per path instructions, crates/admin-cli/** command-surface changes require regenerated reference documentation.

🤖 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/managed_host/tests.rs` around lines 349 - 396,
Regenerate and commit the admin-cli reference documentation for the new
managed-host erase-metadata command surface introduced by
parse_erase_metadata_routes_to_erase_metadata. Follow the repository’s
established documentation-generation process and ensure the generated output
reflects the required --bmc-mac argument and dry-run/confirm options.

Source: Path instructions

7 changes: 7 additions & 0 deletions crates/api-core/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,13 @@ impl Forge for Api {
crate::handlers::machine::admin_force_delete_machine(self, request).await
}

async fn erase_host_metadata_by_bmc_mac(
&self,
request: Request<rpc::EraseHostMetadataByBmcMacRequest>,
) -> Result<Response<rpc::EraseHostMetadataByBmcMacResponse>, Status> {
crate::handlers::erase_host_metadata::erase_host_metadata_by_bmc_mac(self, request).await
}

/// Example TOML data in request.text:
///
/// [lo-ip]
Expand Down
1 change: 1 addition & 0 deletions crates/api-core/src/auth/internal_rbac_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ impl InternalRBACRules {
x.perm("FindExploredMlxDeviceHostIds", vec![ForgeAdminCLI]);
x.perm("FindExploredMlxDevicesByIds", vec![ForgeAdminCLI]);
x.perm("AdminForceDeleteMachine", vec![ForgeAdminCLI, Machineatron]);
x.perm("EraseHostMetadataByBmcMac", vec![ForgeAdminCLI]);
x.perm("AdminForceDeleteRack", vec![ForgeAdminCLI, Machineatron]);
x.perm("AdminForceDeleteSwitch", vec![ForgeAdminCLI, Machineatron]);
x.perm(
Expand Down
Loading
Loading