Skip to content

Commit

Permalink
Decouple interface and startup cfg generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaelemc committed Dec 13, 2024
1 parent fe417ae commit 8eff445
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions nodes/iol/iol.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type iol struct {
nvramFile string
partialStartupCfg string
bootCfg string
interfaces []IOLInterface
}

func (n *iol) Init(cfg *types.NodeConfig, opts ...nodes.NodeOption) error {
Expand Down Expand Up @@ -135,7 +136,7 @@ func (n *iol) PreDeploy(ctx context.Context, params *nodes.PreDeployParams) erro
func (n *iol) PostDeploy(ctx context.Context, params *nodes.PostDeployParams) error {
log.Infof("Running postdeploy actions for Cisco IOL '%s' node", n.Cfg.ShortName)

return n.GenInterfaceConfig(ctx)
return n.GenBootConfig(ctx)
}

func (n *iol) CreateIOLFiles(ctx context.Context) error {
Expand All @@ -149,10 +150,8 @@ func (n *iol) CreateIOLFiles(ctx context.Context) error {
// create these files so the bind monut doesn't automatically
// make folders.
utils.CreateFile(path.Join(n.Cfg.LabDir, "boot_config.txt"), "")
utils.CreateFile(path.Join(n.Cfg.LabDir, "iouyap.ini"), "")
utils.CreateFile(path.Join(n.Cfg.LabDir, "NETMAP"), "")

return nil
return n.GenInterfaceConfig(ctx)
}

// Generate interfaces configuration for IOL (and iouyap/netmap).
Expand All @@ -163,8 +162,6 @@ func (n *iol) GenInterfaceConfig(_ context.Context) error {

slot, port := 0, 0

IOLInterfaces := []IOLInterface{}

// Regexp to pull number out of linux'ethX' interface naming
IntfRegExpr := regexp.MustCompile("[0-9]+")

Expand All @@ -182,7 +179,7 @@ func (n *iol) GenInterfaceConfig(_ context.Context) error {
netmapdata += fmt.Sprintf("%s:%d/%d 513:%d/%d\n", n.Pid, slot, port, slot, port)

// populate template array for config
IOLInterfaces = append(IOLInterfaces,
n.interfaces = append(n.interfaces,
IOLInterface{
intf.GetIfaceName(),
x,
Expand All @@ -194,9 +191,16 @@ func (n *iol) GenInterfaceConfig(_ context.Context) error {
}

// create IOUYAP and NETMAP file for interface mappings
utils.CreateFile(path.Join(n.Cfg.LabDir, "iouyap.ini"), iouyapData)
utils.CreateFile(path.Join(n.Cfg.LabDir, "NETMAP"), netmapdata)
err := utils.CreateFile(path.Join(n.Cfg.LabDir, "iouyap.ini"), iouyapData)
if err != nil {
return err
}
err = utils.CreateFile(path.Join(n.Cfg.LabDir, "NETMAP"), netmapdata)

return err
}

func (n *iol) GenBootConfig(_ context.Context) error {
n.bootCfg = cfgTemplate

if n.Cfg.StartupConfig != "" {
Expand All @@ -222,7 +226,7 @@ func (n *iol) GenInterfaceConfig(_ context.Context) error {
MgmtIPv6Addr: n.Cfg.MgmtIPv6Address,
MgmtIPv6PrefixLen: n.Cfg.MgmtIPv6PrefixLength,
MgmtIPv6GW: n.Cfg.MgmtIPv6Gateway,
DataIFaces: IOLInterfaces,
DataIFaces: n.interfaces,
PartialCfg: n.partialStartupCfg,
}

Expand All @@ -236,10 +240,7 @@ func (n *iol) GenInterfaceConfig(_ context.Context) error {
return err
}

// write it to disk
utils.CreateFile(path.Join(n.Cfg.LabDir, "boot_config.txt"), buf.String())

return err
return utils.CreateFile(path.Join(n.Cfg.LabDir, "boot_config.txt"), buf.String())
}

type IOLTemplateData struct {
Expand Down

0 comments on commit 8eff445

Please sign in to comment.