Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per node cfg template #127

Merged
merged 2 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const (
dockerNetName = "clab"
dockerNetIPv4Addr = "172.20.20.0/24"
dockerNetIPv6Addr = "2001:172:20:20::/80"

defaultConfigTemplate = "/etc/containerlab/templates/srl/srlconfig.tpl"
)

// supported kinds
Expand Down Expand Up @@ -203,7 +205,15 @@ func (c *cLab) configInitialization(nodeCfg *NodeConfig, kind string) string {
if nodeCfg.Config != "" {
return nodeCfg.Config
}
return c.Config.Topology.Kinds[kind].Config
if kindConfig, ok := c.Config.Topology.Kinds[kind]; ok {
if kindConfig.Config != "" {
return kindConfig.Config
}
}
if c.Config.Topology.Defaults.Config != "" {
return c.Config.Topology.Defaults.Config
}
return defaultConfigTemplate
}

func (c *cLab) imageInitialization(nodeCfg *NodeConfig, kind string) string {
Expand Down
2 changes: 1 addition & 1 deletion clab/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (c *cLab) CreateNodeDirStructure(node *Node) (err error) {

// GenerateConfig generates configuration for the nodes
func (node *Node) generateConfig(dst string) error {
tpl, err := template.New("srlconfig.tpl").ParseFiles("/etc/containerlab/templates/srl/srlconfig.tpl")
tpl, err := template.New(fmt.Sprintf("config-template-%s", node.ShortName)).ParseFiles(node.Config)
if err != nil {
return err
}
Expand Down