Skip to content

Commit

Permalink
vars
Browse files Browse the repository at this point in the history
  • Loading branch information
kellerza committed Jul 7, 2021
1 parent 01c08d9 commit 31cb5f1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions clab/config/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func PrepareVars(nodes map[string]nodes.Node, links map[int]*types.Link) map[str
if _, ok := res[name]["role"]; !ok {
res[name]["role"] = nodeCfg.Kind
}
// Add the map of all nodes to each node
res[name]["nodes"] = res
}

// prepare all links
Expand All @@ -48,6 +50,8 @@ func PrepareVars(nodes map[string]nodes.Node, links map[int]*types.Link) map[str
if err != nil {
log.Errorf("cannot prepare link vars for %d. %s: %s", lIdx, link.String(), err)
}
varsA["far"] = res[link.B.Node.ShortName]
varsB["far"] = res[link.A.Node.ShortName]
res[link.A.Node.ShortName]["links"] = append(res[link.A.Node.ShortName]["links"].([]interface{}), varsA)
res[link.B.Node.ShortName]["links"] = append(res[link.B.Node.ShortName]["links"].([]interface{}), varsB)
}
Expand All @@ -56,9 +60,9 @@ func PrepareVars(nodes map[string]nodes.Node, links map[int]*types.Link) map[str

// Prepare variables for a specific link
func prepareLinkVars(lIdx int, link *types.Link, varsA, varsB map[string]interface{}) error {
varsA["far"] = link.B.Node
varsB["far"] = link.A.Node

// Add a key/value(s) pairs to the links vars (varsA & varsB)
// If multiple vars are specified, each links also gets the far end value
addV := func(key string, v1 interface{}, v2 ...interface{}) {
varsA[key] = v1
if len(v2) == 0 {
Expand Down

0 comments on commit 31cb5f1

Please sign in to comment.