Skip to content
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

Adjust modules for NetBox 4.0 support #1234

Merged
merged 7 commits into from
May 18, 2024
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
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:

- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run black
uses: psf/black@stable
Expand All @@ -35,10 +35,10 @@ jobs:
steps:

- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
steps:

- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Clone & Start netbox-docker containers - ${{ matrix.VERSION }}
run: |
Expand All @@ -100,7 +100,7 @@ jobs:
cd ..

- name: Set up Python ${{ env.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ env.python-version }}

Expand Down
10 changes: 9 additions & 1 deletion plugins/modules/netbox_custom_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
required: false
type: list
elements: raw
object_types:
description:
- The content type(s) to apply this custom field to (NetBox 4.0+)
required: false
type: list
elements: raw
version_added: "3.19.0"
type:
description:
- The type of custom field
Expand Down Expand Up @@ -227,6 +234,7 @@ def main():
required=True,
options=dict(
content_types=dict(required=False, type="list", elements="raw"),
object_types=dict(required=False, type="list", elements="raw"),
type=dict(
required=False,
choices=[
Expand Down Expand Up @@ -279,7 +287,7 @@ def main():
)

required_if = [
("state", "present", ["content_types", "name"]),
("state", "present", ["name"]),
("state", "absent", ["name"]),
]

Expand Down
10 changes: 9 additions & 1 deletion plugins/modules/netbox_custom_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
type: list
elements: raw
version_added: "3.10.0"
object_types:
description:
- The object type(s) to apply this custom link to (NetBox 4.0+)
required: false
type: list
elements: raw
version_added: "3.19.0"
name:
description:
- The name of the custom link
Expand Down Expand Up @@ -147,6 +154,7 @@ def main():
options=dict(
content_type=dict(required=False, type="raw"),
content_types=dict(required=False, type="list", elements="raw"),
object_types=dict(required=False, type="list", elements="raw"),
name=dict(required=True, type="str"),
link_text=dict(required=True, type="raw"),
link_url=dict(required=True, type="raw"),
Expand All @@ -165,7 +173,7 @@ def main():
("state", "absent", ["name"]),
]

required_one_of = [("content_type", "content_types")]
required_one_of = [("content_type", "content_types", "object_types")]

module = NetboxAnsibleModule(
argument_spec=argument_spec,
Expand Down
14 changes: 11 additions & 3 deletions plugins/modules/netbox_export_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@
required: false
type: list
elements: raw
version_added: "3.10.0"
version_added: "3.10.0"
object_types:
description:
- The object type to apply this export template to (NetBox 4.0+)
required: false
type: list
elements: raw
version_added: "3.10.0"
name:
description:
- The name of the export template
Expand Down Expand Up @@ -84,7 +91,7 @@
netbox_url: http://netbox.local
netbox_token: thisIsMyToken
data:
content_types: ["dcim.device", "virtualization.virtualmachine"]
object_types: ["dcim.device", "virtualization.virtualmachine"]
name: /etc/hosts
description: "Generate entries for /etc/hosts"
as_attachment: true
Expand Down Expand Up @@ -144,6 +151,7 @@ def main():
options=dict(
content_type=dict(required=False, type="raw"),
content_types=dict(required=False, type="list", elements="raw"),
object_types=dict(required=False, type="list", elements="raw"),
name=dict(required=True, type="str"),
description=dict(required=False, type="str"),
template_code=dict(required=True, type="raw"),
Expand All @@ -160,7 +168,7 @@ def main():
("state", "absent", ["name"]),
]

required_one_of = [["content_type", "content_types"]]
required_one_of = [["content_type", "content_types", "object_types"]]

module = NetboxAnsibleModule(
argument_spec=argument_spec,
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/targets/v4.0/tasks/netbox_custom_field.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
content_types:
object_types:
- "dcim.device"
name: A_CustomField
type: text
Expand All @@ -24,7 +24,7 @@
- test_one['diff']['after']['state'] == "present"
- test_one['custom_field']['name'] == "A_CustomField"
- test_one['custom_field']['required'] == false
- test_one['custom_field']['content_types'] == ["dcim.device"]
- test_one['custom_field']['object_types'] == ["dcim.device"]
- test_one['custom_field']['type'] == "text"
- test_one['custom_field']['weight'] == 100
- test_one['msg'] == "custom_field A_CustomField created"
Expand All @@ -34,7 +34,7 @@
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
content_types:
object_types:
- "dcim.device"
name: A_CustomField
state: present
Expand All @@ -52,7 +52,7 @@
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
content_types:
object_types:
- "dcim.device"
name: "A_CustomField"
description: "Added a description"
Expand All @@ -74,7 +74,7 @@
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
content_types:
object_types:
- "virtualization.virtualmachine"
name: "A_CustomField"
description: "Added a description"
Expand All @@ -86,7 +86,7 @@
assert:
that:
- test_four is changed
- test_four['diff']['after']['content_types'] == ["virtualization.virtualmachine"]
- test_four['diff']['after']['object_types'] == ["virtualization.virtualmachine"]
- test_four['custom_field']['name'] == "A_CustomField"
- test_four['msg'] == "custom_field A_CustomField updated"

Expand All @@ -113,7 +113,7 @@
# netbox_url: http://localhost:32768
# netbox_token: 0123456789abcdef0123456789abcdef01234567
# data:
# content_types:
# object_types:
# - "dcim.device"
# name: A_CustomField
# type: text
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/targets/v4.0/tasks/netbox_custom_link.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
content_types:
object_types:
- "dcim.device"
name: Custom Link
link_text: Open Web management
Expand All @@ -24,7 +24,7 @@
- test_one['diff']['before']['state'] == "absent"
- test_one['diff']['after']['state'] == "present"
- test_one['custom_link']['name'] == "Custom Link"
- test_one['custom_link']['content_types'] == ["dcim.device"]
- test_one['custom_link']['object_types'] == ["dcim.device"]
- test_one['custom_link']['link_text'] == "Open Web management"
- test_one['msg'] == "custom_link Custom Link created"

Expand All @@ -33,7 +33,7 @@
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
content_types:
object_types:
- "dcim.device"
name: Custom Link
link_text: Open Web management
Expand All @@ -53,7 +53,7 @@
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
content_types:
object_types:
- "dcim.device"
name: Custom Link
link_text: Open Web management
Expand All @@ -75,7 +75,7 @@
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
content_types:
object_types:
- "virtualization.virtualmachine"
name: Custom Link
link_text: Open Web management
Expand All @@ -87,7 +87,7 @@
assert:
that:
- test_four is changed
- test_four['diff']['after']['content_types'] == ["virtualization.virtualmachine"]
- test_four['diff']['after']['object_types'] == ["virtualization.virtualmachine"]
- test_four['custom_link']['name'] == "Custom Link"
- test_four['msg'] == "custom_link Custom Link updated"

Expand All @@ -96,7 +96,7 @@
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
content_types:
object_types:
- "virtualization.virtualmachine"
name: Custom Link
link_text: Open Web management
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/targets/v4.0/tasks/netbox_export_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
content_types:
object_types:
- "dcim.device"
name: Example Export Template
description: Export Devices
Expand All @@ -25,7 +25,7 @@
- test_one['diff']['before']['state'] == "absent"
- test_one['diff']['after']['state'] == "present"
- test_one['export_template']['name'] == "Example Export Template"
- test_one['export_template']['content_types'] == ["dcim.device"]
- test_one['export_template']['object_types'] == ["dcim.device"]
- test_one['export_template']['description'] == "Export Devices"
- test_one['msg'] == "export_template Example Export Template created"

Expand All @@ -34,7 +34,7 @@
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
content_types:
object_types:
- "dcim.device"
name: Example Export Template
description: Export Devices
Expand All @@ -55,7 +55,7 @@
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
content_types:
object_types:
- "dcim.device"
name: Example Export Template
description: Export Devices
Expand All @@ -78,7 +78,7 @@
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
content_types:
object_types:
- "virtualization.virtualmachine"
name: Example Export Template
description: Export Devices
Expand All @@ -91,7 +91,7 @@
assert:
that:
- test_four is changed
- test_four['diff']['after']['content_types'] == ["virtualization.virtualmachine"]
- test_four['diff']['after']['object_types'] == ["virtualization.virtualmachine"]
- test_four['export_template']['name'] == "Example Export Template"
- test_four['msg'] == "export_template Example Export Template updated"

Expand All @@ -100,7 +100,7 @@
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
content_types:
object_types:
- "virtualization.virtualmachine"
name: Example Export Template
description: Export Devices
Expand Down