-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathrecord_ptr.go
66 lines (59 loc) · 1.66 KB
/
record_ptr.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
package infoblox
import "fmt"
// RecordPtr returns the PTR record resource
func (c *Client) RecordPtr() *Resource {
return &Resource{
conn: c,
wapiObject: "record:ptr",
}
}
// RecordPtrObject defines the PTR record object's fields
type RecordPtrObject struct {
Object
Comment string `json:"comment,omitempty"`
Ipv4Addr string `json:"ipv4addr,omitempty"`
Ipv6Addr string `json:"ipv6addr,omitempty"`
Name string `json:"name,omitempty"`
PtrDname string `json:"ptrdname,omitempty"`
Ttl int `json:"ttl,omitempty"`
View string `json:"view,omitempty"`
Zone string `json:"zone,omitempty"`
}
// RecordPtrObject instantiates a PTR record object with a WAPI ref
func (c *Client) RecordPtrObject(ref string) *RecordPtrObject {
ptr := RecordPtrObject{}
ptr.Object = Object{
Ref: ref,
r: c.RecordPtr(),
}
return &ptr
}
// GetRecordPtr fetches a PTR record from the Infoblox WAPI by its ref
func (c *Client) GetRecordPtr(ref string, opts *Options) (*RecordPtrObject, error) {
resp, err := c.RecordPtrObject(ref).get(opts)
if err != nil {
return nil, fmt.Errorf("Could not get created PTR record: %s", err)
}
var out RecordPtrObject
err = resp.Parse(&out)
if err != nil {
return nil, err
}
return &out, nil
}
// FindRecordPtr searches the Infoblox WAPI for the PTR object with the given
// name
func (c *Client) FindRecordPtr(name string) ([]RecordPtrObject, error) {
field := "name"
conditions := []Condition{Condition{Field: &field, Value: name}}
resp, err := c.RecordPtr().find(conditions, nil)
if err != nil {
return nil, err
}
var out []RecordPtrObject
err = resp.Parse(&out)
if err != nil {
return nil, err
}
return out, nil
}