/
remote_location.go
85 lines (54 loc) · 2.12 KB
/
remote_location.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
package aci
import (
"bytes"
"fmt"
)
func rnPath(location string) string {
return "path-" + location
}
// RemoteLocationAdd creates a new remote location.
func (c *Client) RemoteLocationAdd(location, host, protocol, remotePort, remotePath, username, password, descr string) error {
me := "RemoteLocationAdd"
rn := rnPath(location)
api := "/api/node/mo/uni/fabric/" + rn + ".json"
url := c.getURL(api)
j := fmt.Sprintf(`{"fileRemotePath":{"attributes":{"dn":"uni/fabric/%s","remotePort":"%s","name":"%s","descr":"%s","host":"%s","protocol":"%s","remotePath":"%s","userName":"%s","userPasswd":"%s","rn":"%s","status":"created"}}}`,
rn, remotePort, location, descr, host, protocol, remotePath, username, password, rn)
c.debugf("%s: url=%s json=%s", me, url, j)
body, errPost := c.post(url, contentTypeJSON, bytes.NewBufferString(j))
if errPost != nil {
return fmt.Errorf("%s: %v", me, errPost)
}
c.debugf("%s: reply: %s", me, string(body))
return parseJSONError(body)
}
// RemoteLocationDel deletes an existing remote location.
func (c *Client) RemoteLocationDel(location string) error {
me := "RemoteLocationDel"
rn := rnPath(location)
api := "/api/node/mo/uni/fabric.json"
url := c.getURL(api)
j := fmt.Sprintf(`{"fabricInst":{"attributes":{"dn":"uni/fabric","status":"modified"},"children":[{"fileRemotePath":{"attributes":{"dn":"uni/fabric/%s","status":"deleted"}}}]}}`,
rn)
c.debugf("%s: url=%s json=%s", me, url, j)
body, errPost := c.post(url, contentTypeJSON, bytes.NewBufferString(j))
if errPost != nil {
return fmt.Errorf("%s: %v", me, errPost)
}
c.debugf("%s: reply: %s", me, string(body))
return parseJSONError(body)
}
// RemoteLocationList retrieves the list of remote locations.
func (c *Client) RemoteLocationList() ([]map[string]interface{}, error) {
me := "RemoteLocationList"
key := "fileRemotePath"
api := "/api/node/class/" + key + ".json"
url := c.getURL(api)
c.debugf("%s: url=%s", me, url)
body, errGet := c.get(url)
if errGet != nil {
return nil, fmt.Errorf("%s: %v", me, errGet)
}
c.debugf("%s: reply: %s", me, string(body))
return jsonImdataAttributes(c, body, key, me)
}