Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgres server backup-support #566

Merged
merged 20 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 73 additions & 9 deletions plugins/modules/azure_rm_postgresqlserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
description:
- The name of the resource group that contains the resource. You can obtain this value from the Azure Resource Manager API or the portal.
required: True
type: str
name:
description:
- The name of the server.
required: True
type: str
sku:
description:
- The SKU (pricing tier) of the server.
type: dict
suboptions:
name:
description:
Expand All @@ -47,13 +50,24 @@
location:
description:
- Resource location. If not set, location from the resource group will be used as default.
type: str
storage_mb:
description:
- The maximum storage allowed for a server.
type: int
geo_redundant_backup:
karisN marked this conversation as resolved.
Show resolved Hide resolved
description:
- Choose between locally redundant(default) or geo-redundant backup. This cannot be updated after first deployment
type: bool
default: False
backup_retention_days:
description:
- Backup retention period between 7 and 35 days. 7 days by default if not set
type: int
version:
description:
- Server version.
type: str
choices:
- '9.5'
- '9.6'
Expand All @@ -72,17 +86,34 @@
admin_username:
description:
- The administrator's login name of a server. Can only be specified when the server is being created (and is required for creation).
type: str
admin_password:
description:
- The password of the administrator login.
type: str
create_mode:
description:
- Create mode of SQL Server.
default: Default
- Create mode of SQL Server. Blank (default), restore from geo redundant (geo_restore), or restore from point in time (point_in_time_restore).
type: str
default: default
choices:
- default
- geo_restore
- point_in_time_restore
source_server_id:
description:
- Id if the source server if I(create_mode=default).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karisN There is something wrong with this description statement. Please refer to the relevant documents of this module and describe it again. Thank you very much!

type: str
restore_point_in_time:
description:
- Restore point creation time (ISO8601 format), specifying the time to restore from.
- Required if I(create_mode=point_in_time_restore).
type: str
state:
description:
- Assert the state of the PostgreSQL server. Use C(present) to create or update a server and C(absent) to delete it.
default: present
type: str
choices:
- present
- absent
Expand Down Expand Up @@ -178,6 +209,13 @@ def __init__(self):
storage_mb=dict(
type='int'
),
geo_redundant_backup=dict(
type='bool',
karisN marked this conversation as resolved.
Show resolved Hide resolved
default=False
karisN marked this conversation as resolved.
Show resolved Hide resolved
),
backup_retention_days=dict(
type='int',
),
version=dict(
type='str',
choices=['9.5', '9.6', '10', '11']
Expand All @@ -192,7 +230,14 @@ def __init__(self):
),
create_mode=dict(
type='str',
default='Default'
default='default',
choices=['default', 'geo_restore', 'point_in_time_restore']
),
source_server_id=dict(
Fred-sun marked this conversation as resolved.
Show resolved Hide resolved
type='str'
),
restore_point_in_time=dict(
type='str'
),
admin_username=dict(
type='str'
Expand All @@ -210,7 +255,7 @@ def __init__(self):

self.resource_group = None
self.name = None
self.parameters = dict()
self.parameters = {'properties': {'create_mode': 'default'}}
self.tags = None

self.results = dict(changed=False)
Expand Down Expand Up @@ -239,20 +284,39 @@ def exec_module(self, **kwargs):
elif key == "location":
self.parameters["location"] = kwargs[key]
elif key == "storage_mb":
self.parameters.setdefault("properties", {}).setdefault("storage_profile", {})["storage_mb"] = kwargs[key]
self.parameters.setdefault("properties", {}).setdefault("storage_profile", {})["storage_mb"] = \
kwargs[key]
elif key == "storage_autogrow":
self.parameters.setdefault("properties", {}).setdefault("storage_profile", {})["storage_autogrow"] = ('Enabled' if kwargs[key]
else 'Disabled')
self.parameters.setdefault("properties", {}).setdefault("storage_profile", {})[
"storage_autogrow"] = ('Enabled' if kwargs[key]
else 'Disabled')
elif key == "geo_redundant_backup":
self.parameters.setdefault("properties", {}).setdefault("storage_profile", {})[
"geo_redundant_backup"] = \
'Enabled' if kwargs[key] else 'Disabled'
elif key == "backup_retention_days":
self.parameters.setdefault("properties", {}).setdefault("storage_profile", {})[
"backup_retention_days"] = kwargs[key]
elif key == "version":
self.parameters.setdefault("properties", {})["version"] = kwargs[key]
elif key == "enforce_ssl":
self.parameters.setdefault("properties", {})["ssl_enforcement"] = 'Enabled' if kwargs[key] else 'Disabled'
self.parameters.setdefault("properties", {})["ssl_enforcement"] = 'Enabled' if kwargs[
key] else 'Disabled'
elif key == "create_mode":
self.parameters.setdefault("properties", {})["create_mode"] = kwargs[key]
if kwargs[key] == 'default':
self.parameters["properties"]["create_mode"] = 'Default'
elif kwargs[key] == 'point_in_time_restore':
self.parameters["properties"]["create_mode"] = 'PointInTimeRestore'
elif kwargs[key] == 'geo_restore':
self.parameters["properties"]["create_mode"] = 'GeoRestore'
elif key == "admin_username":
self.parameters.setdefault("properties", {})["administrator_login"] = kwargs[key]
elif key == "admin_password":
self.parameters.setdefault("properties", {})["administrator_login_password"] = kwargs[key]
elif key == "source_server_id":
self.parameters["properties"]["source_server_id"] = kwargs[key]
elif key == "restore_point_in_time":
self.parameters["properties"]["restore_point_in_time"] = kwargs[key]

old_response = None
response = None
Expand Down
23 changes: 17 additions & 6 deletions plugins/modules/azure_rm_postgresqlserver_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@
description:
- The name of the server.
type: str
tags:
description:
- Limit results by providing a list of tags. Format tags as 'key' or 'key:value'.
type: list

extends_documentation_fragment:
- azure.azcollection.azure
- azure.azcollection.azure_tags

author:
- Zim Kalinowski (@zikalino)
Expand Down Expand Up @@ -142,6 +139,18 @@
returned: always
type: str
sample: postgreabdud1223.postgres.database.azure.com
backup_retention_days:
description:
- Backup retention period between 7 and 35 days. 7 days by default if not set.
returned: always
type: int
sample: 7
geo_redundant_backup:
description:
- Choose between locally redundant(default) or geo-redundant backup. This cannot be updated after first deployment.
returned: always
type: str
sample: Disabled
tags:
description:
- Tags assigned to the resource. Dictionary of string:string pairs.
Expand Down Expand Up @@ -172,7 +181,7 @@ def __init__(self):
type='str'
),
tags=dict(
type='list'
type='dict'
)
)
# store the results of the module operation
Expand All @@ -182,7 +191,7 @@ def __init__(self):
self.resource_group = None
self.name = None
self.tags = None
super(AzureRMPostgreSqlServersInfo, self).__init__(self.module_arg_spec, supports_tags=False)
super(AzureRMPostgreSqlServersInfo, self).__init__(self.module_arg_spec, supports_tags=True)

def exec_module(self, **kwargs):
is_old_facts = self.module._name == 'azure_rm_postgresqlserver_facts'
Expand Down Expand Up @@ -245,6 +254,8 @@ def format_item(self, item):
'admin_username': d['administrator_login'],
'user_visible_state': d['user_visible_state'],
'fully_qualified_domain_name': d['fully_qualified_domain_name'],
'geo_redundant_backup': d['storage_profile']['geo_redundant_backup'],
karisN marked this conversation as resolved.
Show resolved Hide resolved
'backup_retention_days': d['storage_profile']['backup_retention_days'],
'tags': d.get('tags')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
storage_mb: 51200
enforce_ssl: True
storage_autogrow: True
backup_retention_days: 7
admin_username: zimxyz
admin_password: Password123!
tags:
Expand All @@ -118,6 +119,7 @@
storage_mb: 51200
enforce_ssl: True
storage_autogrow: True
backup_retention_days: 7
admin_username: zimxyz
admin_password: Password123!
tags:
Expand All @@ -144,6 +146,7 @@
- output.servers[0]['fully_qualified_domain_name'] != None
- output.servers[0]['tags']['aaa'] == 'bbb'
- output.servers[0]['tags']['ccc'] == 'ddd'
- output.servers[0]['backup_retention_days'] == 7

- name: Gather facts PostgreSQL Server
azure_rm_postgresqlserver_info:
Expand Down
2 changes: 0 additions & 2 deletions tests/sanity/ignore-2.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ plugins/modules/azure_rm_postgresqlconfiguration.py validate-modules:parameter-t
plugins/modules/azure_rm_postgresqlconfiguration_info.py validate-modules:return-syntax-error
plugins/modules/azure_rm_postgresqldatabase.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_postgresqlfirewallrule.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_postgresqlserver.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_postgresqlserver_info.py validate-modules:parameter-list-no-elements
plugins/modules/azure_rm_rediscache.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_rediscache.py validate-modules:doc-default-does-not-match-spec
plugins/modules/azure_rm_rediscache.py validate-modules:doc-type-does-not-match-spec
Expand Down
2 changes: 0 additions & 2 deletions tests/sanity/ignore-2.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ plugins/modules/azure_rm_postgresqlconfiguration.py validate-modules:parameter-t
plugins/modules/azure_rm_postgresqlconfiguration_info.py validate-modules:return-syntax-error
plugins/modules/azure_rm_postgresqldatabase.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_postgresqlfirewallrule.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_postgresqlserver.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_postgresqlserver_info.py validate-modules:parameter-list-no-elements
plugins/modules/azure_rm_rediscache.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_rediscache.py validate-modules:doc-default-does-not-match-spec
plugins/modules/azure_rm_rediscache.py validate-modules:doc-type-does-not-match-spec
Expand Down
2 changes: 0 additions & 2 deletions tests/sanity/ignore-2.12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,6 @@ plugins/modules/azure_rm_postgresqlconfiguration.py validate-modules:parameter-t
plugins/modules/azure_rm_postgresqlconfiguration_info.py validate-modules:return-syntax-error
plugins/modules/azure_rm_postgresqldatabase.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_postgresqlfirewallrule.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_postgresqlserver.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_postgresqlserver_info.py validate-modules:parameter-list-no-elements
plugins/modules/azure_rm_rediscache.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_rediscache.py validate-modules:doc-default-does-not-match-spec
plugins/modules/azure_rm_rediscache.py validate-modules:doc-type-does-not-match-spec
Expand Down
1 change: 0 additions & 1 deletion tests/sanity/ignore-2.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ plugins/modules/azure_rm_mysqlfirewallrule.py validate-modules:parameter-type-no
plugins/modules/azure_rm_postgresqlconfiguration.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_postgresqldatabase.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_postgresqlfirewallrule.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_postgresqlserver.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_rediscache.py validate-modules:parameter-type-not-in-doc
plugins/modules/azure_rm_rediscache.py validate-modules:doc-default-does-not-match-spec
plugins/modules/azure_rm_rediscache.py validate-modules:doc-type-does-not-match-spec
Expand Down