Skip to content

Commit 58039a9

Browse files
Feature: provide subnet ordering parameters for section module (#129)
* list_order type should be int, not bool * Provide options to set subnet ordering of section - Add possibility to set subnet ordering for section from Ansible, even though the setting only reflects in GUI - Add option 'order_by' as choice of 'subnet' and 'description' - Add option 'order_direction' as choice of 'asc' and 'desc' - Update documentation according to that enhancement --------- Co-authored-by: Steven Hodges <shodges@vermeer.com>
1 parent 340c0f9 commit 58039a9

File tree

6 files changed

+101
-63
lines changed

6 files changed

+101
-63
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
enhancements:
2+
- Add possibility to set subnet ordering for section from Ansible, even though the setting only reflects in GUI
3+
- Add option `order_by` as choice of `subnet` and 'description'
4+
- Add option `order_direction` as choice of `asc` and `desc`
5+
breaking_changes:
6+
- Remove `list_oder`, as this parameters serves no purpose

docs/plugins/address_module.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ Parameters
347347

348348
<div class="ansible-option-cell">
349349

350-
IP address to handle
350+
IP address to hanle
351351

352352

353353
.. raw:: html

docs/plugins/section_module.rst

Lines changed: 66 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -203,21 +203,21 @@ Parameters
203203
* - .. raw:: html
204204

205205
<div class="ansible-option-cell">
206-
<div class="ansibleOptionAnchor" id="parameter-list_order"></div>
206+
<div class="ansibleOptionAnchor" id="parameter-name"></div>
207207

208-
.. _ansible_collections.codeaffen.phpipam.section_module__parameter-list_order:
208+
.. _ansible_collections.codeaffen.phpipam.section_module__parameter-name:
209209

210210
.. rst-class:: ansible-option-title
211211

212-
**list_order**
212+
**name**
213213

214214
.. raw:: html
215215

216-
<a class="ansibleOptionLink" href="#parameter-list_order" title="Permalink to this option"></a>
216+
<a class="ansibleOptionLink" href="#parameter-name" title="Permalink to this option"></a>
217217

218218
.. ansible-option-type-line::
219219

220-
:ansible-option-type:`integer`
220+
:ansible-option-type:`string` / :ansible-option-required:`required`
221221

222222
.. raw:: html
223223

@@ -227,7 +227,7 @@ Parameters
227227

228228
<div class="ansible-option-cell">
229229

230-
Order in sections list view
230+
Name of the section
231231

232232

233233
.. raw:: html
@@ -237,21 +237,21 @@ Parameters
237237
* - .. raw:: html
238238

239239
<div class="ansible-option-cell">
240-
<div class="ansibleOptionAnchor" id="parameter-name"></div>
240+
<div class="ansibleOptionAnchor" id="parameter-order_by"></div>
241241

242-
.. _ansible_collections.codeaffen.phpipam.section_module__parameter-name:
242+
.. _ansible_collections.codeaffen.phpipam.section_module__parameter-order_by:
243243

244244
.. rst-class:: ansible-option-title
245245

246-
**name**
246+
**order_by**
247247

248248
.. raw:: html
249249

250-
<a class="ansibleOptionLink" href="#parameter-name" title="Permalink to this option"></a>
250+
<a class="ansibleOptionLink" href="#parameter-order_by" title="Permalink to this option"></a>
251251

252252
.. ansible-option-type-line::
253253

254-
:ansible-option-type:`string` / :ansible-option-required:`required`
254+
:ansible-option-type:`string`
255255

256256
.. raw:: html
257257

@@ -261,7 +261,61 @@ Parameters
261261

262262
<div class="ansible-option-cell">
263263

264-
Name of the section
264+
Specifies the field to use for sorting the returned subnets
265+
266+
267+
.. rst-class:: ansible-option-line
268+
269+
:ansible-option-choices:`Choices:`
270+
271+
- :ansible-option-choices-entry:`"subnet"`
272+
- :ansible-option-choices-entry:`"description"`
273+
274+
275+
.. raw:: html
276+
277+
</div>
278+
279+
* - .. raw:: html
280+
281+
<div class="ansible-option-cell">
282+
<div class="ansibleOptionAnchor" id="parameter-order_direction"></div>
283+
284+
.. _ansible_collections.codeaffen.phpipam.section_module__parameter-order_direction:
285+
286+
.. rst-class:: ansible-option-title
287+
288+
**order_direction**
289+
290+
.. raw:: html
291+
292+
<a class="ansibleOptionLink" href="#parameter-order_direction" title="Permalink to this option"></a>
293+
294+
.. ansible-option-type-line::
295+
296+
:ansible-option-type:`string`
297+
298+
.. raw:: html
299+
300+
</div>
301+
302+
- .. raw:: html
303+
304+
<div class="ansible-option-cell">
305+
306+
Determines the sorting direction, either ascending or descending
307+
308+
'asc' sorts from A to Z or from smallest to largest number
309+
310+
'desc' sorts from Z to A or from largest to smallest number
311+
312+
313+
.. rst-class:: ansible-option-line
314+
315+
:ansible-option-choices:`Choices:`
316+
317+
- :ansible-option-choices-entry:`"asc"`
318+
- :ansible-option-choices-entry:`"desc"`
265319

266320

267321
.. raw:: html
@@ -624,44 +678,6 @@ Parameters
624678
- :ansible-option-choices-entry:`true`
625679

626680

627-
.. raw:: html
628-
629-
</div>
630-
631-
* - .. raw:: html
632-
633-
<div class="ansible-option-cell">
634-
<div class="ansibleOptionAnchor" id="parameter-subnet_ordering"></div>
635-
636-
.. _ansible_collections.codeaffen.phpipam.section_module__parameter-subnet_ordering:
637-
638-
.. rst-class:: ansible-option-title
639-
640-
**subnet_ordering**
641-
642-
.. raw:: html
643-
644-
<a class="ansibleOptionLink" href="#parameter-subnet_ordering" title="Permalink to this option"></a>
645-
646-
.. ansible-option-type-line::
647-
648-
:ansible-option-type:`string`
649-
650-
.. raw:: html
651-
652-
</div>
653-
654-
- .. raw:: html
655-
656-
<div class="ansible-option-cell">
657-
658-
How to order subnets within this section
659-
660-
661-
.. rst-class:: ansible-option-line
662-
663-
:ansible-option-default-bold:`Default:` :ansible-option-default:`"subnet,asc"`
664-
665681
.. raw:: html
666682

667683
</div>

plugins/modules/section.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@
5656
type: bool
5757
required: false
5858
default: no
59-
subnet_ordering:
60-
description: How to order subnets within this section
59+
order_by:
60+
description: Specifies the field to use for sorting the returned subnets
6161
type: str
62+
choices: [ subnet, description ]
6263
required: false
63-
default: "subnet,asc"
64-
list_order:
65-
description: Order in sections list view
66-
type: int
64+
order_direction:
65+
description:
66+
- Determines the sorting direction, either ascending or descending
67+
- "'asc' sorts from A to Z or from smallest to largest number"
68+
- "'desc' sorts from Z to A or from largest to smallest number"
69+
type: str
70+
choices: [ asc, desc ]
6771
required: false
6872
show_vlan:
6973
description: Show/hide VLANs in subnet list view
@@ -125,17 +129,26 @@ def main():
125129
parent=dict(type='entity', controller='sections', required=False, default=None, phpipam_name='masterSection'),
126130
permissions=dict(type='json', required=False, default=None),
127131
strict_mode=dict(type='bool', required=False),
128-
subnet_ordering=dict(type='bool', required=False, phpipam_name='subnetOrdering'),
129-
list_order=dict(type='bool', required=False, phpipam_name='order'),
132+
order_by=dict(type=str, required=False, choices=['subnet', 'description']),
133+
order_direction=dict(type=str, required=False, choices=['asc', 'desc']),
134+
subnetOrdering=dict(type=str, required=False),
130135
show_vlan=dict(type='bool', required=False, phpipam_name='showVLAN'),
131136
show_vrf=dict(type='bool', required=False, phpipam_name='showVRF'),
132137
show_supernets_only=dict(type='bool', required=False, phpipam_name='showSupernetOnly'),
133138
dns_resolver=dict(type='entity', controller='tools/nameservers', required=False, phpipam_name='DNS'),
134-
)
139+
),
140+
required_together=[['order_by', 'order_direction']],
135141
)
136142

137-
if not module.desired_absent:
138-
pass
143+
module_params = module.phpipam_params
144+
145+
if 'order_by' in module_params and 'order_direction' in module_params:
146+
module_params['subnetOrdering'] = module_params['order_by'] + ',' + module_params['order_direction']
147+
del module_params['order_by']
148+
del module_params['order_direction']
149+
150+
# if not module.desired_absent:
151+
# pass
139152

140153
with module.api_connection():
141154
module.run()

tests/test_playbooks/tasks/section.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
parent: "{{ section.parent | default(omit) }}"
1111
permissions: "{{ section.permissions | default(omit) }}"
1212
strict_mode: "{{ section.strict_mode | default(omit) }}"
13-
subnet_ordering: "{{ section.subnet_ordering | default(omit) }}"
13+
order_by: "{{ section.order_by | default(omit) }}"
14+
order_direction: "{{ section.order_direction | default(omit) }}"
1415
list_order: "{{ section.list_order | default(omit) }}"
1516
show_vlan: "{{ section.show_vlan | default(omit) }}"
1617
show_vrf: "{{ section.show_vrf | default(omit) }}"

tests/test_playbooks/vars/section.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
base_section_data:
33
name: "Example Inc."
44
show_supernets_only: yes
5+
order_by: subnet
6+
order_direction: asc
57

68
sections:
79
- name: "ACME Inc."

0 commit comments

Comments
 (0)