Skip to content

Allow adding power port templates to modules #1105

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 4 commits into from
Nov 2, 2023
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
1 change: 1 addition & 0 deletions plugins/lookup/nb_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def get_endpoint(netbox, term):
"module-bays": {"endpoint": netbox.dcim.module_bays},
"module-bay-templates": {"endpoint": netbox.dcim.module_bay_templates},
"module-bay-types": {"endpoint": netbox.dcim.module_bay_types},
"module-types": {"endpoint": netbox.dcim.module_types},
"modules": {"endpoint": netbox.dcim.modules},
"object-changes": {"endpoint": netbox.extras.object_changes},
"permissions": {"endpoint": netbox.users.permissions},
Expand Down
1 change: 1 addition & 0 deletions plugins/module_utils/netbox_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
"lag": "interfaces",
"manufacturer": "manufacturers",
"master": "devices",
"module_type": "module_types",
"nat_inside": "ip_addresses",
"nat_outside": "ip_addresses",
"platform": "platforms",
Expand Down
34 changes: 29 additions & 5 deletions plugins/modules/netbox_power_port_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@
device_type:
description:
- The device type the power port is attached to
required: true
- Either I(device_type) or I(module_type) are required
type: raw
module_type:
description:
- The module type the power port is attached to
- Either I(device_type) or I(module_type) are required
type: raw
name:
description:
Expand Down Expand Up @@ -175,6 +180,17 @@
device_type: Test Device Type
state: present

- name: Create power port for a module type within NetBox
netbox.netbox.netbox_power_port_template:
netbox_url: http://netbox.local
netbox_token: thisIsMyToken
data:
name: Test Power Port Template
module_type: Test Module Type
type: iec-60320-c6
maximum_draw: 750
state: present

- name: Update power port with other fields
netbox.netbox.netbox_power_port_template:
netbox_url: http://netbox.local
Expand Down Expand Up @@ -230,7 +246,8 @@ def main():
type="dict",
required=True,
options=dict(
device_type=dict(required=True, type="raw"),
device_type=dict(required=False, type="raw"),
module_type=dict(required=False, type="raw"),
name=dict(required=True, type="str"),
type=dict(
required=False,
Expand Down Expand Up @@ -346,12 +363,19 @@ def main():
)

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

required_one_of = [
("device_type", "module_type"),
]

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_one_of=required_one_of,
)

netbox_power_port_template = NetboxDcimModule(module, NB_POWER_PORT_TEMPLATES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
### NETBOX_POWER_PORT_TEMPLATE
##
##
- name: "POWER_PORT_TEMPLATE 0: Create device type for testing power ports"
- name: "POWER_PORT_TEMPLATE 0.1: Create device type for testing power ports on device types"
netbox.netbox.netbox_device_type:
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
Expand All @@ -16,6 +16,15 @@
manufacturer: Test Manufacturer
state: present

- name: "POWER_PORT_TEMPLATE 0.2: Create module type for testing power ports on module types"
netbox.netbox.netbox_module_type:
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
model: Module Type Power Tests
manufacturer: Test Manufacturer
state: present

- name: "POWER_PORT_TEMPLATE 1: Necessary info creation"
netbox.netbox.netbox_power_port_template:
netbox_url: http://localhost:32768
Expand Down Expand Up @@ -118,3 +127,86 @@
- test_five['diff']['before']['state'] == "present"
- test_five['diff']['after']['state'] == "absent"
- test_five['msg'] == "power_port_template Power Port Template 2 deleted"

- name: "POWER_PORT_TEMPLATE 6: Necessary info creation"
netbox.netbox.netbox_power_port_template:
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
name: Module Power Port Template
module_type: Module Type Power Tests
state: present
register: test_six

- name: "POWER_PORT_TEMPLATE 6: ASSERT - Necessary info creation"
assert:
that:
- test_six is changed
- test_six['diff']['before']['state'] == "absent"
- test_six['diff']['after']['state'] == "present"
- test_six['power_port_template']['name'] == "Module Power Port Template"
- test_six['power_port_template']['module_type'] == 1
- test_six['msg'] == "power_port_template Module Power Port Template created"

- name: "POWER_PORT_TEMPLATE 7: Create duplicate"
netbox.netbox.netbox_power_port_template:
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
name: Module Power Port Template
module_type: Module Type Power Tests
state: present
register: test_seven

- name: "POWER_PORT_TEMPLATE 7: ASSERT - Create duplicate"
assert:
that:
- not test_seven['changed']
- test_seven['power_port_template']['name'] == "Module Power Port Template"
- test_seven['power_port_template']['module_type'] == 1
- test_seven['msg'] == "power_port_template Module Power Port Template already exists"

- name: "POWER_PORT_TEMPLATE 8: Update power_port_template with other fields"
netbox.netbox.netbox_power_port_template:
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
name: Module Power Port Template
module_type: Module Type Power Tests
type: ita-e
allocated_draw: 10
maximum_draw: 20
state: present
register: test_eight

- name: "POWER_PORT_TEMPLATE 8: ASSERT - Update power_port_template with other fields"
assert:
that:
- test_eight is changed
- test_eight['diff']['after']['type'] == "ita-e"
- test_eight['diff']['after']['allocated_draw'] == 10
- test_eight['diff']['after']['maximum_draw'] == 20
- test_eight['power_port_template']['name'] == "Module Power Port Template"
- test_eight['power_port_template']['module_type'] == 1
- test_eight['power_port_template']['type'] == "ita-e"
- test_eight['power_port_template']['allocated_draw'] == 10
- test_eight['power_port_template']['maximum_draw'] == 20
- test_eight['msg'] == "power_port_template Module Power Port Template updated"

- name: "POWER_PORT_TEMPLATE 9: Delete Power Port Template"
netbox.netbox.netbox_power_port_template:
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
name: Module Power Port Template
module_type: Module Type Power Tests
state: absent
register: test_nine

- name: "POWER_PORT_TEMPLATE 9: ASSERT - Delete Power Port Template"
assert:
that:
- test_nine is changed
- test_nine['diff']['before']['state'] == "present"
- test_nine['diff']['after']['state'] == "absent"
- test_nine['msg'] == "power_port_template Module Power Port Template deleted"
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
### NETBOX_POWER_PORT_TEMPLATE
##
##
- name: "POWER_PORT_TEMPLATE 0: Create device type for testing power ports"
- name: "POWER_PORT_TEMPLATE 0.1: Create device type for testing power ports on device types"
netbox.netbox.netbox_device_type:
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
Expand All @@ -16,6 +16,15 @@
manufacturer: Test Manufacturer
state: present

- name: "POWER_PORT_TEMPLATE 0.2: Create module type for testing power ports on module types"
netbox.netbox.netbox_module_type:
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
model: Module Type Power Tests
manufacturer: Test Manufacturer
state: present

- name: "POWER_PORT_TEMPLATE 1: Necessary info creation"
netbox.netbox.netbox_power_port_template:
netbox_url: http://localhost:32768
Expand Down Expand Up @@ -118,3 +127,86 @@
- test_five['diff']['before']['state'] == "present"
- test_five['diff']['after']['state'] == "absent"
- test_five['msg'] == "power_port_template Power Port Template 2 deleted"

- name: "POWER_PORT_TEMPLATE 6: Necessary info creation"
netbox.netbox.netbox_power_port_template:
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
name: Module Power Port Template
module_type: Module Type Power Tests
state: present
register: test_six

- name: "POWER_PORT_TEMPLATE 6: ASSERT - Necessary info creation"
assert:
that:
- test_six is changed
- test_six['diff']['before']['state'] == "absent"
- test_six['diff']['after']['state'] == "present"
- test_six['power_port_template']['name'] == "Module Power Port Template"
- test_six['power_port_template']['module_type'] == 1
- test_six['msg'] == "power_port_template Module Power Port Template created"

- name: "POWER_PORT_TEMPLATE 7: Create duplicate"
netbox.netbox.netbox_power_port_template:
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
name: Module Power Port Template
module_type: Module Type Power Tests
state: present
register: test_seven

- name: "POWER_PORT_TEMPLATE 7: ASSERT - Create duplicate"
assert:
that:
- not test_seven['changed']
- test_seven['power_port_template']['name'] == "Module Power Port Template"
- test_seven['power_port_template']['module_type'] == 1
- test_seven['msg'] == "power_port_template Module Power Port Template already exists"

- name: "POWER_PORT_TEMPLATE 8: Update power_port_template with other fields"
netbox.netbox.netbox_power_port_template:
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
name: Module Power Port Template
module_type: Module Type Power Tests
type: ita-e
allocated_draw: 10
maximum_draw: 20
state: present
register: test_eight

- name: "POWER_PORT_TEMPLATE 8: ASSERT - Update power_port_template with other fields"
assert:
that:
- test_eight is changed
- test_eight['diff']['after']['type'] == "ita-e"
- test_eight['diff']['after']['allocated_draw'] == 10
- test_eight['diff']['after']['maximum_draw'] == 20
- test_eight['power_port_template']['name'] == "Module Power Port Template"
- test_eight['power_port_template']['module_type'] == 1
- test_eight['power_port_template']['type'] == "ita-e"
- test_eight['power_port_template']['allocated_draw'] == 10
- test_eight['power_port_template']['maximum_draw'] == 20
- test_eight['msg'] == "power_port_template Module Power Port Template updated"

- name: "POWER_PORT_TEMPLATE 9: Delete Power Port Template"
netbox.netbox.netbox_power_port_template:
netbox_url: http://localhost:32768
netbox_token: 0123456789abcdef0123456789abcdef01234567
data:
name: Module Power Port Template
module_type: Module Type Power Tests
state: absent
register: test_nine

- name: "POWER_PORT_TEMPLATE 9: ASSERT - Delete Power Port Template"
assert:
that:
- test_nine is changed
- test_nine['diff']['before']['state'] == "present"
- test_nine['diff']['after']['state'] == "absent"
- test_nine['msg'] == "power_port_template Module Power Port Template deleted"