cyber witchery lab

netbox.rs: an ergonomic netbox client in rust

interact with netbox in your code and cli
cargo install netbox-cli

links: repo docs crates.io

netbox.rs is a rust project that provides three pieces:

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}'

  1. announcement for that project will follow when the dust settles.↩︎