Skip to content

Commit

Permalink
srlv1
Browse files Browse the repository at this point in the history
  • Loading branch information
kellerza committed May 25, 2021
1 parent b4248c5 commit f51b5e0
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 7 deletions.
1 change: 1 addition & 0 deletions clab/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var defaultConfigTemplates = map[string]string{

// DefaultCredentials holds default username and password per each kind
var DefaultCredentials = map[string][]string{
"srl": {"admin", "admin"},
"vr-sros": {"admin", "admin"},
"vr-vmx": {"admin", "admin@123"},
"vr-xrv9k": {"clab", "clab@123"},
Expand Down
35 changes: 30 additions & 5 deletions clab/config/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type SshTransport struct {
// Contains the first read after connecting
LoginMessage SshReply

ConfigStart func(s *SshTransport)
ConfigCommit func(s *SshTransport) SshReply

// SSH parameters used in connect
// defualt: 22
Port int
Expand Down Expand Up @@ -156,8 +159,10 @@ func (t *SshTransport) Run(command string, timeout int) SshReply {
// Session NEEDS to be configurable for other kinds
// Part of the Transport interface
func (t *SshTransport) Write(snip *ConfigSnippet) error {
t.Run("/configure global", 2)
t.Run("discard", 2)
if t.ConfigStart == nil {
return fmt.Errorf("SSH Transport not ready %s", snip.TargetNode.Kind)
}
t.ConfigStart(t)

c, b := 0, 0
for _, l := range snip.Lines() {
Expand All @@ -170,9 +175,8 @@ func (t *SshTransport) Write(snip *ConfigSnippet) error {
t.Run(l, 3)
}

// Commit
commit := t.Run("commit", 10)
//commit += t.Run("", 10)
commit := t.ConfigCommit(t)

log.Infof("COMMIT %s - %d lines %d bytes\n%s", snip, c, b, commit.result)
return nil
}
Expand Down Expand Up @@ -278,3 +282,24 @@ func (ses *SshSession) Close() {
log.Debugf("Closing session")
ses.Session.Close()
}

func (s *SshTransport) SetupKind(kind string) {
switch kind {
case "srl":
s.ConfigStart = func(s *SshTransport) {
s.Run("enter candidate", 10)
}
s.ConfigCommit = func(s *SshTransport) SshReply {
return s.Run("commit now", 10)
}
case "vr-sros":
s.ConfigStart = func(s *SshTransport) {
s.Run("/configure global", 2)
s.Run("discard", 1)
}
s.ConfigCommit = func(s *SshTransport) SshReply {
return s.Run("commit", 10)
}

}
}
2 changes: 2 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ func newSSHTransport(node *clab.Node) (*config.SshTransport, error) {
c.SshConfig,
clab.DefaultCredentials[node.Kind][0],
clab.DefaultCredentials[node.Kind][1])

c.SetupKind(node.Kind)
return c, nil
}
return nil, fmt.Errorf("no tranport implemented for kind: %s", kind)
Expand Down
14 changes: 14 additions & 0 deletions templates/srl/base-link.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{ expect .port "^ethernet-\\d+/\\d+$" }}
{{ expect .name "string" }}
{{ expect .ip "ip" }}
{{ optional .vlan "0-4095" }}

#enter candidate
set / interface {{ .port }} ethernet-1/1
set / interface {{ .port }} admin-state enable
set / interface {{ .port }} subinterface 0
set / interface {{ .port }} subinterface 0 ipv4
set / interface {{ .port }} subinterface 0 ipv4 address {{ .ip }}
set / network-instance default
set / network-instance default interface {{ .port }}.{{ default 0 .vlan }}
#commit now
Empty file added templates/srl/base-node.tmpl
Empty file.
5 changes: 3 additions & 2 deletions templates/vr-sros/base-link.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{ optional .vlan "1-4096" }}
{{ optional .isis_iid "0-32" }}
{{ expect .port "^\\d+/\\d/" }}
{{ expect .name "string" }}
{{ expect .ip "ip" }}
{{ optional .vlan "0-4096" }}
{{ optional .isis_iid "0-32" }}

{{ if contains "/c" .port }}
/configure port {{ slice 0 -2 .port }} admin-state enable
Expand Down

0 comments on commit f51b5e0

Please sign in to comment.