Skip to content

Commit

Permalink
Add UpdateMgmtIntf func
Browse files Browse the repository at this point in the history
- Updates IOL mgmt interface IP addressing on boots that are NOT the first boot.
  • Loading branch information
kaelemc committed Dec 14, 2024
1 parent f1b6857 commit 3179409
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion nodes/iol/iol.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"strconv"
"strings"
"text/template"
"time"

"github.com/hairyhenderson/gomplate/v3"
"github.com/hairyhenderson/gomplate/v3/data"
Expand Down Expand Up @@ -69,11 +70,13 @@ type iol struct {
partialStartupCfg string
bootCfg string
interfaces []IOLInterface
firstBoot bool
}

func (n *iol) Init(cfg *types.NodeConfig, opts ...nodes.NodeOption) error {
// Init DefaultNode
n.DefaultNode = *nodes.NewDefaultNode(n)
n.firstBoot = false

n.Cfg = cfg
for _, o := range opts {
Expand Down Expand Up @@ -136,7 +139,17 @@ 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.GenBootConfig(ctx)
n.GenBootConfig(ctx)

// Must update mgmt IP if not first boot
if !n.firstBoot {
// iol has a 5sec boot delay, wait a few extra secs for the console
time.Sleep(7 * time.Second)

return n.UpdateMgmtIntf(ctx)
}

return nil
}

func (n *iol) CreateIOLFiles(ctx context.Context) error {
Expand All @@ -145,6 +158,7 @@ func (n *iol) CreateIOLFiles(ctx context.Context) error {
if !utils.FileExists(path.Join(n.Cfg.LabDir, n.nvramFile)) {
// create nvram file
utils.CreateFile(path.Join(n.Cfg.LabDir, n.nvramFile), "")
n.firstBoot = true
}

// create these files so the bind monut doesn't automatically
Expand Down Expand Up @@ -343,3 +357,11 @@ func (n *iol) CheckInterfaceName() error {
func isPartialConfigFile(c string) bool {
return strings.Contains(strings.ToUpper(c), ".PARTIAL")
}

func (n *iol) UpdateMgmtIntf(ctx context.Context) error {

mgmt_str := fmt.Sprintf("\renable\rconfig terminal\rinterface Ethernet0/0\rip address %s %s\ripv6 address %s/%d\rend\rwr\r",
n.Cfg.MgmtIPv4Address, utils.CIDRToDDN(n.Cfg.MgmtIPv4PrefixLength), n.Cfg.MgmtIPv6Address, n.Cfg.MgmtIPv6PrefixLength)

return n.Runtime.WriteToStdinNoWait(ctx, n.Cfg.ContainerID, []byte(mgmt_str))
}

0 comments on commit 3179409

Please sign in to comment.