Skip to content

Commit 9695036

Browse files
committed
fixed wiring for maintenance
1 parent a817566 commit 9695036

5 files changed

Lines changed: 299 additions & 239 deletions

File tree

crates/admin-cli/src/rack/maintenance/args.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
use std::path::PathBuf;
19+
1820
use carbide_uuid::rack::RackId;
1921
use clap::Parser;
2022

@@ -63,10 +65,26 @@ pub struct MaintenanceOptions {
6365

6466
#[clap(
6567
long,
66-
help = "Target firmware version for firmware-upgrade activity (omit for RMS default)"
68+
help = "Raw SOT JSON for firmware-upgrade activity (prefer --sot-json-file)"
6769
)]
6870
pub firmware_version: Option<String>,
6971

72+
#[clap(
73+
long = "sot-json-file",
74+
value_name = "PATH",
75+
help = "SOT JSON file for RMS ApplyFirmwareObjectFromJSON"
76+
)]
77+
pub sot_json_file: Option<PathBuf>,
78+
79+
#[clap(
80+
long = "access-token",
81+
help = "Artifact access token; required with --sot-json-file"
82+
)]
83+
pub access_token: Option<String>,
84+
85+
#[clap(long = "force-update", help = "Force firmware update when supported")]
86+
pub force_update: bool,
87+
7088
#[clap(
7189
long,
7290
help = "Firmware components to update, e.g. BMC,CPLD,BIOS (omit for all components)",

crates/admin-cli/src/rack/maintenance/cmd.rs

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,63 @@
1818
use ::rpc::forge as rpc;
1919

2020
use super::args::MaintenanceOptions;
21-
use crate::errors::CarbideCliResult;
21+
use crate::errors::{CarbideCliError, CarbideCliResult};
2222
use crate::rpc::ApiClient;
2323

24+
fn resolve_firmware_upgrade_source(
25+
args: &MaintenanceOptions,
26+
) -> CarbideCliResult<(String, Option<String>)> {
27+
if args.firmware_version.is_some() && args.sot_json_file.is_some() {
28+
return Err(CarbideCliError::ChooseOneError(
29+
"--firmware-version",
30+
"--sot-json-file",
31+
));
32+
}
33+
34+
let firmware_version = if let Some(path) = args.sot_json_file.as_ref() {
35+
let config_json = std::fs::read_to_string(path)?;
36+
serde_json::from_str::<serde_json::Value>(&config_json)?;
37+
config_json
38+
} else {
39+
args.firmware_version.clone().unwrap_or_default()
40+
};
41+
42+
let access_token = args.access_token.as_ref().and_then(|token| {
43+
if token.trim().is_empty() {
44+
None
45+
} else {
46+
Some(token.clone())
47+
}
48+
});
49+
50+
if args.sot_json_file.is_some() && access_token.is_none() {
51+
return Err(CarbideCliError::GenericError(
52+
"--access-token is required with --sot-json-file".to_string(),
53+
));
54+
}
55+
if args.access_token.is_some() && firmware_version.trim().is_empty() {
56+
return Err(CarbideCliError::GenericError(
57+
"--access-token requires SOT JSON from --sot-json-file or --firmware-version"
58+
.to_string(),
59+
));
60+
}
61+
if access_token.is_some() {
62+
serde_json::from_str::<serde_json::Value>(&firmware_version)?;
63+
}
64+
65+
Ok((firmware_version, access_token))
66+
}
67+
2468
pub async fn on_demand_rack_maintenance(
2569
api_client: &ApiClient,
2670
args: MaintenanceOptions,
2771
) -> CarbideCliResult<()> {
2872
use rpc::maintenance_activity_config::Activity as ProtoActivity;
2973

30-
let firmware_version = args.firmware_version.unwrap_or_default();
74+
let (firmware_version, access_token) = resolve_firmware_upgrade_source(&args)?;
3175
let components = args.components.unwrap_or_default();
3276
let firmware_object_id = args.firmware_object_id.unwrap_or_default();
77+
let force_update = args.force_update;
3378

3479
let activities: Vec<rpc::MaintenanceActivityConfig> = args
3580
.activities
@@ -41,8 +86,8 @@ pub async fn on_demand_rack_maintenance(
4186
rpc::FirmwareUpgradeActivity {
4287
firmware_version: firmware_version.clone(),
4388
components: components.clone(),
44-
access_token: None,
45-
force_update: false,
89+
access_token: access_token.clone(),
90+
force_update,
4691
},
4792
)),
4893
"nvos-update" => Ok(ProtoActivity::NvosUpdate(

0 commit comments

Comments
 (0)