From f7dec21cfd564b3c7f6ef7151d62a45638c8b256 Mon Sep 17 00:00:00 2001 From: Steven Hodges Date: Fri, 10 Jan 2025 13:10:37 -0600 Subject: [PATCH 1/2] list_order type should be int, not bool --- plugins/modules/section.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/section.py b/plugins/modules/section.py index 954c665..a78dadc 100644 --- a/plugins/modules/section.py +++ b/plugins/modules/section.py @@ -126,7 +126,7 @@ def main(): permissions=dict(type='json', required=False, default=None), strict_mode=dict(type='bool', required=False), subnet_ordering=dict(type='bool', required=False, phpipam_name='subnetOrdering'), - list_order=dict(type='bool', required=False, phpipam_name='order'), + list_order=dict(type='int', required=False, phpipam_name='order'), show_vlan=dict(type='bool', required=False, phpipam_name='showVLAN'), show_vrf=dict(type='bool', required=False, phpipam_name='showVRF'), show_supernets_only=dict(type='bool', required=False, phpipam_name='showSupernetOnly'), From 8a09daabb6a5dbf2869103f2307aa0401252898e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Mei=C3=9Fner?= Date: Tue, 24 Jun 2025 21:55:10 +0200 Subject: [PATCH 2/2] 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 --- ...rdering_parameters_in_sections_module.yaml | 6 + docs/plugins/address_module.rst | 2 +- docs/plugins/section_module.rst | 116 ++++++++++-------- plugins/modules/section.py | 35 ++++-- tests/test_playbooks/tasks/section.yml | 3 +- tests/test_playbooks/vars/section.yml | 2 + 6 files changed, 101 insertions(+), 63 deletions(-) create mode 100644 changelogs/fragments/provide_subnet_ordering_parameters_in_sections_module.yaml diff --git a/changelogs/fragments/provide_subnet_ordering_parameters_in_sections_module.yaml b/changelogs/fragments/provide_subnet_ordering_parameters_in_sections_module.yaml new file mode 100644 index 0000000..84bc757 --- /dev/null +++ b/changelogs/fragments/provide_subnet_ordering_parameters_in_sections_module.yaml @@ -0,0 +1,6 @@ +enhancements: +- 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` +breaking_changes: +- Remove `list_oder`, as this parameters serves no purpose diff --git a/docs/plugins/address_module.rst b/docs/plugins/address_module.rst index 2a8ea9e..4f0cc79 100644 --- a/docs/plugins/address_module.rst +++ b/docs/plugins/address_module.rst @@ -347,7 +347,7 @@ Parameters
- IP address to handle + IP address to hanle .. raw:: html diff --git a/docs/plugins/section_module.rst b/docs/plugins/section_module.rst index 2a33a8d..27706b3 100644 --- a/docs/plugins/section_module.rst +++ b/docs/plugins/section_module.rst @@ -203,21 +203,21 @@ Parameters * - .. raw:: html
-
+
- .. _ansible_collections.codeaffen.phpipam.section_module__parameter-list_order: + .. _ansible_collections.codeaffen.phpipam.section_module__parameter-name: .. rst-class:: ansible-option-title - **list_order** + **name** .. raw:: html - + .. ansible-option-type-line:: - :ansible-option-type:`integer` + :ansible-option-type:`string` / :ansible-option-required:`required` .. raw:: html @@ -227,7 +227,7 @@ Parameters
- Order in sections list view + Name of the section .. raw:: html @@ -237,21 +237,21 @@ Parameters * - .. raw:: html
-
+
- .. _ansible_collections.codeaffen.phpipam.section_module__parameter-name: + .. _ansible_collections.codeaffen.phpipam.section_module__parameter-order_by: .. rst-class:: ansible-option-title - **name** + **order_by** .. raw:: html - + .. ansible-option-type-line:: - :ansible-option-type:`string` / :ansible-option-required:`required` + :ansible-option-type:`string` .. raw:: html @@ -261,7 +261,61 @@ Parameters
- Name of the section + Specifies the field to use for sorting the returned subnets + + + .. rst-class:: ansible-option-line + + :ansible-option-choices:`Choices:` + + - :ansible-option-choices-entry:`"subnet"` + - :ansible-option-choices-entry:`"description"` + + + .. raw:: html + +
+ + * - .. raw:: html + +
+
+ + .. _ansible_collections.codeaffen.phpipam.section_module__parameter-order_direction: + + .. rst-class:: ansible-option-title + + **order_direction** + + .. raw:: html + + + + .. ansible-option-type-line:: + + :ansible-option-type:`string` + + .. raw:: html + +
+ + - .. raw:: html + +
+ + Determines the sorting direction, either ascending or descending + + 'asc' sorts from A to Z or from smallest to largest number + + 'desc' sorts from Z to A or from largest to smallest number + + + .. rst-class:: ansible-option-line + + :ansible-option-choices:`Choices:` + + - :ansible-option-choices-entry:`"asc"` + - :ansible-option-choices-entry:`"desc"` .. raw:: html @@ -624,44 +678,6 @@ Parameters - :ansible-option-choices-entry:`true` - .. raw:: html - -
- - * - .. raw:: html - -
-
- - .. _ansible_collections.codeaffen.phpipam.section_module__parameter-subnet_ordering: - - .. rst-class:: ansible-option-title - - **subnet_ordering** - - .. raw:: html - - - - .. ansible-option-type-line:: - - :ansible-option-type:`string` - - .. raw:: html - -
- - - .. raw:: html - -
- - How to order subnets within this section - - - .. rst-class:: ansible-option-line - - :ansible-option-default-bold:`Default:` :ansible-option-default:`"subnet,asc"` - .. raw:: html
diff --git a/plugins/modules/section.py b/plugins/modules/section.py index a78dadc..4e34c1f 100644 --- a/plugins/modules/section.py +++ b/plugins/modules/section.py @@ -56,14 +56,18 @@ type: bool required: false default: no - subnet_ordering: - description: How to order subnets within this section + order_by: + description: Specifies the field to use for sorting the returned subnets type: str + choices: [ subnet, description ] required: false - default: "subnet,asc" - list_order: - description: Order in sections list view - type: int + order_direction: + description: + - Determines the sorting direction, either ascending or descending + - "'asc' sorts from A to Z or from smallest to largest number" + - "'desc' sorts from Z to A or from largest to smallest number" + type: str + choices: [ asc, desc ] required: false show_vlan: description: Show/hide VLANs in subnet list view @@ -125,17 +129,26 @@ def main(): parent=dict(type='entity', controller='sections', required=False, default=None, phpipam_name='masterSection'), permissions=dict(type='json', required=False, default=None), strict_mode=dict(type='bool', required=False), - subnet_ordering=dict(type='bool', required=False, phpipam_name='subnetOrdering'), - list_order=dict(type='int', required=False, phpipam_name='order'), + order_by=dict(type=str, required=False, choices=['subnet', 'description']), + order_direction=dict(type=str, required=False, choices=['asc', 'desc']), + subnetOrdering=dict(type=str, required=False), show_vlan=dict(type='bool', required=False, phpipam_name='showVLAN'), show_vrf=dict(type='bool', required=False, phpipam_name='showVRF'), show_supernets_only=dict(type='bool', required=False, phpipam_name='showSupernetOnly'), dns_resolver=dict(type='entity', controller='tools/nameservers', required=False, phpipam_name='DNS'), - ) + ), + required_together=[['order_by', 'order_direction']], ) - if not module.desired_absent: - pass + module_params = module.phpipam_params + + if 'order_by' in module_params and 'order_direction' in module_params: + module_params['subnetOrdering'] = module_params['order_by'] + ',' + module_params['order_direction'] + del module_params['order_by'] + del module_params['order_direction'] + + # if not module.desired_absent: + # pass with module.api_connection(): module.run() diff --git a/tests/test_playbooks/tasks/section.yml b/tests/test_playbooks/tasks/section.yml index 36cde32..cf88b21 100644 --- a/tests/test_playbooks/tasks/section.yml +++ b/tests/test_playbooks/tasks/section.yml @@ -10,7 +10,8 @@ parent: "{{ section.parent | default(omit) }}" permissions: "{{ section.permissions | default(omit) }}" strict_mode: "{{ section.strict_mode | default(omit) }}" - subnet_ordering: "{{ section.subnet_ordering | default(omit) }}" + order_by: "{{ section.order_by | default(omit) }}" + order_direction: "{{ section.order_direction | default(omit) }}" list_order: "{{ section.list_order | default(omit) }}" show_vlan: "{{ section.show_vlan | default(omit) }}" show_vrf: "{{ section.show_vrf | default(omit) }}" diff --git a/tests/test_playbooks/vars/section.yml b/tests/test_playbooks/vars/section.yml index 5884d78..9e5329f 100644 --- a/tests/test_playbooks/vars/section.yml +++ b/tests/test_playbooks/vars/section.yml @@ -2,6 +2,8 @@ base_section_data: name: "Example Inc." show_supernets_only: yes + order_by: subnet + order_direction: asc sections: - name: "ACME Inc."