diff --git a/nodes/fortinet_fortigate/fortigate.go b/nodes/fortinet_fortigate/fortigate.go index 72cc1037f5..23eeb93748 100644 --- a/nodes/fortinet_fortigate/fortigate.go +++ b/nodes/fortinet_fortigate/fortigate.go @@ -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" @@ -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" ) @@ -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") @@ -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 +}