/
cloudn_registration.go
66 lines (54 loc) · 2.01 KB
/
cloudn_registration.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 goaviatrix
import (
"context"
)
type CloudnRegistration struct {
CID string `form:"CID"`
Action string `form:"action"`
ControllerAddress string `form:"controller_ip_or_fqdn"`
Username string `form:"username"`
Password string `form:"password"`
Name string `form:"gateway_name"`
PrependAsPath []string
}
// CreateCloudnRegistration should only be called with a CloudN Client, not the default controller Client
func (c *Client) CreateCloudnRegistration(ctx context.Context, cloudnRegistration *CloudnRegistration) error {
cloudnRegistration.CID = c.CID
cloudnRegistration.Action = "register_caag_with_controller"
return c.PostAPIContext(ctx, cloudnRegistration.Action, cloudnRegistration, BasicCheck)
}
func (c *Client) GetCloudnRegistration(ctx context.Context, cloudnRegistration *CloudnRegistration) (*CloudnRegistration, error) {
data := map[string]string{
"action": "list_cloudwan_devices_summary",
"CID": c.CID,
}
type CloudnRegistrationAPIResult struct {
Name string `json:"rgw_name"`
Username string `json:"username"`
Hostname string `json:"hostname"`
}
type CloudnRegistrationAPIResponse struct {
Results []CloudnRegistrationAPIResult
}
var resp CloudnRegistrationAPIResponse
err := c.GetAPIContext(ctx, &resp, data["action"], data, BasicCheck)
if err != nil {
return nil, err
}
for _, cloudnRegistrationResult := range resp.Results {
if cloudnRegistrationResult.Name == cloudnRegistration.Name {
cloudnRegistration.ControllerAddress = cloudnRegistrationResult.Hostname
cloudnRegistration.Username = cloudnRegistrationResult.Username
return cloudnRegistration, nil
}
}
return nil, ErrNotFound
}
func (c *Client) DeleteCloudnRegistration(ctx context.Context, cloudnRegistration *CloudnRegistration) error {
data := map[string]string{
"action": "deregister_cloudwan_device",
"CID": c.CID,
"device_name": cloudnRegistration.Name,
}
return c.PostAPIContext(ctx, data["action"], data, BasicCheck)
}