-
Notifications
You must be signed in to change notification settings - Fork 0
/
nso.go
66 lines (60 loc) · 2.1 KB
/
nso.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
package main
import (
"net/http"
"net/url"
"strings"
)
func fullConfig(u *url.URL, d string) (req *http.Request, err error) {
// "http://admin:admin@mrstn-nso.cisco.com:8080/api/config/devices/device/mrstn-5501-1.cisco.com/config?deep=true"
u.Path = "api/config/devices/device/" + d + "/config"
// All the details
q := u.Query()
q.Set("deep", "true")
u.RawQuery = q.Encode()
// Request
req, err = http.NewRequest("GET", u.String(), nil)
req.Header.Add("Accept", "application/vnd.yang.data+json")
return req, err
}
func interfaceConfig(u *url.URL, d string) (req *http.Request, err error) {
u.Path = "api/running/devices/device/" + d + "/config/interface/TenGigE"
// All the details
q := u.Query()
q.Set("deep", "true")
u.RawQuery = q.Encode()
// Request
req, err = http.NewRequest("GET", u.String(), nil)
req.Header.Add("Accept", "application/vnd.yang.collection+json")
return req, err
}
func routerConfig(u *url.URL, d string) (req *http.Request, err error) {
// static, isis, bgp, etc...
p := "static"
u.Path = "api/running/devices/device/" + d + "/config/router/" + p
// All the details
q := u.Query()
q.Set("deep", "true")
u.RawQuery = q.Encode()
// Request
req, err = http.NewRequest("GET", u.String(), nil)
req.Header.Add("Accept", "application/vnd.yang.data+json")
return req, err
}
func setRouterConfig(u *url.URL, d string, p string, c string) (req *http.Request, err error) {
// PUT, POST -> REPLACE. PATH -> MERGE
// p = static, isis, bgp, etc...
u.Path = "api/running/devices/device/" + d + "/config/router/" + p
// Request
req, err = http.NewRequest("PATCH", u.String(), strings.NewReader(c))
req.Header.Add("Content-Type", "application/vnd.yang.data+json")
req.Header.Add("Accept", "application/vnd.yang.data+json")
return req, err
}
func syncFrom(u *url.URL, d string) (req *http.Request, err error) {
u.Path = "api/running/devices/device/" + d + "/_operations/sync-from"
// Request
req, err = http.NewRequest("POST", u.String(), nil)
req.Header.Add("Content-Type", "application/vnd.yang.operation+json")
req.Header.Add("Accept", "application/vnd.yang.operation+json")
return req, err
}