Last active
April 26, 2024 21:42
-
-
Save ross/0ff009f4b558921ec034063ff4cc1100 to your computer and use it in GitHub Desktop.
octodns gen-zones
This file contains hidden or 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 os import mkdir | |
from os.path import exists | |
from sys import argv, exit | |
from uuid import uuid4 | |
from yaml import dump | |
try: | |
n = int(argv[1]) | |
except IndexError: | |
n = 1000 | |
dynamic = 'dynamic' in argv | |
if not exists('tmp/in'): | |
if not exists('tmp'): | |
mkdir('tmp') | |
mkdir('tmp/in') | |
else: | |
print('tmp/in exists, need to delete it and run again') | |
exit(1) | |
if not exists('tmp/out'): | |
mkdir('tmp/out') | |
with open('tmp/large.yaml', 'w') as cfg: | |
cfg.write( | |
''' | |
manager: | |
max_workers: 1 | |
providers: | |
in: | |
class: octodns.provider.yaml.YamlProvider | |
directory: tmp/in | |
out: | |
class: octodns.provider.yaml.YamlProvider | |
directory: tmp/out | |
zones: | |
''' | |
) | |
if dynamic: | |
cfg.write(""" '*': | |
sources: | |
- in | |
targets: | |
- out | |
""") | |
for _ in range(n): | |
name = f'{uuid4().hex}.com.' | |
if not dynamic: | |
cfg.write( | |
f''' {name}: | |
sources: | |
- in | |
targets: | |
- out | |
''' | |
) | |
with open(f'tmp/in/{name}yaml', 'w') as zn: | |
zn.write(f'''--- | |
? '' | |
: - type: A | |
value: 1.2.3.4 | |
- type: NS | |
values: | |
- ns1.{name} | |
- ns2.{name} | |
ns1: | |
type: A | |
value: 2.3.4.5 | |
ns2: | |
type: A | |
value: 3.4.5.6 | |
''') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment