Open dotwaffle opened 9 years ago
FYI, the changes I've made so far are:
commit b586a919f0722dc17be075e10936f560e89446f7
Author: Matthew Walster <mwalster@fastly.com>
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 <mwalster@fastly.com>
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"
I'm trying to add Arista EOS support, and I'm having trouble because I'm not able to see the ssh output. It would be great if there was a debug flag that spit everything into a logfile or to stdout.
For instance, the devices I'm logging into give me the unhelpful error:
I'm struggling to debug it, I think it might be something to do with the handling of "enable" but without further data I can't continue.
Any pointers?