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
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ pub type RedfishFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;

/// Interface to a BMC Redfish server. All calls will include one or more HTTP network calls.
pub trait Redfish: Send + Sync + 'static {
/// Populate IDs needed by `Managers/{id}` / `Systems/{id}` URL builders.
/// Vendor wrappers are pre-initialised, so default is a no-op.
fn initialize<'a>(&'a mut self) -> RedfishFuture<'a, Result<(), RedfishError>> {
Box::pin(async move { Ok(()) })
}

/// Rename a user
fn change_username<'a>(
&'a self,
Expand Down
22 changes: 22 additions & 0 deletions src/standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ pub struct RedfishStandard {
service_root: ServiceRoot,
}
impl Redfish for RedfishStandard {
fn initialize<'a>(&'a mut self) -> crate::RedfishFuture<'a, Result<(), RedfishError>> {
Box::pin(RedfishStandard::initialize(self))
}

fn create_user<'a>(
&'a self,
username: &'a str,
Expand Down Expand Up @@ -1332,6 +1336,24 @@ impl RedfishStandard {
}
}

/// Fetch service root + first system/manager id; populate
/// `manager_id` / `system_id` / `service_root`.
pub async fn initialize(&mut self) -> Result<(), RedfishError> {
let service_root = self.get_service_root().await?;
let systems = self.get_systems().await?;
let managers = self.get_managers().await?;
let system_id = systems.first().ok_or_else(|| RedfishError::GenericError {
error: "No systems found in service root".to_string(),
})?;
let manager_id = managers.first().ok_or_else(|| RedfishError::GenericError {
error: "No managers found in service root".to_string(),
})?;
self.set_system_id(system_id)?;
self.set_manager_id(manager_id)?;
self.set_service_root(service_root)?;
Ok(())
}

pub fn system_id(&self) -> &str {
&self.system_id
}
Expand Down