CORD-1919 only use IPv4 addresses
Change-Id: I944b780f405113cc344e7198ec44ca36bffbcad7
(cherry picked from commit 566d957b0d7b19da3e9fd93e066ce976dcd45018)
diff --git a/config-generator/handlers.go b/config-generator/handlers.go
index a12da98..3363c6c 100644
--- a/config-generator/handlers.go
+++ b/config-generator/handlers.go
@@ -97,23 +97,29 @@
return a + b
},
"gateway": func(ips []string) string {
- if len(ips) > 0 {
- parts := strings.Split(ips[0], ".")
- ip := ""
- for _, v := range parts[:len(parts)-1] {
- ip = ip + v + "."
+ // Find the first v4 address, as determined by
+ // not having a ':' in the IP
+ for _, ip := range ips {
+ if strings.Index(ip, ":") == -1 {
+ parts := strings.Split(ip, ".")
+ targetIp := ""
+ for _, v := range parts[:len(parts)-1] {
+ targetIp = targetIp + v + "."
+ }
+ return targetIp + "254/24"
}
- return ip + "254/24"
- } else {
- return "0.0.0.254/24"
}
+ return "0.0.0.254/24"
},
"vlan": func(ips []string) string {
- if (len(ips) > 0) {
- return strings.Split(ips[0], ".")[2]
- } else {
- return "0"
+ // Find the first v4 address, as determined by
+ // not having a ':' in the IP
+ for _, ip := range ips {
+ if strings.Index(ip, ":") == -1 {
+ return strings.Split(ip, ".")[2]
+ }
}
+ return "0"
},
}