2021-02-26 23:26:32 +01:00
|
|
|
#!/usr/bin/env python3
|
2020-10-08 22:28:12 +02:00
|
|
|
from collections import Counter
|
2021-02-27 01:02:03 +01:00
|
|
|
from datetime import datetime
|
2020-12-11 19:37:00 +01:00
|
|
|
import yaml
|
|
|
|
import pynetbox
|
2023-03-24 20:13:38 +01:00
|
|
|
from glob import glob
|
2020-12-11 19:37:00 +01:00
|
|
|
import os
|
2020-02-20 14:52:01 +01:00
|
|
|
|
2023-03-03 22:03:17 +01:00
|
|
|
import settings
|
2023-03-24 20:13:38 +01:00
|
|
|
from netbox_api import NetBox
|
2021-05-16 14:46:09 +02:00
|
|
|
|
2020-12-11 19:37:00 +01:00
|
|
|
|
2021-08-25 18:57:38 +02:00
|
|
|
def main():
|
|
|
|
startTime = datetime.now()
|
2023-03-03 22:03:17 +01:00
|
|
|
args = settings.args
|
2021-08-25 18:57:38 +02:00
|
|
|
|
2023-03-24 20:13:38 +01:00
|
|
|
netbox = NetBox(settings)
|
|
|
|
files, vendors = settings.dtl_repo.get_devices(
|
|
|
|
f'{settings.dtl_repo.repo_path}/device-types/', args.vendors)
|
|
|
|
|
|
|
|
settings.handle.log(f'{len(vendors)} Vendors Found')
|
|
|
|
device_types = settings.dtl_repo.parse_files(files, slugs=args.slugs)
|
|
|
|
settings.handle.log(f'{len(device_types)} Device-Types Found')
|
|
|
|
netbox.create_manufacturers(vendors)
|
|
|
|
netbox.create_device_types(device_types)
|
|
|
|
|
|
|
|
if netbox.modules:
|
|
|
|
settings.handle.log("Modules Enabled. Creating Modules...")
|
|
|
|
files, vendors = settings.dtl_repo.get_devices(
|
|
|
|
f'{settings.dtl_repo.repo_path}/module-types/', args.vendors)
|
|
|
|
settings.handle.log(f'{len(vendors)} Module Vendors Found')
|
|
|
|
module_types = settings.dtl_repo.parse_files(files, slugs=args.slugs)
|
|
|
|
settings.handle.log(f'{len(module_types)} Module-Types Found')
|
|
|
|
netbox.create_manufacturers(vendors)
|
|
|
|
netbox.create_module_types(module_types)
|
|
|
|
|
|
|
|
settings.handle.log('---')
|
|
|
|
settings.handle.verbose_log(
|
|
|
|
f'Script took {(datetime.now() - startTime)} to run')
|
|
|
|
settings.handle.log(f'{netbox.counter["added"]} devices created')
|
2023-03-28 15:37:50 +02:00
|
|
|
settings.handle.log(f'{netbox.counter["images"]} images uploaded')
|
2023-03-24 20:13:38 +01:00
|
|
|
settings.handle.log(
|
|
|
|
f'{netbox.counter["updated"]} interfaces/ports updated')
|
|
|
|
settings.handle.log(
|
|
|
|
f'{netbox.counter["manufacturer"]} manufacturers created')
|
2022-09-08 18:48:24 +02:00
|
|
|
if settings.NETBOX_FEATURES['modules']:
|
2023-03-24 20:13:38 +01:00
|
|
|
settings.handle.log(
|
|
|
|
f'{netbox.counter["module_added"]} modules created')
|
|
|
|
settings.handle.log(
|
|
|
|
f'{netbox.counter["module_port_added"]} module interface / ports created')
|
2022-09-08 03:37:23 +02:00
|
|
|
|
|
|
|
|
2021-08-25 18:57:38 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|