Expand description
A dependency-free, strongly typed eDSL and base contracts for network device operations and declarative infrastructure resources.
The imperative API runs operations directly through Driver and
Execute. The declarative API describes desired resources for an
IacBackend. These models are intentionally separate.
§Direct execution
use network_device::{
AdministrativeState, Driver, Execute, InterfaceName, Run,
SetInterfaceState, operation,
};
use std::convert::Infallible;
use std::future::Future;
struct Device;
impl Driver for Device {
type Error = Infallible;
}
impl Execute<SetInterfaceState> for Device {
type Output = ();
fn execute<'a>(
&'a self,
_operation: SetInterfaceState,
) -> impl Future<Output = Result<Self::Output, Self::Error>> + Send + 'a {
async { Ok(()) }
}
}
let name = InterfaceName::try_from("Ethernet1/1").expect("valid interface name");
operation(SetInterfaceState::new(name, AdministrativeState::Enabled))
.run(&Device)
.await?;§IaC backend
use network_device::{
AdministrativeState, IacBackend, InterfaceConfiguration, InterfaceName,
};
use std::convert::Infallible;
use std::future::Future;
struct LocalBackend;
impl IacBackend<InterfaceConfiguration> for LocalBackend {
type Error = Infallible;
type Plan = usize;
type ApplyResult = ();
fn plan<'a>(
&'a self,
desired: &'a InterfaceConfiguration,
) -> impl Future<Output = Result<Self::Plan, Self::Error>> + Send + 'a {
async move { Ok(usize::from(desired.administrative_state.is_some())) }
}
fn apply<'a>(
&'a self,
_desired: &'a InterfaceConfiguration,
) -> impl Future<Output = Result<Self::ApplyResult, Self::Error>> + Send + 'a {
async { Ok(()) }
}
}
let desired = InterfaceConfiguration::new(
InterfaceName::try_from("Ethernet1/1").expect("valid interface name"),
)
.administrative_state(AdministrativeState::Enabled);
let backend = LocalBackend;
let _plan = backend.plan(&desired).await?;
backend.apply(&desired).await?;§Driver connection and credentials
DriverConnector constructs and authenticates a concrete provider driver
from a provider-defined target and authentication value. Credential lookup
remains the responsibility of the integrating application. For example, an
integration can resolve an oss_providers::CredentialMaterial using its
CredentialProvider, convert that value into the selected connector’s
Authentication type, and pass it to DriverConnector::connect. This
crate has no dependency on oss-providers, Vault, or a credential store.
Structs§
- Ensure
Static Route - Imperative operation to ensure a static route exists.
- Interface
Configuration - A declarative desired configuration for an interface.
- Interface
Name - A validated, vendor-neutral interface identifier.
- IpPrefix
- A validated IP address and network prefix length.
- IpPrefix
Error - Error returned when an IP prefix length exceeds its address family’s limit.
- Operation
Step - A typed step in a direct-operation program.
- Remove
Static Route - Imperative operation to remove a static route.
- Sequence
- Two operation steps executed in order.
- SetInterface
Description - Imperative operation to set an interface description.
- SetInterface
State - Imperative operation to set an interface’s administrative state.
- Static
Route - A static route’s destination and next-hop address.
- Static
Route Configuration - A declarative desired configuration for a static route.
Enums§
- Administrative
State - Desired administrative state for an interface.
- Interface
Name Error - Validation errors for
InterfaceName. - IpPrefix
Parse Error - Parsing errors for
IpPrefix. - Static
Route Error - Validation error for
StaticRoute.
Traits§
- Driver
- A device driver capable of executing one or more typed operations.
- Driver
Connector - Constructs and authenticates a provider-specific device driver.
- Execute
- Executes a specific operation on a
Driver. - IacBackend
- Plans and applies a resource’s declarative desired state.
- Run
- Runs a DSL value against a statically selected driver.
Functions§
- operation
- Starts a typed operation step.