made client_of a default attribute

This commit is contained in:
Yannik 2020-06-23 20:38:50 +02:00
parent d021745cde
commit 04937f5a9d
2 changed files with 10 additions and 9 deletions

View file

@ -33,6 +33,7 @@ fn main() {
pub struct Host { pub struct Host {
name: String, name: String,
ip: String, ip: String,
parent: String,
kind: HostKind, kind: HostKind,
} }
impl Host { impl Host {
@ -79,19 +80,20 @@ impl Host {
} }
fn to_dot_edge(&self) -> Option<String> { fn to_dot_edge(&self) -> Option<String> {
match self.kind { match self.kind {
HostKind::Client { ref parent, ref ssid, .. } => HostKind::Client { ref ssid, .. } =>
format!("\"{name}\" -- \"{parent}\" [label=\"{ssid}\"]", name=self.name, parent=parent, ssid=ssid).into(), format!("\"{name}\" -- \"{parent}\" [label=\"{ssid}\"]", name=self.name, parent=self.parent, ssid=ssid).into(),
HostKind::AccessPoint { ref parent, .. } => // hier eventuelle ausnahmen für bestimmte typen die keine parents haben eintragen
format!("\"{name}\" -- \"{parent}\"", name=self.name, parent=parent).into(), // mainly template und sol
_ => None, _ =>
format!("\"{name}\" -- \"{parent}\"", name=self.name, parent=self.parent).into(),
} }
} }
} }
#[derive(Debug)] #[derive(Debug)]
enum HostKind { enum HostKind {
Client { mac: String, subnet: String, coordinates: Option<[f64;2]>, parent: String, ssid: String }, Client { mac: String, subnet: String, coordinates: Option<[f64;2]>, ssid: String },
AccessPoint { mac: String, ssid: String, parent: String }, AccessPoint { mac: String, ssid: String },
Service, Service,
Other, Other,
} }

View file

@ -56,16 +56,15 @@ impl RawHost {
Host Host
{ name: name.clone() { name: name.clone()
, ip: self.ansible_host , ip: self.ansible_host
, parent: self.client_of.unwrap_or_else(|| missingwarn("client_of"))
, kind: match self.kind.as_ref() , kind: match self.kind.as_ref()
{ "wlan-ap" => HostKind::AccessPoint { "wlan-ap" => HostKind::AccessPoint
{ mac: self.mac.unwrap_or_else(|| missingpanic("mac")) { mac: self.mac.unwrap_or_else(|| missingpanic("mac"))
, ssid: self.link_ssid.unwrap_or_else(|| missingwarn("link_ssid")) , ssid: self.link_ssid.unwrap_or_else(|| missingwarn("link_ssid"))
, parent: self.client_of.unwrap_or_else(|| missingwarn("client_of"))
} }
, "client" => HostKind::Client , "client" => HostKind::Client
{ subnet: self.subnet.unwrap_or_else(|| missingpanic("subnet")) { subnet: self.subnet.unwrap_or_else(|| missingpanic("subnet"))
, coordinates: self.coordinate , coordinates: self.coordinate
, parent: self.client_of.unwrap_or_else(|| missingwarn("client_of"))
, mac: self.mac.unwrap_or_else(|| missingpanic("mac")) , mac: self.mac.unwrap_or_else(|| missingpanic("mac"))
, ssid: self.link_ssid.unwrap_or_else(|| missingwarn("link_ssid")) , ssid: self.link_ssid.unwrap_or_else(|| missingwarn("link_ssid"))
} }