Skip to content

Commit e4daee9

Browse files
authored
Merge pull request #1513 from davi2367/module_type_ports
add module_type for front and rear port templates
2 parents 1608cf5 + 5c72cea commit e4daee9

File tree

6 files changed

+327
-13
lines changed

6 files changed

+327
-13
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
minor_changes:
3+
- Add `module_type` as supported to `netbox_rear_port_template`
4+
- Add `module_type` as supported to `netbox_front_port_template`

plugins/modules/netbox_front_port_template.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@
3434
device_type:
3535
description:
3636
- The device type the front port template is attached to
37-
required: true
37+
- Either I(device_type) or I(module_type) are required
38+
type: raw
39+
module_type:
40+
description:
41+
- The module type the front port template is attached to
42+
- Either I(device_type) or I(module_type) are required
3843
type: raw
3944
name:
4045
description:
@@ -103,6 +108,17 @@
103108
rear_port_template: Test Rear Port Template
104109
state: present
105110
111+
- name: Create front port template for a module type within NetBox
112+
netbox.netbox.netbox_front_port_template:
113+
netbox_url: http://netbox.local
114+
netbox_token: thisIsMyToken
115+
data:
116+
name: Test Front Port Template
117+
module_type: Test Module Type
118+
type: bnc
119+
rear_port_template: Test Rear Port Template
120+
state: present
121+
106122
- name: Update front port template with other fields
107123
netbox.netbox.netbox_front_port_template:
108124
netbox_url: http://netbox.local
@@ -160,7 +176,8 @@ def main():
160176
type="dict",
161177
required=True,
162178
options=dict(
163-
device_type=dict(required=True, type="raw"),
179+
device_type=dict(required=False, type="raw"),
180+
module_type=dict(required=False, type="raw"),
164181
name=dict(required=True, type="str"),
165182
type=dict(
166183
required=False,
@@ -192,12 +209,19 @@ def main():
192209
)
193210

194211
required_if = [
195-
("state", "present", ["device_type", "name", "type", "rear_port_template"]),
196-
("state", "absent", ["device_type", "name", "type", "rear_port_template"]),
212+
("state", "present", ["name", "type", "rear_port_template"]),
213+
("state", "absent", ["name", "type", "rear_port_template"]),
214+
]
215+
216+
required_one_of = [
217+
("device_type", "module_type"),
197218
]
198219

199220
module = NetboxAnsibleModule(
200-
argument_spec=argument_spec, supports_check_mode=True, required_if=required_if
221+
argument_spec=argument_spec,
222+
supports_check_mode=True,
223+
required_if=required_if,
224+
required_one_of=required_one_of,
201225
)
202226

203227
netbox_front_port_template = NetboxDcimModule(module, NB_FRONT_PORT_TEMPLATES)

plugins/modules/netbox_rear_port_template.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@
3434
device_type:
3535
description:
3636
- The device type the rear port template is attached to
37-
required: true
37+
- Either I(device_type) or I(module_type) are required
38+
type: raw
39+
module_type:
40+
description:
41+
- The module type the rear port template is attached to
42+
- Either I(device_type) or I(module_type) are required
3843
type: raw
3944
name:
4045
description:
@@ -97,6 +102,16 @@
97102
type: bnc
98103
state: present
99104
105+
- name: Create rear port template for a module type within NetBox
106+
netbox.netbox.netbox_rear_port_template:
107+
netbox_url: http://netbox.local
108+
netbox_token: thisIsMyToken
109+
data:
110+
name: Test Rear Port Template
111+
module_type: Test Module Type
112+
type: bnc
113+
state: present
114+
100115
- name: Update rear port template with other fields
101116
netbox.netbox.netbox_rear_port_template:
102117
netbox_url: http://netbox.local
@@ -152,7 +167,8 @@ def main():
152167
type="dict",
153168
required=True,
154169
options=dict(
155-
device_type=dict(required=True, type="raw"),
170+
device_type=dict(required=False, type="raw"),
171+
module_type=dict(required=False, type="raw"),
156172
name=dict(required=True, type="str"),
157173
type=dict(
158174
required=False,
@@ -183,12 +199,19 @@ def main():
183199
)
184200

185201
required_if = [
186-
("state", "present", ["device_type", "name", "type"]),
187-
("state", "absent", ["device_type", "name", "type"]),
202+
("state", "present", ["name", "type"]),
203+
("state", "absent", ["name", "type"]),
204+
]
205+
206+
required_one_of = [
207+
("device_type", "module_type"),
188208
]
189209

190210
module = NetboxAnsibleModule(
191-
argument_spec=argument_spec, supports_check_mode=True, required_if=required_if
211+
argument_spec=argument_spec,
212+
supports_check_mode=True,
213+
required_if=required_if,
214+
required_one_of=required_one_of,
192215
)
193216

194217
netbox_rear_port_template = NetboxDcimModule(module, NB_REAR_PORT_TEMPLATES)

tests/integration/targets/v4.3/tasks/netbox_front_port_template.yml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
### NETBOX_FRONT_PORT_TEMPLATE
88
##
99
##
10+
- name: "NETBOX_FRONT_PORT_TEMPLATE 0.1: Create module type for testing power ports on module types"
11+
netbox.netbox.netbox_module_type:
12+
netbox_url: http://localhost:32768
13+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
14+
data:
15+
model: Module Type Front And Rear Port Tests
16+
manufacturer: Test Manufacturer
17+
state: present
18+
1019
- name: "FRONT_PORT_TEMPLATE 1: Necessary info creation"
1120
netbox.netbox.netbox_front_port_template:
1221
netbox_url: http://localhost:32768
@@ -145,3 +154,142 @@
145154
- test_six['front_port_template']['type'] == "bnc"
146155
- test_six['front_port_template']['rear_port'] == 1
147156
- test_six['msg'] == "front_port_template Front Port Template already exists"
157+
158+
- name: "FRONT_PORT_TEMPLATE 7: Necessary info creation"
159+
netbox.netbox.netbox_front_port_template:
160+
netbox_url: http://localhost:32768
161+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
162+
data:
163+
name: Module Type Front Port Template
164+
module_type: Module Type Front And Rear Port Tests
165+
type: bnc
166+
rear_port_template: Module Type Rear Port Template
167+
state: present
168+
register: test_seven
169+
170+
- name: "FRONT_PORT_TEMPLATE 7: ASSERT - Necessary info creation"
171+
ansible.builtin.assert:
172+
that:
173+
- test_seven is changed
174+
- test_seven['diff']['before']['state'] == "absent"
175+
- test_seven['diff']['after']['state'] == "present"
176+
- test_seven['front_port_template']['name'] == "Module Type Front Port Template"
177+
- test_seven['front_port_template']['module_type'] == 1
178+
- test_seven['front_port_template']['type'] == "bnc"
179+
- test_seven['front_port_template']['rear_port'] == 4
180+
- test_seven['msg'] == "front_port_template Module Type Front Port Template created"
181+
182+
- name: "FRONT_PORT_TEMPLATE 8: Create duplicate"
183+
netbox.netbox.netbox_front_port_template:
184+
netbox_url: http://localhost:32768
185+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
186+
data:
187+
name: Module Type Front Port Template
188+
module_type: Module Type Front And Rear Port Tests
189+
type: bnc
190+
rear_port_template: Module Type Rear Port Template
191+
state: present
192+
register: test_eight
193+
194+
- name: "FRONT_PORT_TEMPLATE 8: ASSERT - Create duplicate"
195+
ansible.builtin.assert:
196+
that:
197+
- not test_eight['changed']
198+
- test_eight['front_port_template']['name'] == "Module Type Front Port Template"
199+
- test_eight['front_port_template']['module_type'] == 1
200+
- test_eight['front_port_template']['type'] == "bnc"
201+
- test_eight['front_port_template']['rear_port'] == 4
202+
- test_eight['msg'] == "front_port_template Module Type Front Port Template already exists"
203+
204+
- name: "FRONT_PORT_TEMPLATE 9: Update Front Port Template with other fields"
205+
netbox.netbox.netbox_front_port_template:
206+
netbox_url: http://localhost:32768
207+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
208+
data:
209+
name: Module Type Front Port Template
210+
module_type: Module Type Front And Rear Port Tests
211+
type: bnc
212+
rear_port_template: Module Type Rear Port Template
213+
rear_port_template_position: 5
214+
state: present
215+
register: test_nine
216+
217+
- name: "FRONT_PORT_TEMPLATE 9: ASSERT - Update Front Port Template with other fields"
218+
ansible.builtin.assert:
219+
that:
220+
- test_nine is changed
221+
- test_nine['diff']['after']['rear_port_position'] == 5
222+
- test_nine['front_port_template']['name'] == "Module Type Front Port Template"
223+
- test_nine['front_port_template']['module_type'] == 1
224+
- test_nine['front_port_template']['type'] == "bnc"
225+
- test_nine['front_port_template']['rear_port_position'] == 5
226+
- test_nine['front_port_template']['rear_port'] == 4
227+
- test_nine['msg'] == "front_port_template Module Type Front Port Template updated"
228+
229+
- name: "FRONT_PORT_TEMPLATE 10: Create Front Port Template for Delete Test"
230+
netbox.netbox.netbox_front_port_template:
231+
netbox_url: http://localhost:32768
232+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
233+
data:
234+
name: Module Type Front Port Template 2
235+
module_type: Module Type Front And Rear Port Tests
236+
type: bnc
237+
rear_port_template: Module Type Rear Port Template
238+
state: present
239+
register: test_ten
240+
241+
- name: "FRONT_PORT_TEMPLATE 10: ASSERT - Create Front Port Template for Delete Test"
242+
ansible.builtin.assert:
243+
that:
244+
- test_ten is changed
245+
- test_ten['diff']['before']['state'] == "absent"
246+
- test_ten['diff']['after']['state'] == "present"
247+
- test_ten['front_port_template']['name'] == "Module Type Front Port Template 2"
248+
- test_ten['front_port_template']['module_type'] == 1
249+
- test_ten['front_port_template']['type'] == "bnc"
250+
- test_ten['front_port_template']['rear_port'] == 4
251+
- test_ten['msg'] == "front_port_template Module Type Front Port Template 2 created"
252+
253+
- name: "FRONT_PORT_TEMPLATE 11: Delete Front Port Template"
254+
netbox.netbox.netbox_front_port_template:
255+
netbox_url: http://localhost:32768
256+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
257+
data:
258+
name: Module Type Front Port Template 2
259+
module_type: Module Type Front And Rear Port Tests
260+
type: bnc
261+
rear_port_template: Module Type Rear Port Template
262+
state: absent
263+
register: test_eleven
264+
265+
- name: "FRONT_PORT_TEMPLATE 11: ASSERT - Delete Front Port Template"
266+
ansible.builtin.assert:
267+
that:
268+
- test_eleven is changed
269+
- test_eleven['diff']['before']['state'] == "present"
270+
- test_eleven['diff']['after']['state'] == "absent"
271+
- test_eleven['msg'] == "front_port_template Module Type Front Port Template 2 deleted"
272+
273+
- name: "FRONT_PORT_TEMPLATE 12: Create duplicate with rear_port_template dictionary"
274+
netbox.netbox.netbox_front_port_template:
275+
netbox_url: http://localhost:32768
276+
netbox_token: "0123456789abcdef0123456789abcdef01234567"
277+
data:
278+
name: Module Type Front Port Template
279+
module_type: Module Type Front And Rear Port Tests
280+
type: bnc
281+
rear_port_template:
282+
module: Module Type Front And Rear Port Tests
283+
name: Module Type Rear Port Template
284+
state: present
285+
register: test_twelve
286+
287+
- name: "FRONT_PORT_TEMPLATE 12: ASSERT - Create duplicate with rear_port_template dictionary"
288+
ansible.builtin.assert:
289+
that:
290+
- not test_twelve['changed']
291+
- test_twelve['front_port_template']['name'] == "Module Type Front Port Template"
292+
- test_twelve['front_port_template']['module_type'] == 1
293+
- test_twelve['front_port_template']['type'] == "bnc"
294+
- test_twelve['front_port_template']['rear_port'] == 4
295+
- test_twelve['msg'] == "front_port_template Module Type Front Port Template already exists"

tests/integration/targets/v4.3/tasks/netbox_power_port_template.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
- test_six['diff']['before']['state'] == "absent"
146146
- test_six['diff']['after']['state'] == "present"
147147
- test_six['power_port_template']['name'] == "Module Power Port Template"
148-
- test_six['power_port_template']['module_type'] == 1
148+
- test_six['power_port_template']['module_type'] == 2
149149
- test_six['msg'] == "power_port_template Module Power Port Template created"
150150

151151
- name: "POWER_PORT_TEMPLATE 7: Create duplicate"
@@ -163,7 +163,7 @@
163163
that:
164164
- not test_seven['changed']
165165
- test_seven['power_port_template']['name'] == "Module Power Port Template"
166-
- test_seven['power_port_template']['module_type'] == 1
166+
- test_seven['power_port_template']['module_type'] == 2
167167
- test_seven['msg'] == "power_port_template Module Power Port Template already exists"
168168

169169
- name: "POWER_PORT_TEMPLATE 8: Update power_port_template with other fields"
@@ -187,7 +187,7 @@
187187
- test_eight['diff']['after']['allocated_draw'] == 10
188188
- test_eight['diff']['after']['maximum_draw'] == 20
189189
- test_eight['power_port_template']['name'] == "Module Power Port Template"
190-
- test_eight['power_port_template']['module_type'] == 1
190+
- test_eight['power_port_template']['module_type'] == 2
191191
- test_eight['power_port_template']['type'] == "ita-e"
192192
- test_eight['power_port_template']['allocated_draw'] == 10
193193
- test_eight['power_port_template']['maximum_draw'] == 20

0 commit comments

Comments
 (0)