Skip to content

Commit ab639d9

Browse files
authored
Adjust netbox_prefix and netbox_cluster for scope and scope_type (#1367)
* Update netbox_prefix for NetBox 4.2 * Adjust test file to include tags for each test * Reformat netbox_prefix * Fix removed_in_version * Linting * Add changelog fragment * Fix fragment section
1 parent 89e2b26 commit ab639d9

File tree

6 files changed

+535
-76
lines changed

6 files changed

+535
-76
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
minor_changes:
2+
- netbox_prefix - Add options scope and scope_type for NetBox 4.2+
3+
- netbox_cluster - Add options scope and scope_type for NetBox 4.2+

plugins/modules/netbox_cluster.py

+56-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,28 @@
5353
type: raw
5454
site:
5555
description:
56-
- Required if I(state=present) and the cluster does not exist yet
56+
- Required if I(state=present) and the cluster does not exist yet (Deprecated in NetBox 4.2+)
57+
- Will be removed in version 5.0.0
5758
required: false
5859
type: raw
60+
scope_type:
61+
description:
62+
- Type of scope to be applied (NetBox 4.2+)
63+
required: false
64+
type: str
65+
choices:
66+
- "dcim.location"
67+
- "dcim.rack"
68+
- "dcim.region"
69+
- "dcim.site"
70+
- "dcim.sitegroup"
71+
version_added: "3.21.0"
72+
scope:
73+
description:
74+
- Object related to scope type (NetBox 4.2+)
75+
required: false
76+
type: raw
77+
version_added: "3.21.0"
5978
description:
6079
description:
6180
- The description of the cluster
@@ -131,6 +150,19 @@
131150
site: SITE
132151
status: planned
133152
state: present
153+
154+
- name: Update the group and scope of an existing cluster (NetBox 4.2+)
155+
netbox.netbox.netbox_cluster:
156+
netbox_url: http://netbox.local
157+
netbox_token: thisIsMyToken
158+
data:
159+
name: Test Cluster
160+
cluster_type: qemu
161+
cluster_group: GROUP
162+
scope_type: "dcim.site"
163+
scope: SITE
164+
status: planned
165+
state: present
134166
"""
135167

136168
RETURN = r"""
@@ -170,7 +202,24 @@ def main():
170202
status=dict(required=False, type="raw"),
171203
cluster_type=dict(required=False, type="raw"),
172204
cluster_group=dict(required=False, type="raw"),
173-
site=dict(required=False, type="raw"),
205+
site=dict(
206+
required=False,
207+
type="raw",
208+
removed_in_version="5.0.0",
209+
removed_from_collection="netbox.netbox",
210+
),
211+
scope_type=dict(
212+
required=False,
213+
type="str",
214+
choices=[
215+
"dcim.location",
216+
"dcim.rack",
217+
"dcim.region",
218+
"dcim.site",
219+
"dcim.sitegroup",
220+
],
221+
),
222+
scope=dict(required=False, type="raw"),
174223
tenant=dict(required=False, type="raw"),
175224
description=dict(required=False, type="str"),
176225
comments=dict(required=False, type="str"),
@@ -182,9 +231,13 @@ def main():
182231
)
183232

184233
required_if = [("state", "present", ["name"]), ("state", "absent", ["name"])]
234+
required_together = [("scope_type", "scope")]
185235

186236
module = NetboxAnsibleModule(
187-
argument_spec=argument_spec, supports_check_mode=True, required_if=required_if
237+
argument_spec=argument_spec,
238+
supports_check_mode=True,
239+
required_if=required_if,
240+
required_together=required_together,
188241
)
189242

190243
netbox_cluster = NetboxVirtualizationModule(module, NB_CLUSTERS)

plugins/modules/netbox_prefix.py

+52-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,28 @@
5555
type: int
5656
site:
5757
description:
58-
- Site that prefix is associated with
58+
- Site that prefix is associated with (Deprecated in NetBox 4.2+)
59+
- Will be removed in version 5.0.0
5960
required: false
6061
type: raw
62+
scope_type:
63+
description:
64+
- Type of scope to be applied (NetBox 4.2+)
65+
required: false
66+
type: str
67+
choices:
68+
- "dcim.location"
69+
- "dcim.rack"
70+
- "dcim.region"
71+
- "dcim.site"
72+
- "dcim.sitegroup"
73+
version_added: "3.21.0"
74+
scope:
75+
description:
76+
- Object related to scope type (NetBox 4.2+)
77+
required: false
78+
type: raw
79+
version_added: "3.21.0"
6180
vrf:
6281
description:
6382
- VRF that prefix is associated with
@@ -212,6 +231,20 @@
212231
site: Test Site
213232
state: present
214233
first_available: true
234+
235+
- name: Create prefix with scope (NetBox 4.2+)
236+
netbox.netbox.netbox_prefix:
237+
netbox_url: http://netbox.local
238+
netbox_token: thisIsMyToken
239+
data:
240+
prefix: 10.156.32.0/19
241+
scope_type: "dcim.site"
242+
scope: Test Site
243+
vrf: Test VRF
244+
tenant: Test Tenant
245+
status: Reserved
246+
description: Test description
247+
state: present
215248
"""
216249

217250
RETURN = r"""
@@ -252,7 +285,24 @@ def main():
252285
prefix=dict(required=False, type="raw"),
253286
parent=dict(required=False, type="raw"),
254287
prefix_length=dict(required=False, type="int"),
255-
site=dict(required=False, type="raw"),
288+
site=dict(
289+
required=False,
290+
type="raw",
291+
removed_in_version="5.0.0",
292+
removed_from_collection="netbox.netbox",
293+
),
294+
scope_type=dict(
295+
required=False,
296+
type="str",
297+
choices=[
298+
"dcim.location",
299+
"dcim.rack",
300+
"dcim.region",
301+
"dcim.site",
302+
"dcim.sitegroup",
303+
],
304+
),
305+
scope=dict(required=False, type="raw"),
256306
vrf=dict(required=False, type="raw"),
257307
tenant=dict(required=False, type="raw"),
258308
vlan=dict(required=False, type="raw"),

0 commit comments

Comments
 (0)