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:
| 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.
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.DateTimeOffsettype.Edm.DateTimeOffsetprimitive wrapper- edm_
duration Edm.Durationtype.Edm.Durationprimitive wrapper- edm_
primitive_ type Edm.PrimitiveTypetype.- nav_
property - Navigation property wrapper. Navigation property wrapper for generated types
- odata
- Type for
@odata.ididentifier. 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
Actionsstruct in different parts of the Redfish object tree. - Async
Task - Outcome of a mutating Redfish operation that can complete asynchronously.
- Async
Task Location - Location of an asynchronous task monitor.
- Data
Stream - Named data stream accepted by multipart upload methods.
- EdmDate
Time Offset - Type corresponding to
Edm.DateTimeOffset. - EdmDuration
EdmDurationrepresented by Edm.EdmDuration type.- EdmGuid
- A Universally Unique Identifier (UUID).
- Filter
Query - Builder for Redfish
$filterquery parameters according to DSP0266 specification. - Http
Push UriUpdate Request UpdateServicerawHttpPushUriupload request data.- Multipart
Update Request - Multipart
UpdateServiceupload request data. - NoRepair
- The document as it came: the repair of a read that asks for none.
- ODataE
Tag - Type for
@odata.etagidentifier. - ODataId
- Type for
@odata.ididentifier. - OemMultipart
Part - OEM multipart form part.
- OemMultipart
Part Name Error - 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.idproperty is specified). - Reference
Leaf ReferenceLeafis special type that is used for navigation properties that if correspondingEntityTypewas not compiled to the tree.- Session
Create Response - Redfish session creation returns the session resource in the response body,
the authentication token in the
X-Auth-Tokenheader, and the session URI in theLocationheader. - Stream
Event - One event a server-sent event stream delivered.
- Upload
Stream - Streamed body accepted by deprecated raw upload methods.
Enums§
- Additional
Properties - Represents any valid JSON value.
- BmcError
Class - Classification of a BMC operation error for resource-level policy.
- EdmPrimitive
Type - Represents Edm.PrimitiveType
- Modification
Response - Outcome of a mutating Redfish operation.
- NavProperty
- Navigation property variants. All navigation properties in generated code are wrapped with this type.
- Repair
Error - What a repaired read can fail with.
Traits§
- Action
Error - 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
Bmcimplementation. - 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.
- Entity
Type Ref - Entity type reference trait implemented by the CSDL compiler
for all generated entity types and for all
NavProperty<T>whereTis a struct for an entity type. - Expandable
- Defines entity types that support
$expandvia query parameters. - Filter
Property - Trait for types that can be used as filter properties in
ODataqueries - Redfish
Settings - Supports the
@Redfish.Settingsworkflow on updatable entity types. - Repair
- A rewrite of documents before they are deserialized.
- ToFilter
Literal - Trait for types that can be converted to filter literals
- ToSnake
Case - Trait for converting enum variants to
snake_casestrings - Updatable
- This trait is assigned to entity types that are marked as updatable in the CSDL specification.
- Upload
Reader - Async reader accepted by upload methods.
Functions§
- de_
optional_ nullable - Deserialize an optional nullable field. nv-redfish models these fields
with
Option<Option<T>>, whereNonemeans “no field” andSome(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>, whereNonemeans null. - without_
event_ ids streamas a stream ofStreamEvents that carry no id: the view a transport that does not surface SSE ids gives throughBmc::stream_events.
Type Aliases§
- BoxTry
Stream - Boxed fallible stream used by BMC streaming APIs.
- Decode
Error - A document that did not deserialize, with the path to the property that failed.
- Dynamic
Properties - Represents dynamic properties that can be assigned to Complex Type in CSDL.
- OemMultipart
Part Reader - Reader type used for OEM multipart form parts.