netbox.rs is a rust project that provides three
pieces:
- a low-level rust client autogenerated from an openapi spec,
- an ergonomic client intended to be used by humans in their code, and
- a cli that you can use to interact with netbox from your terminal.
why?
i realized that most existing rust solutions for interacting with netbox did not fit my needs. i want a client that would be a joy to use, because i’ll be using it extensively across many follow-on projects, most notably alembic, the larger dcim/ipam tool i’m currently working on1.
quick start
from rust:
use netbox::{Client, ClientConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ClientConfig::new("https://netbox.example.com", "your-api-token");
let client = Client::new(config)?;
let devices = client.dcim().devices().list(None).await?;
for device in devices.results {
println!("device: {} (id: {})", device.display, device.id);
}
Ok(())
}in the cli:
# list devices
netbox-cli --url https://netbox.example.com --token $TOKEN dcim devices list
# create a circuit
netbox-cli circuits circuits create --json '{"cid":"CIR-1001","provider":1,"type":1}'
# special: interaction with the branching plugin
netbox-cli plugin-branch-action 1 merge --json '{"commit":true}'announcement for that project will follow when the dust settles.↩︎