This commit is contained in:
parent
cebad8abe4
commit
965bcf3cc8
2 changed files with 24 additions and 29 deletions
|
@ -45,8 +45,7 @@ impl InterfaceConfig {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let interface_ip = host_range.bitor(interface_address);
|
Ok(host_range.bitor(interface_address))
|
||||||
Ok(interface_ip)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
50
src/main.rs
50
src/main.rs
|
@ -2,7 +2,6 @@
|
||||||
use reqwest::blocking::get;
|
use reqwest::blocking::get;
|
||||||
use std::{thread::{sleep}};
|
use std::{thread::{sleep}};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt::format;
|
|
||||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use chrono::{Utc, Duration};
|
use chrono::{Utc, Duration};
|
||||||
|
@ -156,7 +155,6 @@ fn compare_zones(old_zone: &ZoneConfig, new_zone: &ZoneConfig) -> Vec<String> {
|
||||||
|
|
||||||
if old_zone.entries != new_zone.entries {
|
if old_zone.entries != new_zone.entries {
|
||||||
let mut added: Vec<&ZoneEntry> = vec![];
|
let mut added: Vec<&ZoneEntry> = vec![];
|
||||||
let mut deleted: Vec<&ZoneEntry>;
|
|
||||||
let mut modified: Vec<&ZoneEntry> = vec![];
|
let mut modified: Vec<&ZoneEntry> = vec![];
|
||||||
|
|
||||||
new_zone.entries.iter().for_each(|entry| {
|
new_zone.entries.iter().for_each(|entry| {
|
||||||
|
@ -172,17 +170,17 @@ fn compare_zones(old_zone: &ZoneConfig, new_zone: &ZoneConfig) -> Vec<String> {
|
||||||
}
|
}
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
if matches.len() == 0 {
|
if matches.is_empty() {
|
||||||
added.push(entry);
|
added.push(entry);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
deleted = old_zone.entries.iter().filter(|old_entry| {
|
let deleted: Vec<&ZoneEntry> = old_zone.entries.iter().filter(|old_entry| {
|
||||||
!new_zone.entries.contains(old_entry) &&
|
!new_zone.entries.contains(old_entry) &&
|
||||||
new_zone.entries.iter().find(|changed_entry| { changed_entry.name == old_entry.name }).is_none()
|
!new_zone.entries.iter().any(|changed_entry| { changed_entry.name == old_entry.name })
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
if deleted.len() != 0 {
|
if !deleted.is_empty() {
|
||||||
let mut deleted_entries_vec = vec![];
|
let mut deleted_entries_vec = vec![];
|
||||||
|
|
||||||
for entry in deleted {
|
for entry in deleted {
|
||||||
|
@ -198,7 +196,7 @@ fn compare_zones(old_zone: &ZoneConfig, new_zone: &ZoneConfig) -> Vec<String> {
|
||||||
info_pieces.push(msg);
|
info_pieces.push(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if added.len() != 0 {
|
if !added.is_empty() {
|
||||||
let mut added_entries_vec = vec![];
|
let mut added_entries_vec = vec![];
|
||||||
|
|
||||||
for entry in added {
|
for entry in added {
|
||||||
|
@ -214,7 +212,7 @@ fn compare_zones(old_zone: &ZoneConfig, new_zone: &ZoneConfig) -> Vec<String> {
|
||||||
info_pieces.push(msg);
|
info_pieces.push(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if modified.len() != 0 {
|
if !modified.is_empty() {
|
||||||
let mut modified_entries_vec = vec![];
|
let mut modified_entries_vec = vec![];
|
||||||
|
|
||||||
for entry in modified {
|
for entry in modified {
|
||||||
|
@ -268,7 +266,6 @@ fn main() {
|
||||||
|
|
||||||
if ifaces.interfaces != new_cfg.interfaces {
|
if ifaces.interfaces != new_cfg.interfaces {
|
||||||
let mut new: Vec<(&String, &Ipv6Addr)> = vec![];
|
let mut new: Vec<(&String, &Ipv6Addr)> = vec![];
|
||||||
let deleted: Vec<(&String, &Ipv6Addr)>;
|
|
||||||
let mut modified: Vec<(&String, &Ipv6Addr)> = vec![];
|
let mut modified: Vec<(&String, &Ipv6Addr)> = vec![];
|
||||||
|
|
||||||
new_cfg.interfaces.iter().for_each(|(interface, address)| {
|
new_cfg.interfaces.iter().for_each(|(interface, address)| {
|
||||||
|
@ -279,10 +276,10 @@ fn main() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let matches: Vec<&Ipv6Addr> = ifaces.interfaces.values().filter(|addr| {
|
let matches: Vec<&Ipv6Addr> = ifaces.interfaces.values().filter(|addr| {
|
||||||
*addr == address
|
addr == &address
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
if matches.len() == 0 {
|
if matches.is_empty() {
|
||||||
new.push((interface, address));
|
new.push((interface, address));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -291,8 +288,8 @@ fn main() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
deleted = ifaces.interfaces.iter().filter(|(interface, address)| {
|
let deleted: Vec<(&String, &Ipv6Addr)> = ifaces.interfaces.iter().filter(|(interface, address)| {
|
||||||
!new_cfg.interfaces.contains_key(*interface) && modified.iter().find(|(_, new_addr)| { new_addr == address }).is_none()
|
!new_cfg.interfaces.contains_key(*interface) && !modified.iter().any(|(_, new_addr)| { new_addr == address })
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
for (name, addr) in deleted {
|
for (name, addr) in deleted {
|
||||||
|
@ -312,18 +309,17 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (name, addr) in modified {
|
for (name, addr) in modified {
|
||||||
let info_msg;
|
let info_msg= if ifaces.interfaces.contains_key(name) {
|
||||||
if ifaces.interfaces.contains_key(name) {
|
|
||||||
let old_addr = ifaces.interfaces.get(name).expect("contains check on ifaces was successful");
|
let old_addr = ifaces.interfaces.get(name).expect("contains check on ifaces was successful");
|
||||||
info_msg = format!("Changed interface address of '{name}' from '{old_addr}' to '{addr}'");
|
format!("Changed interface address of '{name}' from '{old_addr}' to '{addr}'")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let old_name = ifaces.interfaces.iter()
|
let old_name = ifaces.interfaces.iter()
|
||||||
.find(|(_, old_addr)| { old_addr == &addr })
|
.find(|(_, old_addr)| { old_addr == &addr })
|
||||||
.expect("modified entry should not exist if this fails")
|
.expect("modified entry should not exist if this fails")
|
||||||
.0;
|
.0;
|
||||||
info_msg = format!("Changed interface name for '{addr}' from '{old_name}' to '{name}'");
|
format!("Changed interface name for '{addr}' from '{old_name}' to '{name}'")
|
||||||
}
|
};
|
||||||
|
|
||||||
match connected_to_journal() {
|
match connected_to_journal() {
|
||||||
true => info!("[INFO] {info_msg}"),
|
true => info!("[INFO] {info_msg}"),
|
||||||
|
@ -379,21 +375,21 @@ fn main() {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let changed_zones: Vec<&ZoneConfig> = new_cfgs.iter().filter(|new_cfg| {
|
let changed_zones: Vec<&ZoneConfig> = new_cfgs.iter().filter(|new_cfg| {
|
||||||
zone_cfgs.iter().find(|old_cfg| {
|
zone_cfgs.iter().any(|old_cfg| {
|
||||||
old_cfg.name == new_cfg.name && old_cfg != new_cfg
|
old_cfg.name == new_cfg.name && &old_cfg != new_cfg
|
||||||
}).is_some()
|
})
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
let deleted_zones: Vec<&ZoneConfig> = zone_cfgs.iter().filter(|old_cfg| {
|
let deleted_zones: Vec<&ZoneConfig> = zone_cfgs.iter().filter(|old_cfg| {
|
||||||
new_cfgs.iter().find(|new_cfg| {
|
!new_cfgs.iter().any(|new_cfg| {
|
||||||
old_cfg.name == new_cfg.name
|
old_cfg.name == new_cfg.name
|
||||||
}).is_none()
|
})
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
let added_zones: Vec<&ZoneConfig> = new_cfgs.iter().filter(|new_cfg| {
|
let added_zones: Vec<&ZoneConfig> = new_cfgs.iter().filter(|new_cfg| {
|
||||||
zone_cfgs.iter().find(|old_cfg| {
|
!zone_cfgs.iter().any(|old_cfg| {
|
||||||
old_cfg.name == new_cfg.name
|
old_cfg.name == new_cfg.name
|
||||||
}).is_none()
|
})
|
||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
if deleted_zones.len() == 1 && added_zones.len() == 1 {
|
if deleted_zones.len() == 1 && added_zones.len() == 1 {
|
||||||
|
@ -412,7 +408,7 @@ fn main() {
|
||||||
println!("{}", info_pieces.join(", "));
|
println!("{}", info_pieces.join(", "));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if deleted_zones.len() != 0 {
|
if !deleted_zones.is_empty() {
|
||||||
let mut info_pieces = vec![];
|
let mut info_pieces = vec![];
|
||||||
for deleted_zone in deleted_zones {
|
for deleted_zone in deleted_zones {
|
||||||
info_pieces.push(deleted_zone.name.clone());
|
info_pieces.push(deleted_zone.name.clone());
|
||||||
|
@ -429,7 +425,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if added_zones.len() != 0 {
|
if !added_zones.is_empty() {
|
||||||
let mut info_pieces = vec![];
|
let mut info_pieces = vec![];
|
||||||
for added_zone in added_zones {
|
for added_zone in added_zones {
|
||||||
info_pieces.push(added_zone.name.clone());
|
info_pieces.push(added_zone.name.clone());
|
||||||
|
|
Loading…
Reference in a new issue