From 7305f7eb6aa1521b3cee6b09300973e6455cc4ab Mon Sep 17 00:00:00 2001 From: Nick Thompson <13121431+nsthompson@users.noreply.github.com> Date: Mon, 24 Mar 2025 16:33:01 -0500 Subject: [PATCH 1/6] updated netbox_circuit_termination.py to support termination_id and termination_type requirements from NetBox 4.2.0 release --- plugins/modules/netbox_circuit_termination.py | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/plugins/modules/netbox_circuit_termination.py b/plugins/modules/netbox_circuit_termination.py index 4a05d62cf..1dc2922f6 100644 --- a/plugins/modules/netbox_circuit_termination.py +++ b/plugins/modules/netbox_circuit_termination.py @@ -49,16 +49,22 @@ required: false type: bool version_added: 3.5.0 - site: + termination_id: description: - - The site the circuit termination will be assigned to + - The ProviderNewtork, Location, Site, Region, or SiteGroup ID of the circuit termination will be assigned to required: false - type: raw - provider_network: + type: int + termination_type: description: - - The provider_network the circuit termination will be assigned to + - The type the circuit termination will be assigned to + choices: + - dcim.site + - dcim.location + - dcim.region + - dcim.sitegroup + - circuits.providernetwork required: false - type: raw + type: str port_speed: description: - The speed of the port (Kbps) @@ -100,7 +106,8 @@ data: circuit: Test Circuit term_side: A - site: Test Site + termination_id: 1 + termination_type: dcim.site port_speed: 10000 state: present @@ -163,8 +170,8 @@ def main(): circuit=dict(required=True, type="raw"), term_side=dict(required=True, choices=["A", "Z"]), mark_connected=dict(required=False, type="bool"), - site=dict(required=False, type="raw"), - provider_network=dict(required=False, type="raw"), + termination_id=dict(required=False, type="int"), + termination_type=dict(required=False, type="str"), port_speed=dict(required=False, type="int"), upstream_speed=dict(required=False, type="int"), xconnect_id=dict(required=False, type="str"), From f12b3e46f680e19ff68c5ecd41b7fa3f28f7402f Mon Sep 17 00:00:00 2001 From: Nick Thompson <13121431+nsthompson@users.noreply.github.com> Date: Mon, 24 Mar 2025 16:44:02 -0500 Subject: [PATCH 2/6] fixed typo in documentation --- plugins/modules/netbox_circuit_termination.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/netbox_circuit_termination.py b/plugins/modules/netbox_circuit_termination.py index 1dc2922f6..392aa711a 100644 --- a/plugins/modules/netbox_circuit_termination.py +++ b/plugins/modules/netbox_circuit_termination.py @@ -51,7 +51,7 @@ version_added: 3.5.0 termination_id: description: - - The ProviderNewtork, Location, Site, Region, or SiteGroup ID of the circuit termination will be assigned to + - The ProviderNetwork, Location, Site, Region, or SiteGroup ID of the circuit termination will be assigned to required: false type: int termination_type: From a0118d3a455d91191284d2861084e7eacfea8417 Mon Sep 17 00:00:00 2001 From: Nick Thompson <13121431+nsthompson@users.noreply.github.com> Date: Tue, 25 Mar 2025 12:38:38 -0500 Subject: [PATCH 3/6] added backward compatibility with NetBox versions before 4.2.0 --- plugins/modules/netbox_circuit_termination.py | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/plugins/modules/netbox_circuit_termination.py b/plugins/modules/netbox_circuit_termination.py index 392aa711a..18febc408 100644 --- a/plugins/modules/netbox_circuit_termination.py +++ b/plugins/modules/netbox_circuit_termination.py @@ -51,12 +51,12 @@ version_added: 3.5.0 termination_id: description: - - The ProviderNetwork, Location, Site, Region, or SiteGroup ID of the circuit termination will be assigned to + - The ProviderNetwork, Location, Site, Region, or SiteGroup ID of the circuit termination will be assigned to. This is used with NetBox versions >= 4.2.0. required: false type: int termination_type: description: - - The type the circuit termination will be assigned to + - The type the circuit termination will be assigned to. This is used with NetBox versions >= 4.2.0. choices: - dcim.site - dcim.location @@ -65,6 +65,16 @@ - circuits.providernetwork required: false type: str + site: + description: + - The site the circuit termination will be assigned to. This is used with NetBox versions before 4.2.0. + required: false + type: raw + provider_network: + description: + - The provider_network the circuit termination will be assigned to. This is used with NetBox versions before 4.2.0. + required: false + type: raw port_speed: description: - The speed of the port (Kbps) @@ -99,7 +109,7 @@ gather_facts: false tasks: - - name: Create circuit termination within NetBox with only required information + - name: Create circuit termination within NetBox version 4.2.0 or later with only required information netbox.netbox.netbox_circuit_termination: netbox_url: http://netbox.local netbox_token: thisIsMyToken @@ -111,6 +121,17 @@ port_speed: 10000 state: present + - name: Create circuit termination within NetBox versions earlier than 4.2.0 with only required information + netbox.netbox.netbox_circuit_termination: + netbox_url: http://netbox.local + netbox_token: thisIsMyToken + data: + circuit: Test Circuit + term_side: A + site: Test Site + port_speed: 10000 + state: present + - name: Update circuit termination with other fields netbox.netbox.netbox_circuit_termination: netbox_url: http://netbox.local @@ -172,6 +193,8 @@ def main(): mark_connected=dict(required=False, type="bool"), termination_id=dict(required=False, type="int"), termination_type=dict(required=False, type="str"), + site=dict(required=False, type="raw"), + provider_network=dict(required=False, type="raw"), port_speed=dict(required=False, type="int"), upstream_speed=dict(required=False, type="int"), xconnect_id=dict(required=False, type="str"), @@ -187,8 +210,18 @@ def main(): ("state", "absent", ["circuit", "term_side"]), ] + mutually_exclusive = [ + ("termination_id", "site"), + ("termination_type", "site"), + ("termination_id", "provider_network"), + ("termination_type", "provider_network") + ] + 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, + mutually_exclusive=mutually_exclusive ) netbox_circuit_termination = NetboxCircuitsModule(module, NB_CIRCUIT_TERMINATIONS) From 20b5dc80b9c8bde40fdfadf546e7eafa9bcbf3a6 Mon Sep 17 00:00:00 2001 From: Nick Thompson <13121431+nsthompson@users.noreply.github.com> Date: Tue, 25 Mar 2025 16:47:31 -0500 Subject: [PATCH 4/6] black formatting and changelog fragement --- changelogs/fragments/netbox_circuit_termination.yml | 2 ++ plugins/modules/netbox_circuit_termination.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/netbox_circuit_termination.yml diff --git a/changelogs/fragments/netbox_circuit_termination.yml b/changelogs/fragments/netbox_circuit_termination.yml new file mode 100644 index 000000000..9e08c4cc5 --- /dev/null +++ b/changelogs/fragments/netbox_circuit_termination.yml @@ -0,0 +1,2 @@ +minor_changes: + - netbox_circuit_termination - Add parameters termination_id and termination_type for NetBox 4.2+ diff --git a/plugins/modules/netbox_circuit_termination.py b/plugins/modules/netbox_circuit_termination.py index 18febc408..0b8633a91 100644 --- a/plugins/modules/netbox_circuit_termination.py +++ b/plugins/modules/netbox_circuit_termination.py @@ -54,6 +54,7 @@ - The ProviderNetwork, Location, Site, Region, or SiteGroup ID of the circuit termination will be assigned to. This is used with NetBox versions >= 4.2.0. required: false type: int + version_added: 4.2.0 termination_type: description: - The type the circuit termination will be assigned to. This is used with NetBox versions >= 4.2.0. @@ -65,6 +66,7 @@ - circuits.providernetwork required: false type: str + version_added: 4.2.0 site: description: - The site the circuit termination will be assigned to. This is used with NetBox versions before 4.2.0. @@ -214,14 +216,14 @@ def main(): ("termination_id", "site"), ("termination_type", "site"), ("termination_id", "provider_network"), - ("termination_type", "provider_network") + ("termination_type", "provider_network"), ] module = NetboxAnsibleModule( argument_spec=argument_spec, supports_check_mode=True, required_if=required_if, - mutually_exclusive=mutually_exclusive + mutually_exclusive=mutually_exclusive, ) netbox_circuit_termination = NetboxCircuitsModule(module, NB_CIRCUIT_TERMINATIONS) From 790546a7704203904dbbc426a42fc2f5f419e0c4 Mon Sep 17 00:00:00 2001 From: Nick Thompson <13121431+nsthompson@users.noreply.github.com> Date: Wed, 26 Mar 2025 08:27:03 -0500 Subject: [PATCH 5/6] fixed doc-choices-do-not-match-spec CI failure --- plugins/modules/netbox_circuit_termination.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/modules/netbox_circuit_termination.py b/plugins/modules/netbox_circuit_termination.py index 0b8633a91..c52cc636a 100644 --- a/plugins/modules/netbox_circuit_termination.py +++ b/plugins/modules/netbox_circuit_termination.py @@ -194,7 +194,17 @@ def main(): term_side=dict(required=True, choices=["A", "Z"]), mark_connected=dict(required=False, type="bool"), termination_id=dict(required=False, type="int"), - termination_type=dict(required=False, type="str"), + termination_type=dict( + required=False, + type="str", + choices=[ + "dcim.site", + "dcim.location", + "dcim.region", + "dcim.sitegroup", + "circuits.providernetwork", + ], + ), site=dict(required=False, type="raw"), provider_network=dict(required=False, type="raw"), port_speed=dict(required=False, type="int"), From 720d1d485d08afe0c8a58c702b6a0a4f9be3ebc6 Mon Sep 17 00:00:00 2001 From: Nick Thompson <13121431+nsthompson@users.noreply.github.com> Date: Wed, 26 Mar 2025 08:32:36 -0500 Subject: [PATCH 6/6] fixed line length failure from CI checks --- plugins/modules/netbox_circuit_termination.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/modules/netbox_circuit_termination.py b/plugins/modules/netbox_circuit_termination.py index c52cc636a..6bf5aec2b 100644 --- a/plugins/modules/netbox_circuit_termination.py +++ b/plugins/modules/netbox_circuit_termination.py @@ -51,13 +51,15 @@ version_added: 3.5.0 termination_id: description: - - The ProviderNetwork, Location, Site, Region, or SiteGroup ID of the circuit termination will be assigned to. This is used with NetBox versions >= 4.2.0. + - The ProviderNetwork, Location, Site, Region, or SiteGroup ID of the circuit termination will be assigned to. + - This parameter is used with NetBox versions >= 4.2.0. required: false type: int version_added: 4.2.0 termination_type: description: - - The type the circuit termination will be assigned to. This is used with NetBox versions >= 4.2.0. + - The type the circuit termination will be assigned to. + - This parameter is used with NetBox versions >= 4.2.0. choices: - dcim.site - dcim.location @@ -69,12 +71,14 @@ version_added: 4.2.0 site: description: - - The site the circuit termination will be assigned to. This is used with NetBox versions before 4.2.0. + - The site the circuit termination will be assigned to. + - This parameter is used with NetBox versions before 4.2.0. required: false type: raw provider_network: description: - - The provider_network the circuit termination will be assigned to. This is used with NetBox versions before 4.2.0. + - The provider_network the circuit termination will be assigned to. + - This parameter is used with NetBox versions before 4.2.0. required: false type: raw port_speed: