aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils/main.go30
1 files changed, 23 insertions, 7 deletions
diff --git a/utils/main.go b/utils/main.go
index db27e9c..f419292 100644
--- a/utils/main.go
+++ b/utils/main.go
@@ -1,10 +1,12 @@
package main
import (
+ "cmp"
"fmt"
"log"
"net/netip"
"os"
+ "slices"
"utils/yaml_ipam"
)
@@ -28,6 +30,9 @@ func work() error {
return err
}
+ networks := slices.SortedFunc(slices.Values(ipam.networks), CompareNetwork)
+ roots := slices.SortedFunc(slices.Values(ipam.FindRoots()), CompareNetwork)
+
fmt.Printf("digraph {\n")
//fmt.Printf(" layout=dot\n")
//fmt.Printf(" layout=twopi\n")
@@ -39,19 +44,22 @@ func work() error {
//fmt.Printf(" rankdir=TB\n")
fmt.Printf("\n")
fmt.Printf(" # Nodes\n")
- for _, n := range ipam.networks {
+ for _, n := range networks {
fmt.Printf(" %s [ label = \"%s\\n%s\"];\n", n.name, n.name, n.prefix)
}
- for _, n := range ipam.FindRoots() {
+
+ fmt.Printf("\n")
+ fmt.Printf(" # Roots\n")
+ for _, n := range roots {
fmt.Printf(" %s [ root = true ];\n", n.name)
}
fmt.Printf("\n")
fmt.Printf(" # Relationships\n")
- for _, n := range ipam.networks {
+ for _, n := range networks {
for _, c := range ipam.networks {
if c.parent == n {
- fmt.Printf(" %s -> %s;\n", n.name, c.name)
+ fmt.Printf(" %s -> %s;\n", n.name, c.name)
}
}
}
@@ -124,6 +132,14 @@ type Network struct {
hosts []networkHost
}
+func CompareNetwork(a, b *Network) int {
+ return cmp.Compare(a.name, b.name)
+}
+
+func (n *Network) Compare(other *Network) int {
+ return cmp.Compare(n.name, other.name)
+}
+
type networkHost struct {
name string
address netip.Addr
@@ -133,10 +149,10 @@ func processNetworks(networks map[string]yaml_ipam.Network6Yaml) (*Ipam, error)
var ns []*Network
for name, net := range networks {
- log.Printf("Processing net %v\net", name)
+ log.Printf("Processing net %v\n", name)
prefix, err := netip.ParsePrefix(net.Range)
if err != nil {
- return nil, fmt.Errorf("error parsing net range: %v\net", err)
+ return nil, fmt.Errorf("error parsing net range: %v", err)
}
log.Printf("prefix: %s", prefix.String())
@@ -144,7 +160,7 @@ func processNetworks(networks map[string]yaml_ipam.Network6Yaml) (*Ipam, error)
for hostname, a := range net.Hosts {
addr, err := netip.ParseAddr(a)
if err != nil {
- return nil, fmt.Errorf("network: %s, unable to parse host address %s\net", n.name, a)
+ return nil, fmt.Errorf("network: %s, unable to parse host address %s", n.name, a)
}
n.hosts = append(n.hosts, networkHost{