示例#1
0
def create_snapshot_policy(anf_client,
                           resource_group_name,
                           anf_account_name,
                           snapshot_policy_name,
                           location,
                           tags=None):
    """Creates a snapshot policy within an account

    Function that creates a Snapshot Policy. Snapshot policies are tied to
    one specific account and use schedules to determine when, and how many
    snapshots to take/keep of volumes.

    Args:
        anf_client (NetAppManagementClient): Azure Resource Provider
            Client designed to interact with ANF resources
        resource_group_name (string): Name of the resource group where the
            account will be created
        anf_account_name (string): Name of the Account where the snapshot
            policy will be created
        snapshot_policy_name (string): Name of the Snapshot Policy to be
            created
        location (string): Azure short name of the region where resource will
            be deployed
        tags (object): Optional. Key-value pairs to tag the resource, default
            value is None. E.g. {'cc':'1234','dept':'IT'}

    Returns:
        SnapshotPolicy: Returns the newly created SnapshotPolicy resource
    """
    hourly_schedule = HourlySchedule(snapshots_to_keep=2, minute=20)

    daily_schedule = DailySchedule(snapshots_to_keep=3, hour=3, minute=30)

    weekly_schedule = WeeklySchedule(snapshots_to_keep=4,
                                     day="Monday",
                                     hour=4,
                                     minute=40)

    monthly_schedule = MonthlySchedule(snapshots_to_keep=5,
                                       days_of_month="10,11,12",
                                       hour=5,
                                       minute=50)

    snapshot_policy_body = SnapshotPolicy(hourly_schedule=hourly_schedule,
                                          daily_schedule=daily_schedule,
                                          weekly_schedule=weekly_schedule,
                                          monthly_schedule=monthly_schedule,
                                          location=location,
                                          enabled=True)

    return anf_client.snapshot_policies.create(resource_group_name,
                                               anf_account_name,
                                               snapshot_policy_name,
                                               snapshot_policy_body)
示例#2
0
def patch_snapshot_policy(client, resource_group_name, account_name, snapshot_policy_name, location,
                          hourly_snapshots=0, hourly_minute=0,
                          daily_snapshots=0, daily_minute=0, daily_hour=0,
                          weekly_snapshots=0, weekly_minute=0, weekly_hour=0, weekly_day=None,
                          monthly_snapshots=0, monthly_minute=0, monthly_hour=0, monthly_days=None,
                          enabled=False):
    body = SnapshotPolicyPatch(
        location=location,
        hourly_schedule=HourlySchedule(snapshots_to_keep=hourly_snapshots, minute=hourly_minute),
        daily_schedule=DailySchedule(snapshots_to_keep=daily_snapshots, minute=daily_minute, hour=daily_hour),
        weekly_schedule=WeeklySchedule(snapshots_to_keep=weekly_snapshots, minute=weekly_minute,
                                       hour=weekly_hour, day=weekly_day),
        monthly_schedule=MonthlySchedule(snapshots_to_keep=monthly_snapshots, minute=monthly_minute,
                                         hour=monthly_hour, days_of_month=monthly_days),
        enabled=enabled)
    return client.update(body, resource_group_name, account_name, snapshot_policy_name)
示例#3
0
    def test_update_snapshot_policies(self):
        create_snapshot_policy(self.client, TEST_SNAPSHOT_POLICY_1)

        snapshot_policy_body = SnapshotPolicyPatch(
            location=LOCATION,
            hourly_schedule={},
            daily_schedule=DailySchedule(snapshots_to_keep=1, minute=50, hour=1),
            weekly_schedule={},
            monthly_schedule={},
            enabled=False
        )
        snapshot_policy = self.client.snapshot_policies.begin_update(TEST_RG, TEST_ACC_1, TEST_SNAPSHOT_POLICY_1, snapshot_policy_body).result()
        assert snapshot_policy.daily_schedule.snapshots_to_keep == 1
        assert snapshot_policy.daily_schedule.hour == 1
        assert snapshot_policy.daily_schedule.minute == 50

        delete_snapshot_policy(self.client, TEST_SNAPSHOT_POLICY_1, live=self.is_live)
        delete_account(self.client, TEST_RG, TEST_ACC_1)
示例#4
0
def create_snapshot_policy(client,
                           resource_group_name,
                           account_name,
                           snapshot_policy_name,
                           location,
                           hourly_snapshots=None,
                           hourly_minute=None,
                           daily_snapshots=None,
                           daily_minute=None,
                           daily_hour=None,
                           weekly_snapshots=None,
                           weekly_minute=None,
                           weekly_hour=None,
                           weekly_day=None,
                           monthly_snapshots=None,
                           monthly_minute=None,
                           monthly_hour=None,
                           monthly_days=None,
                           enabled=False,
                           tags=None):
    body = SnapshotPolicy(
        location=location,
        hourly_schedule=HourlySchedule(snapshots_to_keep=hourly_snapshots,
                                       minute=hourly_minute),
        daily_schedule=DailySchedule(snapshots_to_keep=daily_snapshots,
                                     minute=daily_minute,
                                     hour=daily_hour),
        weekly_schedule=WeeklySchedule(snapshots_to_keep=weekly_snapshots,
                                       minute=weekly_minute,
                                       hour=weekly_hour,
                                       day=weekly_day),
        monthly_schedule=MonthlySchedule(snapshots_to_keep=monthly_snapshots,
                                         minute=monthly_minute,
                                         hour=monthly_hour,
                                         days_of_month=monthly_days),
        enabled=enabled,
        tags=tags)
    return client.create(resource_group_name, account_name,
                         snapshot_policy_name, body)