-
Notifications
You must be signed in to change notification settings - Fork 0
/
policy-export.go
50 lines (39 loc) · 981 Bytes
/
policy-export.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
package policy
/*
import (
"fmt"
"mmesh.dev/m-api-go/grpc/resources/topology"
"mmesh.dev/m-cli/pkg/client/subnet"
)
func (api *API) Export() {
s := subnet.GetSubnet(false)
fmt.Println()
fmt.Println(networkPolicyExport(s))
fmt.Println()
}
func networkPolicyExport(s *topology.Subnet) string {
header := `# mmesh networkPolicy
apiVersion: v1
kind: NetworkPolicy
tenant: ` + s.TenantID + `
network: ` + s.NetID + `
subnet: ` + s.SubnetID + `
enabled: true
networkPolicy:
defaultPolicy: ` + s.NetworkPolicy.DefaultPolicy.String() + `
networkFilters:`
var nfilters string
for _, nf := range s.NetworkPolicy.NetworkFilters {
f := `
- index: ` + fmt.Sprintf("%d", nf.Index) + `
description: ` + nf.Description + `
srcIPNet: ` + nf.SrcIPNet + `
dstIPNet: ` + nf.DstIPNet + `
proto: ` + nf.Proto.String() + `
dstPort: ` + fmt.Sprintf("%d", nf.DstPort) + `
policy: ` + nf.Policy.String()
nfilters += f
}
return header + nfilters
}
*/