Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented a function to fetch information about ip address. #213

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions object_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
sdas-infoblox marked this conversation as resolved.
Show resolved Hide resolved

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))
}
sdas-infoblox marked this conversation as resolved.
Show resolved Hide resolved

return res, err
}
38 changes: 38 additions & 0 deletions object_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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())
sdas-infoblox marked this conversation as resolved.
Show resolved Hide resolved
Expect(err).To(BeNil())
})
})
})