labctl: segments sur des bridges de l'hôte, routeurs et passerelle VRRP #2
All checks were successful
Tests / test (push) Successful in 3m46s
All checks were successful
Tests / test (push) Successful in 3m46s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
e0de56a64f
commit
e9a0c19b72
24 changed files with 1766 additions and 578 deletions
|
|
@ -18,6 +18,8 @@ const (
|
|||
|
||||
ReservedInterface = "mgmt0"
|
||||
LoopbackInterface = "lo1"
|
||||
|
||||
MaxVRID = 255
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -74,14 +76,23 @@ func (t *Topology) Validate() error {
|
|||
if s.Name == LoopbackInterface {
|
||||
add("segment %s: name is reserved for the loopback interface", s.Name)
|
||||
}
|
||||
sw, ok := nodes[s.Switch]
|
||||
switch {
|
||||
case s.Switch == "":
|
||||
add("segment %s: switch is required", s.Name)
|
||||
case !ok:
|
||||
add("segment %s: switch %s is not a declared node", s.Name, s.Switch)
|
||||
case sw.Role != RoleSwitch:
|
||||
add("segment %s: %s is a %s, not a switch", s.Name, s.Switch, sw.Role)
|
||||
if s.legacySwitch != "" {
|
||||
add("segment %s: switch was replaced by routers: declare %s with role %s, attach it to %s through its segments, and list it in segments.%s.routers", s.Name, s.legacySwitch, RoleRouter, s.Name, s.Name)
|
||||
}
|
||||
seenRouters := map[string]bool{}
|
||||
for _, name := range s.Routers {
|
||||
r, ok := nodes[name]
|
||||
switch {
|
||||
case seenRouters[name]:
|
||||
add("segment %s: router %s listed twice", s.Name, name)
|
||||
case !ok:
|
||||
add("segment %s: router %s is not a declared node", s.Name, name)
|
||||
case r.Role != RoleRouter:
|
||||
add("segment %s: %s is a %s, not a %s", s.Name, name, r.Role, RoleRouter)
|
||||
case !contains(r.Segments, s.Name):
|
||||
add("segment %s: router %s is not attached to it", s.Name, name)
|
||||
}
|
||||
seenRouters[name] = true
|
||||
}
|
||||
if s.MTU < MinMTU || s.MTU > MaxMTU {
|
||||
add("segment %s: mtu %d out of range [%d, %d]", s.Name, s.MTU, MinMTU, MaxMTU)
|
||||
|
|
@ -99,19 +110,25 @@ func (t *Topology) Validate() error {
|
|||
}
|
||||
}
|
||||
|
||||
attached := map[string]int{}
|
||||
hosting := map[string]int{}
|
||||
for _, s := range t.Segments {
|
||||
hosting[s.Switch]++
|
||||
for i, s := range t.Segments {
|
||||
if len(s.Routers) > 1 {
|
||||
if i+1 > MaxVRID {
|
||||
add("segment %s: a segment with several routers must be among the first %d, its rank sets the vrrp id", s.Name, MaxVRID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
attached := map[string]int{}
|
||||
for _, n := range t.Nodes {
|
||||
if !namePattern.MatchString(n.Name) {
|
||||
add("node %s: name must match %s", n.Name, namePattern)
|
||||
}
|
||||
switch n.Role {
|
||||
case RoleSwitch, RoleRR, RoleHost:
|
||||
case RoleRouter, RoleRR, RoleHost:
|
||||
case "switch":
|
||||
add("node %s: role switch was renamed %s: attach it to its segments through segments and addresses, and list it in segments.<name>.routers", n.Name, RoleRouter)
|
||||
default:
|
||||
add("node %s: role %q must be one of %s, %s, %s", n.Name, n.Role, RoleSwitch, RoleRR, RoleHost)
|
||||
add("node %s: role %q must be one of %s, %s, %s", n.Name, n.Role, RoleRouter, RoleRR, RoleHost)
|
||||
}
|
||||
if !images[n.Image] {
|
||||
add("node %s: image %q is not declared", n.Name, n.Image)
|
||||
|
|
@ -123,15 +140,6 @@ func (t *Topology) Validate() error {
|
|||
add("node %s: memory must be at least %d MiB", n.Name, MinMemory)
|
||||
}
|
||||
validateExtras(n, segments, add)
|
||||
if n.Role == RoleSwitch {
|
||||
if len(n.Segments) > 0 || len(n.Addresses) > 0 {
|
||||
add("node %s: a switch carries its segments through segments.<name>.switch, not through segments or addresses", n.Name)
|
||||
}
|
||||
if hosting[n.Name] == 0 {
|
||||
add("node %s: switch carries no segment", n.Name)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if len(n.Segments) == 0 {
|
||||
add("node %s: must be attached to at least one segment", n.Name)
|
||||
}
|
||||
|
|
@ -174,16 +182,8 @@ func (t *Topology) Validate() error {
|
|||
|
||||
func validateExtras(n Node, segments map[string]Segment, add func(string, ...any)) {
|
||||
carried := map[string]bool{}
|
||||
if n.Role == RoleSwitch {
|
||||
for name, s := range segments {
|
||||
if s.Switch == n.Name {
|
||||
carried[name] = true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for _, name := range n.Segments {
|
||||
carried[name] = true
|
||||
}
|
||||
for _, name := range n.Segments {
|
||||
carried[name] = true
|
||||
}
|
||||
names := make([]string, 0, len(n.Secondary))
|
||||
for name := range n.Secondary {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue