Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_registrationassignment_info.py

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # Copyright (c) 2020 Fred-Sun, (@Fred-Sun)
4 #
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8 __metaclass__ = type
9
10
11 DOCUMENTATION = '''
12 ---
13 module: azure_rm_registrationassignment_info
14 version_added: '1.3.0'
15 short_description: Get RegistrationAssignment info
16 description:
17 - Get info of RegistrationAssignment.
18 options:
19 scope:
20 description:
21 - Scope of the registration assignment.
22 required: true
23 type: str
24 registration_assignment_id:
25 description:
26 - ID of the registration assignment.
27 type: str
28 extends_documentation_fragment:
29 - azure.azcollection.azure
30 - azure.azcollection.azure_tags
31 author:
32 - Fred-Sun (@Fred-Sun)
33
34 '''
35
36 EXAMPLES = '''
37 - name: Get Registration Assignment
38 azure_rm_registrationassignment_info:
39 registration_assignment_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
40 scope: subscription/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup
41
42
43 - name: Get All Registration Assignments in scope(subscription)
44 azure_rm_registrationassignment_info:
45 scope: subscription/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
46 '''
47
48 RETURN = '''
49 registration_assignments:
50 description:
51 - A list of dict results where the key is the name of the RegistrationAssignment.
52 - The values are the facts for that RegistrationAssignment.
53 returned: always
54 type: complex
55 contains:
56 properties:
57 description:
58 - Properties of a registration assignment.
59 returned: always
60 type: complex
61 contains:
62 registration_definition_id:
63 description:
64 - Fully qualified path of the registration definition.
65 returned: always
66 type: str
67 sample: /subscriptions/xxx-xxx/providers/Microsoft.ManagedServices/registrationDefinitions/xxx-xxx
68 id:
69 description:
70 - The fully qualified path of the registration assignment.
71 returned: always
72 type: str
73 sample: /subscriptions/xxx-xxxf/providers/Microsoft.ManagedServices/registrationAssignments/xxx-xxx
74 type:
75 description:
76 - Type of the resource.
77 returned: always
78 type: str
79 sample: Microsoft.ManagedServices/registrationAssignment
80 name:
81 description:
82 - Name of the registration assignment.
83 returned: always
84 type: str
85 sample: 9b2895ec-fb1e-4a1e-a978-abd9933d6b20
86 '''
87
88 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBase
89 try:
90 from azure.mgmt.managedservices import ManagedServicesClient
91 except ImportError:
92 # This is handled in azure_rm_common
93 pass
94
95
96 class AzureRMRegistrationAssignmentInfo(AzureRMModuleBase):
97 def __init__(self):
98 self.module_arg_spec = dict(
99 scope=dict(
100 type='str',
101 required=True
102 ),
103 registration_assignment_id=dict(
104 type='str'
105 )
106 )
107
108 self.scope = None
109 self.registration_assignment_id = None
110 self.expand_registration_definition = False
111
112 self.results = dict(changed=False)
113 self.mgmt_client = None
114 self.state = None
115 self.url = None
116 self.status_code = [200]
117
118 self.mgmt_client = None
119 super(AzureRMRegistrationAssignmentInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=True)
120
121 def exec_module(self, **kwargs):
122
123 for key in self.module_arg_spec:
124 setattr(self, key, kwargs[key])
125
126 self.mgmt_client = self.get_mgmt_svc_client(ManagedServicesClient,
127 base_url=self._cloud_environment.endpoints.resource_manager,
128 api_version='2022-10-01',
129 suppress_subscription_id=True)
130
131 if (self.scope is not None and self.registration_assignment_id is not None):
132 self.results['registration_assignments'] = self.format_item(self.get())
133 elif (self.scope is not None):
134 self.results['registration_assignments'] = self.format_item(self.list())
135
136 if len(self.results['registration_assignments']) > 0:
137 for item in self.results['registration_assignments']:
138 if item.get('properties', None) is not None:
139 registration_definition_id = item['properties']['registration_definition_id']
140 item['properties'].clear()
141 item['properties']['registration_definition_id'] = registration_definition_id
142 return self.results
143
144 def get(self):
145 response = None
146
147 try:
148 response = self.mgmt_client.registration_assignments.get(scope=self.scope,
149 registration_assignment_id=self.registration_assignment_id,
150 expand_registration_definition=self.expand_registration_definition)
151 except Exception as e:
152 self.log('Could not get info for @(Model.ModuleOperationNameUpper).')
153
154 return response
155
156 def list(self):
157 response = None
158
159 try:
160 response = self.mgmt_client.registration_assignments.list(scope=self.scope,
161 expand_registration_definition=self.expand_registration_definition)
162 except Exception as e:
163 self.log('Could not get info for @(Model.ModuleOperationNameUpper).')
164
165 return response
166
167 def format_item(self, item):
168 if hasattr(item, 'as_dict'):
169 return [item.as_dict()]
170 elif item is not None:
171 result = []
172 items = list(item)
173 for tmp in items:
174 result.append(tmp.as_dict())
175 return result
176 else:
177 return []
178
179
180 def main():
181 AzureRMRegistrationAssignmentInfo()
182
183
184 if __name__ == '__main__':
185 main()