diff --git a/src/lib.rs b/src/lib.rs index c20c26272..f9129e4a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,6 +77,12 @@ pub type RedfishFuture<'a, T> = Pin + 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, diff --git a/src/standard.rs b/src/standard.rs index fd4a2436a..fc15512f0 100644 --- a/src/standard.rs +++ b/src/standard.rs @@ -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, @@ -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 }