Skip to content
Snippets Groups Projects
Verified Commit 3a7eaf8e authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

Re-introduce old faker provider for ip networks

Since the default one does not support limiting the subnet size
parent e9a7d85d
Branches
Tags
1 merge request!172Add IPAM step to IPtrunk creation
import contextlib
import ipaddress
import logging
import os
from pathlib import Path
......@@ -41,6 +42,23 @@ class UseJuniperSide(strEnum):
class FakerProvider(BaseProvider):
def ipv4_network(self, *, min_subnet=1, max_subnet=32) -> ipaddress.IPv4Network:
subnet = str(self.generator.random_int(min=min_subnet, max=max_subnet))
ipv4 = self.generator.ipv4()
interface = ipaddress.IPv4Interface(ipv4 + "/" + subnet)
# Extra step for converting ``10.53.92.39/24`` to ``10.53.92.0/24``
network = interface.network.network_address
return ipaddress.IPv4Network(str(network) + "/" + subnet)
def ipv6_network(self, *, min_subnet=1, max_subnet=128) -> ipaddress.IPv6Network:
subnet = str(self.generator.random_int(min=min_subnet, max=max_subnet))
ipv6 = self.generator.ipv6()
interface = ipaddress.IPv6Interface(ipv6 + "/" + subnet)
network = interface.network.network_address
return ipaddress.IPv6Network(str(network) + "/" + subnet)
def tt_number(self) -> str:
random_date = self.generator.date(pattern="%Y%m%d")
random_int = self.generator.random_int(min=10000000, max=99999999)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment