Skip to content

Commit

Permalink
Merge 0b622f0 into 5a06209
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-at-dell authored Sep 30, 2021
2 parents 5a06209 + 0b622f0 commit b13a3a3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type Ipamer interface {
// PrefixesOverlapping will check if one ore more prefix of newPrefixes is overlapping
// with one of existingPrefixes
PrefixesOverlapping(existingPrefixes []string, newPrefixes []string) error
// Retrieve all existing Prefix CIDRs from the underlying storage
ReadAllPrefixCidrs() ([]string, error)
}

type ipamer struct {
Expand Down
5 changes: 5 additions & 0 deletions prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@ func (i *ipamer) newPrefix(cidr, parentCidr string) (*Prefix, error) {
return p, nil
}

// Retrieve all existing Prefix CIDRs from the underlying storage
func (i *ipamer) ReadAllPrefixCidrs() ([]string, error) {
return i.storage.ReadAllPrefixCidrs()
}

func (p *Prefix) String() string {
return p.Cidr
}
Expand Down
17 changes: 17 additions & 0 deletions prefix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1456,3 +1456,20 @@ func TestAcquireIPParallel(t *testing.T) {
}
})
}

func TestIpamer_ReadAllPrefixCidrs(t *testing.T) {

testWithBackends(t, func(t *testing.T, ipam *ipamer) {
const cidr = "192.168.0.0/20"

prefix, err := ipam.NewPrefix(cidr)
require.Nil(t, err)
require.NotNil(t, prefix)

cidrs, err := ipam.ReadAllPrefixCidrs()
require.Nil(t, err)
require.NotNil(t, cidrs)
require.Equal(t, 1, len(cidrs))
require.Equal(t, cidr, cidrs[0])
})
}

0 comments on commit b13a3a3

Please sign in to comment.