Skip to content

Commit

Permalink
added runtime specific CLI spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Sep 11, 2021
1 parent faa25e3 commit 2e6ae5e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
4 changes: 2 additions & 2 deletions nodes/ceos/ceos.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ func createCEOSFiles(node *types.NodeConfig) error {
}

// ceosPostDeploy runs postdeploy actions which are required for ceos nodes
func ceosPostDeploy(_ context.Context, _ runtime.ContainerRuntime, node *types.NodeConfig) error {
d, err := utils.SpawnCLIviaExec("arista_eos", node.LongName)
func ceosPostDeploy(_ context.Context, r runtime.ContainerRuntime, node *types.NodeConfig) error {
d, err := utils.SpawnCLIviaExec("arista_eos", node.LongName, r.GetName())
if err != nil {
return err
}
Expand Down
11 changes: 8 additions & 3 deletions nodes/srl/srl.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,16 @@ func generateSRLTopologyFile(nodeType, labDir string, _ int) error {
}

// addDefaultConfig adds srl default configuration such as tls certs and gnmi/json-rpc
func addDefaultConfig(_ context.Context, _ runtime.ContainerRuntime, node *types.NodeConfig) error {
func addDefaultConfig(_ context.Context, r runtime.ContainerRuntime, node *types.NodeConfig) error {
// give srlinux 5 seconds to settle internal boot sequences
time.Sleep(time.Second * 5)

d, err := utils.SpawnCLIviaExec("nokia_srlinux", node.LongName)
// containerd needs to sleep a bit more
if r.GetName() == "containerd" {
time.Sleep(time.Second * 10)
}

d, err := utils.SpawnCLIviaExec("nokia_srlinux", node.LongName, r.GetName())
if err != nil {
return err
}
Expand All @@ -311,7 +316,7 @@ func addDefaultConfig(_ context.Context, _ runtime.ContainerRuntime, node *types
fmt.Sprintf("system json-rpc-server admin-state enable network-instance mgmt https admin-state enable tls-profile %s", tlsServerProfileName),
}

resp, err := d.SendConfigs(cfgs)
resp, err := d.SendConfigs(cfgs, base.WithSendEager(true))
if err != nil {
return err
} else if resp.Failed != nil {
Expand Down
21 changes: 17 additions & 4 deletions utils/networkcli.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utils

import (
"strings"
"time"

"github.com/scrapli/scrapligo/driver/base"
Expand All @@ -17,11 +18,24 @@ var (
"arista_eos": "Cli",
"nokia_srlinux": "sr_cli",
}

// map of the cli exec command and its argument per runtime
// which is used to spawn CLI session
CLIExecCommand = map[string]map[string]string{
"docker": {
"exec": "docker",
"open": "exec -it",
},
"containerd": {
"exec": "ctr",
"open": "-n clab task exec -t --exec-id clab",
},
}
)

// SpawnCLIviaExec spawns a CLI session over container runtime exec function
// end ensures the CLI is available to be used for sending commands over
func SpawnCLIviaExec(platform, contName string) (*network.Driver, error) {
func SpawnCLIviaExec(platform, contName, runtime string) (*network.Driver, error) {
var d *network.Driver
var err error

Expand Down Expand Up @@ -50,9 +64,8 @@ func SpawnCLIviaExec(platform, contName string) (*network.Driver, error) {
return nil, err
}

// TODO: implement for ctr (containerd)
execCmd := "docker"
openCmd := []string{"exec", "-it"}
execCmd := CLIExecCommand[runtime]["exec"]
openCmd := strings.Split(CLIExecCommand[runtime]["open"], " ")

t, _ := d.Transport.Impl.(transport.SystemTransport)
t.SetExecCmd(execCmd)
Expand Down

0 comments on commit 2e6ae5e

Please sign in to comment.