forked from infobloxopen/infoblox-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
object_manager_network_container.go
117 lines (92 loc) · 2.84 KB
/
object_manager_network_container.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package ibclient
import (
"fmt"
"regexp"
)
func (objMgr *ObjectManager) CreateNetworkContainer(netview string, cidr string, isIPv6 bool, comment string, eas EA) (*NetworkContainer, error) {
container := NewNetworkContainer(netview, cidr, isIPv6, comment, eas)
ref, err := objMgr.connector.CreateObject(container)
if err != nil {
return nil, err
}
container.Ref = ref
return container, nil
}
// TODO normalize IPv4 and IPv6 addresses
func (objMgr *ObjectManager) GetNetworkContainer(netview string, cidr string, isIPv6 bool, eaSearch EA) (*NetworkContainer, error) {
var res []NetworkContainer
nc := NewNetworkContainer(netview, cidr, isIPv6, "", nil)
nc.eaSearch = EASearch(eaSearch)
sf := map[string]string{
"network_view": netview,
"network": cidr,
}
queryParams := NewQueryParams(false, sf)
err := objMgr.connector.GetObject(nc, "", queryParams, &res)
if err != nil {
return nil, err
} else if res == nil || len(res) == 0 {
return nil, NewNotFoundError("network container not found")
}
return &res[0], nil
}
func (objMgr *ObjectManager) GetNetworkContainerByRef(ref string) (*NetworkContainer, error) {
nc := NewNetworkContainer("", "", false, "", nil)
err := objMgr.connector.GetObject(
nc, ref, NewQueryParams(false, nil), nc)
if err != nil {
return nil, err
}
return nc, nil
}
func (objMgr *ObjectManager) UpdateNetworkContainer(
ref string,
setEas EA,
comment string) (*NetworkContainer, error) {
nc := &NetworkContainer{}
nc.returnFields = []string{"extattrs", "comment"}
err := objMgr.connector.GetObject(
nc, ref, NewQueryParams(false, nil), nc)
if err != nil {
return nil, err
}
nc.Ea = setEas
nc.Comment = comment
// Network view is not allowed to be updated,
// thus making its name empty (will not appear among data which we update).
netViewSaved := nc.NetviewName
nc.NetviewName = ""
reference, err := objMgr.connector.UpdateObject(nc, ref)
if err != nil {
return nil, err
}
nc.Ref = reference
nc.NetviewName = netViewSaved
return nc, nil
}
func (objMgr *ObjectManager) AllocateNetworkContainer(
netview string,
cidr string,
isIPv6 bool,
prefixLen uint,
comment string,
eas EA) (*NetworkContainer, error) {
containerInfo := NewNetworkContainerNextAvailableInfo(netview, cidr, prefixLen, isIPv6)
container := NewNetworkContainerNextAvailable(containerInfo, isIPv6, comment, eas)
ref, err := objMgr.connector.CreateObject(container)
if err != nil {
return nil, err
}
if isIPv6 {
return BuildIPv6NetworkContainerFromRef(ref)
} else {
return BuildNetworkContainerFromRef(ref)
}
}
func (objMgr *ObjectManager) DeleteNetworkContainer(ref string) (string, error) {
ncRegExp := regexp.MustCompile("^(ipv6)?networkcontainer\\/.+")
if !ncRegExp.MatchString(ref) {
return "", fmt.Errorf("'ref' does not reference a network container")
}
return objMgr.connector.DeleteObject(ref)
}