Refactor nbhelper

Change-Id: I69d10d164fac3eb319e072447a520905880c31dd
diff --git a/scripts/edgeconfig.py b/scripts/edgeconfig.py
index fc49606..7034f6c 100644
--- a/scripts/edgeconfig.py
+++ b/scripts/edgeconfig.py
@@ -14,7 +14,7 @@
 import nbhelper
 import os
 
-from ruamel import yaml
+from ruamel.yaml import YAML
 
 # main function that calls other functions
 if __name__ == "__main__":
@@ -32,46 +32,40 @@
     }
 
     args = nbhelper.initialize(extra_args)
-    tenant = nbhelper.NBTenant()
+    tenant = nbhelper.Tenant()
 
     # use base_config for additional items
-    base_yaml = yaml.safe_load(args.base_config.read())
+    yaml = YAML(typ="rt")
+    base_yaml = yaml.load(args.base_config.read())
 
-    dhcpd_subnets = []
     dhcpd_interfaces = []
 
-    # reverse zones aggregate across RFC1918 IP prefix
-    dns_reverse_zones = nbhelper.NBDNSReverseZones()
-    for prefix in tenant.get_prefixes().values():
+    # TODO
+    # dhcpd_if = dhcpd_subnet.dhcpd_interface
+    dns_forward_zones = nbhelper.service.dnsFowardZoneConfigGenerator()
+    dns_reverse_zones = nbhelper.service.dnsReverseZoneConfigGenerator()
+    dhcpd_subnets = nbhelper.service.dhcpSubnetConfigGenerator()
 
-        nbhelper.NBDNSForwardZone.get_fwd_zone(prefix)
-        dns_reverse_zones.add_prefix(prefix)
-        dhcpd_subnet = nbhelper.NBDHCPSubnet(prefix)
-        dhcpd_if = dhcpd_subnet.dhcpd_interface
-
-        if dhcpd_if and dhcpd_if not in dhcpd_interfaces:
-            dhcpd_interfaces.append(dhcpd_if)
-
-        dhcpd_subnets.append(dhcpd_subnet)
-
-    for device in tenant.get_devices():
+    for device in tenant.get_devices(device_types=["server", "router", "switch"]):
         output_yaml = base_yaml.copy()
 
         if (
-            isinstance(device, nbhelper.NBDevice)
+            isinstance(device, nbhelper.Device)
             and device.data.device_role.slug == "router"
         ) or (
-            isinstance(device, nbhelper.NBVirtualMachine)
+            isinstance(device, nbhelper.VirtualMachine)
             and device.data.role.slug == "router"
         ):
-            output_yaml["dns_forward_zones"] = nbhelper.NBDNSForwardZone.all_fwd_zones()
+            output_yaml["dns_forward_zones"] = dns_forward_zones
             output_yaml["dns_reverse_zones"] = dns_reverse_zones
             output_yaml["dhcpd_subnets"] = dhcpd_subnets
-            output_yaml["dhcpd_interfaces"] = dhcpd_interfaces
+            output_yaml["dhcpd_interfaces"] = list(device.internal_interfaces.keys())
             output_yaml["netprep_nftables"] = device.generate_nftables()
             output_yaml.update(device.generate_extra_config())
+            output_yaml = nbhelper.utils.apply_as_router(output_yaml)
 
         output_yaml["netprep_netplan"] = device.generate_netplan()
 
-        with open("inventory/host_vars/%s.yaml" % device.name, "w") as f:
-            f.write(yaml.safe_dump(output_yaml, indent=2))
+        with open("inventory/host_vars/%s.yaml" % device.fullname, "w") as f:
+            # yaml.compact(seq_seq=False, seq_map=False)
+            yaml.dump(output_yaml, f)