Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is right now a verbatim copy of the existing vr-csr kind. I expect they will diverge in the future though, so it is best to create a copy now rather than encourage branching logic in the same file.
- Loading branch information
Showing
2 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright 2020 Nokia | ||
// Licensed under the BSD 3-Clause License. | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
package vr_c8000v | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"path" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/srl-labs/containerlab/netconf" | ||
"github.com/srl-labs/containerlab/nodes" | ||
"github.com/srl-labs/containerlab/types" | ||
"github.com/srl-labs/containerlab/utils" | ||
) | ||
|
||
var ( | ||
kindnames = []string{"cisco_8000v", "vr-c8000v"} | ||
defaultCredentials = nodes.NewCredentials("admin", "admin") | ||
) | ||
|
||
const ( | ||
scrapliPlatformName = "cisco_iosxe" | ||
|
||
configDirName = "config" | ||
startupCfgFName = "startup-config.cfg" | ||
) | ||
|
||
// Register registers the node in the NodeRegistry. | ||
func Register(r *nodes.NodeRegistry) { | ||
r.Register(kindnames, func() nodes.Node { | ||
return new(vrC8000v) | ||
}, defaultCredentials) | ||
} | ||
|
||
type vrC8000v struct { | ||
nodes.DefaultNode | ||
} | ||
|
||
func (n *vrC8000v) Init(cfg *types.NodeConfig, opts ...nodes.NodeOption) error { | ||
// Init DefaultNode | ||
n.DefaultNode = *nodes.NewDefaultNode(n) | ||
// set virtualization requirement | ||
n.HostRequirements.VirtRequired = true | ||
|
||
n.Cfg = cfg | ||
for _, o := range opts { | ||
o(n) | ||
} | ||
// env vars are used to set launch.py arguments in vrnetlab container | ||
defEnv := map[string]string{ | ||
"CONNECTION_MODE": nodes.VrDefConnMode, | ||
"USERNAME": defaultCredentials.GetUsername(), | ||
"PASSWORD": defaultCredentials.GetPassword(), | ||
"DOCKER_NET_V4_ADDR": n.Mgmt.IPv4Subnet, | ||
"DOCKER_NET_V6_ADDR": n.Mgmt.IPv6Subnet, | ||
} | ||
n.Cfg.Env = utils.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, configDirName), ":/config")) | ||
|
||
if n.Cfg.Env["CONNECTION_MODE"] == "macvtap" { | ||
// mount dev dir to enable macvtap | ||
n.Cfg.Binds = append(n.Cfg.Binds, "/dev:/dev") | ||
} | ||
|
||
n.Cfg.Cmd = fmt.Sprintf("--username %s --password %s --hostname %s --connection-mode %s --trace", | ||
n.Cfg.Env["USERNAME"], n.Cfg.Env["PASSWORD"], n.Cfg.ShortName, n.Cfg.Env["CONNECTION_MODE"]) | ||
|
||
return nil | ||
} | ||
|
||
func (s *vrC8000v) PreDeploy(_ context.Context, params *nodes.PreDeployParams) error { | ||
utils.CreateDirectory(s.Cfg.LabDir, 0777) | ||
_, err := s.LoadOrGenerateCertificate(params.Cert, params.TopologyName) | ||
if err != nil { | ||
return nil | ||
} | ||
return nodes.LoadStartupConfigFileVr(s, configDirName, startupCfgFName) | ||
} | ||
|
||
func (n *vrC8000v) SaveConfig(_ context.Context) error { | ||
err := netconf.SaveConfig(n.Cfg.LongName, | ||
defaultCredentials.GetUsername(), | ||
defaultCredentials.GetPassword(), | ||
scrapliPlatformName, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
log.Infof("saved %s running configuration to startup configuration file\n", n.Cfg.ShortName) | ||
return nil | ||
} | ||
|
||
// CheckInterfaceName checks if a name of the interface referenced in the topology file correct. | ||
func (n *vrC8000v) CheckInterfaceName() error { | ||
return nodes.GenericVMInterfaceCheck(n.Cfg.ShortName, n.Endpoints) | ||
} |