forked from infobloxopen/infoblox-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
object_manager.go
300 lines (251 loc) · 12.8 KB
/
object_manager.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
package ibclient
import (
"encoding/json"
"errors"
"fmt"
)
// Compile-time interface checks
var _ IBObjectManager = new(ObjectManager)
type IBObjectManager interface {
GetDNSView(name string) (*DNSView, error)
AllocateIP(netview string, cidr string, ipAddr string, isIPv6 bool, macOrDuid string, name string, comment string, eas EA) (*FixedAddress, error)
AllocateNetwork(netview string, cidr string, isIPv6 bool, prefixLen uint, comment string, eas EA) (network *Network, err error)
AllocateNetworkContainer(netview string, cidr string, isIPv6 bool, prefixLen uint, comment string, eas EA) (netContainer *NetworkContainer, err error)
CreateARecord(netView string, dnsView string, name string, cidr string, ipAddr string, ttl uint32, useTTL bool, comment string, ea EA) (*RecordA, error)
CreateAAAARecord(netView string, dnsView string, recordName string, cidr string, ipAddr string, useTtl bool, ttl uint32, comment string, eas EA) (*RecordAAAA, error)
CreateZoneAuth(fqdn string, ea EA) (*ZoneAuth, error)
CreateCNAMERecord(dnsview string, canonical string, recordname string, useTtl bool, ttl uint32, comment string, eas EA) (*RecordCNAME, error)
CreateDefaultNetviews(globalNetview string, localNetview string) (globalNetviewRef string, localNetviewRef string, err error)
CreateEADefinition(eadef EADefinition) (*EADefinition, error)
CreateHostRecord(enabledns bool, enabledhcp bool, recordName string, netview string, dnsview string, ipv4cidr string, ipv6cidr string, ipv4Addr string, ipv6Addr string, macAddr string, duid string, useTtl bool, ttl uint32, comment string, eas EA, aliases []string) (*HostRecord, error)
CreateMXRecord(dnsView string, fqdn string, mx string, preference uint32, ttl uint32, useTtl bool, comment string, eas EA) (*RecordMX, error)
CreateNetwork(netview string, cidr string, isIPv6 bool, comment string, eas EA) (*Network, error)
CreateNetworkContainer(netview string, cidr string, isIPv6 bool, comment string, eas EA) (*NetworkContainer, error)
CreateNetworkView(name string, comment string, setEas EA) (*NetworkView, error)
CreatePTRRecord(networkView string, dnsView string, ptrdname string, recordName string, cidr string, ipAddr string, useTtl bool, ttl uint32, comment string, eas EA) (*RecordPTR, error)
CreateSRVRecord(dnsView string, name string, priority uint32, weight uint32, port uint32, target string, ttl uint32, useTtl bool, comment string, eas EA) (*RecordSRV, error)
CreateTXTRecord(dnsView string, recordName string, text string, ttl uint32, useTtl bool, comment string, eas EA) (*RecordTXT, error)
CreateZoneDelegated(fqdn string, delegate_to []NameServer) (*ZoneDelegated, error)
DeleteARecord(ref string) (string, error)
DeleteAAAARecord(ref string) (string, error)
DeleteZoneAuth(ref string) (string, error)
DeleteCNAMERecord(ref string) (string, error)
DeleteFixedAddress(ref string) (string, error)
DeleteHostRecord(ref string) (string, error)
DeleteMXRecord(ref string) (string, error)
DeleteNetwork(ref string) (string, error)
DeleteNetworkContainer(ref string) (string, error)
DeleteNetworkView(ref string) (string, error)
DeletePTRRecord(ref string) (string, error)
DeleteSRVRecord(ref string) (string, error)
DeleteTXTRecord(ref string) (string, error)
DeleteZoneDelegated(ref string) (string, error)
GetARecordByRef(ref string) (*RecordA, error)
GetARecord(dnsview string, recordName string, ipAddr string) (*RecordA, error)
GetAAAARecord(dnsview string, recordName string, ipAddr string) (*RecordAAAA, error)
GetAAAARecordByRef(ref string) (*RecordAAAA, error)
GetCNAMERecord(dnsview string, canonical string, recordName string) (*RecordCNAME, error)
GetCNAMERecordByRef(ref string) (*RecordCNAME, error)
GetEADefinition(name string) (*EADefinition, error)
GetFixedAddress(netview string, cidr string, ipAddr string, isIPv6 bool, macOrDuid string) (*FixedAddress, error)
GetFixedAddressByRef(ref string) (*FixedAddress, error)
GetHostRecord(netview string, dnsview string, recordName string, ipv4addr string, ipv6addr string) (*HostRecord, error)
SearchHostRecordByAltId(internalId string, ref string, eaNameForInternalId string) (*HostRecord, error)
GetHostRecordByRef(ref string) (*HostRecord, error)
GetIpAddressFromHostRecord(host HostRecord) (string, error)
GetMXRecord(dnsView string, fqdn string, mx string, preference uint32) (*RecordMX, error)
GetMXRecordByRef(ref string) (*RecordMX, error)
GetNetwork(netview string, cidr string, isIPv6 bool, ea EA) (*Network, error)
GetNetworkByEA(netview string, ea map[string]interface{}) (interface{}, error)
GetNetworkByRef(ref string) (*Network, error)
GetNetworkContainer(netview string, cidr string, isIPv6 bool, eaSearch EA) (*NetworkContainer, error)
GetNetworkContainerByRef(ref string) (*NetworkContainer, error)
GetNetworkView(name string) (*NetworkView, error)
GetNetworkViewByRef(ref string) (*NetworkView, error)
GetPTRRecord(dnsview string, ptrdname string, recordName string, ipAddr string) (*RecordPTR, error)
GetPTRRecordByRef(ref string) (*RecordPTR, error)
GetSRVRecord(dnsView string, name string, target string, port uint32) (*RecordSRV, error)
GetSRVRecordByRef(ref string) (*RecordSRV, error)
GetTXTRecord(dnsview string, name string) (*RecordTXT, error)
GetTXTRecordByRef(ref string) (*RecordTXT, error)
GetZoneAuthByRef(ref string) (*ZoneAuth, error)
GetZoneDelegated(fqdn string) (*ZoneDelegated, error)
GetCapacityReport(name string) ([]CapacityReport, error)
GetUpgradeStatus(statusType string) ([]UpgradeStatus, error)
GetAllMembers() ([]Member, error)
GetGridInfo() ([]Grid, error)
GetGridLicense() ([]License, error)
ReleaseIP(netview string, cidr string, ipAddr string, isIPv6 bool, macAddr string) (string, error)
UpdateAAAARecord(ref string, netView string, recordName string, cidr string, ipAddr string, useTtl bool, ttl uint32, comment string, setEas EA) (*RecordAAAA, error)
UpdateCNAMERecord(ref string, canonical string, recordName string, useTtl bool, ttl uint32, comment string, setEas EA) (*RecordCNAME, error)
UpdateFixedAddress(fixedAddrRef string, netview string, name string, cidr string, ipAddr string, matchclient string, macOrDuid string, comment string, eas EA) (*FixedAddress, error)
UpdateHostRecord(hostRref string, enabledns bool, enabledhcp bool, name string, netview string, dnsView string, ipv4cidr string, ipv6cidr string, ipv4Addr string, ipv6Addr string, macAddress string, duid string, useTtl bool, ttl uint32, comment string, eas EA, aliases []string) (*HostRecord, error)
UpdateMXRecord(ref string, dnsView string, fqdn string, mx string, preference uint32, ttl uint32, useTtl bool, comment string, eas EA) (*RecordMX, error)
UpdateNetwork(ref string, setEas EA, comment string) (*Network, error)
UpdateNetworkContainer(ref string, setEas EA, comment string) (*NetworkContainer, error)
UpdateNetworkView(ref string, name string, comment string, setEas EA) (*NetworkView, error)
UpdatePTRRecord(ref string, netview string, ptrdname string, name string, cidr string, ipAddr string, useTtl bool, ttl uint32, comment string, setEas EA) (*RecordPTR, error)
UpdateSRVRecord(ref string, name string, priority uint32, weight uint32, port uint32, target string, ttl uint32, useTtl bool, comment string, eas EA) (*RecordSRV, error)
UpdateTXTRecord(ref string, recordName string, text string, ttl uint32, useTtl bool, comment string, eas EA) (*RecordTXT, error)
UpdateARecord(ref string, name string, ipAddr string, cidr string, netview string, ttl uint32, useTTL bool, comment string, eas EA) (*RecordA, error)
UpdateZoneDelegated(ref string, delegate_to []NameServer) (*ZoneDelegated, error)
}
type ObjectManager struct {
connector IBConnector
cmpType string
tenantID string
}
func NewObjectManager(connector IBConnector, cmpType string, tenantID string) IBObjectManager {
objMgr := &ObjectManager{}
objMgr.connector = connector
objMgr.cmpType = cmpType
objMgr.tenantID = tenantID
return objMgr
}
// CreateMultiObject unmarshals the result into slice of maps
func (objMgr *ObjectManager) CreateMultiObject(req *MultiRequest) ([]map[string]interface{}, error) {
conn := objMgr.connector.(*Connector)
queryParams := NewQueryParams(false, nil)
res, err := conn.makeRequest(CREATE, req, "", queryParams)
if err != nil {
return nil, err
}
var result []map[string]interface{}
err = json.Unmarshal(res, &result)
if err != nil {
return nil, err
}
return result, nil
}
// GetUpgradeStatus returns the grid upgrade information
func (objMgr *ObjectManager) GetUpgradeStatus(statusType string) ([]UpgradeStatus, error) {
var res []UpgradeStatus
if statusType == "" {
// TODO option may vary according to the WAPI version, need to
// throw relevant error.
msg := fmt.Sprintf("Status type can not be nil")
return res, errors.New(msg)
}
upgradestatus := NewUpgradeStatus(UpgradeStatus{})
sf := map[string]string{
"type": statusType,
}
queryParams := NewQueryParams(false, sf)
err := objMgr.connector.GetObject(upgradestatus, "", queryParams, &res)
return res, err
}
// GetAllMembers returns all members information
func (objMgr *ObjectManager) GetAllMembers() ([]Member, error) {
var res []Member
memberObj := NewMember(Member{})
err := objMgr.connector.GetObject(
memberObj, "", NewQueryParams(false, nil), &res)
return res, err
}
// GetCapacityReport returns all capacity for members
func (objMgr *ObjectManager) GetCapacityReport(name string) ([]CapacityReport, error) {
var res []CapacityReport
capacityReport := NewCapcityReport(CapacityReport{})
sf := map[string]string{
"name": name,
}
queryParams := NewQueryParams(false, sf)
err := objMgr.connector.GetObject(capacityReport, "", queryParams, &res)
return res, err
}
// GetLicense returns the license details for member
func (objMgr *ObjectManager) GetLicense() ([]License, error) {
var res []License
licenseObj := NewLicense(License{})
err := objMgr.connector.GetObject(
licenseObj, "", NewQueryParams(false, nil), &res)
return res, err
}
// GetLicense returns the license details for grid
func (objMgr *ObjectManager) GetGridLicense() ([]License, error) {
var res []License
licenseObj := NewGridLicense(License{})
err := objMgr.connector.GetObject(
licenseObj, "", NewQueryParams(false, nil), &res)
return res, err
}
// GetGridInfo returns the details for grid
func (objMgr *ObjectManager) GetGridInfo() ([]Grid, error) {
var res []Grid
gridObj := NewGrid(Grid{})
err := objMgr.connector.GetObject(
gridObj, "", NewQueryParams(false, nil), &res)
return res, err
}
// CreateZoneAuth creates zones and subs by passing fqdn
func (objMgr *ObjectManager) CreateZoneAuth(
fqdn string,
eas EA) (*ZoneAuth, error) {
zoneAuth := NewZoneAuth(ZoneAuth{
Fqdn: fqdn,
Ea: eas})
ref, err := objMgr.connector.CreateObject(zoneAuth)
zoneAuth.Ref = ref
return zoneAuth, err
}
// Retreive a authortative zone by ref
func (objMgr *ObjectManager) GetZoneAuthByRef(ref string) (*ZoneAuth, error) {
res := NewZoneAuth(ZoneAuth{})
if ref == "" {
return nil, fmt.Errorf("empty reference to an object is not allowed")
}
err := objMgr.connector.GetObject(
res, ref, NewQueryParams(false, nil), res)
return res, err
}
// DeleteZoneAuth deletes an auth zone
func (objMgr *ObjectManager) DeleteZoneAuth(ref string) (string, error) {
return objMgr.connector.DeleteObject(ref)
}
// GetZoneAuth returns the authoritatives zones
func (objMgr *ObjectManager) GetZoneAuth() ([]ZoneAuth, error) {
var res []ZoneAuth
zoneAuth := NewZoneAuth(ZoneAuth{})
err := objMgr.connector.GetObject(
zoneAuth, "", NewQueryParams(false, nil), &res)
return res, err
}
// GetZoneDelegated returns the delegated zone
func (objMgr *ObjectManager) GetZoneDelegated(fqdn string) (*ZoneDelegated, error) {
if len(fqdn) == 0 {
return nil, nil
}
var res []ZoneDelegated
zoneDelegated := NewZoneDelegated(ZoneDelegated{})
sf := map[string]string{
"fqdn": fqdn,
}
queryParams := NewQueryParams(false, sf)
err := objMgr.connector.GetObject(zoneDelegated, "", queryParams, &res)
if err != nil || res == nil || len(res) == 0 {
return nil, err
}
return &res[0], nil
}
// CreateZoneDelegated creates delegated zone
func (objMgr *ObjectManager) CreateZoneDelegated(fqdn string, delegate_to []NameServer) (*ZoneDelegated, error) {
zoneDelegated := NewZoneDelegated(ZoneDelegated{
Fqdn: fqdn,
DelegateTo: delegate_to})
ref, err := objMgr.connector.CreateObject(zoneDelegated)
zoneDelegated.Ref = ref
return zoneDelegated, err
}
// UpdateZoneDelegated updates delegated zone
func (objMgr *ObjectManager) UpdateZoneDelegated(ref string, delegate_to []NameServer) (*ZoneDelegated, error) {
zoneDelegated := NewZoneDelegated(ZoneDelegated{
Ref: ref,
DelegateTo: delegate_to})
refResp, err := objMgr.connector.UpdateObject(zoneDelegated, ref)
zoneDelegated.Ref = refResp
return zoneDelegated, err
}
// DeleteZoneDelegated deletes delegated zone
func (objMgr *ObjectManager) DeleteZoneDelegated(ref string) (string, error) {
return objMgr.connector.DeleteObject(ref)
}