Open dgjustice opened 3 years ago
I was also thinking about supporting a whitelist or blacklist. e.g. pass it a list of blocks to exclude due to business logic restrictions etc.
I like the thought of a whitelist/blacklist, sounds like it would be very useful.
Another use case I have considered in the past is maintaining octet size. This comes into play when replacing IP addresses that change the whitespace of the output. As networking is still heavy parsing, this has bit me before. Imagine
IP Name description
-------------------------------------------------------
10.1.1.1 Hello description should start on char 25
10.1.1.2 World description should start on char 25
turns into
IP Name description
-------------------------------------------------------
100.30.182.1 Hello description should start on char 25
1.1.1.2 World description should start on char 25
For that use case, would it be better to address the issue in the template that generates test cases?
template = """IP Name description
-------------------------------------------------------
{ip1} Hello description should start on char 25
{ip2} World description should start on char 25
"""
ip1 = "100.30.182.1"
ip2 = "1.1.1.2"
print(template.format(ip1=ip1, ip2=ip2))
template = """IP Name description
-------------------------------------------------------
{ip1:<14} Hello description should start on char 25
{ip2:<14} World description should start on char 25
"""
print(template.format(ip1=ip1, ip2=ip2))
IP Name description
-------------------------------------------------------
100.30.182.1 Hello description should start on char 25
1.1.1.2 World description should start on char 25
IP Name description
-------------------------------------------------------
100.30.182.1 Hello description should start on char 25
1.1.1.2 World description should start on char 25
Would this address your concern?
The use case is anonymizing and generating the data. Imagine taking in dozens of outputs for an ntc-templates PR and you obviously cannot use your companies IPs, so you want to anonymize. If you anonymize without keeping the octet structure the same, you will end up with bad data.
I've poked around with this quite a bit this week, and I hope to have a draft submitted tomorrow. I think randomization and obfuscation should be dealt with in different functions. I am happy to add the latter based on the work you shared from the ansible module.
Environment
Proposed Functionality
This functionality is largely supported in Faker, but I am proposing a stand-alone utility with extra nerd knobs.
generate_random_ip(*args)
and/orgenerate_random_network(*args)
args:
returns:
ipaddress.ip_address
/ipaddress.ip_network
Use Case
Random IP/networks for unit testing
@itdependsnetworks @jeffkala