Skip to content

Commit a1418e2

Browse files
authored
fix: fix find_bmc_ips_by_power_shelf_ids to retrieve the ip from machine interfaces instead of expected powershelves (#903)
## Description fix: fix find_bmc_ips_by_power_shelf_ids to retrieve the ip from machine interfaces instead of expected powershelves ## Type of Change <!-- Check one that best describes this PR --> - [ ] **Add** - New feature or capability - [ ] **Change** - Changes in existing functionality - [x] **Fix** - Bug fixes - [ ] **Remove** - Removed features or deprecated functionality - [ ] **Internal** - Internal changes (refactoring, tests, docs, etc.) ## Related Issues (Optional) <!-- If applicable, provide GitHub Issue. --> ## Breaking Changes - [ ] This PR contains breaking changes <!-- If checked above, describe the breaking changes and migration steps --> ## Testing <!-- How was this tested? Check all that apply --> - [ ] Unit tests added/updated - [ ] Integration tests added/updated - [ ] Manual testing performed - [ ] No testing required (docs, internal refactor, etc.) ## Additional Notes <!-- Any additional context, deployment notes, or reviewer guidance -->
1 parent 8f10483 commit a1418e2

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

crates/api-db/src/power_shelf.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,19 +311,21 @@ use std::net::IpAddr;
311311

312312
use mac_address::MacAddress;
313313

314-
/// Resolve PowerShelfIds to BMC/PMC IPs.
314+
/// Resolve PowerShelfIds to BMC/PMC IPs via the machine_interfaces path.
315315
pub async fn find_bmc_ips_by_power_shelf_ids(
316316
db: impl crate::db_read::DbReader<'_>,
317317
power_shelf_ids: &[PowerShelfId],
318318
) -> DatabaseResult<Vec<(PowerShelfId, IpAddr)>> {
319319
let sql = r#"
320-
SELECT
320+
SELECT DISTINCT ON (ps.id)
321321
ps.id,
322-
eps.bmc_ip_address
322+
mia.address
323323
FROM power_shelves ps
324324
JOIN expected_power_shelves eps ON eps.serial_number = ps.config->>'name'
325+
JOIN machine_interfaces mi ON mi.mac_address = eps.bmc_mac_address
326+
JOIN machine_interface_addresses mia ON mia.interface_id = mi.id
325327
WHERE ps.id = ANY($1)
326-
AND eps.bmc_ip_address IS NOT NULL
328+
ORDER BY ps.id
327329
"#;
328330

329331
sqlx::query_as(sql)

0 commit comments

Comments
 (0)