11package commando
22
33import (
4- "github.com/scrapli/scrapligo/driver/base"
5- "github.com/scrapli/scrapligo/driver/core"
64 "github.com/scrapli/scrapligo/driver/network"
5+ "github.com/scrapli/scrapligo/driver/options"
6+ "github.com/scrapli/scrapligo/platform"
77 "github.com/scrapli/scrapligo/transport"
8+ "github.com/scrapli/scrapligo/util"
89 log "github.com/sirupsen/logrus"
9- "github.com/srl-labs/srlinux-scrapli"
1010)
1111
1212func (app * appCfg ) validTransport (t string ) bool {
1313 switch t {
14- case transport .SystemTransportName :
14+ case transport .SystemTransport :
1515 return true
16- case transport .StandardTransportName :
16+ case transport .StandardTransport :
1717 return true
18- case transport .TelnetTransportName :
18+ case transport .TelnetTransport :
1919 return true
2020 default :
2121 return false
2222 }
2323}
2424
25- func (app * appCfg ) loadCredentials (o []base .Option , c string ) ([]base .Option , error ) {
25+ func (app * appCfg ) loadCredentials (o []util .Option , c string ) ([]util .Option , error ) {
2626 creds , ok := app .credentials [c ]
2727 if ! ok {
2828 return o , errInvalidCredentialsName
2929 }
3030
3131 if creds .Username != "" {
32- o = append (o , base .WithAuthUsername (creds .Username ))
32+ o = append (o , options .WithAuthUsername (creds .Username ))
3333 }
3434
3535 if creds .Password != "" {
36- o = append (o , base .WithAuthPassword (creds .Password ))
36+ o = append (o , options .WithAuthPassword (creds .Password ))
3737 }
3838
3939 if creds .SecondaryPassword != "" {
40- o = append (o , base .WithAuthSecondary (creds .SecondaryPassword ))
40+ o = append (o , options .WithAuthSecondary (creds .SecondaryPassword ))
4141 }
4242
4343 if creds .PrivateKey != "" {
44- o = append (o , base .WithAuthPrivateKey (creds .PrivateKey ))
44+ o = append (o , options .WithAuthPrivateKey (creds .PrivateKey , "" ))
4545 }
4646
4747 return o , nil
4848}
4949
50- func (app * appCfg ) loadTransport (o []base .Option , t string ) ([]base .Option , error ) {
51- // default to strict key false and standard transport, so load those into options first
50+ func (app * appCfg ) loadTransport (o []util .Option , t string ) ([]util .Option , error ) {
51+ // default to standard transport, so load those into options first
5252 o = append (
5353 o ,
54- base .WithTransportType (transport .StandardTransportName ),
55- base .WithAuthStrictKey (false ),
54+ options .WithTransportType (transport .StandardTransport ),
5655 )
5756
5857 transp , ok := app .transports [t ]
@@ -66,31 +65,31 @@ func (app *appCfg) loadTransport(o []base.Option, t string) ([]base.Option, erro
6665 }
6766
6867 if transp .Port != 0 {
69- o = append (o , base .WithPort (transp .Port ))
68+ o = append (o , options .WithPort (transp .Port ))
7069 }
7170
72- if transp .StrictKey {
73- o = append (o , base . WithAuthStrictKey ( transp . StrictKey ))
71+ if ! transp .StrictKey {
72+ o = append (o , options . WithAuthNoStrictKey ( ))
7473 }
7574
7675 if transp .SSHConfigFile != "" {
77- o = append (o , base .WithSSHConfigFile (transp .SSHConfigFile ))
76+ o = append (o , options .WithSSHConfigFile (transp .SSHConfigFile ))
7877 }
7978
8079 if transp .TransportType != "" {
8180 if ! app .validTransport (transp .TransportType ) {
8281 return nil , errInvalidTransport
8382 }
8483
85- o = append (o , base .WithTransportType (transp .TransportType ))
84+ o = append (o , options .WithTransportType (transp .TransportType ))
8685 }
8786
8887 return o , nil
8988}
9089
9190// loadOptions loads options from the provided inventory.
92- func (app * appCfg ) loadOptions (d * device ) ([]base .Option , error ) {
93- var o []base .Option
91+ func (app * appCfg ) loadOptions (d * device ) ([]util .Option , error ) {
92+ var o []util .Option
9493
9594 var err error
9695
@@ -133,22 +132,19 @@ func (app *appCfg) openCoreConn(name string, d *device) (*network.Driver, error)
133132 return nil , err
134133 }
135134
136- switch d .Platform {
137- case "nokia_srlinux" :
138- driver , err = srlinux .NewSRLinuxDriver (
139- d .Address ,
140- o ... ,
141- )
142- default :
143- driver , err = core .NewCoreDriver (
144- d .Address ,
145- d .Platform ,
146- o ... ,
147- )
135+ plat , err := platform .NewPlatform (
136+ d .Platform ,
137+ d .Address ,
138+ o ... ,
139+ )
140+ if err != nil {
141+ log .Errorf ("failed to create platform instance for device %s; error: %+v\n " , err , name )
142+ return nil , err
148143 }
149144
145+ driver , err = plat .GetNetworkDriver ()
150146 if err != nil {
151- log .Errorf ("failed to create driver for device %s; error: %+v\n " , err , name )
147+ log .Errorf ("failed to create driver instance for device %s; error: %+v\n " , err , name )
152148 return nil , err
153149 }
154150
0 commit comments