From 6ab38472be13d8fe60320f4518a9753de41378e4 Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Tue, 29 Dec 2020 16:24:16 -0500 Subject: [PATCH 01/18] circuits model startup_scripts --- initializers/circuit_types.yml | 6 ++++++ initializers/circuits.yml | 6 ++++++ initializers/providers.yml | 6 ++++++ startup_scripts/280_providers.py | 18 +++++++++++++++++ startup_scripts/290_circuit_types.py | 18 +++++++++++++++++ startup_scripts/300_circuits.py | 29 ++++++++++++++++++++++++++++ 6 files changed, 83 insertions(+) create mode 100644 initializers/circuit_types.yml create mode 100644 initializers/circuits.yml create mode 100644 initializers/providers.yml create mode 100644 startup_scripts/280_providers.py create mode 100644 startup_scripts/290_circuit_types.py create mode 100644 startup_scripts/300_circuits.py diff --git a/initializers/circuit_types.yml b/initializers/circuit_types.yml new file mode 100644 index 0000000..0e9c356 --- /dev/null +++ b/initializers/circuit_types.yml @@ -0,0 +1,6 @@ +# - name: VPLS +# slug: vpls +# - name: MPLS +# slug: mpls +# - name: Internet +# slug: internet diff --git a/initializers/circuits.yml b/initializers/circuits.yml new file mode 100644 index 0000000..44e0a3a --- /dev/null +++ b/initializers/circuits.yml @@ -0,0 +1,6 @@ +# - cid: Circuit_ID-1 +# provider: Provider1 +# type: Internet +# - name: Circuit_ID-2 +# provider: Provider2 +# type: MPLS diff --git a/initializers/providers.yml b/initializers/providers.yml new file mode 100644 index 0000000..ca2ca1a --- /dev/null +++ b/initializers/providers.yml @@ -0,0 +1,6 @@ +# - name: Provider1 +# slug: provider1 +# asn: 121 +# - name: Provider2 +# slug: provider2 +# asn: 122 diff --git a/startup_scripts/280_providers.py b/startup_scripts/280_providers.py new file mode 100644 index 0000000..393d5ed --- /dev/null +++ b/startup_scripts/280_providers.py @@ -0,0 +1,18 @@ +from circuits.models import Provider +from startup_script_utils import * +import sys + +providers = load_yaml('/opt/netbox/initializers/providers.yml') + +if providers is None: + sys.exit() + +for params in providers: + custom_field_data = pop_custom_fields(params) + + provider, created = Provider.objects.get_or_create(**params) + + if created: + set_custom_fields_values(name, custom_field_data) + + print("📡 Created provider", provider.name) diff --git a/startup_scripts/290_circuit_types.py b/startup_scripts/290_circuit_types.py new file mode 100644 index 0000000..b6dca6c --- /dev/null +++ b/startup_scripts/290_circuit_types.py @@ -0,0 +1,18 @@ +from circuits.models import CircuitType +from startup_script_utils import * +import sys + +circuit_types = load_yaml('/opt/netbox/initializers/circuit_types.yml') + +if circuit_types is None: + sys.exit() + +for params in circuit_types: + custom_field_data = pop_custom_fields(params) + + circuit_type, created = CircuitType.objects.get_or_create(**params) + + if created: + set_custom_fields_values(name, custom_field_data) + + print("⚡ Created Circuit Type", circuit_type.name) diff --git a/startup_scripts/300_circuits.py b/startup_scripts/300_circuits.py new file mode 100644 index 0000000..3d2bf24 --- /dev/null +++ b/startup_scripts/300_circuits.py @@ -0,0 +1,29 @@ +from circuits.models import Circuit, Provider, CircuitType +from startup_script_utils import * +import sys + +circuits = load_yaml('/opt/netbox/initializers/circuits.yml') + +if circuits is None: + sys.exit() + +required_assocs = { + 'provider': (Provider, 'name'), + 'circuit_type': (CircuitType, 'name') +} + +for params in circuits: + custom_field_data = pop_custom_fields(params) + + for assoc, details in required_assocs.items(): + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + circuit, created = Circuit.objects.get_or_create(**params) + + if created: + set_custom_fields_values(cid, custom_field_data) + + print("⚡ Created Circuit", circuit.cid) From 31f52041f87e6f5cd412a06fdfeeb320197a3d86 Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Tue, 29 Dec 2020 18:27:41 -0500 Subject: [PATCH 02/18] correct circuit model startup scripts --- initializers/circuit_types.yml | 12 ++++++------ initializers/circuits.yml | 2 +- initializers/providers.yml | 12 ++++++------ startup_scripts/280_providers.py | 2 +- startup_scripts/290_circuit_types.py | 2 +- startup_scripts/300_circuits.py | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/initializers/circuit_types.yml b/initializers/circuit_types.yml index 0e9c356..95dee30 100644 --- a/initializers/circuit_types.yml +++ b/initializers/circuit_types.yml @@ -1,6 +1,6 @@ -# - name: VPLS -# slug: vpls -# - name: MPLS -# slug: mpls -# - name: Internet -# slug: internet +- name: VPLS + slug: vpls +- name: MPLS + slug: mpls +- name: Internet + slug: internet diff --git a/initializers/circuits.yml b/initializers/circuits.yml index 44e0a3a..93b4659 100644 --- a/initializers/circuits.yml +++ b/initializers/circuits.yml @@ -1,6 +1,6 @@ # - cid: Circuit_ID-1 # provider: Provider1 # type: Internet -# - name: Circuit_ID-2 +# - cid: Circuit_ID-2 # provider: Provider2 # type: MPLS diff --git a/initializers/providers.yml b/initializers/providers.yml index ca2ca1a..4d0e5b0 100644 --- a/initializers/providers.yml +++ b/initializers/providers.yml @@ -1,6 +1,6 @@ -# - name: Provider1 -# slug: provider1 -# asn: 121 -# - name: Provider2 -# slug: provider2 -# asn: 122 +- name: Provider1 + slug: provider1 + asn: 121 +- name: Provider2 + slug: provider2 + asn: 122 diff --git a/startup_scripts/280_providers.py b/startup_scripts/280_providers.py index 393d5ed..e927dda 100644 --- a/startup_scripts/280_providers.py +++ b/startup_scripts/280_providers.py @@ -13,6 +13,6 @@ for params in providers: provider, created = Provider.objects.get_or_create(**params) if created: - set_custom_fields_values(name, custom_field_data) + set_custom_fields_values(provider, custom_field_data) print("📡 Created provider", provider.name) diff --git a/startup_scripts/290_circuit_types.py b/startup_scripts/290_circuit_types.py index b6dca6c..441f059 100644 --- a/startup_scripts/290_circuit_types.py +++ b/startup_scripts/290_circuit_types.py @@ -13,6 +13,6 @@ for params in circuit_types: circuit_type, created = CircuitType.objects.get_or_create(**params) if created: - set_custom_fields_values(name, custom_field_data) + set_custom_fields_values(circuit_type, custom_field_data) print("⚡ Created Circuit Type", circuit_type.name) diff --git a/startup_scripts/300_circuits.py b/startup_scripts/300_circuits.py index 3d2bf24..456c792 100644 --- a/startup_scripts/300_circuits.py +++ b/startup_scripts/300_circuits.py @@ -9,7 +9,7 @@ if circuits is None: required_assocs = { 'provider': (Provider, 'name'), - 'circuit_type': (CircuitType, 'name') + 'type': (CircuitType, 'name') } for params in circuits: @@ -24,6 +24,6 @@ for params in circuits: circuit, created = Circuit.objects.get_or_create(**params) if created: - set_custom_fields_values(cid, custom_field_data) + set_custom_fields_values(circuit, custom_field_data) print("⚡ Created Circuit", circuit.cid) From 3094665092155cc23cd0d05e2d0dc6349ebe9c0a Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Tue, 29 Dec 2020 19:36:58 -0500 Subject: [PATCH 03/18] add tags & secret roles --- initializers/secret_roles.yml | 4 ++++ initializers/tags.yml | 12 ++++++++++++ startup_scripts/020_tags.py | 23 +++++++++++++++++++++++ startup_scripts/310_secret_roles.py | 14 ++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 initializers/secret_roles.yml create mode 100644 initializers/tags.yml create mode 100644 startup_scripts/020_tags.py create mode 100644 startup_scripts/310_secret_roles.py diff --git a/initializers/secret_roles.yml b/initializers/secret_roles.yml new file mode 100644 index 0000000..d85e719 --- /dev/null +++ b/initializers/secret_roles.yml @@ -0,0 +1,4 @@ +# - name: Super Secret Passwords +# slug: super-secret +# - name: SNMP Communities +# slug: snmp \ No newline at end of file diff --git a/initializers/tags.yml b/initializers/tags.yml new file mode 100644 index 0000000..1cbe3be --- /dev/null +++ b/initializers/tags.yml @@ -0,0 +1,12 @@ +# - name: Tag 1 +# slug: tag-1 +# color: Pink +# - name: Tag 2 +# slug: tag-2 +# color: Cyan +# - name: Tag 3 +# slug: tag-3 +# color: Grey +# - name: Tag 4 +# slug: tag-4 +# color: Teal diff --git a/startup_scripts/020_tags.py b/startup_scripts/020_tags.py new file mode 100644 index 0000000..2939e75 --- /dev/null +++ b/startup_scripts/020_tags.py @@ -0,0 +1,23 @@ +from extras.models import Tag +from utilities.choices import ColorChoices + +from startup_script_utils import load_yaml +import sys + +tags = load_yaml('/opt/netbox/initializers/tags.yml') + +if tags is None: + sys.exit() + +for params in tags: + if 'color' in params: + color = params.pop('color') + + for color_tpl in ColorChoices: + if color in color_tpl: + params['color'] = color_tpl[0] + + tag, created = Tag.objects.get_or_create(**params) + + if created: + print("🎨 Created Tag", tag.name) diff --git a/startup_scripts/310_secret_roles.py b/startup_scripts/310_secret_roles.py new file mode 100644 index 0000000..9b0e816 --- /dev/null +++ b/startup_scripts/310_secret_roles.py @@ -0,0 +1,14 @@ +from secrets.models import SecretRole +from startup_script_utils import load_yaml +import sys + +secret_roles = load_yaml('/opt/netbox/initializers/secret_roles.yml') + +if secret_roles is None: + sys.exit() + +for params in secret_roles: + secret_role, created = SecretRole.objects.get_or_create(**params) + + if created: + print("🔑 Created Secret Role", secret_role.name) From 621fa1293411475db6564ff828b8bd4ea9ad8f1d Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Tue, 29 Dec 2020 22:09:31 -0500 Subject: [PATCH 04/18] comment out secret roles --- initializers/secret_roles.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/initializers/secret_roles.yml b/initializers/secret_roles.yml index d85e719..239906a 100644 --- a/initializers/secret_roles.yml +++ b/initializers/secret_roles.yml @@ -1,4 +1,4 @@ # - name: Super Secret Passwords # slug: super-secret # - name: SNMP Communities -# slug: snmp \ No newline at end of file +# slug: snmp From 90018fc6d7e0070367d6e1e90c03a03e571c73bc Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Tue, 29 Dec 2020 22:10:19 -0500 Subject: [PATCH 05/18] add cluster group startup script --- initializers/cluster_groups.yml | 4 ++++ initializers/clusters.yml | 1 + startup_scripts/165_cluster_groups.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 initializers/cluster_groups.yml create mode 100644 startup_scripts/165_cluster_groups.py diff --git a/initializers/cluster_groups.yml b/initializers/cluster_groups.yml new file mode 100644 index 0000000..a611afa --- /dev/null +++ b/initializers/cluster_groups.yml @@ -0,0 +1,4 @@ +# - name: Group 1 +# slug: group-1 +# - name: Group 2 +# slug: group-2 diff --git a/initializers/clusters.yml b/initializers/clusters.yml index 1b1aca0..692be6c 100644 --- a/initializers/clusters.yml +++ b/initializers/clusters.yml @@ -1,5 +1,6 @@ # - name: cluster1 # type: Hyper-V +# group: Group 1 # - name: cluster2 # type: Hyper-V # site: SING 1 diff --git a/startup_scripts/165_cluster_groups.py b/startup_scripts/165_cluster_groups.py new file mode 100644 index 0000000..b52518a --- /dev/null +++ b/startup_scripts/165_cluster_groups.py @@ -0,0 +1,14 @@ +from virtualization.models import ClusterGroup +from startup_script_utils import load_yaml +import sys + +cluster_groups = load_yaml('/opt/netbox/initializers/cluster_groups.yml') + +if cluster_groups is None: + sys.exit() + +for params in cluster_groups: + cluster_group, created = ClusterGroup.objects.get_or_create(**params) + + if created: + print("🗄️ Created Cluster Group", cluster_group.name) From 0f1cc9eea09235ab229602f906ad58bc9aca4ec0 Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Wed, 30 Dec 2020 18:22:12 -0500 Subject: [PATCH 06/18] add tenant to aggregate startup_script --- startup_scripts/160_aggregates.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/startup_scripts/160_aggregates.py b/startup_scripts/160_aggregates.py index cc1d220..40aea1b 100644 --- a/startup_scripts/160_aggregates.py +++ b/startup_scripts/160_aggregates.py @@ -3,6 +3,7 @@ import sys from ipam.models import Aggregate, RIR from netaddr import IPNetwork from startup_script_utils import * +from tenancy.models import Tenant aggregates = load_yaml('/opt/netbox/initializers/aggregates.yml') @@ -13,6 +14,10 @@ required_assocs = { 'rir': (RIR, 'name') } +optional_assocs = { + 'tenant': (Tenant, 'name'), +} + for params in aggregates: custom_field_data = pop_custom_fields(params) @@ -24,6 +29,13 @@ for params in aggregates: params[assoc] = model.objects.get(**query) + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + aggregate, created = Aggregate.objects.get_or_create(**params) if created: From cbaaffc58914da9de93d1f7abfc59ff90ac41f24 Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Wed, 30 Dec 2020 18:23:12 -0500 Subject: [PATCH 07/18] =?UTF-8?q?add=20extra=20space=20after=20=E2=96=B6?= =?UTF-8?q?=EF=B8=8F=20to=20remove=20text=20overlap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- startup_scripts/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/startup_scripts/__main__.py b/startup_scripts/__main__.py index dc4cdc9..f85a1de 100644 --- a/startup_scripts/__main__.py +++ b/startup_scripts/__main__.py @@ -20,7 +20,7 @@ with scandir(this_dir) as it: if not f.name.endswith('.py'): continue - print(f"▶️ Running the startup script {f.path}") + print(f"▶️ Running the startup script {f.path}") try: runpy.run_path(f.path) except SystemExit as e: From 8d8c58df549e891d2923c0bab65ad636636942e8 Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Wed, 30 Dec 2020 19:09:08 -0500 Subject: [PATCH 08/18] optional assoc to cluster & circuit startup_script --- initializers/circuits.yml | 1 + initializers/clusters.yml | 1 + startup_scripts/170_clusters.py | 4 +++- startup_scripts/300_circuits.py | 12 ++++++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/initializers/circuits.yml b/initializers/circuits.yml index 93b4659..d47b06f 100644 --- a/initializers/circuits.yml +++ b/initializers/circuits.yml @@ -1,6 +1,7 @@ # - cid: Circuit_ID-1 # provider: Provider1 # type: Internet +# tenant: tenant1 # - cid: Circuit_ID-2 # provider: Provider2 # type: MPLS diff --git a/initializers/clusters.yml b/initializers/clusters.yml index 692be6c..4e15477 100644 --- a/initializers/clusters.yml +++ b/initializers/clusters.yml @@ -1,6 +1,7 @@ # - name: cluster1 # type: Hyper-V # group: Group 1 +# tenant: tenant1 # - name: cluster2 # type: Hyper-V # site: SING 1 diff --git a/startup_scripts/170_clusters.py b/startup_scripts/170_clusters.py index ffd965e..85e462f 100644 --- a/startup_scripts/170_clusters.py +++ b/startup_scripts/170_clusters.py @@ -3,6 +3,7 @@ import sys from dcim.models import Site from startup_script_utils import * from virtualization.models import Cluster, ClusterType, ClusterGroup +from tenancy.models import Tenant clusters = load_yaml('/opt/netbox/initializers/clusters.yml') @@ -15,7 +16,8 @@ required_assocs = { optional_assocs = { 'site': (Site, 'name'), - 'group': (ClusterGroup, 'name') + 'group': (ClusterGroup, 'name'), + 'tenant': (Tenant, 'name') } for params in clusters: diff --git a/startup_scripts/300_circuits.py b/startup_scripts/300_circuits.py index 456c792..d53272c 100644 --- a/startup_scripts/300_circuits.py +++ b/startup_scripts/300_circuits.py @@ -1,4 +1,5 @@ from circuits.models import Circuit, Provider, CircuitType +from tenancy.models import Tenant from startup_script_utils import * import sys @@ -12,6 +13,10 @@ required_assocs = { 'type': (CircuitType, 'name') } +optional_assocs = { + 'tenant': (Tenant, 'name') +} + for params in circuits: custom_field_data = pop_custom_fields(params) @@ -21,6 +26,13 @@ for params in circuits: params[assoc] = model.objects.get(**query) + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + circuit, created = Circuit.objects.get_or_create(**params) if created: From e3946af27c08496eb12a049f97963a605bc5f05d Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Wed, 30 Dec 2020 19:09:27 -0500 Subject: [PATCH 09/18] added tenant to example aggregates.yml --- initializers/aggregates.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/initializers/aggregates.yml b/initializers/aggregates.yml index d923a04..1d89272 100644 --- a/initializers/aggregates.yml +++ b/initializers/aggregates.yml @@ -1,6 +1,7 @@ -# - prefix: 10.0.0.0/16 -# rir: RFC1918 -# - prefix: fd00:ccdd::/32 -# rir: RFC4193 ULA -# - prefix: 2001:db8::/32 -# rir: RFC3849 + # - prefix: 10.0.0.0/16 + # rir: RFC1918 + # tenant: tenant1 + # - prefix: fd00:ccdd::/32 + # rir: RFC4193 ULA + # - prefix: 2001:db8::/32 + # rir: RFC3849 From dfb0327340d370fd3ebece5d62e8cf5a61842b95 Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Wed, 30 Dec 2020 19:10:30 -0500 Subject: [PATCH 10/18] Added power startup_scripts --- initializers/power_feeds.yml | 16 +++++++++++ initializers/power_panels.yml | 5 ++++ startup_scripts/330_power_panels.py | 41 +++++++++++++++++++++++++++++ startup_scripts/340_power_feeds.py | 41 +++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 initializers/power_feeds.yml create mode 100644 initializers/power_panels.yml create mode 100644 startup_scripts/330_power_panels.py create mode 100644 startup_scripts/340_power_feeds.py diff --git a/initializers/power_feeds.yml b/initializers/power_feeds.yml new file mode 100644 index 0000000..1c7b222 --- /dev/null +++ b/initializers/power_feeds.yml @@ -0,0 +1,16 @@ +# - name: power feed 1 +# #site: AMS 1 +# power_panel: power panel AMS 1 +# voltage: 208 +# amperage: 50 +# max_utilization: 80 +# phase: Single phase +# rack: rack-01 +# - name: power feed 2 +# #site: SING 1 +# power_panel: power panel SING 1 +# voltage: 208 +# amperage: 50 +# max_utilization: 80 +# phase: Three-phase +# rack: rack-03 diff --git a/initializers/power_panels.yml b/initializers/power_panels.yml new file mode 100644 index 0000000..1205851 --- /dev/null +++ b/initializers/power_panels.yml @@ -0,0 +1,5 @@ +# - name: power panel AMS 1 +# site: AMS 1 +# - name: power panel SING 1 +# site: SING 1 +# rack_group: cage 101 diff --git a/startup_scripts/330_power_panels.py b/startup_scripts/330_power_panels.py new file mode 100644 index 0000000..3057a96 --- /dev/null +++ b/startup_scripts/330_power_panels.py @@ -0,0 +1,41 @@ +import sys + +from dcim.models import Site, RackGroup, PowerPanel +from startup_script_utils import * +from tenancy.models import Tenant + +power_panels = load_yaml('/opt/netbox/initializers/power_panels.yml') + +if power_panels is None: + sys.exit() + +required_assocs = { + 'site': (Site, 'name') +} + +optional_assocs = { + 'rack_group': (RackGroup, 'name') +} + +for params in power_panels: + custom_field_data = pop_custom_fields(params) + + for assoc, details in required_assocs.items(): + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + power_panel, created = PowerPanel.objects.get_or_create(**params) + + if created: + set_custom_fields_values(power_panel, custom_field_data) + + print("⚡ Created Power Panel", power_panel.site, power_panel.name) diff --git a/startup_scripts/340_power_feeds.py b/startup_scripts/340_power_feeds.py new file mode 100644 index 0000000..fc7ee38 --- /dev/null +++ b/startup_scripts/340_power_feeds.py @@ -0,0 +1,41 @@ +import sys + +from dcim.models import Rack, PowerPanel, PowerFeed +from startup_script_utils import * +from tenancy.models import Tenant + +power_feeds = load_yaml('/opt/netbox/initializers/power_feeds.yml') + +if power_feeds is None: + sys.exit() + +required_assocs = { + 'power_panel': (PowerPanel, 'name') +} + +optional_assocs = { + 'rack': (Rack, 'name') +} + +for params in power_feeds: + custom_field_data = pop_custom_fields(params) + + for assoc, details in required_assocs.items(): + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + power_feed, created = PowerFeed.objects.get_or_create(**params) + + if created: + set_custom_fields_values(power_feed, custom_field_data) + + print("⚡ Created Power Feed", power_feed.name) From 818266ace1449183aefd06377b8bbb7285b4a916 Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Wed, 30 Dec 2020 19:10:46 -0500 Subject: [PATCH 11/18] added services startup_script --- initializers/services.yml | 10 ++++++++++ startup_scripts/320_services.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 initializers/services.yml create mode 100644 startup_scripts/320_services.py diff --git a/initializers/services.yml b/initializers/services.yml new file mode 100644 index 0000000..49b081c --- /dev/null +++ b/initializers/services.yml @@ -0,0 +1,10 @@ +# - name: SSH +# protocol: TCP +# ports: +# - 22 +# virtual_machine: virtual machine 1 +# - name: FTP +# protocol: TCP +# ports: +# - 21 +# device: server01 diff --git a/startup_scripts/320_services.py b/startup_scripts/320_services.py new file mode 100644 index 0000000..800f215 --- /dev/null +++ b/startup_scripts/320_services.py @@ -0,0 +1,29 @@ +from ipam.models import Service +from dcim.models import Device +from virtualization.models import VirtualMachine +from startup_script_utils import load_yaml +import sys + +services = load_yaml('/opt/netbox/initializers/services.yml') + +if services is None: + sys.exit() + +optional_assocs = { + 'device': (Device, 'name'), + 'virtual_machine': (VirtualMachine, 'name') +} + +for params in services: + + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + service, created = Service.objects.get_or_create(**params) + + if created: + print("🧰 Created Service", service.name) From 94509f86d799b718edc166a4369a7de2a9b1164e Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Wed, 30 Dec 2020 19:11:09 -0500 Subject: [PATCH 12/18] added route_targets startup_script --- initializers/route_targets.yml | 3 +++ startup_scripts/175_route_targets.py | 31 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 initializers/route_targets.yml create mode 100644 startup_scripts/175_route_targets.py diff --git a/initializers/route_targets.yml b/initializers/route_targets.yml new file mode 100644 index 0000000..2ef1406 --- /dev/null +++ b/initializers/route_targets.yml @@ -0,0 +1,3 @@ +# - name: 65000:1001 +# tenant: tenant1 +# - name: 65000:1002 diff --git a/startup_scripts/175_route_targets.py b/startup_scripts/175_route_targets.py new file mode 100644 index 0000000..efdaba6 --- /dev/null +++ b/startup_scripts/175_route_targets.py @@ -0,0 +1,31 @@ +import sys + +from ipam.models import RouteTarget +from startup_script_utils import * +from tenancy.models import Tenant + +route_targets = load_yaml('/opt/netbox/initializers/route_targets.yml') + +if route_targets is None: + sys.exit() + +optional_assocs = { + 'tenant': (Tenant, 'name') +} + +for params in route_targets: + custom_field_data = pop_custom_fields(params) + + for assoc, details in optional_assocs.items(): + if assoc in params: + model, field = details + query = { field: params.pop(assoc) } + + params[assoc] = model.objects.get(**query) + + route_target, created = RouteTarget.objects.get_or_create(**params) + + if created: + set_custom_fields_values(route_target, custom_field_data) + + print("🎯 Created Route Target", route_target.name) From 728a16c93d714a8835396f72972a3e7cff4334d2 Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Fri, 15 Jan 2021 09:19:21 -0500 Subject: [PATCH 13/18] correct initializers commenting --- initializers/aggregates.yml | 14 +++++++------- initializers/circuit_types.yml | 12 ++++++------ initializers/power_feeds.yml | 2 +- initializers/providers.yml | 12 ++++++------ 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/initializers/aggregates.yml b/initializers/aggregates.yml index 1d89272..b04eb7e 100644 --- a/initializers/aggregates.yml +++ b/initializers/aggregates.yml @@ -1,7 +1,7 @@ - # - prefix: 10.0.0.0/16 - # rir: RFC1918 - # tenant: tenant1 - # - prefix: fd00:ccdd::/32 - # rir: RFC4193 ULA - # - prefix: 2001:db8::/32 - # rir: RFC3849 +# - prefix: 10.0.0.0/16 +# rir: RFC1918 +# tenant: tenant1 +# - prefix: fd00:ccdd::/32 +# rir: RFC4193 ULA +# - prefix: 2001:db8::/32 +# rir: RFC3849 diff --git a/initializers/circuit_types.yml b/initializers/circuit_types.yml index 95dee30..0e9c356 100644 --- a/initializers/circuit_types.yml +++ b/initializers/circuit_types.yml @@ -1,6 +1,6 @@ -- name: VPLS - slug: vpls -- name: MPLS - slug: mpls -- name: Internet - slug: internet +# - name: VPLS +# slug: vpls +# - name: MPLS +# slug: mpls +# - name: Internet +# slug: internet diff --git a/initializers/power_feeds.yml b/initializers/power_feeds.yml index 1c7b222..9e6a7af 100644 --- a/initializers/power_feeds.yml +++ b/initializers/power_feeds.yml @@ -7,7 +7,7 @@ # phase: Single phase # rack: rack-01 # - name: power feed 2 -# #site: SING 1 +# site: SING 1 # power_panel: power panel SING 1 # voltage: 208 # amperage: 50 diff --git a/initializers/providers.yml b/initializers/providers.yml index 4d0e5b0..ca2ca1a 100644 --- a/initializers/providers.yml +++ b/initializers/providers.yml @@ -1,6 +1,6 @@ -- name: Provider1 - slug: provider1 - asn: 121 -- name: Provider2 - slug: provider2 - asn: 122 +# - name: Provider1 +# slug: provider1 +# asn: 121 +# - name: Provider2 +# slug: provider2 +# asn: 122 From 02713e1465c67ff3f0b2d917fc45fd5cc6806ead Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Fri, 15 Jan 2021 09:23:21 -0500 Subject: [PATCH 14/18] showcase protcol options in services initializer --- initializers/services.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/initializers/services.yml b/initializers/services.yml index 49b081c..59647df 100644 --- a/initializers/services.yml +++ b/initializers/services.yml @@ -3,8 +3,8 @@ # ports: # - 22 # virtual_machine: virtual machine 1 -# - name: FTP -# protocol: TCP +# - name: MISC +# protocol: UDP # ports: -# - 21 +# - 4000 # device: server01 From 4260e9b864ec653c1e086195b8237b0cd88cd762 Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Fri, 15 Jan 2021 09:26:09 -0500 Subject: [PATCH 15/18] more comment corrections --- initializers/power_feeds.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/initializers/power_feeds.yml b/initializers/power_feeds.yml index 9e6a7af..4b1338a 100644 --- a/initializers/power_feeds.yml +++ b/initializers/power_feeds.yml @@ -1,5 +1,5 @@ # - name: power feed 1 -# #site: AMS 1 +# site: AMS 1 # power_panel: power panel AMS 1 # voltage: 208 # amperage: 50 From 00fa1793d066554816e759a4b56c7657c5b205f1 Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Fri, 15 Jan 2021 14:14:07 -0500 Subject: [PATCH 16/18] update services examples --- initializers/services.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/initializers/services.yml b/initializers/services.yml index 59647df..8d4441c 100644 --- a/initializers/services.yml +++ b/initializers/services.yml @@ -1,7 +1,12 @@ -# - name: SSH +# - name: DNS # protocol: TCP # ports: -# - 22 +# - 53 +# virtual_machine: virtual machine 1 +# - name: DNS +# protocol: UDP +# ports: +# - 53 # virtual_machine: virtual machine 1 # - name: MISC # protocol: UDP From 788aeacd9b4377fac4f751efeaacf4ea02c646c7 Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Fri, 15 Jan 2021 14:25:42 -0500 Subject: [PATCH 17/18] correct missing required sites in power_feeds --- startup_scripts/340_power_feeds.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/startup_scripts/340_power_feeds.py b/startup_scripts/340_power_feeds.py index fc7ee38..8660da5 100644 --- a/startup_scripts/340_power_feeds.py +++ b/startup_scripts/340_power_feeds.py @@ -1,6 +1,6 @@ import sys -from dcim.models import Rack, PowerPanel, PowerFeed +from dcim.models import Rack, PowerPanel, PowerFeed, Site from startup_script_utils import * from tenancy.models import Tenant @@ -10,7 +10,8 @@ if power_feeds is None: sys.exit() required_assocs = { - 'power_panel': (PowerPanel, 'name') + 'power_panel': (PowerPanel, 'name'), + 'site': (Site, 'name') } optional_assocs = { From 2372c1eeff14e6a511acf7c9ce880bdc4f865720 Mon Sep 17 00:00:00 2001 From: ryanmerolle Date: Fri, 15 Jan 2021 15:02:01 -0500 Subject: [PATCH 18/18] remove site from power_feeds --- initializers/power_feeds.yml | 2 -- startup_scripts/340_power_feeds.py | 5 ++--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/initializers/power_feeds.yml b/initializers/power_feeds.yml index 4b1338a..7ef5891 100644 --- a/initializers/power_feeds.yml +++ b/initializers/power_feeds.yml @@ -1,5 +1,4 @@ # - name: power feed 1 -# site: AMS 1 # power_panel: power panel AMS 1 # voltage: 208 # amperage: 50 @@ -7,7 +6,6 @@ # phase: Single phase # rack: rack-01 # - name: power feed 2 -# site: SING 1 # power_panel: power panel SING 1 # voltage: 208 # amperage: 50 diff --git a/startup_scripts/340_power_feeds.py b/startup_scripts/340_power_feeds.py index 8660da5..fc7ee38 100644 --- a/startup_scripts/340_power_feeds.py +++ b/startup_scripts/340_power_feeds.py @@ -1,6 +1,6 @@ import sys -from dcim.models import Rack, PowerPanel, PowerFeed, Site +from dcim.models import Rack, PowerPanel, PowerFeed from startup_script_utils import * from tenancy.models import Tenant @@ -10,8 +10,7 @@ if power_feeds is None: sys.exit() required_assocs = { - 'power_panel': (PowerPanel, 'name'), - 'site': (Site, 'name') + 'power_panel': (PowerPanel, 'name') } optional_assocs = {