From 86675278ab0d2bcd05ce7475e21603b8ebf09318 Mon Sep 17 00:00:00 2001 From: Aleksandar Radunovic Date: Mon, 15 Oct 2018 15:14:11 +0200 Subject: [PATCH] Add manufacturer seeds --- initializers/manufacturers.yml | 6 ++++++ startup_scripts/42_manufacturers.py | 14 ++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 initializers/manufacturers.yml create mode 100644 startup_scripts/42_manufacturers.py diff --git a/initializers/manufacturers.yml b/initializers/manufacturers.yml new file mode 100644 index 0000000..18aef10 --- /dev/null +++ b/initializers/manufacturers.yml @@ -0,0 +1,6 @@ +# - name: Cisco +# slug: cisco +# - name: Intel +# slug: intel +# - name: NoName +# slug: noname diff --git a/startup_scripts/42_manufacturers.py b/startup_scripts/42_manufacturers.py new file mode 100644 index 0000000..49714bd --- /dev/null +++ b/startup_scripts/42_manufacturers.py @@ -0,0 +1,14 @@ +from dcim.models import Manufacturer +from ruamel.yaml import YAML + +with open('/opt/netbox/initializers/manufacturers.yml', 'r') as stream: + yaml = YAML(typ='safe') + manufacturers = yaml.load(stream) + + if manufacturers is not None: + for manufacturer_params in manufacturers: + manufacturer, created = Manufacturer.objects.get_or_create(**manufacturer_params) + + if created: + print("Created Manufacturer", manufacturer.name) +