forked from udhos/acigo
/
aaep_l2.go
59 lines (38 loc) · 1.51 KB
/
aaep_l2.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
package aci
import (
"bytes"
"fmt"
)
// AttachableAccessEntityProfileDomainL2Add attaches an L2 Domain to the AAEP.
func (c *Client) AttachableAccessEntityProfileDomainL2Add(aep, l2dom string) error {
me := "AttachableAccessEntityProfileDomainL2Add"
rnE := rnAEP(aep)
rn := rnL2Dom(l2dom)
api := "/api/node/mo/uni/infra/" + rnE + ".json"
url := c.getURL(api)
j := fmt.Sprintf(`{"infraRsDomP":{"attributes":{"tDn":"uni/%s","status":"created"}}}`, 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)
}
// AttachableAccessEntityProfileDomainL2Del detaches an L2 Domain from the AAEP.
func (c *Client) AttachableAccessEntityProfileDomainL2Del(aep, l2dom string) error {
me := "AttachableAccessEntityProfileDomainL2Del"
rnE := rnAEP(aep)
rn := rnL2Dom(l2dom)
api := "/api/node/mo/uni/infra/" + rnE + ".json"
url := c.getURL(api)
j := fmt.Sprintf(`{"infraAttEntityP":{"attributes":{"dn":"uni/infra/%s","status":"modified"},"children":[{"infraRsDomP":{"attributes":{"dn":"uni/infra/%s/rsdomP-[uni/%s]","status":"deleted"}}}]}}`,
rnE, rnE, 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)
}