diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2024-10-26 16:08:20 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2024-10-26 16:08:20 +0200 |
commit | 19822dde9f01d54776233fe153b6ea5d5b21c454 (patch) | |
tree | f822577eb7c25391d5fe44fef6e1f11f748f88a5 | |
parent | 404578aae4b3440215843bd2d0c156df2450e534 (diff) | |
download | infra-19822dde9f01d54776233fe153b6ea5d5b21c454.tar.gz infra-19822dde9f01d54776233fe153b6ea5d5b21c454.tar.bz2 infra-19822dde9f01d54776233fe153b6ea5d5b21c454.tar.xz infra-19822dde9f01d54776233fe153b6ea5d5b21c454.zip |
ipam util
-rw-r--r-- | ansible/group_vars/all/ipam.yml | 9 | ||||
-rw-r--r-- | utils/main.go | 31 |
2 files changed, 31 insertions, 9 deletions
diff --git a/ansible/group_vars/all/ipam.yml b/ansible/group_vars/all/ipam.yml index 27c40be..4caa80d 100644 --- a/ansible/group_vars/all/ipam.yml +++ b/ansible/group_vars/all/ipam.yml @@ -47,5 +47,14 @@ ipam6: conflatorio: "fdb1:4242:3538:2008:8042:32ff:fe0c:7161" danneri: "fdb1:4242:3538:2008:9422:d355:95b7:f170" + k8s: + range: "fdb1:4242:3538:3000::/52" + danneri_cluster: + range: "fdb1:4242:3538:3009::/112" + danneri_service: + range: "fdb1:4242:3538:300a::/100" + danneri_service2: + range: "fdb1:4242:3538:300a::/112" + dn42: range: "fd00::/8" diff --git a/utils/main.go b/utils/main.go index f419292..42adbd6 100644 --- a/utils/main.go +++ b/utils/main.go @@ -13,7 +13,7 @@ import ( func main() { err := work() if err != nil { - _, _ = fmt.Fprintf(os.Stderr, "Error reading file: %v\n", err) + _, _ = fmt.Fprintf(os.Stderr, "%v\n", err) os.Exit(1) } } @@ -36,12 +36,20 @@ func work() error { fmt.Printf("digraph {\n") //fmt.Printf(" layout=dot\n") //fmt.Printf(" layout=twopi\n") - fmt.Printf(" layout=circo\n") + fmt.Printf(" layout=fdp\n") + //fmt.Printf(" layout=circo\n") + //fmt.Printf(" layout=neato\n") //fmt.Printf(" ranksep=3\n") //fmt.Printf(" ratio=auto\n") //fmt.Printf(" rankdir=LR\n") //fmt.Printf(" rankdir=RL\n") - //fmt.Printf(" rankdir=TB\n") + fmt.Printf(" rankdir=TB\n") + //fmt.Printf(" sep=3\n") + //fmt.Printf(" overlap_scaling=-10\n") + fmt.Printf("node [len=10];") + fmt.Printf("node [shape=box];") + fmt.Printf("overlap=false") + fmt.Printf("\n") fmt.Printf(" # Nodes\n") for _, n := range networks { @@ -59,7 +67,8 @@ func work() error { 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.name, c.name) + fmt.Printf(";\n") } } } @@ -88,6 +97,10 @@ type Ipam struct { networks []*Network } +func contains(a, b netip.Prefix) bool { + return b.Bits() > a.Bits() && b.Overlaps(a) +} + func (ipam *Ipam) ResolveParents() { for _, n := range ipam.networks { log.Printf("network %s/%s", n.name, n.prefix) @@ -95,14 +108,14 @@ func (ipam *Ipam) ResolveParents() { if n == p { continue } - //log.Printf("candidate %s/%s", p.name, p.prefix) - if p.prefix.Contains(n.prefix.Addr()) { + log.Printf(" candidate %s/%s", p.name, p.prefix) + if contains(p.prefix, n.prefix) { if n.parent == nil { - log.Printf("found parent %s/%s", p.name, p.prefix) + log.Printf(" found parent %s/%s", p.name, p.prefix) n.parent = p } else { - if n.parent.prefix.Contains(p.prefix.Addr()) { - log.Printf("found better parent %s/%s", p.name, p.prefix) + if n.parent.prefix.Bits() < p.prefix.Bits() { + log.Printf(" found better parent %s/%s", p.name, p.prefix) n.parent = p } } |