Skip to content

Commit

Permalink
add interface creation logic v1
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteOtter committed Apr 25, 2024
1 parent ba02c0c commit c0aa30e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/publisher/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn create_device(
client: &ThanixClient,
payload: &WritableDeviceWithConfigContextRequest,
) -> Result<i64, NetBoxApiError> {
println!("Creating Device in NetBox...");
println!("Creating device in NetBox...");

match dcim_devices_create(client, payload.clone()) {
Ok(response) => {
Expand Down Expand Up @@ -111,7 +111,7 @@ pub fn create_interface(
client: &ThanixClient,
payload: WritableInterfaceRequest,
) -> Result<i64, NetBoxApiError> {
println!("Creating interface in NetBox...");
println!("Creating network interface in NetBox...");

match dcim_interfaces_create(client, payload) {
Ok(response) => {
Expand All @@ -127,7 +127,9 @@ pub fn create_interface(
}
}
Err(e) => {
panic!("[FATAL] NetBox connection failed. {}", e);
eprintln!("\x1b[33m[warning]\x1b[0m Error while decoding NetBox Response. This is probably still fine and a problem with NetBox.\nError: {}", e);
let exc = NetBoxApiError::Other(e.to_string());
Err(exc)
}
}
}
39 changes: 29 additions & 10 deletions src/publisher/translator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! TODO:
//! - Identify primary IPv4 or IPv6 using the primary_network_interface field from `ConfigData`.
use core::net::IpAddr;
use std::collections::HashMap;
use std::process;
use std::str::FromStr;
use thanix_client::paths::{
Expand Down Expand Up @@ -165,24 +166,42 @@ pub fn information_to_interface(
payload.device = device_id.to_owned();
// payload.vdcs = todo!();
// payload.module = todo!();
payload.name = match config_data.system.primary_network_interface {
Some(interface_name) => interface_name,
payload.name = match &config_data.system.primary_network_interface {
Some(interface_name) => interface_name.to_owned(),
None => String::from("Nazara Generic Network Interface"),
};
// payload.label = todo!();
// payload.r#type = todo!();
// FIXME:
payload.r#type = String::from("bridge");
// payload.parent = todo!();
// payload.bridge = todo!();
// payload.lag = todo!();
// payload.mtu = todo!();
payload.mac_address = todo!("Search for nwi specified as primary, get mac address.");
payload.speed = todo!();

// Get the interfce we are looking for as primary, then get its parameters.
// These filter statements can probably be split off into their own function.
payload.mac_address = match &config_data.system.primary_network_interface {
Some(nwi_name) => {
let interface = machine.network_information.iter().find(|nwi| nwi.name == nwi_name.to_owned());
interface.map(|nwi| nwi.mac_addr.clone()).flatten()
},
None => None,
};
payload.speed = match config_data.system.primary_network_interface {
Some(nwi_name) => {
let interface = machine.network_information.iter().find(|nwi| nwi.name == nwi_name);
interface.map(|nwi| nwi.interface_speed.clone()).flatten()
},
None => None,
};
payload.description = String::from("This interface was automatically created by Nazara.");
payload.mode = todo!();
payload.rf_role = todo!();
payload.rf_channel = todo!();
payload.poe_mode = todo!();
payload.poe_type = todo!();
// payload.mode = todo!();
// payload.rf_role = todo!();
// payload.rf_channel = todo!();
// payload.poe_mode = todo!();
// payload.poe_type = todo!();
// FIXME:
payload.custom_fields = Some(HashMap::new());

payload
}
Expand Down

0 comments on commit c0aa30e

Please sign in to comment.