Skip to content

Adjust netbox_prefix and netbox_cluster for scope and scope_type #1367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelogs/fragments/scope_prefix_cluster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- netbox_prefix - Add options scope and scope_type for NetBox 4.2+
- netbox_cluster - Add options scope and scope_type for NetBox 4.2+
59 changes: 56 additions & 3 deletions plugins/modules/netbox_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,28 @@
type: raw
site:
description:
- Required if I(state=present) and the cluster does not exist yet
- Required if I(state=present) and the cluster does not exist yet (Deprecated in NetBox 4.2+)
- Will be removed in version 5.0.0
required: false
type: raw
scope_type:
description:
- Type of scope to be applied (NetBox 4.2+)
required: false
type: str
choices:
- "dcim.location"
- "dcim.rack"
- "dcim.region"
- "dcim.site"
- "dcim.sitegroup"
version_added: "3.21.0"
scope:
description:
- Object related to scope type (NetBox 4.2+)
required: false
type: raw
version_added: "3.21.0"
description:
description:
- The description of the cluster
Expand Down Expand Up @@ -131,6 +150,19 @@
site: SITE
status: planned
state: present

- name: Update the group and scope of an existing cluster (NetBox 4.2+)
netbox.netbox.netbox_cluster:
netbox_url: http://netbox.local
netbox_token: thisIsMyToken
data:
name: Test Cluster
cluster_type: qemu
cluster_group: GROUP
scope_type: "dcim.site"
scope: SITE
status: planned
state: present
"""

RETURN = r"""
Expand Down Expand Up @@ -170,7 +202,24 @@ def main():
status=dict(required=False, type="raw"),
cluster_type=dict(required=False, type="raw"),
cluster_group=dict(required=False, type="raw"),
site=dict(required=False, type="raw"),
site=dict(
required=False,
type="raw",
removed_in_version="5.0.0",
removed_from_collection="netbox.netbox",
),
scope_type=dict(
required=False,
type="str",
choices=[
"dcim.location",
"dcim.rack",
"dcim.region",
"dcim.site",
"dcim.sitegroup",
],
),
scope=dict(required=False, type="raw"),
tenant=dict(required=False, type="raw"),
description=dict(required=False, type="str"),
comments=dict(required=False, type="str"),
Expand All @@ -182,9 +231,13 @@ def main():
)

required_if = [("state", "present", ["name"]), ("state", "absent", ["name"])]
required_together = [("scope_type", "scope")]

module = NetboxAnsibleModule(
argument_spec=argument_spec, supports_check_mode=True, required_if=required_if
argument_spec=argument_spec,
supports_check_mode=True,
required_if=required_if,
required_together=required_together,
)

netbox_cluster = NetboxVirtualizationModule(module, NB_CLUSTERS)
Expand Down
54 changes: 52 additions & 2 deletions plugins/modules/netbox_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,28 @@
type: int
site:
description:
- Site that prefix is associated with
- Site that prefix is associated with (Deprecated in NetBox 4.2+)
- Will be removed in version 5.0.0
required: false
type: raw
scope_type:
description:
- Type of scope to be applied (NetBox 4.2+)
required: false
type: str
choices:
- "dcim.location"
- "dcim.rack"
- "dcim.region"
- "dcim.site"
- "dcim.sitegroup"
version_added: "3.21.0"
scope:
description:
- Object related to scope type (NetBox 4.2+)
required: false
type: raw
version_added: "3.21.0"
vrf:
description:
- VRF that prefix is associated with
Expand Down Expand Up @@ -212,6 +231,20 @@
site: Test Site
state: present
first_available: true

- name: Create prefix with scope (NetBox 4.2+)
netbox.netbox.netbox_prefix:
netbox_url: http://netbox.local
netbox_token: thisIsMyToken
data:
prefix: 10.156.32.0/19
scope_type: "dcim.site"
scope: Test Site
vrf: Test VRF
tenant: Test Tenant
status: Reserved
description: Test description
state: present
"""

RETURN = r"""
Expand Down Expand Up @@ -252,7 +285,24 @@ def main():
prefix=dict(required=False, type="raw"),
parent=dict(required=False, type="raw"),
prefix_length=dict(required=False, type="int"),
site=dict(required=False, type="raw"),
site=dict(
required=False,
type="raw",
removed_in_version="5.0.0",
removed_from_collection="netbox.netbox",
),
scope_type=dict(
required=False,
type="str",
choices=[
"dcim.location",
"dcim.rack",
"dcim.region",
"dcim.site",
"dcim.sitegroup",
],
),
scope=dict(required=False, type="raw"),
vrf=dict(required=False, type="raw"),
tenant=dict(required=False, type="raw"),
vlan=dict(required=False, type="raw"),
Expand Down
Loading
Loading