| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
__metaclass__ = type |
| 9 |
|
| 10 |
|
| 11 |
DOCUMENTATION = ''' |
| 12 |
--- |
| 13 |
module: azure_rm_registrationdefinition_info |
| 14 |
version_added: '1.3.0' |
| 15 |
short_description: Get RegistrationDefinition info |
| 16 |
description: |
| 17 |
- Get info of RegistrationDefinition. |
| 18 |
options: |
| 19 |
scope: |
| 20 |
description: |
| 21 |
- The subscription ID defines the subscription in which the registration definition will be retrieved. |
| 22 |
- If not specified, will use the subscription derived from AzureRMAuth. |
| 23 |
type: str |
| 24 |
registration_definition_id: |
| 25 |
description: |
| 26 |
- ID of the registration definition. |
| 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 |
EXAMPLES = ''' |
| 36 |
- name: Get Registration Definition |
| 37 |
azure_rm_registrationdefinition_info: |
| 38 |
registration_definition_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 39 |
|
| 40 |
- name: Get All Registration Definitions from AzureRMAuth's subscription |
| 41 |
azure_rm_registrationdefinition_info: |
| 42 |
|
| 43 |
- name: Get All Registration Definitions in the subscription levle |
| 44 |
azure_rm_registrationdefinition_info: |
| 45 |
scope: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 46 |
''' |
| 47 |
|
| 48 |
RETURN = ''' |
| 49 |
registration_definitions: |
| 50 |
description: |
| 51 |
- A list of dict results where the key is the name of the RegistrationDefinition and the values are the facts for that RegistrationDefinition. |
| 52 |
returned: always |
| 53 |
type: complex |
| 54 |
contains: |
| 55 |
properties: |
| 56 |
description: |
| 57 |
- Properties of a registration definition. |
| 58 |
returned: always |
| 59 |
type: complex |
| 60 |
contains: |
| 61 |
description: |
| 62 |
description: |
| 63 |
- Description of the registration definition. |
| 64 |
returned: always |
| 65 |
type: str |
| 66 |
sample: null |
| 67 |
authorizations: |
| 68 |
description: |
| 69 |
- Authorization tuple containing principal ID of the user/security group or service principal and id of the build-in role. |
| 70 |
returned: always |
| 71 |
type: complex |
| 72 |
contains: |
| 73 |
principal_id: |
| 74 |
description: |
| 75 |
- Principal ID of the security group/service principal/user that would be assigned permissions to the projected subscription. |
| 76 |
returned: always |
| 77 |
type: str |
| 78 |
sample: null |
| 79 |
role_definition_id: |
| 80 |
description: |
| 81 |
- The role definition identifier. |
| 82 |
- The role will define all the permissions that the security group/service principal/user must have on the subscription. |
| 83 |
- The role cannot be an owner role. |
| 84 |
returned: always |
| 85 |
type: str |
| 86 |
sample: null |
| 87 |
registration_definition_name: |
| 88 |
description: |
| 89 |
- Name of the registration definition. |
| 90 |
returned: always |
| 91 |
type: str |
| 92 |
sample: null |
| 93 |
managed_by_tenant_id: |
| 94 |
description: |
| 95 |
- ID of the managedBy tenant. |
| 96 |
returned: always |
| 97 |
type: str |
| 98 |
sample: null |
| 99 |
plan: |
| 100 |
description: |
| 101 |
- Plan details for the managed services. |
| 102 |
returned: always |
| 103 |
type: complex |
| 104 |
contains: |
| 105 |
name: |
| 106 |
description: |
| 107 |
- The plan name. |
| 108 |
returned: always |
| 109 |
type: str |
| 110 |
sample: null |
| 111 |
publisher: |
| 112 |
description: |
| 113 |
- The publisher ID. |
| 114 |
returned: always |
| 115 |
type: str |
| 116 |
sample: null |
| 117 |
product: |
| 118 |
description: |
| 119 |
- The product code. |
| 120 |
returned: always |
| 121 |
type: str |
| 122 |
sample: null |
| 123 |
version: |
| 124 |
description: |
| 125 |
- The plan's version. |
| 126 |
returned: always |
| 127 |
type: str |
| 128 |
sample: null |
| 129 |
id: |
| 130 |
description: |
| 131 |
- Fully qualified path of the registration definition. |
| 132 |
returned: always |
| 133 |
type: str |
| 134 |
sample: null |
| 135 |
type: |
| 136 |
description: |
| 137 |
- Type of the resource. |
| 138 |
returned: always |
| 139 |
type: str |
| 140 |
sample: null |
| 141 |
name: |
| 142 |
description: |
| 143 |
- Name of the registration definition. |
| 144 |
returned: always |
| 145 |
type: str |
| 146 |
sample: null |
| 147 |
''' |
| 148 |
|
| 149 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBase |
| 150 |
try: |
| 151 |
from azure.mgmt.managedservices import ManagedServicesClient |
| 152 |
except ImportError: |
| 153 |
|
| 154 |
pass |
| 155 |
|
| 156 |
|
| 157 |
class AzureRMRegistrationDefinitionInfo(AzureRMModuleBase): |
| 158 |
def __init__(self): |
| 159 |
self.module_arg_spec = dict( |
| 160 |
scope=dict( |
| 161 |
type='str' |
| 162 |
), |
| 163 |
registration_definition_id=dict( |
| 164 |
type='str' |
| 165 |
) |
| 166 |
) |
| 167 |
|
| 168 |
self.scope = None |
| 169 |
self.registration_definition_id = None |
| 170 |
|
| 171 |
self.results = dict(changed=False) |
| 172 |
self.mgmt_client = None |
| 173 |
self.state = None |
| 174 |
self.url = None |
| 175 |
self.status_code = [200] |
| 176 |
|
| 177 |
self.mgmt_client = None |
| 178 |
super(AzureRMRegistrationDefinitionInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=True) |
| 179 |
|
| 180 |
def exec_module(self, **kwargs): |
| 181 |
|
| 182 |
for key in self.module_arg_spec: |
| 183 |
setattr(self, key, kwargs[key]) |
| 184 |
|
| 185 |
if not self.scope: |
| 186 |
self.scope = "/subscriptions/" + self.subscription_id |
| 187 |
else: |
| 188 |
self.scope = "/subscriptions/" + self.scope |
| 189 |
|
| 190 |
self.mgmt_client = self.get_mgmt_svc_client(ManagedServicesClient, |
| 191 |
base_url=self._cloud_environment.endpoints.resource_manager, |
| 192 |
api_version='2022-10-01', |
| 193 |
suppress_subscription_id=True) |
| 194 |
|
| 195 |
if self.registration_definition_id is not None: |
| 196 |
self.results['registration_definitions'] = self.format_item(self.get()) |
| 197 |
else: |
| 198 |
self.results['registration_definitions'] = self.format_item(self.list()) |
| 199 |
return self.results |
| 200 |
|
| 201 |
def get(self): |
| 202 |
response = None |
| 203 |
|
| 204 |
try: |
| 205 |
response = self.mgmt_client.registration_definitions.get(scope=self.scope, |
| 206 |
registration_definition_id=self.registration_definition_id) |
| 207 |
except Exception as e: |
| 208 |
self.log('Could not get info for @(Model.ModuleOperationNameUpper).') |
| 209 |
|
| 210 |
return response |
| 211 |
|
| 212 |
def list(self): |
| 213 |
response = None |
| 214 |
|
| 215 |
try: |
| 216 |
response = self.mgmt_client.registration_definitions.list(scope=self.scope) |
| 217 |
except Exception as e: |
| 218 |
self.log('Could not get info for @(Model.ModuleOperationNameUpper).') |
| 219 |
|
| 220 |
return response |
| 221 |
|
| 222 |
def format_item(self, item): |
| 223 |
if hasattr(item, 'as_dict'): |
| 224 |
return [item.as_dict()] |
| 225 |
elif item is not None: |
| 226 |
result = [] |
| 227 |
items = list(item) |
| 228 |
for tmp in items: |
| 229 |
result.append(tmp.as_dict()) |
| 230 |
return result |
| 231 |
else: |
| 232 |
return [] |
| 233 |
|
| 234 |
|
| 235 |
def main(): |
| 236 |
AzureRMRegistrationDefinitionInfo() |
| 237 |
|
| 238 |
|
| 239 |
if __name__ == '__main__': |
| 240 |
main() |