| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import absolute_import, division, print_function |
| 6 |
__metaclass__ = type |
| 7 |
|
| 8 |
|
| 9 |
DOCUMENTATION = ''' |
| 10 |
--- |
| 11 |
module: azure_rm_postgresqlflexiblebackup_info |
| 12 |
version_added: "3.6.0" |
| 13 |
short_description: Get Azure PostgreSQL Flexible Backup facts |
| 14 |
description: |
| 15 |
- Get or list facts of PostgreSQL Flexible Backup. |
| 16 |
|
| 17 |
options: |
| 18 |
resource_group: |
| 19 |
description: |
| 20 |
- The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal. |
| 21 |
type: str |
| 22 |
required: True |
| 23 |
server_name: |
| 24 |
description: |
| 25 |
- The name of the post gresql server. |
| 26 |
type: str |
| 27 |
required: True |
| 28 |
backup_name: |
| 29 |
description: |
| 30 |
- The name of the post gresql backup. |
| 31 |
type: str |
| 32 |
|
| 33 |
extends_documentation_fragment: |
| 34 |
- azure.azcollection.azure |
| 35 |
|
| 36 |
author: |
| 37 |
- magodo (@magodo) |
| 38 |
- xuzhang3 (@xuzhang3) |
| 39 |
- Fred-sun (@Fred-sun) |
| 40 |
|
| 41 |
''' |
| 42 |
|
| 43 |
EXAMPLES = ''' |
| 44 |
- name: List instance of PostgreSQL Flexible Backup by server name |
| 45 |
azure_rm_postgresqlflexiblebackup_info: |
| 46 |
resource_group: myResourceGroup |
| 47 |
server_name: server_name |
| 48 |
|
| 49 |
- name: Get instances of PostgreSQL Flexible Backup |
| 50 |
azure_rm_postgresqlflexiblebackup_info: |
| 51 |
resource_group: myResourceGroup |
| 52 |
server_name: server_name |
| 53 |
name: backup_name |
| 54 |
''' |
| 55 |
|
| 56 |
RETURN = ''' |
| 57 |
backup: |
| 58 |
description: |
| 59 |
- A list of dictionaries containing facts for PostgreSQL Flexible Backup. |
| 60 |
returned: always |
| 61 |
type: complex |
| 62 |
contains: |
| 63 |
id: |
| 64 |
description: |
| 65 |
- Fully qualified resource ID for the resource. |
| 66 |
returned: always |
| 67 |
type: str |
| 68 |
sample: "/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.DBforPostgreSQL/flexibleServers/posttest/backups/fredbackup" |
| 69 |
backup_name: |
| 70 |
description: |
| 71 |
- Resource name. |
| 72 |
returned: always |
| 73 |
type: str |
| 74 |
sample: fredbackup |
| 75 |
server_name: |
| 76 |
description: |
| 77 |
- The post gresql flexible server name. |
| 78 |
returned: always |
| 79 |
type: str |
| 80 |
sample: posttest |
| 81 |
resource_group: |
| 82 |
description: |
| 83 |
- Name of the resource group. |
| 84 |
returned: always |
| 85 |
type: str |
| 86 |
sample: testRG |
| 87 |
type: |
| 88 |
description: |
| 89 |
- The type of the resource. |
| 90 |
returned: always |
| 91 |
type: str |
| 92 |
sample: Microsoft.DBforPostgreSQL/flexibleServers/backups |
| 93 |
completed_time: |
| 94 |
description: |
| 95 |
- Backup completed time (ISO8601 format). |
| 96 |
type: str |
| 97 |
returned: always |
| 98 |
sample: "2025-04-17T08:11:58.756273+00:00" |
| 99 |
backup_type: |
| 100 |
description: |
| 101 |
- Backup type. |
| 102 |
type: str |
| 103 |
returned: always |
| 104 |
sample: Full |
| 105 |
source: |
| 106 |
description: |
| 107 |
- Backup source. |
| 108 |
type: str |
| 109 |
returned: always |
| 110 |
sample: Automatic |
| 111 |
''' |
| 112 |
|
| 113 |
|
| 114 |
try: |
| 115 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 116 |
from azure.core.exceptions import ResourceNotFoundError |
| 117 |
except ImportError: |
| 118 |
|
| 119 |
pass |
| 120 |
|
| 121 |
|
| 122 |
class AzureRMPostgreSqlFlexibleBackupInfo(AzureRMModuleBase): |
| 123 |
def __init__(self): |
| 124 |
|
| 125 |
self.module_arg_spec = dict( |
| 126 |
resource_group=dict( |
| 127 |
type='str', |
| 128 |
required=True |
| 129 |
), |
| 130 |
server_name=dict( |
| 131 |
type='str', |
| 132 |
required=True |
| 133 |
), |
| 134 |
backup_name=dict( |
| 135 |
type='str' |
| 136 |
), |
| 137 |
) |
| 138 |
|
| 139 |
self.results = dict( |
| 140 |
changed=False |
| 141 |
) |
| 142 |
self.resource_group = None |
| 143 |
self.backup_name = None |
| 144 |
self.server_name = None |
| 145 |
super(AzureRMPostgreSqlFlexibleBackupInfo, self).__init__(self.module_arg_spec, supports_check_mode=True, supports_tags=False, facts_module=True) |
| 146 |
|
| 147 |
def exec_module(self, **kwargs): |
| 148 |
for key in self.module_arg_spec: |
| 149 |
setattr(self, key, kwargs[key]) |
| 150 |
|
| 151 |
if self.backup_name: |
| 152 |
self.results['backups'] = self.get() |
| 153 |
else: |
| 154 |
self.results['backups'] = self.list_all() |
| 155 |
return self.results |
| 156 |
|
| 157 |
def get(self): |
| 158 |
response = None |
| 159 |
results = [] |
| 160 |
try: |
| 161 |
response = self.postgresql_flexible_client.backups_automatic_and_on_demand.get(resource_group_name=self.resource_group, |
| 162 |
server_name=self.server_name, |
| 163 |
backup_name=self.backup_name) |
| 164 |
self.log("Response : {0}".format(response)) |
| 165 |
except ResourceNotFoundError: |
| 166 |
self.log('Could not get backup facts for PostgreSQL Flexible Server.') |
| 167 |
|
| 168 |
if response: |
| 169 |
results.append(self.format_item(response)) |
| 170 |
|
| 171 |
return results |
| 172 |
|
| 173 |
def list_all(self): |
| 174 |
response = None |
| 175 |
results = [] |
| 176 |
try: |
| 177 |
response = self.postgresql_flexible_client.backups_automatic_and_on_demand.list_by_server(resource_group_name=self.resource_group, |
| 178 |
server_name=self.server_name) |
| 179 |
self.log("Response : {0}".format(response)) |
| 180 |
except Exception as ec: |
| 181 |
self.log('Could not list backups facts for PostgreSQL Flexible Servers.') |
| 182 |
|
| 183 |
if response: |
| 184 |
for item in response: |
| 185 |
results.append(self.format_item(item)) |
| 186 |
|
| 187 |
return results |
| 188 |
|
| 189 |
def format_item(self, item): |
| 190 |
return dict( |
| 191 |
resource_group=self.resource_group, |
| 192 |
server_name=self.server_name, |
| 193 |
backup_type=item.backup_type, |
| 194 |
completed_time=item.completed_time, |
| 195 |
id=item.id, |
| 196 |
name=item.name, |
| 197 |
source=item.source, |
| 198 |
type=item.type |
| 199 |
) |
| 200 |
|
| 201 |
|
| 202 |
def main(): |
| 203 |
AzureRMPostgreSqlFlexibleBackupInfo() |
| 204 |
|
| 205 |
|
| 206 |
if __name__ == '__main__': |
| 207 |
main() |