/
distributed_firewalling_config.go
74 lines (61 loc) · 1.77 KB
/
distributed_firewalling_config.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
package goaviatrix
import (
"context"
"fmt"
)
type DistributedFirewallingConfig struct {
EnableDistributedFirewalling bool `json:"enable_distributed_firewalling"`
}
func (c *Client) EnableDistributedFirewalling(ctx context.Context) error {
action := "enable_controller_feature"
form := map[string]string{
"CID": c.CID,
"action": action,
"feature": "microseg",
}
checkFunc := func(act, method, reason string, ret bool) error {
if !ret {
return fmt.Errorf("rest API %s %s failed: %s", act, method, reason)
}
return nil
}
return c.PostAPIContext2(ctx, nil, action, form, checkFunc)
}
func (c *Client) DisableDistributedFirewalling(ctx context.Context) error {
action := "disable_controller_feature"
form := map[string]string{
"CID": c.CID,
"action": action,
"feature": "microseg",
}
checkFunc := func(act, method, reason string, ret bool) error {
if !ret {
return fmt.Errorf("rest API %s %s failed: %s", act, method, reason)
}
return nil
}
return c.PostAPIContext2(ctx, nil, action, form, checkFunc)
}
func (c *Client) GetDistributedFirewallingStatus(ctx context.Context) (*DistributedFirewallingConfig, error) {
action := "get_controller_feature"
form := map[string]string{
"CID": c.CID,
"action": action,
"feature": "microseg",
}
dFWConfig := &DistributedFirewallingConfig{}
type ControllerSingleFeatureStatus struct {
Feature string `json:"feature"`
Enabled bool `json:"enabled"`
}
type DistributedFirewallingConfigResp struct {
Results ControllerSingleFeatureStatus `json:"results"`
}
var resp DistributedFirewallingConfigResp
err := c.PostAPIContext2(ctx, &resp, action, form, BasicCheck)
if err != nil {
return nil, err
}
dFWConfig.EnableDistributedFirewalling = resp.Results.Enabled
return dFWConfig, nil
}