diff --git a/object_manager.go b/object_manager.go index 14f4c289..93a342a1 100644 --- a/object_manager.go +++ b/object_manager.go @@ -91,6 +91,7 @@ type IBObjectManager interface { 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) + GetIPAddressInfo(ipAddr string) ([]IPv4Address, error) } type ObjectManager struct { @@ -297,3 +298,28 @@ func (objMgr *ObjectManager) UpdateZoneDelegated(ref string, delegate_to []NameS func (objMgr *ObjectManager) DeleteZoneDelegated(ref string) (string, error) { return objMgr.connector.DeleteObject(ref) } + +// GetIPAddressInfo returns information related to an ipv4 address +func (objMgr *ObjectManager) GetIPAddressInfo(ipAddr string) ([]IPv4Address, error) { + if ipAddr == "" { + return nil, fmt.Errorf("empty ipAddr value is not allowed") + } + + sf := map[string]string{ + "ip_address": ipAddr, + } + + var res []IPv4Address + ipv4Info := &IPv4Address{} + + err := objMgr.connector.GetObject( + ipv4Info, "", NewQueryParams(false, sf), &res) + + if err != nil { + return nil, err + } else if res == nil || len(res) == 0 { + return nil, NewNotFoundError(fmt.Sprintf("failed to get IPV4 address object '%s' ", ipAddr)) + } + + return res, err +} diff --git a/object_manager_test.go b/object_manager_test.go index 7a487be1..bfc806f1 100644 --- a/object_manager_test.go +++ b/object_manager_test.go @@ -88,6 +88,8 @@ func (c *fakeConnector) GetObject(obj IBObject, ref string, qp *QueryParams, res *res.(*[]RecordA) = c.resultObject.([]RecordA) case *RecordMX: *res.(*[]RecordMX) = c.resultObject.([]RecordMX) + case *IPv4Address: + *res.(*[]IPv4Address) = c.resultObject.([]IPv4Address) } } else { switch obj.(type) { @@ -521,4 +523,40 @@ var _ = Describe("Object Manager", func() { Expect(err).To(BeNil()) }) }) + + Describe("Get IPAddressInfo", func() { + cmpType := "Docker" + tenantID := "01234567890abcdef01234567890abcdef" + sf := map[string]string{ + "ip_address": "10.38.197.235", + } + zdFakeConnector := &fakeConnector{ + getObjectQueryParams: NewQueryParams(false, sf), + getObjectObj: &IPv4Address{}, + resultObject: []IPv4Address{{ + Ref: "ipv4address/Li5pcHY0X2FkZHJlc3MkMTAuMTk3LjM4LjIzNS8w:10.38.197.235", + IpAddress: "10.38.197.235", + Names: []string{"custom.example.k8s.org", "infoblox.localdomain"}, + Network: "10.38.197.0/24", + NetworkView: "default", + Objects: []string{ + "record:a/ZG5zLmJpbmRfYSQuMS5vcmcuazhzLmV4YW1wbGUsY3VzdG9tLDEwLjE5Ny4zOC4yMzU:custom.example.k8s.org/non-default", + "record:ptr/ZG5zLmJpbmRfcHRyJC5fZGVmYXVsdC5hcnBhLmluLWFkZHIuMTAuMTk3LjM4LjIzNS5pbmZvYmxveC5sb2NhbGRvbWFpbg:235.38.197.10.in-addr.arpa/default", + "record:ptr/ZG5zLmJpbmRfcHRyJC4xLmFycGEuaW4tYWRkci4xMC4xOTcuMzguMjM1LmN1c3RvbS5leGFtcGxlLms4cy5vcmc:235.38.197.10.in-addr.arpa/non-default", + }, + Status: "USED", + Types: []string{"A", "PTR"}, + Usage: []string{"DNS"}, + }}, + } + objMgr := NewObjectManager(zdFakeConnector, cmpType, tenantID) + + var actualObj []IPv4Address + var err error + It("should pass expected get IPAddressInfo", func() { + actualObj, err = objMgr.GetIPAddressInfo("10.38.197.235") + Expect(actualObj).ToNot(BeNil()) + Expect(err).To(BeNil()) + }) + }) })