-
Notifications
You must be signed in to change notification settings - Fork 0
/
operation.go
36 lines (32 loc) · 971 Bytes
/
operation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package eznc
import (
"github.com/Juniper/go-netconf/netconf"
"fmt"
)
// Get's connection handle to device
func Device(host string, username string, password string) (*netconf.Session, error) {
s, err := netconf.DialSSH(host,
netconf.SSHConfigPassword(username, password))
if err != nil {
panic(err)
}
return s, err
}
// Get's RPC execution reply
func Rpc(s *netconf.Session, rpc string) (*netconf.RPCReply, error) {
concat_string := fmt.Sprintf("<%s/>", rpc)
reply, err := s.Exec(netconf.RawMethod(concat_string))
if err != nil {
panic(err)
}
return reply, err
}
// Get's operational command output
func Cli(s *netconf.Session, rpc string, format string) (*netconf.RPCReply, error) {
concat_string := fmt.Sprintf("<command format=\"%s\">%s</command>", format, rpc)
reply, err := s.Exec(netconf.RawMethod(concat_string))
if err != nil {
//panic(err)
}
return reply, err
}