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

Enable retrieving existing Prefix CIDRs from the Ipamer #69

Merged
merged 4 commits into from
Oct 1, 2021
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
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])
})
}