Closed vincentbernat closed 10 months ago
Hi @vincentbernat can you show me how you set up the platform in your Go code?
t.Logf("SRLinux is listening at %s:%d", srLinuxHostname, srLinuxPort)
logger, err := logging.NewInstance(
logging.WithLogger(t.Log),
logging.WithLevel(logging.Info),
)
if err != nil {
t.Fatalf("NewInstance() error:\n%+v", err)
}
plat, err := platform.NewPlatform(
"nokia_srl", srLinuxHostname,
options.WithPort(srLinuxPort),
options.WithAuthNoStrictKey(),
options.WithAuthUsername("admin"),
options.WithAuthPassword("NokiaSrl1!"),
options.WithTransportType(transport.StandardTransport),
options.WithLogger(logger),
)
if err != nil {
t.Fatalf("NewPlatform() error:\n%+v", err)
}
driver, err := plat.GetNetworkDriver()
if err != nil {
t.Fatalf("GetNetworkDriver() error:\n%+v", err)
}
err = driver.Open()
if err != nil {
t.Fatalf("Open() error:\n%+v", err)
}
defer driver.Close()
It is expected to receive failures until you have a complete command. SR Linux by default has disabled complete-on-space, because we find it counter-productive for CLI users, given that autocompletion and suggestions are in place.
With this said, here is an example that works just fine:
package main
import (
"fmt"
"github.com/scrapli/scrapligo/driver/options"
"github.com/scrapli/scrapligo/transport"
"github.com/scrapli/scrapligo/platform"
)
func main() {
p, err := platform.NewPlatform(
// cisco_iosxe refers to the included cisco iosxe platform definition
"nokia_srl",
"clab-srl-srl",
options.WithAuthNoStrictKey(),
options.WithAuthUsername("admin"),
options.WithAuthPassword("NokiaSrl1!"),
options.WithTransportType(transport.StandardTransport),
)
if err != nil {
fmt.Printf("failed to create platform; error: %+v\n", err)
return
}
// fetch the network driver instance from the platform. you need to call this method explicitly
// because the platform may be generic or network -- by having the explicit method to fetch the
// driver you can avoid having to type cast things yourself. if you had a generic driver based
// platform you could call `GetGenericDriver` instead.
d, err := p.GetNetworkDriver()
if err != nil {
fmt.Printf("failed to fetch network driver from the platform; error: %+v\n", err)
return
}
err = d.Open()
if err != nil {
fmt.Printf("failed to open driver; error: %+v\n", err)
return
}
defer d.Close()
// send a command -- as this is a driver created from a *platform* it will have some things
// already done for us -- including disabling paging, so this command that would produce more
// output than the default terminal lines will not cause any issues.
r, err := d.SendCommand("info from state system app-management application mgmt_server state")
if err != nil {
fmt.Printf("failed to send command; error: %+v\n", err)
return
}
if r.Failed != nil {
fmt.Printf("response object indicates failure: %+v\n", r.Failed)
return
}
fmt.Printf(
"sent command '%s', output received (SendCommand):\n %s\n\n\n",
r.Input,
r.Result,
)
}
Output:
go run private/main.go
sent command 'info from state system app-management application mgmt_server state', output received (SendCommand):
system {
app-management {
application mgmt_server {
state running
}
}
}
I am a bit confused since I am now unable to reproduce the issue, but I have configured the container in the meantime. I have tried with a fresh container and I didn't run into the problem either. Note that my problem was not that the command was unsuccessful, it was just stuck. See the last line of log: there is a channel write
and no channel read
.
BTW, I thought that enter candidate
and load factory auto-commit
would restore the initial configuration, but this is not the case.
I see, tbh I don't use bare docker-based srl, always via containerlab, because there we init the system with some defaults enabling gnmi, etc.
Feel free to close this and reopen if/when the same issue occurs.
Hey!
On SR Linux:
I get:
And nothing else after that. The target is SR Linux 23.7.1 as a fresh Docker container.