-
Notifications
You must be signed in to change notification settings - Fork 26
/
record_a.go
65 lines (58 loc) · 1.57 KB
/
record_a.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
package infoblox
import "fmt"
// RecordA returns the A record resource
// https://102.168.2.200/wapidoc/objects/record.a.html
func (c *Client) RecordA() *Resource {
return &Resource{
conn: c,
wapiObject: "record:a",
}
}
// RecordAObject defines the A record object's fields
type RecordAObject struct {
Object
Comment string `json:"comment,omitempty"`
Ipv4Addr string `json:"ipv4addr,omitempty"`
Name string `json:"name,omitempty"`
Ttl int `json:"ttl,omitempty"`
View string `json:"view,omitempty"`
Zone string `json:"zone,omitempty"`
}
// RecordAObject instantiates an A record object with a WAPI ref
func (c *Client) RecordAObject(ref string) *RecordAObject {
a := RecordAObject{}
a.Object = Object{
Ref: ref,
r: c.RecordA(),
}
return &a
}
// GetRecordA fetches an A record from the Infoblox WAPI by its ref
func (c *Client) GetRecordA(ref string, opts *Options) (*RecordAObject, error) {
resp, err := c.RecordAObject(ref).get(opts)
if err != nil {
return nil, fmt.Errorf("Could not get created A record: %s", err)
}
var out RecordAObject
err = resp.Parse(&out)
if err != nil {
return nil, err
}
return &out, nil
}
// FindRecordA searches the Infoblox WAPI for the A record with the given
// name
func (c *Client) FindRecordA(name string) ([]RecordAObject, error) {
field := "name"
conditions := []Condition{Condition{Field: &field, Value: name}}
resp, err := c.RecordA().find(conditions, nil)
if err != nil {
return nil, err
}
var out []RecordAObject
err = resp.Parse(&out)
if err != nil {
return nil, err
}
return out, nil
}