-
Notifications
You must be signed in to change notification settings - Fork 167
feat(admin-cli): erase site metadata for a BMC MAC (#3046) #4013
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
Closed
hatamzad-nv
wants to merge
1
commit into
NVIDIA:main
from
hatamzad-nv:feat/3046-erase-host-metadata-by-bmc-mac
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 machine 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 machine erase-metadata --bmc-mac 00:11:22:33:44:55 --confirm | ||
|
|
||
| ")] | ||
| pub struct Args { | ||
| #[clap( | ||
| long, | ||
| required(true), | ||
| help = "Server BMC MAC address whose lingering site records should be erased" | ||
| )] | ||
| pub bmc_mac: String, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This can be a MacAddress directly and you'll get free argument validation before it gets sent to the server. Not a huge deal though. |
||
|
|
||
| #[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, | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ))); | ||
| } | ||
|
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)?); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(()) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.