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

View file

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