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

[Hold]Support new parameters to azure_rm_backuppolicy.py #1486

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion plugins/module_utils/azure_rm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,13 @@ def default_api_version(self):
from azure.mgmt.iothub import IotHubClient
from azure.mgmt.iothub import models as IoTHubModels
from azure.mgmt.resource.locks import ManagementLockClient
from azure.mgmt.recoveryservicesbackup import RecoveryServicesBackupClient
try:
# Older versions of the library exposed the modules at the root of the package
import azure.mgmt.recoveryservicesbackup.models as RecoveryServicesBackupModels
from azure.mgmt.recoveryservicesbackup import RecoveryServicesBackupClient
except ImportError:
import azure.mgmt.recoveryservicesbackup.activestamp.models as RecoveryServicesBackupModels
from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient
from azure.mgmt.search import SearchManagementClient
from azure.mgmt.datalake.store import DataLakeStoreAccountManagementClient
import azure.mgmt.datalake.store.models as DataLakeStoreAccountModel
Expand Down
122 changes: 119 additions & 3 deletions plugins/modules/azure_rm_backuppolicy.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,22 @@
choices:
- Daily
- Weekly
- Hourly
type: str
schedule_days:
description:
- List of days to execute the schedule.
- Does not apply to Daily frequency.
type: list
elements: str
monthly_retention_count:
description:
- The amount of months to retain backups.
type: int
yearly_retention_count:
description:
- The amount of years to retain backups.
type: int
weekly_retention_count:
description:
- The amount of weeks to retain backups.
Expand All @@ -95,6 +104,52 @@
- Timezone to apply I(schedule_run_time).
default: UTC
type: str
retention_schedule_format_type:
description:
- Retention schedule format for yearly retention policy.
type: str
choices:
- Daily
- Weekly
months_of_year:
description:
- List of months of year of yearly retention policy.
type: list
elements: str
retention_schedule_daily:
description:
- Daily retention format for yearly retention policy.
type: dict
suboptions:
days_of_the_month:
description:
- List of days of the month.
type: list
elements: dict
suboptions:
date:
description:
- Date of the month.
type: int
is_last:
description:
- Whether Date is last date of month.
type: bool
retention_schedule_weekly:
description:
- Weekly retention format for yearly retention policy.
type: dict
suboptions:
days_of_the_week:
description:
- List of days of the week.
type: list
elements: str
weeks_of_the_month:
description:
- List of weeks of month.
type: list
elements: str
extends_documentation_fragment:
- azure.azcollection.azure

Expand Down Expand Up @@ -195,10 +250,33 @@ def __init__(self):
schedule_days=dict(type='list', elements='str'),
weekly_retention_count=dict(type='int'),
daily_retention_count=dict(type='int'),
monthly_retention_count=dict(type='int'),
yearly_retention_count=dict(type='int'),
schedule_weekly_frequency=dict(type='int'),
time_zone=dict(type='str', default='UTC'),
retention_schedule_format_type=dict(type='str', choices=['Daily', 'Weekly']),
months_of_year=dict(type='list', elements='str'),
retention_schedule_daily=dict(
type='dict',
options=dict(
days_of_the_month=dict(
type='list',
elements='dict',
options=dict(
date=dict(type='int'),
is_last=dict(type='bool'),
)
)
)
),
retention_schedule_weekly=dict(
type='dict',
options=dict(
days_of_the_week=dict(type='list', elements='str'),
weeks_of_the_month=dict(type='list', elements='str')
)
)
)

self.vault_name = None
self.name = None
self.resource_group = None
Expand All @@ -208,9 +286,15 @@ def __init__(self):
self.schedule_run_frequency = None
self.schedule_days = None
self.weekly_retention_count = None
self.monthly_retention_count = None
self.yearly_retention_count = None
self.schedule_weekly_frequency = None
self.daily_retention_count = None
self.time_zone = None
self.retention_schedule_format_type = None
self.months_of_year = None
self.retention_schedule_daily = None
self.retention_schedule_weekly = None

self.results = dict(
changed=False,
Expand All @@ -219,12 +303,19 @@ def __init__(self):

required_if = [('schedule_run_frequency', 'Weekly', ['schedule_days', 'weekly_retention_count', 'schedule_run_time']),
('schedule_run_frequency', 'Daily', ['daily_retention_count', 'schedule_run_time']),
('yearly_retention_count', '*', ['retention_schedule_format_type']),
('monthly_retention_count', '*', ['retention_schedule_format_type']),
('retention_schedule_format_type', 'Weekly', ['retention_schedule_weekly']),
('retention_schedule_format_type', 'Daily', ['retention_schedule_daily']),
('state', 'present', ['schedule_run_frequency', 'backup_management_type']),
('log_mode', 'file', ['log_path'])]

mutually_exclusive = [('retention_schedule_daily', 'retention_schedule_weekly')]

super(AzureRMBackupPolicy, self).__init__(derived_arg_spec=self.module_arg_spec,
supports_check_mode=True,
supports_tags=False,
mutually_exclusive=mutually_exclusive,
required_if=required_if)

def exec_module(self, **kwargs):
Expand Down Expand Up @@ -347,22 +438,47 @@ def create_or_update_backup_policy(self):

daily_retention_schedule = None
weekly_retention_schedule = None
monthly_retention_schedule = None
yearly_retention_schedule = None

# Daily backups can have a daily retention or weekly but Weekly backups cannot have a daily retention
if (self.daily_retention_count and self.schedule_run_frequency == "Daily"):
retention_duration = self.recovery_services_backup_models.RetentionDuration(count=self.daily_retention_count, duration_type="Days")
daily_retention_schedule = self.recovery_services_backup_models.DailyRetentionSchedule(retention_times=schedule_run_times_as_datetimes,
retention_duration=retention_duration)

if (self.weekly_retention_count):
if self.weekly_retention_count is not None:
retention_duration = self.recovery_services_backup_models.RetentionDuration(count=self.weekly_retention_count,
duration_type="Weeks")
weekly_retention_schedule = self.recovery_services_backup_models.WeeklyRetentionSchedule(days_of_the_week=self.schedule_days,
retention_times=schedule_run_times_as_datetimes,
retention_duration=retention_duration)

if self.monthly_retention_count is not None:
retention_duration = self.recovery_services_backup_models.RetentionDuration(count=self.monthly_retention_count,
duration_type="Months")
monthly_retention_schedule = self.recovery_services_backup_models.MonthlyRetentionSchedule(
retention_schedule_format_type=self.retention_schedule_format_type,
retention_schedule_daily=self.retention_schedule_daily,
retention_schedule_weekly=self.retention_schedule_weekly,
retention_times=schedule_run_times_as_datetimes,
retention_duration=retention_duration)

if self.yearly_retention_count is not None:
retention_duration = self.recovery_services_backup_models.RetentionDuration(count=self.yearly_retention_count,
duration_type="Years")
yearly_retention_schedule = self.recovery_services_backup_models.YearlyRetentionSchedule(
retention_schedule_format_type=self.retention_schedule_format_type,
months_of_year=self.months_of_year,
retention_schedule_daily=self.retention_schedule_daily,
retention_schedule_weekly=self.retention_schedule_weekly,
retention_times=schedule_run_times_as_datetimes,
retention_duration=retention_duration)

retention_policy = self.recovery_services_backup_models.LongTermRetentionPolicy(daily_schedule=daily_retention_schedule,
weekly_schedule=weekly_retention_schedule)
weekly_schedule=weekly_retention_schedule,
monthly_schedule=monthly_retention_schedule,
yearly_schedule=yearly_retention_schedule)

policy_definition = None

Expand Down
3 changes: 3 additions & 0 deletions plugins/modules/azure_rm_backuppolicy_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ def set_results(self, policy):
self.results['location'] = policy.location
self.results['name'] = policy.name
self.results['type'] = policy.type
self.results['properties'] = dict()
if policy.properties is not None:
self.results['properties'] = policy.properties.as_dict()

else:
self.results['id'] = None
Expand Down
2 changes: 1 addition & 1 deletion requirements-azure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ azure-mgmt-automation==1.0.0
azure-mgmt-iothub==2.2.0
azure-iot-hub==2.6.1
azure-mgmt-recoveryservices==2.0.0
azure-mgmt-recoveryservicesbackup==3.0.0
azure-mgmt-recoveryservicesbackup==4.0.0
azure-mgmt-notificationhubs==7.0.0
azure-mgmt-eventhub==10.1.0