This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from pybatfish.client.session import Session | |
# Step 1: Set up Pybatfish | |
bf = Session(host="localhost") | |
bf.set_network("backup_configs") | |
# Step 2: Load configurations | |
SNAPSHOT_DIR = "tests/data/inputs" | |
bf.init_snapshot(SNAPSHOT_DIR, name="backups", overwrite=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from jsonschema import Draft7Validator, exceptions | |
import netaddr | |
# Define the custom validators | |
def validate_ipv4(validator, ipv4, instance, schema): | |
try: | |
ip = netaddr.IPAddress(instance, version=4) | |
if 'ipv4WithPrefix' in schema and schema['ipv4WithPrefix']: | |
raise exceptions.ValidationError(f"{instance} should not be a plain IPv4 address when prefix length is expected.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Constructed with help from | |
# http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses | |
# Try it on regex101: https://regex101.com/r/yVdrJQ/1 | |
import re | |
IPV4SEG = r'(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])' | |
IPV4ADDR = r'(?:(?:' + IPV4SEG + r'\.){3,3}' + IPV4SEG + r')' | |
IPV6SEG = r'(?:(?:[0-9a-fA-F]){1,4})' | |
IPV6GROUPS = ( |