Skip to content

Commit

Permalink
Enable retrieving existing Prefix CIDRs from the Ipamer (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
rene-at-dell authored Oct 1, 2021
1 parent 5a06209 commit 6dd93fd
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
// ReadAllPrefixCidrs retrieves 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
}

// ReadAllPrefixCidrs retrieves 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 6dd93fd

Please sign in to comment.