| 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_sqlelasticpool_info |
| 14 |
version_added: "1.14.0" |
| 15 |
short_description: Get Azure SQL Elastic Pool facts |
| 16 |
description: |
| 17 |
- Get facts of Azure SQL Elastic Pool. |
| 18 |
|
| 19 |
options: |
| 20 |
resource_group: |
| 21 |
description: |
| 22 |
- The name of the resource group that contains the resource. |
| 23 |
- You can obtain this value from the Azure Resource Manager API or the portal. |
| 24 |
type: str |
| 25 |
required: True |
| 26 |
server_name: |
| 27 |
description: |
| 28 |
- The name of the server. |
| 29 |
type: str |
| 30 |
required: True |
| 31 |
name: |
| 32 |
description: |
| 33 |
- The name of the elastic pool. |
| 34 |
type: str |
| 35 |
tags: |
| 36 |
description: |
| 37 |
- Limit results by providing a list of tags. Format tags as 'key' or 'key:value'. |
| 38 |
type: list |
| 39 |
elements: str |
| 40 |
|
| 41 |
extends_documentation_fragment: |
| 42 |
- azure.azcollection.azure |
| 43 |
|
| 44 |
author: |
| 45 |
- xuzhang3 (@xuzhang3) |
| 46 |
- Fred Sun (@Fred-sun) |
| 47 |
|
| 48 |
''' |
| 49 |
|
| 50 |
EXAMPLES = ''' |
| 51 |
- name: Get instance of SQL Elastic Pool |
| 52 |
azure_rm_sqlelasticpool_info: |
| 53 |
resource_group: testrg |
| 54 |
server_name: testserver |
| 55 |
name: testEP |
| 56 |
|
| 57 |
- name: List instances of SQL Elastic Pool |
| 58 |
azure_rm_sqlelasticpool_info: |
| 59 |
resource_group: testrg |
| 60 |
server_name: testserver |
| 61 |
''' |
| 62 |
|
| 63 |
RETURN = ''' |
| 64 |
elastic_pool: |
| 65 |
description: |
| 66 |
- A list of dictionaries containing facts for SQL Elastic Pool. |
| 67 |
returned: always |
| 68 |
type: complex |
| 69 |
contains: |
| 70 |
id: |
| 71 |
description: |
| 72 |
- Resource ID. |
| 73 |
returned: always |
| 74 |
type: str |
| 75 |
sample: /subscriptions/xxx-xxx/resourceGroups/testrg/providers/Microsoft.Sql/servers/sqlsrvfredsqldb/elasticPools/fedelastic01 |
| 76 |
name: |
| 77 |
description: |
| 78 |
- Elastic Pool name. |
| 79 |
returned: always |
| 80 |
type: str |
| 81 |
sample: testEP |
| 82 |
location: |
| 83 |
description: |
| 84 |
- Resource location. |
| 85 |
returned: always |
| 86 |
type: str |
| 87 |
sample: eastus |
| 88 |
tags: |
| 89 |
description: |
| 90 |
- Resource tags. |
| 91 |
returned: always |
| 92 |
type: dict |
| 93 |
sample: { 'taga':'aaa', 'tagb':'bbb' } |
| 94 |
sku: |
| 95 |
description: |
| 96 |
- The name and tier of the SKU. |
| 97 |
returned: always |
| 98 |
type: complex |
| 99 |
contains: |
| 100 |
name: |
| 101 |
description: |
| 102 |
- The name of the SKU. |
| 103 |
returned: always |
| 104 |
type: str |
| 105 |
sample: GP_Gen5 |
| 106 |
tier: |
| 107 |
description: |
| 108 |
- The SKU tier. |
| 109 |
returned: always |
| 110 |
type: str |
| 111 |
sample: GeneralPurpose |
| 112 |
capacity: |
| 113 |
description: |
| 114 |
- The SKU capacity. |
| 115 |
returned: always |
| 116 |
type: int |
| 117 |
sample: 2 |
| 118 |
family: |
| 119 |
description: |
| 120 |
- If the service has different generations of hardware, for the same SKU, then that can be captured here. |
| 121 |
type: str |
| 122 |
returned: always |
| 123 |
sample: Gen5 |
| 124 |
size: |
| 125 |
description: |
| 126 |
- Size of the particular SKU. |
| 127 |
type: str |
| 128 |
returned: always |
| 129 |
sample: null |
| 130 |
zone_redundant: |
| 131 |
description: |
| 132 |
- Whether or not this database is zone redundant, which means the replicas of this database will be spread across multiple availability zones. |
| 133 |
returned: always |
| 134 |
type: bool |
| 135 |
sample: true |
| 136 |
license_type: |
| 137 |
description: |
| 138 |
- The license type to apply for this elastic pool. |
| 139 |
type: str |
| 140 |
returned: always |
| 141 |
sample: LicenseIncluded |
| 142 |
maintenance_configuration_id: |
| 143 |
description: |
| 144 |
- Maintenance configuration id assigned to the elastic pool. |
| 145 |
type: str |
| 146 |
returned: always |
| 147 |
sample: /subscriptions/xxx-xxx/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/SQL_Default |
| 148 |
max_size_bytes: |
| 149 |
description: |
| 150 |
- The storage limit for the database elastic pool in bytes. |
| 151 |
type: str |
| 152 |
returned: always |
| 153 |
sample: 34359738368 |
| 154 |
per_database_settings: |
| 155 |
description: |
| 156 |
- The per database settings for the elastic pool. |
| 157 |
type: complex |
| 158 |
returned: always |
| 159 |
contains: |
| 160 |
min_capacity: |
| 161 |
description: |
| 162 |
- The minimum capacity all databases are guaranteed |
| 163 |
type: float |
| 164 |
returned: always |
| 165 |
sample: 0.0 |
| 166 |
max_capacity: |
| 167 |
description: |
| 168 |
- The maximum capacity any one database can consume. |
| 169 |
type: float |
| 170 |
returned: always |
| 171 |
sample: 2.0 |
| 172 |
''' |
| 173 |
|
| 174 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 175 |
|
| 176 |
try: |
| 177 |
from azure.core.exceptions import ResourceNotFoundError |
| 178 |
except ImportError: |
| 179 |
|
| 180 |
pass |
| 181 |
|
| 182 |
|
| 183 |
class AzureRMSqlElasticPoolInfo(AzureRMModuleBase): |
| 184 |
def __init__(self): |
| 185 |
|
| 186 |
self.module_arg_spec = dict( |
| 187 |
resource_group=dict( |
| 188 |
type='str', |
| 189 |
required=True |
| 190 |
), |
| 191 |
server_name=dict( |
| 192 |
type='str', |
| 193 |
required=True |
| 194 |
), |
| 195 |
name=dict( |
| 196 |
type='str' |
| 197 |
), |
| 198 |
tags=dict( |
| 199 |
type='list', |
| 200 |
elements='str' |
| 201 |
) |
| 202 |
) |
| 203 |
|
| 204 |
self.results = dict( |
| 205 |
changed=False |
| 206 |
) |
| 207 |
self.resource_group = None |
| 208 |
self.server_name = None |
| 209 |
self.name = None |
| 210 |
self.tags = None |
| 211 |
super(AzureRMSqlElasticPoolInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False, facts_module=True) |
| 212 |
|
| 213 |
def exec_module(self, **kwargs): |
| 214 |
for key in self.module_arg_spec: |
| 215 |
setattr(self, key, kwargs[key]) |
| 216 |
|
| 217 |
if self.name is not None: |
| 218 |
self.results['elastic_pool'] = self.get() |
| 219 |
else: |
| 220 |
self.results['elastic_pool'] = self.list_by_server() |
| 221 |
return self.results |
| 222 |
|
| 223 |
def get(self): |
| 224 |
response = None |
| 225 |
results = [] |
| 226 |
try: |
| 227 |
response = self.sql_client.elastic_pools.get(resource_group_name=self.resource_group, |
| 228 |
server_name=self.server_name, |
| 229 |
elastic_pool_name=self.name) |
| 230 |
self.log("Response : {0}".format(response)) |
| 231 |
except ResourceNotFoundError: |
| 232 |
self.log('Could not get facts for Elastic Pool.') |
| 233 |
|
| 234 |
if response and self.has_tags(response.tags, self.tags): |
| 235 |
results.append(self.format_item(response)) |
| 236 |
|
| 237 |
return results |
| 238 |
|
| 239 |
def list_by_server(self): |
| 240 |
response = None |
| 241 |
results = [] |
| 242 |
try: |
| 243 |
response = self.sql_client.elastic_pools.list_by_server(resource_group_name=self.resource_group, |
| 244 |
server_name=self.server_name) |
| 245 |
self.log("Response : {0}".format(response)) |
| 246 |
except Exception: |
| 247 |
self.fail('Could not get facts for elastic pool.') |
| 248 |
|
| 249 |
if response is not None: |
| 250 |
for item in response: |
| 251 |
if self.has_tags(item.tags, self.tags): |
| 252 |
results.append(self.format_item(item)) |
| 253 |
|
| 254 |
return results |
| 255 |
|
| 256 |
def format_item(self, item): |
| 257 |
if not item: |
| 258 |
return None |
| 259 |
|
| 260 |
d = dict( |
| 261 |
resource_group=self.resource_group, |
| 262 |
id=item.id, |
| 263 |
name=item.name, |
| 264 |
location=item.location, |
| 265 |
tags=item.tags, |
| 266 |
max_size_bytes=item.max_size_bytes, |
| 267 |
zone_redundant=item.zone_redundant, |
| 268 |
license_type=item.license_type, |
| 269 |
maintenance_configuration_id=item.maintenance_configuration_id, |
| 270 |
per_database_settings=dict(), |
| 271 |
sku=dict() |
| 272 |
) |
| 273 |
|
| 274 |
if item.sku is not None: |
| 275 |
d['sku']['name'] = item.sku.name |
| 276 |
d['sku']['tier'] = item.sku.tier |
| 277 |
d['sku']['size'] = item.sku.size |
| 278 |
d['sku']['family'] = item.sku.family |
| 279 |
d['sku']['capacity'] = item.sku.capacity |
| 280 |
if item.per_database_settings is not None: |
| 281 |
d['per_database_settings']['min_capacity'] = item.per_database_settings.min_capacity |
| 282 |
d['per_database_settings']['max_capacity'] = item.per_database_settings.max_capacity |
| 283 |
|
| 284 |
return d |
| 285 |
|
| 286 |
|
| 287 |
def main(): |
| 288 |
AzureRMSqlElasticPoolInfo() |
| 289 |
|
| 290 |
|
| 291 |
if __name__ == '__main__': |
| 292 |
main() |