Comments (1)
FYI, the changes I've made so far are:
commit b586a919f0722dc17be075e10936f560e89446f7
Author: Matthew Walster <[email protected]>
Date: Wed Jul 1 11:40:10 2015 +0000
Reference Arista in the main collection routine
diff --git a/sweet.go b/sweet.go
index 1c8b385..60b4b5c 100644
--- a/sweet.go
+++ b/sweet.go
@@ -227,6 +227,8 @@ func collectDevice(device DeviceConfig, Opts *SweetOptions) DeviceStatus {
c = newExternalCollector()
} else if device.Method == "junos" {
c = newJunOSCollector()
+ } else if device.Method == "arista" {
+ c = newAristaCollector()
} else {
status.State = StateError
status.ErrorMessage = fmt.Sprintf("Unknown access method: %s", device.Method)
commit 04d8d03b548cc20b9255ef50ff1fdee1e32cfe26
Author: Matthew Walster <[email protected]>
Date: Wed Jul 1 11:37:27 2015 +0000
Initial import of Arista model
diff --git a/arista.go b/arista.go
new file mode 100644
index 0000000..e37b4f8
--- /dev/null
+++ b/arista.go
@@ -0,0 +1,65 @@
+package sweet
+
+import (
+ "fmt"
+ "strings"
+)
+
+type Arista struct {
+}
+
+func newAristaCollector() Collector {
+ return Arista{}
+}
+
+func (collector Arista) Collect(device DeviceConfig) (map[string]string, error) {
+ result := make(map[string]string)
+
+ c, err := newSSHCollector(device)
+ if err != nil {
+ return result, fmt.Errorf("Error connecting to %s: %s", device.Hostname, err.Error())
+ }
+
+ if err := expect("assword:", c.Receive); err != nil {
+ return result, fmt.Errorf("Missing password prompt: %s", err.Error())
+ }
+ c.Send <- device.Config["pass"] + "\n"
+ multi := []string{"#", ">", "assword:"}
+ m, err := expectMulti(multi, c.Receive)
+ if err != nil {
+ return result, fmt.Errorf("Invalid response to password: %s", err.Error())
+ }
+ if m == "assword:" {
+ return result, fmt.Errorf("Bad username or password.")
+ } else if m == ">" {
+ c.Send <- "enable\n"
+ if err := expect("assword:", c.Receive); err != nil {
+ return result, fmt.Errorf("Missing enable password prompt: %s", err.Error())
+ }
+ c.Send <- device.Config["enable"] + "\n"
+ if err := expect("#", c.Receive); err != nil {
+ return result, fmt.Errorf("Enable attempt failed: %s", err.Error())
+ }
+ }
+ c.Send <- "terminal length 0\n"
+ if err := expect("#", c.Receive); err != nil {
+ return result, fmt.Errorf("Command 'terminal length 0' failed: %s", err.Error())
+ }
+ c.Send <- "show running-config\n"
+ result["config"], err = expectSaveTimeout("#", c.Receive, device.CommandTimeout)
+ if err != nil {
+ return result, fmt.Errorf("Command 'show running-config' failed: %s", err.Error())
+ }
+ c.Send <- "show version\n"
+ result["version"], err = expectSaveTimeout("#", c.Receive, device.CommandTimeout)
+ if err != nil {
+ return result, fmt.Errorf("Command 'show version' failed: %s", err.Error())
+ }
+
+ // cleanup config results
+ result["config"] = strings.TrimSpace(strings.TrimPrefix(result["config"], "show running-config"))
+
+ c.Send <- "exit\n"
+
+ return result, nil
+}
diff --git a/arista_test.go b/arista_test.go
new file mode 100644
index 0000000..d571969
--- /dev/null
+++ b/arista_test.go
@@ -0,0 +1,40 @@
+package sweet
+
+import (
+ "os"
+ "strings"
+ "testing"
+ "time"
+)
+
+func TestAristaGood(t *testing.T) {
+ d := new(DeviceConfig)
+ d.Config = make(map[string]string)
+ d.Method = "Arista"
+ d.Timeout = 10 * time.Second
+
+ if os.Getenv("SWEET_TEST_HOST") == "" {
+ t.Error("Test requries SWEET_TEST_HOST environment variable")
+ return
+ }
+ if os.Getenv("SWEET_TEST_USER") == "" {
+ t.Error("Test requries SWEET_TEST_USER environment variable")
+ return
+ }
+ if os.Getenv("SWEET_TEST_PASS") == "" {
+ t.Error("Test requries SWEET_TEST_PASS environment variable")
+ return
+ }
+
+ d.Hostname = os.Getenv("SWEET_TEST_HOST")
+ d.Config["user"] = os.Getenv("SWEET_TEST_USER")
+ d.Config["pass"] = os.Getenv("SWEET_TEST_PASS")
+
+ d.Target = d.Hostname
+
+ s := CollectArista(*d)
+ if !strings.Contains(s["config"], "end") {
+ t.Errorf("Config missing end at the end")
+ }
+
+}
and to reference that in main.go (which I won't commit):
13:26:09 [mwalster@mwmbp:~/Code/gohome/src/github.com/dotwaffle/sweet] arista(+1/-1) ± git diff
diff --git a/cmd/main.go b/cmd/main.go
index 776b8e2..35fac5b 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -4,8 +4,8 @@ package main
import (
"errors"
- "github.com/appliedtrust/sweet"
"github.com/docopt/docopt-go"
+ "github.com/dotwaffle/sweet"
"github.com/vaughan0/go-ini"
"log/syslog"
"os"
from sweet.
Related Issues (15)
- "show conf" does not work with Cisco NX-OS HOT 2
- Trailing prompt on Cisco config pull
- ntp clock-period causes commit spam
- Uptime causes commit spam
- backups halfway if # in config
- is this project still alive ? HOT 1
- runs, then exits with "exit status 128" HOT 3
- small changes create large diffs HOT 2
- Juniper & F5 Native Support HOT 2
- Cisco switches return no config HOT 6
- telnet? HOT 1
- webserver access password HOT 1
- Web interface wont start HOT 1
- Zombie SSH Processes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sweet.