Debian Codegraph @

ansible_collections/cisco/intersight/plugins/modules/intersight_domain_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_domain_info
16 short_description: Gather information about UCS Domain Profiles in Cisco Intersight
17 description:
18 - Gather information about UCS Domain Profiles (SwitchClusterProfiles) in L(Cisco Intersight,https://intersight.com).
19 - Returns enriched data including SwitchProfiles (A and B), their assigned Fabric Interconnects, and attached PolicyBuckets.
20 - Information can be filtered by O(name) and O(organization).
21 - If no filters are passed, all UCS Domain Profiles will be returned.
22 - For more information see L(Cisco Intersight,https://intersight.com/apidocs/fabric/SwitchClusterProfiles/get/).
23 extends_documentation_fragment: intersight
24 options:
25 name:
26 description:
27 - The name of the UCS Domain Profile to gather information from.
28 type: str
29 organization:
30 description:
31 - The name of the Organization to filter UCS Domain Profiles by.
32 type: str
33 author:
34 - Ron Gershburg (@rgershbu)
35 '''
36
37 EXAMPLES = r'''
38 - name: Fetch a specific UCS Domain Profile by name
39 cisco.intersight.intersight_domain_info:
40 api_private_key: "{{ api_private_key }}"
41 api_key_id: "{{ api_key_id }}"
42 organization: "default"
43 name: "Domain-01"
44
45 - name: Fetch all UCS Domain Profiles in an organization
46 cisco.intersight.intersight_domain_info:
47 api_private_key: "{{ api_private_key }}"
48 api_key_id: "{{ api_key_id }}"
49 organization: "default"
50
51 - name: Fetch all UCS Domain Profiles
52 cisco.intersight.intersight_domain_info:
53 api_private_key: "{{ api_private_key }}"
54 api_key_id: "{{ api_key_id }}"
55 '''
56
57 RETURN = r'''
58 api_response:
59 description:
60 - List of UCS Domain Profiles with enriched SwitchProfile details.
61 - Each profile includes a C(SwitchProfiles) list containing the SwitchProfile data
62 for Fabric Interconnect A and B, including their C(AssignedSwitch) and C(PolicyBucket).
63 returned: always
64 type: list
65 elements: dict
66 sample:
67 - Name: "Domain-01"
68 ObjectType: "fabric.SwitchClusterProfile"
69 SwitchProfiles:
70 - Name: "Domain-01-A"
71 SwitchId: "A"
72 AssignedSwitch:
73 Moid: "abc123"
74 ObjectType: "network.Element"
75 PolicyBucket:
76 - Moid: "pol123"
77 ObjectType: "fabric.SystemQosPolicy"
78 - Name: "Domain-01-B"
79 SwitchId: "B"
80 AssignedSwitch: null
81 PolicyBucket: []
82 '''
83
84
85 from ansible.module_utils.basic import AnsibleModule
86 from ansible_collections.cisco.intersight.plugins.module_utils.intersight import (
87 IntersightModule,
88 intersight_argument_spec,
89 )
90
91
92 def enrich_with_switch_profiles(intersight, clusters):
93 """Fetch SwitchProfiles for each cluster and attach them to the response."""
94 for cluster in clusters:
95 cluster_moid = cluster.get('Moid')
96 if not cluster_moid:
97 cluster['SwitchProfiles'] = []
98 continue
99
100 intersight.get_resource(
101 resource_path='/fabric/SwitchProfiles',
102 query_params={
103 '$filter': f"SwitchClusterProfile.Moid eq '{cluster_moid}'",
104 '$select': 'Name,Moid,SwitchId,AssignedSwitch,PolicyBucket,ConfigContext',
105 },
106 return_list=True,
107 )
108
109 profiles = intersight.result['api_response']
110 if not isinstance(profiles, list):
111 profiles = [profiles] if profiles else []
112
113 cluster['SwitchProfiles'] = profiles
114
115 return clusters
116
117
118 def main():
119 argument_spec = intersight_argument_spec.copy()
120 argument_spec.update(
121 name=dict(type='str'),
122 organization=dict(type='str'),
123 )
124
125 module = AnsibleModule(
126 argument_spec,
127 supports_check_mode=True,
128 )
129
130 intersight = IntersightModule(module)
131 intersight.result['api_response'] = {}
132 intersight.result['trace_id'] = ''
133
134 query_params = intersight.set_query_params()
135
136 intersight.get_resource(
137 resource_path='/fabric/SwitchClusterProfiles',
138 query_params=query_params,
139 return_list=True,
140 )
141
142 clusters = intersight.result['api_response']
143 if not isinstance(clusters, list):
144 clusters = [clusters] if clusters else []
145
146 enriched = enrich_with_switch_profiles(intersight, clusters)
147
148 intersight.result['api_response'] = enriched
149 module.exit_json(**intersight.result)
150
151
152 if __name__ == '__main__':
153 main()