Skip to content

Commit 8546bbe

Browse files
authored
New module: netbox_config_context (#610)
* New module: netbox_config_context
1 parent 204782e commit 8546bbe

File tree

4 files changed

+421
-3
lines changed

4 files changed

+421
-3
lines changed

plugins/module_utils/netbox_extras.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
SLUG_REQUIRED,
1212
)
1313

14+
NB_CONFIG_CONTEXTS = "config_contexts"
1415
NB_TAGS = "tags"
1516

1617

@@ -23,6 +24,7 @@ def run(self):
2324
This function should have all necessary code for endpoints within the application
2425
to create/update/delete the endpoint objects
2526
Supported endpoints:
27+
- config_contexts
2628
- tags
2729
"""
2830
# Used to dynamically set key when returning results

plugins/module_utils/netbox_utils.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"site_groups",
7171
"virtual_chassis",
7272
],
73-
extras=["tags"],
73+
extras=["config_contexts", "tags"],
7474
ipam=[
7575
"aggregates",
7676
"ip_addresses",
@@ -96,6 +96,7 @@
9696
cluster="name",
9797
cluster_group="slug",
9898
cluster_type="slug",
99+
config_context="name",
99100
device="name",
100101
device_role="slug",
101102
device_type="slug",
@@ -150,7 +151,9 @@
150151
"circuits.circuittermination": "circuit_terminations",
151152
"cluster": "clusters",
152153
"cluster_group": "cluster_groups",
154+
"cluster_groups": "cluster_groups",
153155
"cluster_type": "cluster_types",
156+
"config_context": "config_contexts",
154157
"dcim.consoleport": "console_ports",
155158
"dcim.consoleserverport": "console_server_ports",
156159
"dcim.frontport": "front_ports",
@@ -162,6 +165,7 @@
162165
"device": "devices",
163166
"device_role": "device_roles",
164167
"device_type": "device_types",
168+
"device_types": "device_types",
165169
"export_targets": "route_targets",
166170
"group": "tenant_groups",
167171
"import_targets": "route_targets",
@@ -181,6 +185,7 @@
181185
"parent_vm_interface": "interfaces",
182186
"parent_region": "regions",
183187
"parent_tenant_group": "tenant_groups",
188+
"platforms": "platforms",
184189
"power_panel": "power_panels",
185190
"power_port": "power_ports",
186191
"power_port_template": "power_port_templates",
@@ -193,19 +198,24 @@
193198
"rack_group": "rack_groups",
194199
"rack_role": "rack_roles",
195200
"region": "regions",
201+
"regions": "regions",
196202
"rear_port": "rear_ports",
197203
"rear_port_template": "rear_port_templates",
198204
"rir": "rirs",
205+
"roles": "device_roles",
199206
"route_targets": "route_targets",
200207
# Just a placeholder as scope can be several different types including sites.
201208
"scope": "sites",
202209
"services": "services",
203210
"site": "sites",
204211
"site_group": "site_groups",
212+
"sites": "sites",
205213
"tags": "tags",
206214
"tagged_vlans": "vlans",
207215
"tenant": "tenants",
216+
"tenants": "tenants",
208217
"tenant_group": "tenant_groups",
218+
"tenant_groups": "tenant_groups",
209219
"termination_a": "interfaces",
210220
"termination_b": "interfaces",
211221
"untagged_vlan": "vlans",
@@ -227,6 +237,7 @@
227237
"clusters": "cluster",
228238
"cluster_groups": "cluster_group",
229239
"cluster_types": "cluster_type",
240+
"config_contexts": "config_context",
230241
"console_ports": "console_port",
231242
"console_port_templates": "console_port_template",
232243
"console_server_ports": "console_server_port",
@@ -285,6 +296,21 @@
285296
"cluster": set(["name", "type"]),
286297
"cluster_group": set(["slug"]),
287298
"cluster_type": set(["slug"]),
299+
"config_context": set(
300+
[
301+
"name",
302+
"regions",
303+
"sites",
304+
"roles",
305+
"device_types",
306+
"platforms",
307+
"cluster_groups",
308+
"clusters",
309+
"tenant_groups",
310+
"tenants",
311+
"tags",
312+
]
313+
),
288314
"console_port": set(["name", "device"]),
289315
"console_port_template": set(["name", "device_type"]),
290316
"console_server_port": set(["name", "device"]),
@@ -907,7 +933,7 @@ def _find_ids(self, data, user_query_params):
907933
self.version, "2.9", greater_or_equal=True
908934
)
909935
and k == "tags"
910-
):
936+
) or (self.endpoint == "config_contexts" and k == "tags"):
911937
continue
912938
if k == "termination_a":
913939
endpoint = CONVERT_TO_ID[data.get("termination_a_type")]
@@ -936,7 +962,18 @@ def _find_ids(self, data, user_query_params):
936962
elif isinstance(v, list):
937963
id_list = list()
938964
for list_item in v:
939-
if k == "tags" and isinstance(list_item, str):
965+
if k in (
966+
"regions",
967+
"sites",
968+
"roles",
969+
"device_types",
970+
"platforms",
971+
"cluster_groups",
972+
"clusters",
973+
"tenant_groups",
974+
"tenants",
975+
"tags",
976+
) and isinstance(list_item, str):
940977
temp_dict = {"slug": self._to_slug(list_item)}
941978
elif isinstance(list_item, dict):
942979
norm_data = self._normalize_data(list_item)

0 commit comments

Comments
 (0)