-
Notifications
You must be signed in to change notification settings - Fork 5
/
junos.go
108 lines (79 loc) · 2.14 KB
/
junos.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package netconf
import (
"time"
lowlevel "github.com/arsonistgopher/go-netconf/drivers/junos/lowlevel"
rpc "github.com/arsonistgopher/go-netconf/rpc"
session "github.com/arsonistgopher/go-netconf/session"
)
// DriverJunos type is for creating a Junos based driver. Maintains state for session and connection. Implements Driver{}
type DriverJunos struct {
Timeout time.Duration // Timeout for SSH timed sessions
Datastore string // NETCONF datastore
Session *session.Session // Session data
}
// New creates a new instance of DriverJunos
func New() *DriverJunos {
return &DriverJunos{}
}
// SetDatastore sets the target datastore on the data structure
func (d *DriverJunos) SetDatastore(ds string) error {
d.Datastore = ds
return nil
}
// Dial function (call this after New())
func (d *DriverJunos) Dial() error {
var err error
d.Session, err = lowlevel.Dial()
if err != nil {
return err
}
if err != nil {
return err
}
return nil
}
// DialTimeout NOT IMPLEMENTED. This driver is transactional based and not required.
func (d *DriverJunos) DialTimeout() error {
return nil
}
// Close function closes the socket
func (d *DriverJunos) Close() error {
// Close the SSH Session if we have one}
err := d.Session.Close()
if err != nil {
return err
}
return nil
}
// Lock the target datastore
func (d *DriverJunos) Lock(ds string) (*rpc.RPCReply, error) {
reply, err := d.Session.Exec(rpc.MethodLock(ds))
if err != nil {
return reply, err
}
return reply, nil
}
// Unlock the target datastore
func (d *DriverJunos) Unlock(ds string) (*rpc.RPCReply, error) {
reply, err := d.Session.Exec(rpc.MethodUnlock(ds))
if err != nil {
return reply, err
}
return reply, nil
}
// SendRaw sends a raw XML envelope
func (d *DriverJunos) SendRaw(rawxml string) (*rpc.RPCReply, error) {
reply, err := d.Session.Exec(rpc.RawMethod(rawxml))
if err != nil {
return reply, err
}
return reply, nil
}
// GetConfig requests the contents of a datastore
func (d *DriverJunos) GetConfig() (*rpc.RPCReply, error) {
reply, err := d.Session.Exec(rpc.MethodGetConfig(d.Datastore))
if err != nil {
return reply, err
}
return reply, nil
}