diff --git a/plugins/module_utils/azure_rm_common.py b/plugins/module_utils/azure_rm_common.py index 526056108..ccc27414d 100644 --- a/plugins/module_utils/azure_rm_common.py +++ b/plugins/module_utils/azure_rm_common.py @@ -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 diff --git a/plugins/modules/azure_rm_backuppolicy.py b/plugins/modules/azure_rm_backuppolicy.py index 4c1f6cca9..06d396df5 100644 --- a/plugins/modules/azure_rm_backuppolicy.py +++ b/plugins/modules/azure_rm_backuppolicy.py @@ -67,6 +67,7 @@ choices: - Daily - Weekly + - Hourly type: str schedule_days: description: @@ -74,6 +75,14 @@ - 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. @@ -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 @@ -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 @@ -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, @@ -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): @@ -347,6 +438,8 @@ 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"): @@ -354,15 +447,38 @@ def create_or_update_backup_policy(self): 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 diff --git a/plugins/modules/azure_rm_backuppolicy_info.py b/plugins/modules/azure_rm_backuppolicy_info.py index ddebb2862..0a1fc24f3 100644 --- a/plugins/modules/azure_rm_backuppolicy_info.py +++ b/plugins/modules/azure_rm_backuppolicy_info.py @@ -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 diff --git a/requirements-azure.txt b/requirements-azure.txt index 5fc0064aa..de084e003 100644 --- a/requirements-azure.txt +++ b/requirements-azure.txt @@ -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