-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
38 lines (32 loc) · 872 Bytes
/
client.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
package netconf
import (
"github.com/scottdware/go-junos"
)
// Client is a client to get the switch configuration using the
// NETCONF protocol.
type Client struct {
auth *junos.AuthMethod
connector connector
}
// New returns a new NetconfClient.
func New(auth *junos.AuthMethod) Client {
return Client{
auth: auth,
connector: junosConnector{},
}
}
// GetConfig connects to a switch, reads the specified configuration section
// and returns its content. The section can be an empty string. In that case,
// the whole configuration will be read.
func (c Client) GetConfig(hostname string, section ...string) (string, error) {
jnpr, err := c.connector.NewSession(hostname, c.auth)
if err != nil {
return "", err
}
defer jnpr.Close()
config, err := jnpr.GetConfig("text", section...)
if err != nil {
return "", err
}
return config, nil
}