-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #593 from srl-labs/ceos-postdep-scrapli
use scrapligo for ceos mgmt provisioning
- Loading branch information
Showing
7 changed files
with
118 additions
and
79 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
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
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
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,70 @@ | ||
package utils | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/scrapli/scrapligo/driver/base" | ||
"github.com/scrapli/scrapligo/driver/core" | ||
"github.com/scrapli/scrapligo/driver/network" | ||
"github.com/scrapli/scrapligo/transport" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/srl-labs/srlinux-scrapli" | ||
) | ||
|
||
var ( | ||
// map of commands per platform which start a CLI app | ||
NetworkOSCLICmd = map[string]string{ | ||
"arista_eos": "Cli", | ||
"nokia_srlinux": "sr_cli", | ||
} | ||
) | ||
|
||
// 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) { | ||
var d *network.Driver | ||
var err error | ||
|
||
switch platform { | ||
case "nokia_srlinux": | ||
d, err = srlinux.NewSRLinuxDriver( | ||
contName, | ||
base.WithAuthBypass(true), | ||
// disable transport timeout | ||
base.WithTimeoutTransport(0), | ||
) | ||
default: | ||
d, err = core.NewCoreDriver( | ||
contName, | ||
platform, | ||
base.WithAuthBypass(true), | ||
base.WithTimeoutTransport(0), | ||
) | ||
} | ||
|
||
if err != nil { | ||
log.Errorf("failed to create driver for device %s; error: %+v\n", err, contName) | ||
return nil, err | ||
} | ||
|
||
// TODO: implement for ctr (containerd) | ||
execCmd := "docker" | ||
openCmd := []string{"exec", "-it"} | ||
|
||
t, _ := d.Transport.(*transport.System) | ||
t.ExecCmd = execCmd | ||
t.OpenCmd = append(openCmd, contName, NetworkOSCLICmd[platform]) | ||
|
||
transportReady := false | ||
for !transportReady { | ||
if err := d.Open(); err != nil { | ||
log.Debugf("%s - Cli not ready (%s) - waiting.", contName, err) | ||
time.Sleep(time.Second * 2) | ||
continue | ||
} | ||
transportReady = true | ||
log.Debugf("%s - Cli ready.", contName) | ||
} | ||
|
||
return d, err | ||
} |