Skip to content

Commit

Permalink
Merge pull request #448 from nautobot/u/tsm1th-add-module-field-to-ports
Browse files Browse the repository at this point in the history
Added module relationship to multiple models for changes in Nautobot 2.3+
  • Loading branch information
joewesch authored Nov 20, 2024
2 parents 1565063 + 96de35b commit 6913d85
Show file tree
Hide file tree
Showing 26 changed files with 1,280 additions and 40 deletions.
2 changes: 1 addition & 1 deletion plugins/module_utils/dcim.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def run(self):

# This is logic to handle interfaces on a VC
if self.endpoint == "interfaces":
if self.nb_object:
if self.nb_object and not self.module.params["module"]:
device = self.nb.dcim.devices.get(self.nb_object.device.id)
if device["virtual_chassis"] and self.nb_object.device.id != self.data["device"]:
if self.module.params.get("update_vc_child"):
Expand Down
32 changes: 29 additions & 3 deletions plugins/modules/console_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
device:
description:
- The device the console port is attached to
required: true
required: false
type: raw
version_added: "3.0.0"
name:
Expand All @@ -48,6 +48,12 @@
required: false
type: str
version_added: "3.0.0"
module:
description:
- The attached module
required: false
type: raw
version_added: "5.4.0"
"""

EXAMPLES = r"""
Expand All @@ -65,6 +71,14 @@
device: Test Device
state: present
- name: Create console port inside module
networktocode.nautobot.console_port:
url: http://nautobot.local
token: thisIsMyToken
name: Test Console Port
module: HooverMaxProModel60
state: present
- name: Update console port with other fields
networktocode.nautobot.console_port:
url: http://nautobot.local
Expand Down Expand Up @@ -115,14 +129,26 @@ def main():
argument_spec.update(deepcopy(TAGS_ARG_SPEC))
argument_spec.update(
dict(
device=dict(required=True, type="raw"),
device=dict(required=False, type="raw"),
module=dict(required=False, type="raw"),
name=dict(required=True, type="str"),
type=dict(required=False, type="str"),
description=dict(required=False, type="str"),
)
)

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
required_one_of = [
("device", "module"),
]
mutually_exclusive = [
("device", "module"),
]
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_one_of=required_one_of,
mutually_exclusive=mutually_exclusive,
)

console_port = NautobotDcimModule(module, NB_CONSOLE_PORTS)
console_port.run()
Expand Down
30 changes: 27 additions & 3 deletions plugins/modules/console_port_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
device_type:
description:
- The device type the console port template is attached to
required: true
required: false
type: raw
version_added: "3.0.0"
name:
Expand All @@ -41,6 +41,12 @@
version_added: "3.0.0"
required: false
type: str
module_type:
description:
- The module type the console port template is attached to
required: false
type: raw
version_added: "5.4.0"
"""

EXAMPLES = r"""
Expand Down Expand Up @@ -101,9 +107,27 @@ def main():
Main entry point for module execution
"""
argument_spec = deepcopy(NAUTOBOT_ARG_SPEC)
argument_spec.update(dict(device_type=dict(required=True, type="raw"), name=dict(required=True, type="str"), type=dict(required=False, type="str")))
argument_spec.update(
dict(
device_type=dict(required=False, type="raw"),
name=dict(required=True, type="str"),
type=dict(required=False, type="str"),
module_type=dict(required=False, type="raw"),
)
)

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
required_one_of = [
("device_type", "module_type"),
]
mutually_exclusive = [
("device_type", "module_type"),
]
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_one_of=required_one_of,
mutually_exclusive=mutually_exclusive,
)

console_port_template = NautobotDcimModule(module, NB_CONSOLE_PORT_TEMPLATES)
console_port_template.run()
Expand Down
32 changes: 29 additions & 3 deletions plugins/modules/console_server_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
device:
description:
- The device the console server port is attached to
required: true
required: false
type: raw
version_added: "3.0.0"
name:
Expand All @@ -48,6 +48,12 @@
required: false
type: str
version_added: "3.0.0"
module:
description:
- The attached module
required: false
type: raw
version_added: "5.4.0"
"""

EXAMPLES = r"""
Expand All @@ -65,6 +71,14 @@
device: Test Device
state: present
- name: Create console server port inside module
networktocode.nautobot.console_server_port:
url: http://nautobot.local
token: thisIsMyToken
name: Test Console Server Port
module: HooverMaxProModel60
state: present
- name: Update console server port with other fields
networktocode.nautobot.console_server_port:
url: http://nautobot.local
Expand Down Expand Up @@ -115,14 +129,26 @@ def main():
argument_spec.update(deepcopy(TAGS_ARG_SPEC))
argument_spec.update(
dict(
device=dict(required=True, type="raw"),
device=dict(required=False, type="raw"),
module=dict(required=False, type="raw"),
name=dict(required=True, type="str"),
type=dict(required=False, type="str"),
description=dict(required=False, type="str"),
)
)

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
required_one_of = [
("device", "module"),
]
mutually_exclusive = [
("device", "module"),
]
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_one_of=required_one_of,
mutually_exclusive=mutually_exclusive,
)

console_server_port = NautobotDcimModule(module, NB_CONSOLE_SERVER_PORTS)
console_server_port.run()
Expand Down
24 changes: 21 additions & 3 deletions plugins/modules/console_server_port_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
device_type:
description:
- The device type the console server port template is attached to
required: true
required: false
type: raw
version_added: "3.0.0"
name:
Expand All @@ -41,6 +41,12 @@
required: false
type: str
version_added: "3.0.0"
module_type:
description:
- The module type the console server port template is attached to
required: false
type: raw
version_added: "5.4.0"
"""

EXAMPLES = r"""
Expand Down Expand Up @@ -103,13 +109,25 @@ def main():
argument_spec = deepcopy(NAUTOBOT_ARG_SPEC)
argument_spec.update(
dict(
device_type=dict(required=True, type="raw"),
device_type=dict(required=False, type="raw"),
name=dict(required=True, type="str"),
type=dict(required=False, type="str"),
module_type=dict(required=False, type="raw"),
)
)

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
required_one_of = [
("device_type", "module_type"),
]
mutually_exclusive = [
("device_type", "module_type"),
]
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_one_of=required_one_of,
mutually_exclusive=mutually_exclusive,
)

console_server_port_template = NautobotDcimModule(module, NB_CONSOLE_SERVER_PORT_TEMPLATES)
console_server_port_template.run()
Expand Down
24 changes: 21 additions & 3 deletions plugins/modules/device_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
device:
description:
- Name of the device the interface will be associated with (case-sensitive)
required: true
required: false
type: raw
version_added: "3.0.0"
status:
Expand Down Expand Up @@ -138,6 +138,12 @@
Use when master device is specified for C(device) and the specified interface exists on a child device
and needs updated
version_added: "3.0.0"
module:
description:
- The attached module
required: false
type: raw
version_added: "5.4.0"
"""

EXAMPLES = r"""
Expand Down Expand Up @@ -278,7 +284,8 @@ def main():
argument_spec.update(
dict(
update_vc_child=dict(type="bool", required=False, default=False),
device=dict(required=True, type="raw"),
device=dict(required=False, type="raw"),
module=dict(required=False, type="raw"),
status=dict(required=False, type="raw"),
name=dict(required=True, type="str"),
label=dict(required=False, type="str"),
Expand All @@ -298,7 +305,18 @@ def main():
)
)

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
required_one_of = [
("device", "module"),
]
mutually_exclusive = [
("device", "module"),
]
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_one_of=required_one_of,
mutually_exclusive=mutually_exclusive,
)

device_interface = NautobotDcimModule(module, NB_INTERFACES, remove_keys=["update_vc_child"])
device_interface.run()
Expand Down
24 changes: 21 additions & 3 deletions plugins/modules/device_interface_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
device_type:
description:
- Name of the device the interface template will be associated with (case-sensitive)
required: true
required: false
type: raw
version_added: "3.0.0"
name:
Expand Down Expand Up @@ -62,6 +62,12 @@
required: false
type: str
version_added: "5.2.0"
module_type:
description:
- The module type the interface template is attached to
required: false
type: raw
version_added: "5.4.0"
"""

EXAMPLES = r"""
Expand Down Expand Up @@ -115,7 +121,7 @@ def main():
argument_spec = deepcopy(NAUTOBOT_ARG_SPEC)
argument_spec.update(
dict(
device_type=dict(required=True, type="raw"),
device_type=dict(required=False, type="raw"),
name=dict(required=True, type="str"),
type=dict(
required=True,
Expand All @@ -124,10 +130,22 @@ def main():
mgmt_only=dict(required=False, type="bool"),
label=dict(required=False, type="str"),
description=dict(required=False, type="str"),
module_type=dict(required=False, type="raw"),
)
)

module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
required_one_of = [
("device_type", "module_type"),
]
mutually_exclusive = [
("device_type", "module_type"),
]
module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True,
required_one_of=required_one_of,
mutually_exclusive=mutually_exclusive,
)

device_interface_template = NautobotDcimModule(module, NB_INTERFACE_TEMPLATES)
device_interface_template.run()
Expand Down
Loading

0 comments on commit 6913d85

Please sign in to comment.