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

SubnetSplitter not subnetting correctly #154

Open
alanwill opened this issue Mar 6, 2017 · 1 comment
Open

SubnetSplitter not subnetting correctly #154

alanwill opened this issue Mar 6, 2017 · 1 comment

Comments

@alanwill
Copy link

alanwill commented Mar 6, 2017

It appears SubnetSplitter isn't subnetting correctly, here's what I'm seeing:

In this scenario I'm requesting 3 /24s and 3/26s from a /22

>>> from netaddr import *
>>> splitter = SubnetSplitter('10.40.0.0/22')
>>> subnet_24s = splitter.extract_subnet(24, count=3)
>>> subnet_26s = splitter.extract_subnet(26, count=3)
>>> print subnet_24s
[IPNetwork('10.40.0.0/24'), IPNetwork('10.40.1.0/24'), IPNetwork('10.40.2.0/24')]
>>> print subnet_26s
[IPNetwork('10.40.2.0/26'), IPNetwork('10.40.2.64/26'), IPNetwork('10.40.2.128/26')]
>>> available = splitter.available_subnets()
>>> print available
[IPNetwork('10.40.2.128/25'), IPNetwork('10.40.3.0/24')]

It's allocating 10.40.2.0/26 even with 10.40.2.0/24 already allocated.

@alanwill
Copy link
Author

alanwill commented Mar 6, 2017

If the above extracts are done in reverse it fails:

>>> from netaddr import *
>>> splitter = SubnetSplitter('10.40.0.0/22')
>>> subnet_26s = splitter.extract_subnet(26, count=3)
>>> print splitter.available_subnets()
[IPNetwork('10.40.0.128/25'), IPNetwork('10.40.1.0/24'), IPNetwork('10.40.2.0/23')]
>>> subnet_24s = splitter.extract_subnet(24, count=3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/python2.7/site-packages/netaddr/contrib/subnet_splitter.py", line 28, in extract_subnet
    subnets = list(cidr.subnet(prefix, count=count))
  File "/lib/python2.7/site-packages/netaddr/ip/__init__.py", line 1271, in subnet
    raise ValueError('count outside of current IP subnet boundary!')
ValueError: count outside of current IP subnet boundary!

It looks like it's not merging what's available in order to perform the 2nd extract but instead taking the 3 subnets and trying to split those individually, is this expected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant