Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netshot update #22

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn main() -> Result<(), Error> {
log::debug!("Building netshot devices simplified inventory");
let netshot_simplified_inventory: HashMap<&String, &String> = netshot_devices
.iter()
.map(|dev| (&dev.management_address.ip, &dev.name))
.map(|dev| (&dev.management_address, &dev.name))
.collect();

log::info!("Getting devices list from Netbox");
Expand Down Expand Up @@ -192,14 +192,14 @@ fn main() -> Result<(), Error> {

let mut devices_to_enable: Vec<String> = Vec::new();
for device in &netshot_disabled_devices {
match netbox_simplified_devices.get(device.management_address.ip.as_str()) {
match netbox_simplified_devices.get(&device.management_address) {
Some(_x) => {
log::debug!(
"{}({}) to be enabled (present on Netbox)",
device.name,
device.management_address.ip
device.management_address
);
devices_to_enable.push(device.management_address.ip.clone());
devices_to_enable.push(device.management_address.clone());
}
None => {}
}
Expand Down
13 changes: 2 additions & 11 deletions src/rest/netshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,12 @@ pub struct NetshotClient {
pub client: reqwest::blocking::Client,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ManagementAddress {
#[serde(rename = "prefixLength")]
pub prefix_length: u8,
#[serde(rename = "addressUsage")]
pub address_usage: String,
pub ip: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Device {
pub id: u32,
pub name: String,
#[serde(rename = "mgmtAddress")]
pub management_address: ManagementAddress,
pub management_address: String,
pub status: String,
}

Expand Down Expand Up @@ -301,7 +292,7 @@ mod tests {

assert_eq!(device.name, "test-device");
assert_eq!(device.id, 1 as u32);
assert_eq!(device.management_address.ip, "1.2.3.4");
assert_eq!(device.management_address, "1.2.3.4");
}

#[test]
Expand Down
12 changes: 2 additions & 10 deletions tests/data/netshot/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,14 @@
"id": 2318,
"name": "test-device.dc",
"family": "Cisco Catalyst 2900",
"mgmtAddress": {
"prefixLength": 0,
"addressUsage": "PRIMARY",
"ip": "1.2.3.4"
},
"mgmtAddress": "1.2.3.4",
"status": "INPRODUCTION"
},
{
"id": 2318,
"name": "test-device.dc",
"family": "Cisco Catalyst 2900",
"mgmtAddress": {
"prefixLength": 0,
"addressUsage": "PRIMARY",
"ip": "1.2.3.4"
},
"mgmtAddress": "1.2.3.4",
"status": "INPRODUCTION"
}
]
Expand Down
6 changes: 1 addition & 5 deletions tests/data/netshot/single_good_device.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
"id": 1,
"name": "test-device",
"family": "Nexus 9000 C93108TC-EX",
"mgmtAddress": {
"prefixLength": 0,
"addressUsage": "PRIMARY",
"ip": "1.2.3.4"
},
"mgmtAddress": "1.2.3.4",
"status": "INPRODUCTION"
}
]
Loading