use http::Method;
use crate::Result;
use crate::api::ActionResponse;
use crate::types::{Chassis, Collection, OdataId, ResetType, actions::ResetRequest};
#[cfg(feature = "_blocking")]
use crate::BlockingClient;
#[cfg(feature = "_async")]
use crate::Client;
#[derive(Debug, Clone, Copy)]
pub struct ChassisService<'a, C> {
client: &'a C,
}
impl<'a, C> ChassisService<'a, C> {
pub(crate) fn new(client: &'a C) -> Self {
Self { client }
}
}
#[cfg(feature = "_async")]
impl<'a> ChassisService<'a, Client> {
pub async fn list(&self) -> Result<Collection<OdataId>> {
let url = self.client.redfish_url(&["Chassis"])?;
self.client.get_json(url).await
}
pub async fn get(&self, chassis_id: &str) -> Result<Chassis> {
let url = self.client.redfish_url(&["Chassis", chassis_id])?;
self.client.get_json(url).await
}
pub async fn reset(
&self,
chassis_id: &str,
reset_type: ResetType,
) -> Result<ActionResponse<serde_json::Value>> {
let url = self
.client
.redfish_url(&["Chassis", chassis_id, "Actions", "Chassis.Reset"])?;
let req = ResetRequest { reset_type };
let raw = self.client.post_json_raw(url.clone(), &req).await?;
ActionResponse::<serde_json::Value>::from_raw_json(
Method::POST,
&url,
raw,
self.client.body_snippet_limit(),
)
}
}
#[cfg(feature = "_blocking")]
impl<'a> ChassisService<'a, BlockingClient> {
pub fn list(&self) -> Result<Collection<OdataId>> {
let url = self.client.redfish_url(&["Chassis"])?;
self.client.get_json(url)
}
pub fn get(&self, chassis_id: &str) -> Result<Chassis> {
let url = self.client.redfish_url(&["Chassis", chassis_id])?;
self.client.get_json(url)
}
pub fn reset(
&self,
chassis_id: &str,
reset_type: ResetType,
) -> Result<ActionResponse<serde_json::Value>> {
let url = self
.client
.redfish_url(&["Chassis", chassis_id, "Actions", "Chassis.Reset"])?;
let req = ResetRequest { reset_type };
let raw = self.client.post_json_raw(url.clone(), &req)?;
ActionResponse::<serde_json::Value>::from_raw_json(
Method::POST,
&url,
raw,
self.client.body_snippet_limit(),
)
}
}