Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_system_qos_policy_info.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7 __metaclass__ = type
8
9 ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'community'}
12
13 DOCUMENTATION = r'''
14 ---
15 module: intersight_system_qos_policy_info
16 short_description: Gather information about System QoS Policies in Cisco Intersight
17 description:
18 - Retrieve comprehensive information about System QoS Policies and their configured classes from L(Cisco Intersight,https://intersight.com).
19 - Query policies by organization, policy name, or filter by specific criteria.
20 - Returns structured data combining policy metadata with detailed QoS class configurations.
21 - Each policy includes all six QoS classes (Bronze, Silver, Gold, Platinum, Best Effort, FC) with their current settings.
22 - Supports filtering by organization and policy name.
23 - If no filters are provided, all System QoS Policies will be returned.
24 - Returns structured data with both policy information and associated QoS class details.
25 extends_documentation_fragment: intersight
26 options:
27 organization:
28 description:
29 - The name of the organization to filter System QoS Policies by.
30 - Use 'default' for the default organization.
31 - When specified, only policies from this organization will be returned.
32 type: str
33 name:
34 description:
35 - The exact name of the System QoS Policy to retrieve information from.
36 - When specified, only the matching policy and its classes will be returned.
37 type: str
38 author:
39 - Ron Gershburg (@rgershbu)
40 '''
41
42 EXAMPLES = r'''
43 # Basic Usage Examples
44
45 - name: Get all System QoS Policies
46 cisco.intersight.intersight_system_qos_policy_info:
47 api_private_key: "{{ api_private_key }}"
48 api_key_id: "{{ api_key_id }}"
49 register: all_qos_policies
50
51 - name: Get System QoS Policies from specific organization
52 cisco.intersight.intersight_system_qos_policy_info:
53 api_private_key: "{{ api_private_key }}"
54 api_key_id: "{{ api_key_id }}"
55 organization: DevNet
56 register: devnet_qos_policies
57
58 - name: Get specific System QoS Policy by name
59 cisco.intersight.intersight_system_qos_policy_info:
60 api_private_key: "{{ api_private_key }}"
61 api_key_id: "{{ api_key_id }}"
62 organization: DevNet
63 name: lab-system-qos
64 register: specific_qos_policy
65
66 - name: Display QoS classes from retrieved policy
67 ansible.builtin.debug:
68 msg: "Policy {{ item.Name }} has {{ item.Classes | length }} QoS classes configured"
69 loop: "{{ specific_qos_policy.intersight_system_qos_policies }}"
70
71 # Advanced filtering and conditional tasks
72
73 - name: Get all System QoS policies and show enabled classes
74 cisco.intersight.intersight_system_qos_policy_info:
75 api_private_key: "{{ api_private_key }}"
76 api_key_id: "{{ api_key_id }}"
77 register: qos_policies
78
79 - name: Show enabled QoS classes for each policy
80 ansible.builtin.debug:
81 msg: |
82 Policy: {{ item.Name }}
83 Enabled Classes: {{ item.Classes | selectattr('AdminState', 'equalto', 'Enabled') | map(attribute='Name') | list }}
84 loop: "{{ qos_policies.intersight_system_qos_policies }}"
85
86 - name: Check if specific policy exists
87 cisco.intersight.intersight_system_qos_policy_info:
88 api_private_key: "{{ api_private_key }}"
89 api_key_id: "{{ api_key_id }}"
90 name: production-qos
91 register: policy_check
92
93 - name: Fail if production policy doesn't exist
94 ansible.builtin.fail:
95 msg: "Production QoS policy not found!"
96 when: policy_check.intersight_system_qos_policies | length == 0
97 '''
98
99 RETURN = r'''
100 intersight_system_qos_policies:
101 description: A list of System QoS Policies with their configurations
102 returned: always
103 type: list
104 elements: dict
105 sample:
106 - Name: "lab-system-qos"
107 Description: "System QoS policy for lab use"
108 Organization:
109 ObjectType: "organization.Organization"
110 Moid: "675450ee69726530014753e2"
111 Tags:
112 - Key: "Site"
113 Value: "RCDN"
114 Classes:
115 - Name: "Bronze"
116 AdminState: "Disabled"
117 Cos: 1
118 Mtu: 1500
119 PacketDrop: true
120 Weight: 7
121 - Name: "Silver"
122 AdminState: "Disabled"
123 Cos: 2
124 Mtu: 1500
125 PacketDrop: true
126 Weight: 8
127 - Name: "Gold"
128 AdminState: "Enabled"
129 Cos: 4
130 Mtu: 1500
131 PacketDrop: true
132 Weight: 9
133 - Name: "Platinum"
134 AdminState: "Enabled"
135 Cos: 5
136 Mtu: 1500
137 PacketDrop: true
138 Weight: 10
139 - Name: "Best Effort"
140 AdminState: "Enabled"
141 Cos: 255
142 Mtu: 1500
143 PacketDrop: true
144 Weight: 5
145 - Name: "FC"
146 AdminState: "Enabled"
147 Cos: 3
148 Mtu: 2240
149 PacketDrop: false
150 Weight: 5
151 CreateTime: "2023-05-15T10:30:45.123Z"
152 ModTime: "2023-05-15T10:30:45.123Z"
153 Moid: "64620ac769726530014a1234"
154 ObjectType: "fabric.SystemQosPolicy"
155 '''
156
157 from ansible.module_utils.basic import AnsibleModule
158 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import IntersightModule, intersight_argument_spec
159
160
161 def main():
162 argument_spec = intersight_argument_spec.copy()
163 argument_spec.update(
164 organization=dict(type='str'),
165 name=dict(type='str'),
166 )
167
168 module = AnsibleModule(
169 argument_spec,
170 supports_check_mode=True,
171 )
172
173 intersight = IntersightModule(module)
174
175 # Resource path for System QoS Policies
176 resource_path = '/fabric/SystemQosPolicies'
177
178 query_params = intersight.set_query_params()
179
180 intersight.get_resource(
181 resource_path=resource_path,
182 query_params=query_params,
183 return_list=True
184 )
185
186 module.exit_json(**intersight.result)
187
188
189 if __name__ == '__main__':
190 main()