Skip to content

Commit 0de8cb7

Browse files
NetBox 2.11 integration tests working and related 2.11 required changes (#511)
1 parent a4cabd0 commit 0de8cb7

File tree

99 files changed

+1998
-1013
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1998
-1013
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: false
1111
matrix:
12-
python-version: [3.6, 3.7]
12+
python-version: [3.6, 3.7, 3.8, 3.9]
1313
steps:
1414
- name: Checkout repo
1515
uses: actions/checkout@v2
@@ -46,8 +46,8 @@ jobs:
4646
matrix:
4747
include:
4848
- python-version: 3.6
49-
VERSION: "v2.9"
50-
INTEGRATION_TESTS: "v2.9"
49+
VERSION: "v2.10"
50+
INTEGRATION_TESTS: "v2.10"
5151
- python-version: 3.6
5252
VERSION: "latest"
5353
INTEGRATION_TESTS: "latest"
@@ -58,13 +58,14 @@ jobs:
5858
uses: actions/setup-python@v2
5959
with:
6060
python-version: ${{ matrix.python-version }}
61-
- name: Clone & Start netbox-docker containers - latest
61+
- name: Clone & Start netbox-docker containers - 2.10
6262
env:
6363
VERSION: ${{ matrix.VERSION }}
6464
run: |
6565
cd ..
6666
git clone https://github.com/netbox-community/netbox-docker.git
6767
cd netbox-docker
68+
git checkout 1.1.0
6869
tee docker-compose.override.yml <<EOF
6970
version: '3.4'
7071
services:
@@ -75,26 +76,25 @@ jobs:
7576
docker-compose up -d --quiet-pull
7677
docker container ls
7778
cd ..
78-
if: matrix.VERSION == 'latest'
79-
- name: Clone & Start netbox-docker containers - 2.9
79+
if: matrix.VERSION == 'v2.10'
80+
- name: Clone & Start netbox-docker containers - latest
8081
env:
8182
VERSION: ${{ matrix.VERSION }}
8283
run: |
8384
cd ..
8485
git clone https://github.com/netbox-community/netbox-docker.git
8586
cd netbox-docker
86-
git checkout 0.26.2
8787
tee docker-compose.override.yml <<EOF
8888
version: '3.4'
8989
services:
90-
nginx:
90+
netbox:
9191
ports:
9292
- 32768:8080
9393
EOF
9494
docker-compose up -d --quiet-pull
9595
docker container ls
9696
cd ..
97-
if: matrix.VERSION == 'v2.9'
97+
if: matrix.VERSION == 'latest'
9898
- name: Install and configure Poetry
9999
uses: snok/install-poetry@v1.1.1
100100
with:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ To keep the code simple, we only officially support the two latest releases of N
1212

1313
- NetBox 2.6+ or the two latest NetBox releases
1414
- Python 3.6+
15-
- Python modules: **pynetbox 5.0.4+**
15+
- Python modules: **pynetbox 5.0.4+**, **packages** if using Ansible < 2.10 as it's included in Ansible 2.10+
1616
- Ansible 2.9+
1717
- NetBox write-enabled token when using modules or read-only token for `nb_lookup/nb_inventory`
1818

changelogs/fragments/2.11-changes.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
minor_changes:
3+
- **netbox_power_panel** - Add `location` option.
4+
- **netbox_rack** - Add `location` option.
5+
- **netbox_vlan_group** - Add `scope_type` option.
6+
- **netbox_vlan_group** - Add `scope` option.
7+
- **netbox_vlan_group** - Add `description` option.
8+
- **netbox_vlan_group** - Add `custom_fields` option.
9+
10+
major_changes:
11+
- **packages** is now a required Python package and gets installed via Ansible 2.10+.

galaxy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace: netbox
99
name: netbox
1010

1111
# The version of the collection. Must be compatible with semantic versioning
12-
version: 3.0.0
12+
version: 3.1.0
1313

1414
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
1515
readme: README.md
@@ -46,7 +46,7 @@ tags:
4646
# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version
4747
# range specifiers can be set and are separated by ','
4848
# dependencies:
49-
# Required for json_query used in lookup plugin integration tests
49+
# Required for json_query used in lookup plugin integration tests
5050
# community.general: ">=1.0.0"
5151

5252
# The URL of the originating SCM repository

meta/runtime.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ requires_ansible: ">=2.9.10"
33
plugin_routing:
44
modules:
55
netbox_interface:
6+
tombstone:
7+
removal_version: "0.1.0"
8+
warning_text: "netbox_interface has been superseceded by netbox.netbox.netbox_device_interface"
69
redirect: netbox.netbox.plugins.modules.netbox_device_interface

plugins/module_utils/netbox_utils.py

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"interfaces",
5252
"interface_templates",
5353
"inventory_items",
54+
"locations",
5455
"manufacturers",
5556
"platforms",
5657
"power_feeds",
@@ -66,6 +67,7 @@
6667
"rear_port_templates",
6768
"regions",
6869
"sites",
70+
"site_groups",
6971
"virtual_chassis",
7072
],
7173
extras=["tags"],
@@ -101,6 +103,7 @@
101103
group="slug",
102104
installed_device="name",
103105
import_targets="name",
106+
location="slug",
104107
manufacturer="slug",
105108
nat_inside="address",
106109
nat_outside="address",
@@ -125,6 +128,7 @@
125128
route_targets="name",
126129
slug="slug",
127130
site="slug",
131+
site_group="slug",
128132
tenant="slug",
129133
tenant_group="slug",
130134
time_zone="timezone",
@@ -166,6 +170,7 @@
166170
"interface_template": "interface_templates",
167171
"ip_addresses": "ip_addresses",
168172
"ipaddresses": "ip_addresses",
173+
"location": "locations",
169174
"lag": "interfaces",
170175
"manufacturer": "manufacturers",
171176
"master": "devices",
@@ -190,8 +195,11 @@
190195
"rear_port_template": "rear_port_templates",
191196
"rir": "rirs",
192197
"route_targets": "route_targets",
198+
# Just a placeholder as scope can be several different types including sites.
199+
"scope": "sites",
193200
"services": "services",
194201
"site": "sites",
202+
"site_group": "site_groups",
195203
"tags": "tags",
196204
"tagged_vlans": "vlans",
197205
"tenant": "tenants",
@@ -232,6 +240,7 @@
232240
"interface_templates": "interface_template",
233241
"inventory_items": "inventory_item",
234242
"ip_addresses": "ip_address",
243+
"locations": "location",
235244
"manufacturers": "manufacturer",
236245
"platforms": "platform",
237246
"power_feeds": "power_feed",
@@ -253,6 +262,7 @@
253262
"route_targets": "route_target",
254263
"services": "services",
255264
"sites": "site",
265+
"site_groups": "site_group",
256266
"tags": "tags",
257267
"tenants": "tenant",
258268
"tenant_groups": "tenant_group",
@@ -300,6 +310,7 @@
300310
"ip_addresses": set(["address", "vrf", "device", "interface", "assigned_object"]),
301311
"ipaddresses": set(["address", "vrf", "device", "interface", "assigned_object"]),
302312
"lag": set(["name"]),
313+
"location": set(["slug"]),
303314
"manufacturer": set(["slug"]),
304315
"master": set(["name"]),
305316
"nat_inside": set(["vrf", "address"]),
@@ -337,7 +348,7 @@
337348
"virtual_chassis": set(["name", "master"]),
338349
"virtual_machine": set(["name", "cluster"]),
339350
"vlan": set(["group", "name", "site", "tenant", "vid", "vlan_group"]),
340-
"vlan_group": set(["slug", "site"]),
351+
"vlan_group": set(["slug", "site", "scope"]),
341352
"vrf": set(["name", "tenant"]),
342353
}
343354

@@ -351,6 +362,7 @@
351362
"rir",
352363
"vrf",
353364
"site",
365+
"scope",
354366
"tenant",
355367
"type",
356368
"virtual_machine",
@@ -390,6 +402,7 @@
390402
# This is used to map non-clashing keys to Netbox API compliant keys to prevent bad logic in code for similar keys but different modules
391403
CONVERT_KEYS = {
392404
"assigned_object": "assigned_object_id",
405+
"scope": "scope_id",
393406
"circuit_type": "type",
394407
"cluster_type": "type",
395408
"cluster_group": "group",
@@ -417,12 +430,14 @@
417430
"device_roles",
418431
"device_types",
419432
"ipam_roles",
433+
"locations",
420434
"rack_groups",
421435
"rack_roles",
422436
"regions",
423437
"rirs",
424438
"roles",
425439
"sites",
440+
"site_groups",
426441
"tags",
427442
"tenants",
428443
"tenant_groups",
@@ -432,6 +447,16 @@
432447
"vlan_groups",
433448
}
434449

450+
SCOPE_TO_ENDPOINT = {
451+
"dcim.location": "locations",
452+
"dcim.rack": "racks",
453+
"dcim.region": "regions",
454+
"dcim.site": "sites",
455+
"dcim.sitegroup": "site_groups",
456+
"virtualization.cluster": "clusters",
457+
"virtualization.clustergroup": "cluster_groups",
458+
}
459+
435460
NETBOX_ARG_SPEC = dict(
436461
netbox_url=dict(type="str", required=True),
437462
netbox_token=dict(type="str", required=True, no_log=True),
@@ -609,8 +634,8 @@ def _convert_identical_keys(self, data):
609634
if self.endpoint == "power_panels" and key == "rack_group":
610635
temp_dict[key] = data[key]
611636
elif key in CONVERT_KEYS:
612-
# This will keep the original key for assigned_object, but also convert to assigned_object_id
613-
if key == "assigned_object":
637+
# This will keep the original key for keys in list, but also convert it.
638+
if key in ("assigned_object", "scope"):
614639
temp_dict[key] = data[key]
615640
new_key = CONVERT_KEYS[key]
616641
temp_dict[new_key] = data[key]
@@ -672,6 +697,8 @@ def _build_query_params(
672697
parent = module_data["termination_a_type"]
673698
elif parent == "termination_b" and module_data.get("termination_b_type"):
674699
parent = module_data["termination_b_type"]
700+
elif parent == "scope":
701+
parent = ENDPOINT_NAME_MAPPING[SCOPE_TO_ENDPOINT[module_data["scope_type"]]]
675702

676703
query_dict = dict()
677704
if user_query_params:
@@ -862,6 +889,9 @@ def _find_ids(self, data, user_query_params):
862889
endpoint = CONVERT_TO_ID[data.get("termination_b_type")]
863890
elif k == "assigned_object":
864891
endpoint = "interfaces"
892+
elif k == "scope":
893+
# Determine endpoint name for scope ID resolution
894+
endpoint = SCOPE_TO_ENDPOINT[data["scope_type"]]
865895
else:
866896
endpoint = CONVERT_TO_ID[k]
867897
search = v
@@ -911,6 +941,12 @@ def _find_ids(self, data, user_query_params):
911941
query_params = self._build_query_params(
912942
k, data, user_query_params
913943
)
944+
elif k == "scope":
945+
query_params = {
946+
QUERY_TYPES.get(
947+
ENDPOINT_NAME_MAPPING[endpoint], "q"
948+
): search
949+
}
914950
else:
915951
query_params = {QUERY_TYPES.get(k, "q"): search}
916952
query_id = self._nb_endpoint_get(nb_endpoint, query_params, k)
@@ -960,7 +996,13 @@ def _normalize_data(self, data):
960996
if sub_data_type == "slug":
961997
data[k][subk] = self._to_slug(subv)
962998
else:
963-
data_type = QUERY_TYPES.get(k, "q")
999+
if k == "scope":
1000+
data_type = QUERY_TYPES.get(
1001+
ENDPOINT_NAME_MAPPING[SCOPE_TO_ENDPOINT[data["scope_type"]]],
1002+
"q",
1003+
)
1004+
else:
1005+
data_type = QUERY_TYPES.get(k, "q")
9641006
if data_type == "slug":
9651007
data[k] = self._to_slug(v)
9661008
elif data_type == "timezone":

0 commit comments

Comments
 (0)