Skip to content
Merged
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
31 changes: 31 additions & 0 deletions redfish/src/chassis/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ use crate::hardware_id::SerialNumber as HardwareIdSerialNumber;
use crate::patch_support::JsonValue;
use crate::patch_support::Payload;
use crate::patch_support::ReadPatchFn;
use crate::resource::ResetType;
use crate::schema::chassis::Chassis as ChassisSchema;
use crate::Error;
use crate::NvBmc;
use crate::Resource;
use crate::ResourceSchema;
use nv_redfish_core::bmc::Bmc;
use nv_redfish_core::ModificationResponse;
use nv_redfish_core::NavProperty;
use std::future::Future;
use std::sync::Arc;
Expand Down Expand Up @@ -147,6 +149,35 @@ impl<B: Bmc> Chassis<B> {
self.data.clone()
}

/// Reset this chassis.
///
/// # Errors
///
/// Returns an error if the chassis does not support the `Reset` action or
/// if invoking the action fails.
pub async fn reset(
&self,
reset_type: Option<ResetType>,
) -> Result<ModificationResponse<()>, Error<B>>
where
B::Error: nv_redfish_core::ActionError,
{
let actions = self
.data
.actions
.as_ref()
.ok_or(Error::ActionNotAvailable)?;

if actions.reset.is_none() {
return Err(Error::ActionNotAvailable);
}

actions
.reset(self.bmc.as_ref(), reset_type)
.await
.map_err(Error::Bmc)
}

/// Get hardware identifier of the network adpater.
#[must_use]
pub fn hardware_id(&self) -> HardwareIdRef<'_, ChassisTag> {
Expand Down
31 changes: 31 additions & 0 deletions redfish/src/chassis/power_supply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::resource::ResetType;
use crate::schema::power_supply::PowerSupply as PowerSupplySchema;
use crate::schema::power_supply_metrics::PowerSupplyMetrics;
use crate::Error;
use crate::NvBmc;
use crate::Resource;
use crate::ResourceSchema;
use nv_redfish_core::Bmc;
use nv_redfish_core::ModificationResponse;
use nv_redfish_core::NavProperty;
use std::sync::Arc;

Expand Down Expand Up @@ -60,6 +62,35 @@ impl<B: Bmc> PowerSupply<B> {
self.data.clone()
}

/// Reset this power supply.
///
/// # Errors
///
/// Returns an error if the power supply does not support the `Reset`
/// action or if invoking the action fails.
pub async fn reset(
&self,
reset_type: Option<ResetType>,
) -> Result<ModificationResponse<()>, Error<B>>
where
B::Error: nv_redfish_core::ActionError,
{
let actions = self
.data
.actions
.as_ref()
.ok_or(Error::ActionNotAvailable)?;

if actions.reset.is_none() {
return Err(Error::ActionNotAvailable);
}

actions
.reset(self.bmc.as_ref(), reset_type)
.await
.map_err(Error::Bmc)
}

/// Get power supply metrics.
///
/// Returns the power supply's performance and state metrics if available.
Expand Down
30 changes: 30 additions & 0 deletions redfish/src/computer_system/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::hardware_id::SerialNumber as HardwareIdSerialNumber;
use crate::patch_support::Payload;
use crate::patch_support::ReadPatchFn;
use crate::resource::PowerState;
use crate::resource::ResetType;
use crate::schema::computer_system::ComputerSystem as ComputerSystemSchema;
use crate::Error;
use crate::NvBmc;
Expand Down Expand Up @@ -187,6 +188,35 @@ impl<B: Bmc> ComputerSystem<B> {
self.data.power_state.and_then(identity)
}

/// Reset this computer system.
///
/// # Errors
///
/// Returns an error if the system does not support the `Reset` action or
/// if invoking the action fails.
pub async fn reset(
&self,
reset_type: Option<ResetType>,
) -> Result<ModificationResponse<()>, Error<B>>
where
B::Error: nv_redfish_core::ActionError,
{
let actions = self
.data
.actions
.as_ref()
.ok_or(Error::ActionNotAvailable)?;

if actions.reset.is_none() {
return Err(Error::ActionNotAvailable);
}

actions
.reset(self.bmc.as_ref(), reset_type)
.await
.map_err(Error::Bmc)
}

/// An array of `BootOptionReference` strings that represent the persistent boot order for with this
/// computer system.
#[must_use]
Expand Down
61 changes: 61 additions & 0 deletions redfish/src/manager/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::resource::ResetType;
use crate::schema::manager::Manager as ManagerSchema;
use crate::schema::manager::ResetToDefaultsType as ManagerResetToDefaultsType;
use crate::Error;
use crate::NvBmc;
use crate::Resource;
use crate::ResourceSchema;
use nv_redfish_core::Bmc;
use nv_redfish_core::ModificationResponse;
use nv_redfish_core::NavProperty;
use std::sync::Arc;

Expand Down Expand Up @@ -72,6 +75,64 @@ impl<B: Bmc> Manager<B> {
self.data.clone()
}

/// Reset this manager.
///
/// # Errors
///
/// Returns an error if the manager does not support the `Reset` action or
/// if invoking the action fails.
pub async fn reset(
&self,
reset_type: Option<ResetType>,
) -> Result<ModificationResponse<()>, Error<B>>
where
B::Error: nv_redfish_core::ActionError,
{
let actions = self
.data
.actions
.as_ref()
.ok_or(Error::ActionNotAvailable)?;

if actions.reset.is_none() {
return Err(Error::ActionNotAvailable);
}

actions
.reset(self.bmc.as_ref(), reset_type)
.await
.map_err(Error::Bmc)
}

/// Reset this manager's settings to defaults.
///
/// # Errors
///
/// Returns an error if the manager does not support the `ResetToDefaults`
/// action or if invoking the action fails.
pub async fn reset_to_defaults(
&self,
reset_type: ManagerResetToDefaultsType,
) -> Result<ModificationResponse<()>, Error<B>>
where
B::Error: nv_redfish_core::ActionError,
{
let actions = self
.data
.actions
.as_ref()
.ok_or(Error::ActionNotAvailable)?;

if actions.reset_to_defaults.is_none() {
return Err(Error::ActionNotAvailable);
}

actions
.reset_to_defaults(self.bmc.as_ref(), Some(reset_type))
.await
.map_err(Error::Bmc)
}

/// Get ethernet interfaces for this manager.
///
/// Returns `Ok(None)` when the ethernet interfaces link is absent.
Expand Down
3 changes: 3 additions & 0 deletions redfish/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ use std::sync::Arc;

pub use item::Manager;

#[doc(inline)]
pub use crate::schema::manager::ResetToDefaultsType as ManagerResetToDefaultsType;

/// Manager collection.
///
/// Provides functions to access collection members.
Expand Down
8 changes: 8 additions & 0 deletions redfish/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ pub use crate::schema::resource::State;
#[cfg(feature = "computer-systems")]
pub use crate::schema::resource::PowerState;

#[doc(inline)]
#[cfg(any(
feature = "chassis",
feature = "computer-systems",
feature = "managers"
))]
pub use crate::schema::resource::ResetType;

/// Redfish resource identifier.
pub type ResourceId = TaggedType<String, ResourceIdTag>;
/// Reference to Redfish resource identifier.
Expand Down
24 changes: 24 additions & 0 deletions tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,27 @@ pub fn anonymous_1_9_service_root(root_id: &ODataId, fields: Value) -> Value {
});
json_merge([&base, &fields])
}

/// Build a Redfish `Actions` payload containing one action target.
pub fn redfish_action_payload(action: &str, target: &str) -> Value {
let mut action_body = serde_json::Map::new();
action_body.insert("target".into(), json!(target));

let mut actions = serde_json::Map::new();
actions.insert(format!("#{action}"), Value::Object(action_body));

let mut payload = serde_json::Map::new();
payload.insert("Actions".into(), Value::Object(actions));
Value::Object(payload)
}

/// Build a Redfish payload with an empty `Actions` object.
pub fn redfish_empty_actions_payload() -> Value {
json!({ "Actions": {} })
}

/// Expect a Redfish reset action request with an empty action response.
pub fn expect_redfish_reset_action(bmc: &Bmc, target: &str, reset_type: Option<&str>) {
let request = reset_type.map_or_else(|| json!({}), |value| json!({ "ResetType": value }));
bmc.expect(Expect::action(target, request, json!(null)));
}
Loading
Loading