| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
__metaclass__ = type |
| 9 |
|
| 10 |
DOCUMENTATION = \ |
| 11 |
''' |
| 12 |
--- |
| 13 |
module: azure_rm_recoveryservicesvault_info |
| 14 |
version_added: '1.1.0' |
| 15 |
short_description: Get or list the Azure Recovery Services vault Details |
| 16 |
description: |
| 17 |
- Get or list the Azure Recovery Services vault Details. |
| 18 |
options: |
| 19 |
resource_group: |
| 20 |
description: |
| 21 |
- The name of the resource group. |
| 22 |
required: true |
| 23 |
type: str |
| 24 |
name: |
| 25 |
description: |
| 26 |
- If this parameter is not configured, all Vaults in the resource group are listed. |
| 27 |
- The name of the Azure Recovery Service Vault. |
| 28 |
type: str |
| 29 |
extends_documentation_fragment: |
| 30 |
- azure.azcollection.azure |
| 31 |
- azure.azcollection.azure_tags |
| 32 |
author: |
| 33 |
- Suyeb Ansari (@suyeb786) |
| 34 |
''' |
| 35 |
|
| 36 |
EXAMPLES = ''' |
| 37 |
- name: List all Azure Recovery Services Vault in same resource group |
| 38 |
azure_rm_recoveryservicesvault_info: |
| 39 |
resource_group: 'myResourceGroup' |
| 40 |
|
| 41 |
- name: Get Azure Recovery Services Vault Details. |
| 42 |
azure_rm_recoveryservicesvault_info: |
| 43 |
resource_group: 'myResourceGroup' |
| 44 |
name: 'testVault' |
| 45 |
''' |
| 46 |
|
| 47 |
RETURN = ''' |
| 48 |
response: |
| 49 |
description: |
| 50 |
- The response about the current state of the recovery services vault. |
| 51 |
returned: always |
| 52 |
type: complex |
| 53 |
contains: |
| 54 |
etag: |
| 55 |
description: |
| 56 |
- A unique read-only string that changes whenever the resource create. |
| 57 |
returned: always |
| 58 |
type: str |
| 59 |
sample: "datetime'2020-09-16T02%3A44%3A27.834293Z'" |
| 60 |
id: |
| 61 |
description: |
| 62 |
- Resource ID. |
| 63 |
returned: always |
| 64 |
type: str |
| 65 |
sample: "/subscriptions/xxxxxxx/resourceGroups/resourcegroup_name/ \ |
| 66 |
providers/Microsoft.RecoveryServices/vaults/rev_name" |
| 67 |
location: |
| 68 |
description: |
| 69 |
- The location of the resource. |
| 70 |
returned: always |
| 71 |
type: str |
| 72 |
sample: "eastus" |
| 73 |
name: |
| 74 |
description: |
| 75 |
- Name of the recovery services vault name. |
| 76 |
returned: always |
| 77 |
type: str |
| 78 |
sample: revault_name |
| 79 |
properties: |
| 80 |
description: |
| 81 |
- The recovery service vault properties. |
| 82 |
returned: always |
| 83 |
type: dict |
| 84 |
sample: { |
| 85 |
"privateEndpointStateForBackup": "None", |
| 86 |
"privateEndpointStateForSiteRecovery": "None", |
| 87 |
"provisioningState": "Succeeded" |
| 88 |
} |
| 89 |
sku: |
| 90 |
description: |
| 91 |
- The sku type of the recovery service vault. |
| 92 |
returned: always |
| 93 |
type: str |
| 94 |
sample: Standard |
| 95 |
type: |
| 96 |
description: |
| 97 |
- The type of the recovery service vault. |
| 98 |
returned: always |
| 99 |
type: str |
| 100 |
sample: "Microsoft.RecoveryServices/vaults" |
| 101 |
tags: |
| 102 |
description: |
| 103 |
- The resource tags. |
| 104 |
returned: when-used |
| 105 |
type: dict |
| 106 |
sample: {'key1': 'value'} |
| 107 |
''' |
| 108 |
|
| 109 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_rest import GenericRestClient |
| 110 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBaseExt |
| 111 |
import json |
| 112 |
|
| 113 |
|
| 114 |
class AzureRMRecoveryServicesVaultInfo(AzureRMModuleBaseExt): |
| 115 |
def __init__(self): |
| 116 |
self.module_arg_spec = dict( |
| 117 |
resource_group=dict( |
| 118 |
type='str', |
| 119 |
required=True |
| 120 |
), |
| 121 |
name=dict( |
| 122 |
type='str', |
| 123 |
) |
| 124 |
) |
| 125 |
|
| 126 |
self.resource_group = None |
| 127 |
self.name = None |
| 128 |
|
| 129 |
self.body = {} |
| 130 |
self.results = dict(changed=False) |
| 131 |
self.mgmt_client = None |
| 132 |
self.url = None |
| 133 |
self.status_code = [200, 201, 202, 204] |
| 134 |
|
| 135 |
self.query_parameters = {} |
| 136 |
self.query_parameters['api-version'] = None |
| 137 |
self.header_parameters = {} |
| 138 |
self.header_parameters['Content-Type'] = 'application/json; charset=utf-8' |
| 139 |
|
| 140 |
super(AzureRMRecoveryServicesVaultInfo, self).__init__(derived_arg_spec=self.module_arg_spec, |
| 141 |
supports_check_mode=True, |
| 142 |
supports_tags=True |
| 143 |
) |
| 144 |
|
| 145 |
def get_api_version(self): |
| 146 |
return '2020-02-02' |
| 147 |
|
| 148 |
def get_url(self): |
| 149 |
if self.name is not None: |
| 150 |
return '/subscriptions/' \ |
| 151 |
+ self.subscription_id \ |
| 152 |
+ '/resourceGroups/' \ |
| 153 |
+ self.resource_group \ |
| 154 |
+ '/providers/Microsoft.RecoveryServices' \ |
| 155 |
+ '/vaults' + '/' \ |
| 156 |
+ self.name |
| 157 |
else: |
| 158 |
return '/subscriptions/' \ |
| 159 |
+ self.subscription_id \ |
| 160 |
+ '/resourceGroups/' \ |
| 161 |
+ self.resource_group \ |
| 162 |
+ '/providers/Microsoft.RecoveryServices' \ |
| 163 |
+ '/vaults' |
| 164 |
|
| 165 |
def exec_module(self, **kwargs): |
| 166 |
for key in list(self.module_arg_spec.keys()): |
| 167 |
if hasattr(self, key): |
| 168 |
setattr(self, key, kwargs[key]) |
| 169 |
elif kwargs[key] is not None: |
| 170 |
self.body[key] = kwargs[key] |
| 171 |
|
| 172 |
self.inflate_parameters(self.module_arg_spec, self.body, 0) |
| 173 |
|
| 174 |
self.query_parameters['api-version'] = self.get_api_version() |
| 175 |
self.url = self.get_url() |
| 176 |
old_response = None |
| 177 |
response = None |
| 178 |
|
| 179 |
self.mgmt_client = self.get_mgmt_svc_client(GenericRestClient, |
| 180 |
base_url=self._cloud_environment.endpoints.resource_manager) |
| 181 |
|
| 182 |
changed = False |
| 183 |
response = self.get_recovery_service_vault_info() |
| 184 |
|
| 185 |
self.results['response'] = response |
| 186 |
self.results['changed'] = changed |
| 187 |
|
| 188 |
return self.results |
| 189 |
|
| 190 |
def get_recovery_service_vault_info(self): |
| 191 |
|
| 192 |
try: |
| 193 |
response = self.mgmt_client.query( |
| 194 |
self.url, |
| 195 |
'GET', |
| 196 |
self.query_parameters, |
| 197 |
self.header_parameters, |
| 198 |
None, |
| 199 |
self.status_code, |
| 200 |
600, |
| 201 |
30, |
| 202 |
) |
| 203 |
except Exception as e: |
| 204 |
self.log('Error in fetching Azure Recovery Service Vault Details.') |
| 205 |
self.fail('Error in fetching Azure Recovery Service Vault Details {0}'.format(str(e))) |
| 206 |
|
| 207 |
if hasattr(response, 'body'): |
| 208 |
response = json.loads(response.body()) |
| 209 |
elif hasattr(response, 'context'): |
| 210 |
response = response.context['deserialized_data'] |
| 211 |
else: |
| 212 |
self.fail("Create or Updating fail, no match message return, return info as {0}".format(response)) |
| 213 |
|
| 214 |
return response |
| 215 |
|
| 216 |
|
| 217 |
def main(): |
| 218 |
AzureRMRecoveryServicesVaultInfo() |
| 219 |
|
| 220 |
|
| 221 |
if __name__ == '__main__': |
| 222 |
main() |