Skip to content

Commit

Permalink
adding no_proxy env variable by default to each clab node
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Weber authored and Tobias Weber committed Dec 17, 2024
1 parent 0984943 commit 821ab8b
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,53 @@ func (c *CLab) createNodeCfg(nodeName string, nodeDef *types.NodeDefinition, idx
// Merge EnvVarFiles content and the existing env variable
nodeCfg.Env = utils.MergeStringMaps(envFileContent, nodeCfg.Env)

// Default set of no_proxy entries
noProxyDefaults := []string{"localhost", "127.0.0.1", "::1", "*.local"}

// check if either of the no_proxy variables exists
noProxyLower, existsLower := nodeCfg.Env["no_proxy"]
noProxyUpper, existsUpper := nodeCfg.Env["NO_PROXY"]
noProxy := ""
if existsLower {
noProxy = noProxyLower
for _, defaultValue := range noProxyDefaults {
if !strings.Contains(noProxy, defaultValue) {
noProxy=noProxy + "," + defaultValue
}
}
} else if existsUpper {
noProxy = noProxyUpper
for _, defaultValue := range noProxyDefaults {
if !strings.Contains(noProxy, defaultValue) {
noProxy=noProxy + "," + defaultValue
}
}
} else {
noProxy = strings.Join(noProxyDefaults, ",")
}

// add all clab nodes to the no_proxy variable, if they have a static IP assigned, add this as well
var noProxyList []string
for key := range c.Config.Topology.Nodes {
noProxyList = append(noProxyList, key)
ipv4address := c.Config.Topology.Nodes[key].GetMgmtIPv4()
if ipv4address != "" {
noProxyList = append(noProxyList, ipv4address)
}
ipv6address := c.Config.Topology.Nodes[key].GetMgmtIPv6()
if ipv6address != "" {
noProxyList = append(noProxyList, ipv6address)
}
}

// sort for better readability
sort.Strings(noProxyList)

noProxy = noProxy + "," + strings.Join(noProxyList, ",")

nodeCfg.Env["no_proxy"] = noProxy
nodeCfg.Env["NO_PROXY"] = noProxy

log.Debugf("node config: %+v", nodeCfg)

// process startup-config
Expand Down

0 comments on commit 821ab8b

Please sign in to comment.