Skip to content
Open
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
49 changes: 41 additions & 8 deletions nodes/fortinet_fortigate/fortigate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
package fortinet_fortigate

import (
"context"
"fmt"
"path"
"path/filepath"
"regexp"

"github.com/charmbracelet/log"
clabconstants "github.com/srl-labs/containerlab/constants"
clabnodes "github.com/srl-labs/containerlab/nodes"
clabtypes "github.com/srl-labs/containerlab/types"
clabutils "github.com/srl-labs/containerlab/utils"
Expand All @@ -25,8 +29,8 @@ var (

const (
scrapliPlatformName = "fortinet_fortios"
configDirName = "config"
startupCfgFName = "startup-config.cfg"
tftpDirName = "tftpboot"
licenseFileName = "appliance.lic"
generateable = true
generateIfFormat = "eth%d"
)
Expand Down Expand Up @@ -76,12 +80,6 @@ func (n *fortigate) Init(cfg *clabtypes.NodeConfig, opts ...clabnodes.NodeOption

n.Cfg.Env = clabutils.MergeStringMaps(defEnv, n.Cfg.Env)

// mount config dir to support startup-config functionality
n.Cfg.Binds = append(
n.Cfg.Binds,
fmt.Sprint(path.Join(n.Cfg.LabDir, n.ConfigDirName), ":/config"),
)

if n.Cfg.Env["CONNECTION_MODE"] == "macvtap" {
// mount dev dir to enable macvtap
n.Cfg.Binds = append(n.Cfg.Binds, "/dev:/dev")
Expand All @@ -101,3 +99,38 @@ func (n *fortigate) Init(cfg *clabtypes.NodeConfig, opts ...clabnodes.NodeOption

return nil
}

func (n *fortigate) PreDeploy(ctx context.Context, params *clabnodes.PreDeployParams) error {

err := n.VRNode.PreDeploy(ctx, params)
if err != nil {
return err
}

// mount config dir to support startup-config functionality
n.Cfg.Binds = append(
n.Cfg.Binds,
fmt.Sprint(path.Join(n.Cfg.LabDir, n.ConfigDirName), ":/config"),
)

cfg := n.Config()

if cfg.License != "" {
// copy license file to node specific lab directory
src := cfg.License
dst := filepath.Join(cfg.LabDir, tftpDirName, licenseFileName)
if err := clabutils.CopyFile(context.Background(), src, dst,
clabconstants.PermissionsFileDefault); err != nil {
return fmt.Errorf("file copy [src %s -> dst %s] failed %v", src, dst, err)
}
log.Debugf("CopyFile src %s -> dst %s succeeded", src, dst)
n.Cfg.Binds = append(
n.Cfg.Binds,
fmt.Sprint(path.Join(n.Cfg.LabDir, tftpDirName), ":/"+tftpDirName),
)
} else {
log.Debugf("No license configured")
}

return nil
}