nv-redfish-core 0.22.2

Semantic-unaware foundation used by code generated from CSDL for nv-redfish
Documentation

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:

Variant Meaning
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.
Empty The 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:

Types Purpose
ODataId, ODataETag Resource URI and concurrency metadata.
EdmDateTimeOffset, EdmDuration, EdmGuid OData timestamps, durations, and UUIDs.
EdmPrimitiveType A value that may be a string, boolean, integer, or decimal.
DynamicProperties<T>, AdditionalProperties Dynamic property maps and arbitrary JSON.
Reference, ReferenceLeaf Resource 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.