Skip to content

Commit

Permalink
make sure preloaded prefixes get populated with default site name (id…
Browse files Browse the repository at this point in the history
  • Loading branch information
mmguero committed Nov 1, 2023
1 parent fd69cad commit e518880
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions netbox/preload/prefixes_defaults.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- prefix: 10.0.0.0/8
site: NETBOX_DEFAULT_SITE
- prefix: 172.16.0.0/12
site: NETBOX_DEFAULT_SITE
- prefix: 192.168.0.0/16
site: NETBOX_DEFAULT_SITE
6 changes: 5 additions & 1 deletion netbox/scripts/netbox_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,12 +617,16 @@ def main():

# only preload catch-all IP Prefixes if explicitly specified and they don't already exist
if args.preloadPrefixes:
defaultSiteName = next(iter([x for x in args.netboxSites]), None)
for loadType in ('vrfs', 'prefixes'):
defaultFileName = os.path.join(tmpPreloadDir, f'{loadType}_defaults.yml')
loadFileName = os.path.join(tmpPreloadDir, f'{loadType}.yml')
if os.path.isfile(defaultFileName) and (not os.path.isfile(loadFileName)):
try:
shutil.copyfile(defaultFileName, loadFileName)
with open(defaultFileName, 'r') as infile:
with open(loadFileName, 'w') as outfile:
for line in infile:
outfile.write(line.replace("NETBOX_DEFAULT_SITE", defaultSiteName))
except Exception:
pass

Expand Down

0 comments on commit e518880

Please sign in to comment.