Skip to main content

Crate nv_redfish_core

Crate nv_redfish_core 

Source
Expand description

§nv-redfish-core

Transport-independent foundation for Redfish client models generated by nv-redfish-csdl-compiler. It defines the Bmc interface, resource identity, navigation properties, actions, operation results, and OData value types shared by generated code and transports.

Use this crate when compiling your own schemas, implementing a transport, or writing generic code over Redfish resources. For HTTP access, use nv-redfish-bmc-http; for standard service models and wrappers, use nv-redfish.

§Installation

[dependencies]
nv-redfish-core = "0.1"

Models generated by the CSDL compiler also use Serde:

serde = { version = "1", features = ["derive"] }

§Read resources and follow navigation properties

Bmc provides asynchronous reads, queries, writes, actions, uploads, and event streams. Read operations return Arc<T>, allowing a transport to share cached resources. Each entity implements EntityTypeRef, which exposes its @odata.id and optional @odata.etag.

A NavProperty<T> holds either a URI reference or an expanded resource. Calling get fetches a reference through Bmc; for an expanded resource it returns a clone of the existing Arc<T> without I/O.

The following small model illustrates the traits normally implemented by the CSDL compiler. The function accepts any Bmc implementation:

use nv_redfish_core::{Bmc, EntityTypeRef, NavProperty, ODataETag, ODataId};
use serde::Deserialize;
use std::sync::Arc;

#[derive(Deserialize)]
struct Resource {
    #[serde(rename = "@odata.id")]
    odata_id: ODataId,
    #[serde(rename = "@odata.etag")]
    etag: Option<ODataETag>,
    #[serde(rename = "Name")]
    name: String,
}

impl EntityTypeRef for Resource {
    fn odata_id(&self) -> &ODataId {
        &self.odata_id
    }

    fn etag(&self) -> Option<&ODataETag> {
        self.etag.as_ref()
    }
}

async fn read_resource<B: Bmc>(bmc: &B) -> Result<Arc<Resource>, B::Error> {
    let id = ODataId::from("/redfish/v1/Chassis/1".to_owned());
    let resource = NavProperty::<Resource>::new_reference(id).get(bmc).await?;
    println!("{}: {}", resource.odata_id(), resource.name);
    Ok(resource)
}

EntityTypeRef::refresh delegates a new read to the transport. Expandable adds $expand support through query::ExpandQuery. FilterQuery builds $filter expressions using property paths or generated property enums:

use nv_redfish_core::FilterQuery;

let query = FilterQuery::eq(&"Status/Health", "OK")
    .and()
    .eq_then(&"Status/State", "Enabled");
assert_eq!(
    query.to_query_string(),
    "$filter=Status/Health eq 'OK' and Status/State eq 'Enabled'",
);

Pass the query to Bmc::filter or NavProperty::filter. Query support depends on the BMC and resource being queried.

§Create, update, delete, and invoke actions

Generated collections and entities implement Creatable, Updatable, and Deletable when allowed by their schemas. These traits delegate operations to Bmc; Updatable::update passes the entity’s ETag to the transport. Generated actions use Action<T, R>, whose run method delegates to Bmc::action.

Mutating operations return ModificationResponse<T>. Handle all four outcomes:

VariantMeaning
Entity(T)The operation completed and returned a typed entity.
Task(AsyncTask)The operation is still running; poll its task monitor.
Message(Value)The operation completed with a success message body.
EmptyThe operation completed without a response body.

An AsyncTask carries the monitor location, an optional retry delay, and an optional task resource URI. Use Bmc::poll to check completion; it returns another ModificationResponse<T>, which may still be Task. The map_entity helpers transform typed results while preserving other outcomes.

Session creation uses SessionCreateResponse<T> to preserve the session entity, authentication token from X-Auth-Token, and logout URI from Location.

§Read JSON and repair documents

Raw lets you read a resource as JSON through the same Bmc interface while retaining its identity and ETag:

use nv_redfish_core::{Bmc, ODataId, Raw};

async fn read_version<B: Bmc>(bmc: &B) -> Result<Option<String>, B::Error> {
    let root = bmc.get::<Raw>(&ODataId::service_root()).await?;
    Ok(root.value()["RedfishVersion"].as_str().map(str::to_owned))
}

A Repair rewrites JSON before typed deserialization. Use Bmc::get_repaired, expand_repaired, or filter_repaired to apply one. NoRepair leaves the document unchanged. RepairError distinguishes transport failures from decode failures; DecodeError records the path to the property that failed.

All reads of a resource through a caching transport should use the same repair: the cache may serve the value produced by an earlier read. Platform repairs and transport decorators are provided by nv-redfish-quirks.

§Value types and streaming

Generated models use these shared types:

TypesPurpose
ODataId, ODataETagResource URI and concurrency metadata.
EdmDateTimeOffset, EdmDuration, EdmGuidOData timestamps, durations, and UUIDs.
EdmPrimitiveTypeA value that may be a string, boolean, integer, or decimal.
DynamicProperties<T>, AdditionalPropertiesDynamic property maps and arbitrary JSON.
Reference, ReferenceLeafResource references used by generated models.

The deserialize helpers preserve the distinction between an absent property and an explicit JSON null: optional nullable fields use Option<Option<T>>, where None means absent and Some(None) means null.

Bmc::stream returns a BoxTryStream<T, E> of decoded payloads. Bmc::stream_events returns StreamEvent<T> values with event IDs when supported by the transport. Pass the last received ID when reopening the stream to request resumption from that event.

MultipartUpdateRequest describes a firmware upload with a named DataStream, parameters, and optional OEM parts. HttpPushUriUpdateRequest and UploadStream describe a raw binary upload through the legacy HttpPushUri endpoint. UploadReader uses futures_io::AsyncRead.

§Implement a transport

Implement Bmc and choose an error type implementing BmcError. The interface uses generic methods and Send futures; consumers normally accept B: Bmc. BmcErrorClass allows resource code to distinguish HTTP errors, response parse failures, transport failures, and other errors. Both multipart_update and http_push_uri_update are required methods of Bmc.

A transport that deserializes JSON itself applies repairs during decoding and reports decode failures through BmcError::into_decode_error. Other transports can read Raw and use repair::decode_raw for repaired reads.

nv-redfish-bmc-http provides an HTTP implementation of Bmc. nv-redfish-bmc-mock provides a mock implementation for tests.

§License

Apache-2.0.

Modules§

action
Action-related types. Redfish Action primitives
bmc
BMC trait and credentials. Baseboard Management Controller (BMC) client abstraction
deserialize
Custom deserialization helpers.
dynamic_properties
Dynamic properties support.
edm_date_time_offset
Edm.DateTimeOffset type. Edm.DateTimeOffset primitive wrapper
edm_duration
Edm.Duration type. Edm.Duration primitive wrapper
edm_primitive_type
Edm.PrimitiveType type.
nav_property
Navigation property wrapper. Navigation property wrapper for generated types
odata
Type for @odata.id identifier. OData identifiers used by generated types
query
Support of redfish queries OData query parameter builders for Redfish API requests.
raw
A document as JSON, before typed deserialization: as it came off the wire, or with the repairs the read asked for.
repair
Repairing documents before they are deserialized.
upload
Upload data types.

Structs§

Action
Defines a serializable and deserializable Action. It is almost always a member of the Actions struct in different parts of the Redfish object tree.
AsyncTask
Outcome of a mutating Redfish operation that can complete asynchronously.
AsyncTaskLocation
Location of an asynchronous task monitor.
DataStream
Named data stream accepted by multipart upload methods.
EdmDateTimeOffset
Type corresponding to Edm.DateTimeOffset.
EdmDuration
EdmDuration represented by Edm.EdmDuration type.
EdmGuid
A Universally Unique Identifier (UUID).
FilterQuery
Builder for Redfish $filter query parameters according to DSP0266 specification.
HttpPushUriUpdateRequest
UpdateService raw HttpPushUri upload request data.
MultipartUpdateRequest
Multipart UpdateService upload request data.
NoRepair
The document as it came: the repair of a read that asks for none.
ODataETag
Type for @odata.etag identifier.
ODataId
Type for @odata.id identifier.
OemMultipartPart
OEM multipart form part.
OemMultipartPartNameError
Error returned when an OEM multipart part name is invalid.
Raw
A Redfish document as JSON.
Reference
Reference variant of the navigation property (only @odata.id property is specified).
ReferenceLeaf
ReferenceLeaf is special type that is used for navigation properties that if corresponding EntityType was not compiled to the tree.
SessionCreateResponse
Redfish session creation returns the session resource in the response body, the authentication token in the X-Auth-Token header, and the session URI in the Location header.
StreamEvent
One event a server-sent event stream delivered.
UploadStream
Streamed body accepted by deprecated raw upload methods.

Enums§

AdditionalProperties
Represents any valid JSON value.
BmcErrorClass
Classification of a BMC operation error for resource-level policy.
EdmPrimitiveType
Represents Edm.PrimitiveType
ModificationResponse
Outcome of a mutating Redfish operation.
NavProperty
Navigation property variants. All navigation properties in generated code are wrapped with this type.
RepairError
What a repaired read can fail with.

Traits§

ActionError
Action error trait. Needed in generated code when an action function is called for an action that wasn’t specified by the server.
Bmc
BMC trait defines access to a Baseboard Management Controller using the Redfish protocol.
BmcError
Error returned by a Bmc implementation.
Creatable
This trait is assigned to the collections that are marked as creatable in the CSDL specification.
Deletable
This trait is assigned to entity types that are marked as deletable in the CSDL specification.
EntityTypeRef
Entity type reference trait implemented by the CSDL compiler for all generated entity types and for all NavProperty<T> where T is a struct for an entity type.
Expandable
Defines entity types that support $expand via query parameters.
FilterProperty
Trait for types that can be used as filter properties in OData queries
RedfishSettings
Supports the @Redfish.Settings workflow on updatable entity types.
Repair
A rewrite of documents before they are deserialized.
ToFilterLiteral
Trait for types that can be converted to filter literals
ToSnakeCase
Trait for converting enum variants to snake_case strings
Updatable
This trait is assigned to entity types that are marked as updatable in the CSDL specification.
UploadReader
Async reader accepted by upload methods.

Functions§

de_optional_nullable
Deserialize an optional nullable field. nv-redfish models these fields with Option<Option<T>>, where None means “no field” and Some(None) means the field is explicitly set to null.
de_required_nullable
Deserialize a required nullable field. nv-redfish models these fields with Option<T>, where None means null.
without_event_ids
stream as a stream of StreamEvents that carry no id: the view a transport that does not surface SSE ids gives through Bmc::stream_events.

Type Aliases§

BoxTryStream
Boxed fallible stream used by BMC streaming APIs.
DecodeError
A document that did not deserialize, with the path to the property that failed.
DynamicProperties
Represents dynamic properties that can be assigned to Complex Type in CSDL.
OemMultipartPartReader
Reader type used for OEM multipart form parts.