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
47 changes: 47 additions & 0 deletions crates/api-db/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use carbide_uuid::dpa_interface::DpaInterfaceId;
use carbide_uuid::instance_type::InstanceTypeId;
use carbide_uuid::machine::{MachineId, MachineType};
use carbide_uuid::machine_validation::MachineValidationId;
use carbide_uuid::rack::RackId;
use chrono::{DateTime, Utc};
use config_version::{ConfigVersion, Versioned};
use health_report::{HealthReport, HealthReportApplyMode};
Expand Down Expand Up @@ -2583,6 +2584,52 @@ impl<'r> FromRow<'r, PgRow> for _HealthReportWrapper {
}
}

/// RMS identity for a compute tray machine: the machine ID (used as the RMS
/// node_id), the BMC IP address, the BMC MAC address, and the rack_id.
#[derive(Debug, sqlx::FromRow)]
pub struct MachineRmsIdentity {
pub id: String,
pub bmc_ip: IpAddr,
pub bmc_mac_address: MacAddress,
pub rack_id: Option<RackId>,
}

/// Look up RMS identities (node_id, rack_id) for compute tray machines by their
/// BMC IP addresses.
pub async fn find_rms_identities_by_bmc_ips(
db: impl crate::db_read::DbReader<'_>,
bmc_ips: &[IpAddr],
) -> DatabaseResult<Vec<MachineRmsIdentity>> {
let ip_strings: Vec<String> = bmc_ips.iter().map(ToString::to_string).collect();
let sql = r#"
SELECT m.id::text, mia.address AS bmc_ip, mi.mac_address AS bmc_mac_address, m.rack_id
FROM machines m
JOIN machine_interfaces mi
ON mi.machine_id = m.id
AND mi.interface_type = 'Bmc'
JOIN machine_interface_addresses mia
ON mia.interface_id = mi.id
WHERE host(mia.address) = ANY($1)
"#;

let rows: Vec<MachineRmsIdentity> = sqlx::query_as(sql)
.bind(ip_strings)
.fetch_all(db)
.await
.map_err(|err| DatabaseError::new("machine::find_rms_identities_by_bmc_ips", err))?;

let mut seen = std::collections::HashSet::with_capacity(rows.len());
for row in &rows {
if !seen.insert(row.bmc_ip) {
return Err(DatabaseError::internal(format!(
"duplicate machine RMS identity mapping for bmc_ip={}",
row.bmc_ip
)));
}
}
Ok(rows)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

pub fn count_healthy_unhealthy_host_machines(
all_machines: &HashMap<MachineId, model::machine::ManagedHostStateSnapshot>,
) -> (i32, i32) {
Expand Down
19 changes: 15 additions & 4 deletions crates/component-manager/src/component_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,22 @@ pub async fn build_component_manager(
};

let compute_tray: Arc<dyn ComputeTrayManager> = match config.compute_tray_backend {
// TODO: implement ComputeTrayManager for RmsBackend
Backend::Rms => {
return Err(ComponentManagerError::InvalidArgument(
"compute_tray_backend 'rms' is not yet supported".into(),
));
let client = rms_client.clone().ok_or_else(|| {
ComponentManagerError::InvalidArgument(
"compute_tray_backend is 'rms' but RMS client is not configured".into(),
)
})?;
let db = db.clone().ok_or_else(|| {
ComponentManagerError::InvalidArgument(
"compute_tray_backend is 'rms' but database pool is not configured".into(),
)
})?;
Arc::new(crate::rms::RmsBackend::new(
client,
rms_switch_system_image_client.clone(),
db,
))
}
Backend::Core => {
let pool = redfish_pool.ok_or_else(|| {
Expand Down
Loading
Loading