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

adding support for next-available-ip for host record and unit testcas… #247

Merged
Merged
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
6 changes: 3 additions & 3 deletions object_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ var _ IBObjectManager = new(ObjectManager)
type IBObjectManager interface {
GetDNSView(name string) (*View, error)
AllocateIP(netview string, cidr string, ipAddr string, isIPv6 bool, macOrDuid string, name string, comment string, eas EA) (*FixedAddress, error)
AllocateNextAvailableIp(name string, objectType string, objectParams map[string]string, params map[string][]string, useEaInheritance bool, isIpv6 bool, ea EA, comment string, disable bool, n *int) (interface{}, error)
AllocateNextAvailableIp(name string, objectType string, objectParams map[string]string, params map[string][]string, useEaInheritance bool, ea EA, comment string, disable bool, n *int, ipAddrType string) (interface{}, error)
AllocateNetwork(netview string, cidr string, isIPv6 bool, prefixLen uint, comment string, eas EA) (network *Network, err error)
AllocateNetworkByEA(netview string, isIPv6 bool, comment string, eas EA, eaMap map[string]string, prefixLen int, object string) (network *Network, err error)
AllocateNetworkByEA(netview string, isIPv6 bool, comment string, eas EA, eaMap map[string]string, prefixLen uint, object string) (network *Network, err error)
AllocateNetworkContainer(netview string, cidr string, isIPv6 bool, prefixLen uint, comment string, eas EA) (netContainer *NetworkContainer, err error)
AllocateNetworkContainerByEA(netview string, isIPv6 bool, comment string, eas EA, eaMap map[string]string, prefixLen int) (*NetworkContainer, error)
AllocateNetworkContainerByEA(netview string, isIPv6 bool, comment string, eas EA, eaMap map[string]string, prefixLen uint) (*NetworkContainer, 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)
Expand Down
10 changes: 5 additions & 5 deletions object_manager_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ func (objMgr *ObjectManager) AllocateNextAvailableIp(
objectParams map[string]string,
params map[string][]string,
useEaInheritance bool,
isIpv6 bool,
ea EA,
comment string,
disable bool, n *int) (interface{}, error) {
disable bool,
n *int, ipAddrType string) (interface{}, error) {

networkIp := NewIpNextAvailable(name, objectType, objectParams, params, useEaInheritance, isIpv6, ea, comment, disable, n)
networkIp := NewIpNextAvailable(name, objectType, objectParams, params, useEaInheritance, ea, comment, disable, n, ipAddrType)

ref, err := objMgr.connector.CreateObject(networkIp)
if err != nil {
Expand All @@ -72,7 +72,7 @@ func (objMgr *ObjectManager) AllocateNextAvailableIp(
}

func (objMgr *ObjectManager) AllocateNetworkByEA(
netview string, isIPv6 bool, comment string, eas EA, eaMap map[string]string, prefixLen int, object string) (network *Network, err error) {
netview string, isIPv6 bool, comment string, eas EA, eaMap map[string]string, prefixLen uint, object string) (network *Network, err error) {

var (
containerObject string
Expand All @@ -92,7 +92,7 @@ func (objMgr *ObjectManager) AllocateNetworkByEA(
ResultField: "networks",
Object: containerObject,
ObjectParams: eaMap,
Params: map[string]uint{"cidr": uint(prefixLen)},
Params: map[string]uint{"cidr": prefixLen},
}

nextAvailableNetwork := NetworkContainerNextAvailable{
Expand Down
9 changes: 2 additions & 7 deletions object_manager_network_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,8 @@ func (objMgr *ObjectManager) AllocateNetworkContainer(
}

func (objMgr *ObjectManager) AllocateNetworkContainerByEA(
netview string, isIPv6 bool, comment string, eas EA, eaMap map[string]string, prefixLen int) (*NetworkContainer, error) {
netview string, isIPv6 bool, comment string, eas EA, eaMap map[string]string, prefixLen uint) (*NetworkContainer, error) {

//if isIPv6 {
// object = "ipv6networkcontainer"
//} else {
// object = "networkcontainer"
//}
var object string
object = getNetworkObjectType(isIPv6, "networkcontainer", "ipv6networkcontainer")

Expand All @@ -123,7 +118,7 @@ func (objMgr *ObjectManager) AllocateNetworkContainerByEA(
ResultField: "networks",
Object: object,
ObjectParams: eaMap,
Params: map[string]uint{"cidr": uint(prefixLen)},
Params: map[string]uint{"cidr": prefixLen},
}

net := NetworkContainerNextAvailable{
Expand Down
44 changes: 44 additions & 0 deletions object_manager_network_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,48 @@ var _ = Describe("Object Manager: network container", func() {
Expect(err).To(BeNil())
})
})

Describe("Allocate IPV4 Network Container by EA", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
cidr := "20.20.1.0/24"
prefixLen := uint(24)
netviewName := "default"
fakeRefReturn := fmt.Sprintf("networkcontainer/ZG5zLm5ldHdvcmskODkuMC4wLjAvMjQvMjU:%s/%s", cidr, netviewName)
ea := EA{"Site": "test"}
eaMap := map[string]string{"Site": "Turkey"}
comment := "Test network container"
resObj, err := BuildNetworkContainerFromRef(fakeRefReturn)
container := &NetworkContainerNextAvailable{
objectType: "networkcontainer",
Network: &NetworkContainerNextAvailableInfo{
Function: "next_available_network",
ResultField: "networks",
Object: "networkcontainer",
ObjectParams: eaMap,
Params: map[string]uint{"cidr": prefixLen},
NetviewName: "",
},
NetviewName: netviewName,
Comment: comment,
Ea: ea,
}

connector := &fakeConnector{
createObjectObj: container,
resultObject: resObj,
fakeRefReturn: fakeRefReturn,
}

objMgr := NewObjectManager(connector, cmpType, tenantID)

var actualNetwork *NetworkContainer
It("should pass expected Network Container Object to CreateObject", func() {
actualNetwork, err = objMgr.AllocateNetworkContainerByEA(netviewName, false, comment, ea, eaMap, prefixLen)
})
It("should return expected Network container Object", func() {
Expect(actualNetwork).To(Equal(connector.resultObject))
Expect(err).To(BeNil())
})
})
})
50 changes: 50 additions & 0 deletions object_manager_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,56 @@ var _ = Describe("Object Manager: network", func() {
})
})

Describe("Allocate IPv6 Network By EA", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
netviewName := "default"
cidr := "2003:db8:abcd:14::/64"
prefixLen := uint(28)
networkName := "default"
//cidr1 := fmt.Sprintf("func:nextavailablenetwork:%s,%s,%d", cidr, netviewName, prefixLen)
fakeRefReturn := fmt.Sprintf("ipv6network/ZG5zLm5ldHdvcmskODkuMC4wLjAvMjQvMjU:%s/%s", cidr, netviewName)
ea := EA{"Region": "East", "Network Name": networkName}
comment := "Test network view"
eaMap := map[string]string{"Site": "Turkey"}

var err error
resObj, err := BuildIPv6NetworkFromRef(fakeRefReturn)
createobj := &NetworkContainerNextAvailable{
objectType: "ipv6network",
Network: &NetworkContainerNextAvailableInfo{
Function: "next_available_network",
ResultField: "networks",
Object: "ipv6networkcontainer",
ObjectParams: eaMap,
Params: map[string]uint{
"cidr": prefixLen,
},
NetviewName: "",
},
NetviewName: netviewName,
Comment: comment,
Ea: ea,
}
connector := &fakeConnector{
createObjectObj: createobj,
resultObject: resObj,
fakeRefReturn: fakeRefReturn,
}

objMgr := NewObjectManager(connector, cmpType, tenantID)

var actualNetwork *Network
It("should pass expected Network Object to CreateObject", func() {
actualNetwork, err = objMgr.AllocateNetworkByEA(
netviewName, true, comment, ea, eaMap, prefixLen, "ipv6network")
})
It("should return expected Network Object", func() {
Expect(actualNetwork).To(Equal(connector.resultObject))
Expect(err).To(BeNil())
})
})

Describe("Get Network", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
Expand Down
35 changes: 24 additions & 11 deletions objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ type IpNextAvailableInfo struct {
UseEaInheritance bool `json:"use_for_ea_inheritance"`
}

func NewIpNextAvailableInfo(objectParams map[string]string, params map[string][]string, useEaInheritance bool, isIpv6 bool) *IpNextAvailableInfo {
func NewIpNextAvailableInfo(objectParams map[string]string, params map[string][]string, useEaInheritance bool, ipAddrType string) *IpNextAvailableInfo {
nextAvailableIpInfo := IpNextAvailableInfo{
Function: "next_available_ip",
ResultField: "ips",
Expand All @@ -218,7 +218,7 @@ func NewIpNextAvailableInfo(objectParams map[string]string, params map[string][]
UseEaInheritance: useEaInheritance,
}

if isIpv6 {
if ipAddrType == "IPV6" {
nextAvailableIpInfo.Object = "ipv6network"
} else {
nextAvailableIpInfo.Object = "network"
Expand All @@ -228,32 +228,45 @@ func NewIpNextAvailableInfo(objectParams map[string]string, params map[string][]
}

func NewIpNextAvailable(name string, objectType string, objectParams map[string]string, params map[string][]string,
useEaInheritance bool, isIpv6 bool, ea EA, comment string, disable bool, n *int) *IpNextAvailable {
useEaInheritance bool, ea EA, comment string, disable bool, n *int, ipAddrType string) *IpNextAvailable {
nextAvailableIP := IpNextAvailable{
Name: name,
objectType: objectType,
Ea: ea,
Comment: comment,
Disable: disable,
}
if n != nil && *n >= 1 {
if n != nil && *n > 1 {
ipInfo := make([]IpNextAvailableInfo, *n)
for i := 0; i < *n; i++ {
ipInfo[i] = *NewIpNextAvailableInfo(objectParams, params, useEaInheritance, isIpv6)
if isIpv6 {
ipInfo[i] = *NewIpNextAvailableInfo(objectParams, params, useEaInheritance, ipAddrType)
if ipAddrType == "IPV6" {
nextAvailableIP.NextAvailableIPv6Addrs = append(nextAvailableIP.NextAvailableIPv6Addrs, NextavailableIPv6Addrs{NextavailableIPv6Addr: ipInfo[i]})
} else {
nextAvailableIP.NextAvailableIPv4Addrs = append(nextAvailableIP.NextAvailableIPv4Addrs, NextavailableIPv4Addrs{NextavailableIPv4Addr: ipInfo[i]})
}
}
} else {
if isIpv6 {
nextAvailableIP.NextAvailableIPv6Addr = NewIpNextAvailableInfo(objectParams, params, useEaInheritance, isIpv6)
} else {
nextAvailableIP.NextAvailableIPv4Addr = NewIpNextAvailableInfo(objectParams, params, useEaInheritance, isIpv6)
switch objectType {
case "record:a":
nextAvailableIP.NextAvailableIPv4Addr = NewIpNextAvailableInfo(objectParams, params, useEaInheritance, "IPV4")
case "record:aaaa":
nextAvailableIP.NextAvailableIPv6Addr = NewIpNextAvailableInfo(objectParams, params, useEaInheritance, "IPV6")
case "record:host":
{
switch ipAddrType {
case "IPV4":
nextAvailableIP.NextAvailableIPv4Addrs = []NextavailableIPv4Addrs{{*NewIpNextAvailableInfo(objectParams, params, useEaInheritance, "IPV4")}}
case "IPV6":
nextAvailableIP.NextAvailableIPv6Addrs = []NextavailableIPv6Addrs{{*NewIpNextAvailableInfo(objectParams, params, useEaInheritance, "IPV6")}}
case "Both":
nextAvailableIP.NextAvailableIPv6Addrs = []NextavailableIPv6Addrs{{NextavailableIPv6Addr: *NewIpNextAvailableInfo(objectParams, params, useEaInheritance, "IPV6")}}
nextAvailableIP.NextAvailableIPv4Addrs = []NextavailableIPv4Addrs{{NextavailableIPv4Addr: *NewIpNextAvailableInfo(objectParams, params, useEaInheritance, "IPV4")}}
}
}
}
}

}
return &nextAvailableIP
}

Expand Down