Skip to content

Instantly share code, notes, and snippets.

@burnyd
Created January 14, 2022 18:42
Show Gist options
  • Save burnyd/4d742ecbd2010d5e725f3649954f7370 to your computer and use it in GitHub Desktop.
Save burnyd/4d742ecbd2010d5e725f3649954f7370 to your computer and use it in GitHub Desktop.
goeapi examples
package main
import (
"fmt"
"github.com/aristanetworks/goeapi"
)
type Conn struct {
Transport string
Host string
Username string
Password string
Port int
}
func main() {
Dev := Conn{
Transport: "http",
Host: "172.20.20.2",
Password: "admin",
Username: "admin",
Port: 80,
}
connect, err := goeapi.Connect(Dev.Transport, Dev.Host, Dev.Username, Dev.Password, Dev.Port)
if err != nil {
fmt.Println(err)
}
enable, err := connect.Enable([]string{"show running-config"})
if err != nil {
fmt.Println(err)
}
getconfig, err := connect.GetConfig("running-config", "", "text")
if err != nil {
fmt.Println(err)
}
for k, v := range enable {
fmt.Println(k, v)
}
fmt.Println(getconfig["output"])
runcommands, err := connect.RunCommands([]string{"show version"}, "text")
if err != nil {
fmt.Println(err)
}
fmt.Println(runcommands.Result)
}
// Enable
0 map[command:show running-config result:! Command: show running-config
! device: ceos1 (cEOSLab, EOS-4.26.0F-21792469.4260F (engineering build))
!
transceiver qsfp default-mode 4x10G
!
service routing protocols model multi-agent
!
hostname ceos1
!
spanning-tree mode mstp
!
no aaa root
!
username admin privilege 15 role network-admin secret sha512 $6$S1jDtSEN/M3/VEsP$fNT4jByGEaYNlEnDxw4qCAyV3dsc/JH5Q7nLLStzZIo0TwUQ3aPuIO2sqVXalm8K74ccIeWQSanzAU5zT9Nj31
!
interface Ethernet1
no switchport
ip address 10.0.0.1/24
!
interface Loopback0
ip address 1.1.1.1/32
!
interface Management0
ip address 172.20.20.2/24
ipv6 address 2001:172:20:20::3/64
!
ip access-list copp
10 permit ip any any
!
ip routing
!
system control-plane
ip access-group copp in
!
router bgp 6500
neighbor 1.1.1.1 remote-as 1
neighbor 2.2.2.2 remote-as 2
neighbor 3.3.3.3 remote-as 3
neighbor 4.4.4.4 remote-as 4
neighbor 5.5.5.5 remote-as 5
neighbor 10.0.0.2 remote-as 6501
redistribute connected
!
router ospf 1
network 0.0.0.0/0 area 0.0.0.0
max-lsa 12000
!
management api http-commands
protocol http
no shutdown
!
management api gnmi
transport grpc default
provider eos-native
!
management api netconf
transport ssh default
!
end]
// Getconfig
! Command: show running-config
! device: ceos1 (cEOSLab, EOS-4.26.0F-21792469.4260F (engineering build))
!
transceiver qsfp default-mode 4x10G
!
service routing protocols model multi-agent
!
hostname ceos1
!
spanning-tree mode mstp
!
no aaa root
!
username admin privilege 15 role network-admin secret sha512 $6$S1jDtSEN/M3/VEsP$fNT4jByGEaYNlEnDxw4qCAyV3dsc/JH5Q7nLLStzZIo0TwUQ3aPuIO2sqVXalm8K74ccIeWQSanzAU5zT9Nj31
!
interface Ethernet1
no switchport
ip address 10.0.0.1/24
!
interface Loopback0
ip address 1.1.1.1/32
!
interface Management0
ip address 172.20.20.2/24
ipv6 address 2001:172:20:20::3/64
!
ip access-list copp
10 permit ip any any
!
ip routing
!
system control-plane
ip access-group copp in
!
router bgp 6500
neighbor 1.1.1.1 remote-as 1
neighbor 2.2.2.2 remote-as 2
neighbor 3.3.3.3 remote-as 3
neighbor 4.4.4.4 remote-as 4
neighbor 5.5.5.5 remote-as 5
neighbor 10.0.0.2 remote-as 6501
redistribute connected
!
router ospf 1
network 0.0.0.0/0 area 0.0.0.0
max-lsa 12000
!
management api http-commands
protocol http
no shutdown
!
management api gnmi
transport grpc default
provider eos-native
!
management api netconf
transport ssh default
!
end
//Runcommands
[map[output: cEOSLab
Hardware version:
Serial number:
Hardware MAC address: 001c.73af.81a6
System MAC address: 001c.73af.81a6
Software image version: 4.26.0F-21792469.4260F (engineering build)
Architecture: i686
Internal build version: 4.26.0F-21792469.4260F
Internal build ID: c5b41f65-54cd-44b1-b576-b5c48700ee19
cEOS tools version: 1.1
Kernel version: 5.11.0-43-generic
Uptime: 0 weeks, 0 days, 14 hours and 43 minutes
Total memory: 65767256 kB
Free memory: 39166528 kB
]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment