Skip to content

Commit

Permalink
Merge pull request #83 from scrapli/platform-type-and-win
Browse files Browse the repository at this point in the history
Platform type and win
  • Loading branch information
carlmontanari authored Jul 10, 2022
2 parents fa8e699 + d74dd40 commit 0081d91
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 102 deletions.
1 change: 1 addition & 0 deletions assets/platforms/arista_eos.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
platform-type: 'arista_eos'
default:
driver-type: 'network'
privilege-levels:
Expand Down
1 change: 1 addition & 0 deletions assets/platforms/cisco_iosxe.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
platform-type: 'cisco_iosxe'
default:
driver-type: 'network'
privilege-levels:
Expand Down
1 change: 1 addition & 0 deletions assets/platforms/cisco_iosxr.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
platform-type: 'cisco_iosxr'
default:
driver-type: 'network'
privilege-levels:
Expand Down
1 change: 1 addition & 0 deletions assets/platforms/cisco_nxos.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
platform-type: 'cisco_nxos'
default:
driver-type: 'network'
privilege-levels:
Expand Down
9 changes: 9 additions & 0 deletions assets/platforms/example.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
---
# platform-type is the "name" or "type" of the platform -- it should match the name of the yaml file
# if it is an embedded asset, it should be of the format vendor_os, i.e. cisco_iosxe, or nokia_srl.
platform-type: 'scrapligo_example'
default:
# driver-type can be either "generic" or "network" for the corresponding scrapli driver base class
driver-type: 'network'
Expand Down Expand Up @@ -75,3 +78,9 @@ default:
- operation: 'channel.write'
input: 'exit'
- operation: 'channel.return'

# options is a list of options that contain a option name and a value, see platform/options.go
# for the available options
options:
- option: port
value: 2022
1 change: 1 addition & 0 deletions assets/platforms/ipinfusion_ocnos.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
platform-type: 'ipinfusion_ocnos'
default:
driver-type: 'network'
privilege-levels:
Expand Down
1 change: 1 addition & 0 deletions assets/platforms/juniper_junos.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
platform-type: 'juniper_junos'
default:
driver-type: 'network'
privilege-levels:
Expand Down
1 change: 1 addition & 0 deletions assets/platforms/nokia_srl.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
platform-type: 'nokia_srl'
default:
driver-type: 'network'
privilege-levels:
Expand Down
1 change: 1 addition & 0 deletions assets/platforms/nokia_sros.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
platform-type: 'nokia_sros'
default:
driver-type: 'network'
privilege-levels:
Expand Down
1 change: 1 addition & 0 deletions assets/platforms/nokia_sros_classic.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
platform-type: 'nokia_sros_classic'
default:
driver-type: 'network'
privilege-levels:
Expand Down
1 change: 1 addition & 0 deletions assets/platforms/paloalto_panos.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
platform-type: 'paloalto_panos'
default:
driver-type: 'network'
privilege-levels:
Expand Down
16 changes: 13 additions & 3 deletions platform/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func NewPlatform(f interface{}, host string, opts ...util.Option) (*Platform, er
}

p := pd.Default
p.platformType = pd.PlatformType

err = setDriver(host, p, opts...)
if err != nil {
Expand All @@ -173,15 +174,18 @@ func NewPlatform(f interface{}, host string, opts ...util.Option) (*Platform, er

// Definition is a struct representing a JSON or YAML platform definition file.
type Definition struct {
Default *Platform `json:"default" yaml:"default"`
Variants map[string]*Platform `json:"variants" yaml:"variants"`
PlatformType string `json:"platform-type" yaml:"platform-type"`
Default *Platform `json:"default" yaml:"default"`
Variants map[string]*Platform `json:"variants" yaml:"variants"`
}

// Platform is a struct that contains JSON or YAML data that represent the attributes required to
// create a generic or network driver to connect to a given device type.
type Platform struct {
platformType string

// DriverType generic||network
DriverType string `yaml:"driver-type"`
DriverType string `json:"driver-type" yaml:"driver-type"`

FailedWhenContains []string `json:"failed-when-contains" yaml:"failed-when-contains"`
OnOpen onXDefinitions `json:"on-open" yaml:"on-open"`
Expand Down Expand Up @@ -298,3 +302,9 @@ func (p *Platform) AsOptions() []util.Option {

return opts
}

// GetPlatformType returns the string name of the platform definition/type, i.e. "cisco_iosxe" or
// "nokia_srl".
func (p *Platform) GetPlatformType() string {
return p.platformType
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"DriverType":"network","failed-when-contains":["% Ambiguous command","% Incomplete command","% Invalid input detected","% Unknown command"],"on-open":null,"on-close":null,"privilege-levels":{"configuration":{"Name":"configuration","Pattern":"(?im)^[\\w.\\-@/:]{1,63}\\([\\w.\\-@/:+]{0,32}\\)#$","NotContains":["tcl)"],"PreviousPriv":"privilege-exec","Deescalate":"end","Escalate":"configure terminal","EscalateAuth":false,"EscalatePrompt":""},"exec":{"Name":"exec","Pattern":"(?im)^[\\w.\\-@/:]{1,63}\u003e$","NotContains":null,"PreviousPriv":"","Deescalate":"","Escalate":"","EscalateAuth":false,"EscalatePrompt":""},"privilege-exec":{"Name":"privilege-exec","Pattern":"(?im)^[\\w.\\-@/:]{1,63}#$","NotContains":null,"PreviousPriv":"exec","Deescalate":"disable","Escalate":"enable","EscalateAuth":true,"EscalatePrompt":"(?im)^(?:enable\\s){0,1}password:\\s?$"},"tclsh":{"Name":"tclsh","Pattern":"(?im)^([\\w.\\-@/+\u003e:]+\\(tcl\\)[\u003e#]|\\+\u003e)$","NotContains":null,"PreviousPriv":"privilege-exec","Deescalate":"tclquit","Escalate":"tclsh","EscalateAuth":false,"EscalatePrompt":""}},"default-desired-privilege-level":"privilege-exec","network-on-open":[{"operation":"acquire-priv"},{"command":"terminal width 512","operation":"driver.send-command"},{"command":"terminal length 0","operation":"driver.send-command"}],"network-on-close":[{"operation":"acquire-priv"},{"input":"exit","operation":"channel.write"},{"operation":"channel.return"}],"options":null}
{"driver-type":"network","failed-when-contains":["% Ambiguous command","% Incomplete command","% Invalid input detected","% Unknown command"],"on-open":null,"on-close":null,"privilege-levels":{"configuration":{"Name":"configuration","Pattern":"(?im)^[\\w.\\-@/:]{1,63}\\([\\w.\\-@/:+]{0,32}\\)#$","NotContains":["tcl)"],"PreviousPriv":"privilege-exec","Deescalate":"end","Escalate":"configure terminal","EscalateAuth":false,"EscalatePrompt":""},"exec":{"Name":"exec","Pattern":"(?im)^[\\w.\\-@/:]{1,63}\u003e$","NotContains":null,"PreviousPriv":"","Deescalate":"","Escalate":"","EscalateAuth":false,"EscalatePrompt":""},"privilege-exec":{"Name":"privilege-exec","Pattern":"(?im)^[\\w.\\-@/:]{1,63}#$","NotContains":null,"PreviousPriv":"exec","Deescalate":"disable","Escalate":"enable","EscalateAuth":true,"EscalatePrompt":"(?im)^(?:enable\\s){0,1}password:\\s?$"},"tclsh":{"Name":"tclsh","Pattern":"(?im)^([\\w.\\-@/+\u003e:]+\\(tcl\\)[\u003e#]|\\+\u003e)$","NotContains":null,"PreviousPriv":"privilege-exec","Deescalate":"tclquit","Escalate":"tclsh","EscalateAuth":false,"EscalatePrompt":""}},"default-desired-privilege-level":"privilege-exec","network-on-open":[{"operation":"acquire-priv"},{"command":"terminal width 512","operation":"driver.send-command"},{"command":"terminal length 0","operation":"driver.send-command"}],"network-on-close":[{"operation":"acquire-priv"},{"input":"exit","operation":"channel.write"},{"operation":"channel.return"}],"options":null}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"DriverType":"network","failed-when-contains":["% Ambiguous command","% Incomplete command","% Invalid input detected","% Unknown command"],"on-open":null,"on-close":null,"privilege-levels":{"configuration":{"Name":"configuration","Pattern":"(?im)^[\\w.\\-@/:]{1,63}\\([\\w.\\-@/:+]{0,32}\\)#$","NotContains":["tcl)"],"PreviousPriv":"privilege-exec","Deescalate":"end","Escalate":"configure terminal","EscalateAuth":false,"EscalatePrompt":""},"exec":{"Name":"exec","Pattern":"(?im)^[\\w.\\-@/:]{1,63}\u003e$","NotContains":null,"PreviousPriv":"","Deescalate":"","Escalate":"","EscalateAuth":false,"EscalatePrompt":""},"privilege-exec":{"Name":"privilege-exec","Pattern":"(?im)^[\\w.\\-@/:]{1,63}#$","NotContains":null,"PreviousPriv":"exec","Deescalate":"disable","Escalate":"enable","EscalateAuth":true,"EscalatePrompt":"^(?:enable\\s){0,1}password:\\s?$"},"tclsh":{"Name":"tclsh","Pattern":"(?im)^([\\w.\\-@/+\u003e:]+\\(tcl\\)[\u003e#]|\\+\u003e)$","NotContains":null,"PreviousPriv":"privilege-exec","Deescalate":"tclquit","Escalate":"tclsh","EscalateAuth":false,"EscalatePrompt":""}},"default-desired-privilege-level":"privilege-exec","network-on-open":[{"operation":"acquire-priv"},{"command":"terminal width 512","operation":"driver.send-command"},{"command":"terminal length 0","operation":"driver.send-command"}],"network-on-close":[{"operation":"acquire-priv"},{"input":"exit","operation":"channel.write"},{"operation":"channel.return"}],"options":null}
{"driver-type":"network","failed-when-contains":["% Ambiguous command","% Incomplete command","% Invalid input detected","% Unknown command"],"on-open":null,"on-close":null,"privilege-levels":{"configuration":{"Name":"configuration","Pattern":"(?im)^[\\w.\\-@/:]{1,63}\\([\\w.\\-@/:+]{0,32}\\)#$","NotContains":["tcl)"],"PreviousPriv":"privilege-exec","Deescalate":"end","Escalate":"configure terminal","EscalateAuth":false,"EscalatePrompt":""},"exec":{"Name":"exec","Pattern":"(?im)^[\\w.\\-@/:]{1,63}\u003e$","NotContains":null,"PreviousPriv":"","Deescalate":"","Escalate":"","EscalateAuth":false,"EscalatePrompt":""},"privilege-exec":{"Name":"privilege-exec","Pattern":"(?im)^[\\w.\\-@/:]{1,63}#$","NotContains":null,"PreviousPriv":"exec","Deescalate":"disable","Escalate":"enable","EscalateAuth":true,"EscalatePrompt":"^(?:enable\\s){0,1}password:\\s?$"},"tclsh":{"Name":"tclsh","Pattern":"(?im)^([\\w.\\-@/+\u003e:]+\\(tcl\\)[\u003e#]|\\+\u003e)$","NotContains":null,"PreviousPriv":"privilege-exec","Deescalate":"tclquit","Escalate":"tclsh","EscalateAuth":false,"EscalatePrompt":""}},"default-desired-privilege-level":"privilege-exec","network-on-open":[{"operation":"acquire-priv"},{"command":"terminal width 512","operation":"driver.send-command"},{"command":"terminal length 0","operation":"driver.send-command"}],"network-on-close":[{"operation":"acquire-priv"},{"input":"exit","operation":"channel.write"},{"operation":"channel.return"}],"options":null}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"DriverType":"network","failed-when-contains":["% Ambiguous command","% Incomplete command","% Invalid input detected","% Unknown command"],"on-open":null,"on-close":null,"privilege-levels":{"overwriteprivs":{"Name":"overwriteprivs","Pattern":"(?im)^[\\w.\\-@/:]{1,63}\u003e$","NotContains":null,"PreviousPriv":"","Deescalate":"","Escalate":"","EscalateAuth":false,"EscalatePrompt":""}},"default-desired-privilege-level":"privilege-exec","network-on-open":[{"operation":"acquire-priv"},{"command":"terminal width 512","operation":"driver.send-command"},{"command":"terminal length 0","operation":"driver.send-command"}],"network-on-close":[{"operation":"acquire-priv"},{"input":"exit","operation":"channel.write"},{"operation":"channel.return"}],"options":null}
{"driver-type":"network","failed-when-contains":["% Ambiguous command","% Incomplete command","% Invalid input detected","% Unknown command"],"on-open":null,"on-close":null,"privilege-levels":{"overwriteprivs":{"Name":"overwriteprivs","Pattern":"(?im)^[\\w.\\-@/:]{1,63}\u003e$","NotContains":null,"PreviousPriv":"","Deescalate":"","Escalate":"","EscalateAuth":false,"EscalatePrompt":""}},"default-desired-privilege-level":"privilege-exec","network-on-open":[{"operation":"acquire-priv"},{"command":"terminal width 512","operation":"driver.send-command"},{"command":"terminal length 0","operation":"driver.send-command"}],"network-on-close":[{"operation":"acquire-priv"},{"input":"exit","operation":"channel.write"},{"operation":"channel.return"}],"options":null}
3 changes: 0 additions & 3 deletions transport/factory.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !windows
// +build !windows

package transport

import (
Expand Down
90 changes: 0 additions & 90 deletions transport/factory_windows.go

This file was deleted.

3 changes: 0 additions & 3 deletions transport/system.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build !windows
// +build !windows

package transport

import (
Expand Down

0 comments on commit 0081d91

Please sign in to comment.