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
Add valid netmask random generator #54
Conversation
The set of network masks generated by this function is incomplete. There are valid uses cases for a /31, /32, /0, /1, etc CIDR. The web page linked to is correct when it states that the IP addresses in that table are "examples of commonly used netmasks." That table is not exhaustive. |
Tools from the standard library can be used to generate subnet masks. For example: >>> import ipaddress
>>> str(ipaddress.ip_network('0.0.0.0/20').netmask)
'255.255.240.0' |
The above only works on Python 3. I'm not sure if there's a similarly convenient tool in Python 2. |
|
||
For more info: http://www.iplocation.net/tools/netmask.php | ||
|
||
:returns: A random valid netmask with the format NNN.NNN.NNN.NNN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"The netmask is chosen from :data:fauxfactory.constants.VALID_NETMASKS
."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just want to make it very clear to clients that they are not really getting a random netmask. They are getting a random netmask from a subset of all available IPv4 netmasks.
186807a
to
e0ba773
Compare
For more info: http://www.iplocation.net/tools/netmask.php | ||
|
||
:returns: The netmask is chosen from | ||
:data:fauxfactory.constants.VALID_NETMASKS. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to surround "fauxfactory.constants.VALID_NETMASKS" with backticks. That didn't show up in my earlier comment. (whoops)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was in doubt about that, thanks for the update.
ACK |
@@ -511,6 +512,19 @@ def gen_mac(delimiter=":"): | |||
return _make_unicode(mac) | |||
|
|||
|
|||
def gen_netmask(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can an issue be created requesting configurable minimum and maximum values for the netmask? A /32 or /0 netmask is valid, and we should be able to generate them, even if those values seem nonsensical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can imagine something like this:
gen_netmask(min_cidr=0, max_cidr=20)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue #55 created
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
FYI, ipaddress is available in Python 2 via a library. See here. |
ACK |
Add valid netmask random generator
I was motivated to create this because this regex used to validate netmasks https://github.com/theforeman/foreman/blob/develop/lib/net/validations.rb#L8.
Also got some info at http://www.iplocation.net/tools/netmask.php.