Пример #1
0
    def disable_protection_with_retain_data(self, container_name, protected_item_name, protected_item):

        protected_item_resource = ProtectedItemResource(
            properties=AzureIaaSComputeVMProtectedItem(source_resource_id=protected_item.virtual_machine_id,
                                                       protection_state=ProtectionState.protection_stopped,
                                                       )
        )

        response = self.backup_client.protected_items.create_or_update(
            self.vault_name, self.resource_group, self.fabric_name, container_name, protected_item_name,
            protected_item_resource, raw=True
        )

        self._validate_operation_response(response)

        job_response = self._get_operation_response(
            response,
            lambda operation_id: self.backup_client.protected_item_operation_results.get(
                self.vault_name, self.resource_group, self.fabric_name, container_name, protected_item_name, operation_id, raw=True,
            ),
            lambda operation_id: self.backup_client.protected_item_operation_statuses.get(
                self.vault_name, self.resource_group, self.fabric_name, container_name, protected_item_name, operation_id,
            ),
        )

        self.context.assertIsNotNone(job_response.job_id)
        return job_response.job_id
    def enable_protection(self, container_name, protected_item_name,
                          policy_name):
        policy = self.get_policy_with_retries(policy_name)
        self.context.assertIsNotNone(policy)

        self.client.protection_containers.refresh(
            self.vault_name, self.resource_group,
            self.test_definition.fabric_name)

        protectable_items = self.client.backup_protectable_items.list(
            self.vault_name, self.resource_group)

        desired_protectable_item = next(
            protectable_item for protectable_item in protectable_items if
            protectable_item.name.lower() in container_name.lower()).properties
        self.context.assertIsNotNone(desired_protectable_item)

        protected_item_resource = ProtectedItemResource(
            properties=AzureIaaSComputeVMProtectedItem(
                policy_id=policy.id,
                source_resource_id=desired_protectable_item.virtual_machine_id)
        )

        response = self.client.protected_items.create_or_update(
            self.vault_name,
            self.resource_group,
            self.fabric_name,
            container_name,
            protected_item_name,
            protected_item_resource,
            raw=True)
        self._validate_operation_response(response)

        job_response = self._get_operation_response(
            container_name,
            protected_item_name,
            response,
            lambda operation_id: self.client.protected_item_operation_results.
            get(
                self.vault_name,
                self.resource_group,
                self.fabric_name,
                container_name,
                protected_item_name,
                operation_id,
                raw=True,
            ),
            lambda operation_id: self.client.protected_item_operation_statuses.
            get(
                self.vault_name,
                self.resource_group,
                self.fabric_name,
                container_name,
                protected_item_name,
                operation_id,
            ),
        )

        self.context.assertIsNotNone(job_response.job_id)
        return job_response.job_id
Пример #3
0
def _get_vm_item_properties_from_vm_id(vm_id):
    if 'Microsoft.Compute/virtualMachines' in vm_id:
        return AzureIaaSComputeVMProtectedItem()
    if 'Microsoft.ClassicCompute/virtualMachines' in vm_id:
        return AzureIaaSClassicComputeVMProtectedItem()
Пример #4
0
def _get_vm_item_properties_from_vm_type(vm_type):
    if vm_type == 'Microsoft.Compute/virtualMachines':
        return AzureIaaSComputeVMProtectedItem()
    if vm_type == 'Microsoft.ClassicCompute/virtualMachines':
        return AzureIaaSClassicComputeVMProtectedItem()
Пример #5
0
def enable_recovery_services_backup():
    credentials, subscription_id = get_credentials()
    backup_client = RecoveryServicesBackupClient(credentials, subscription_id)

    container_name = "iaasvmcontainer;iaasvmcontainerv2;{};{}".format(
        az_resource_group_name, az_vm_name)
    fabric_name = "Azure"
    protected_item_name = "vm;iaasvmcontainerv2;{};{}".format(
        az_resource_group_name, az_vm_name)
    policy = backup_client.protection_policies.get(
        az_recovery_services_vault_name, az_resource_group_name,
        az_recovery_services_backup_policy_name)

    response = backup_client.protection_containers.refresh(
        az_recovery_services_vault_name,
        az_resource_group_name,
        fabric_name,
        raw=True)

    _get_operation_response(
        response,
        lambda operation_id: backup_client.
        protection_container_refresh_operation_results.get(
            az_recovery_services_vault_name,
            az_resource_group_name,
            fabric_name,
            operation_id,
            raw=True,
        ),
        None,
    )

    iaasvm_odata_filter = "backupManagementType eq '{}'".format('AzureIaasVM')
    protectable_items = backup_client.backup_protectable_items.list(
        az_recovery_services_vault_name,
        az_resource_group_name,
        filter=iaasvm_odata_filter,
        raw=True)

    for protectable_item in protectable_items:
        if protectable_item.name.lower() in container_name.lower():
            desired_protectable_item = protectable_item.properties

    protected_item_resource = ProtectedItemResource(
        properties=AzureIaaSComputeVMProtectedItem(
            policy_id=policy.id,
            source_resource_id=desired_protectable_item.virtual_machine_id))

    response = backup_client.protected_items.create_or_update(
        az_recovery_services_vault_name,
        az_resource_group_name,
        fabric_name,
        container_name,
        protected_item_name,
        protected_item_resource,
        raw=True)

    job_response = _get_operation_response(
        response,
        lambda operation_id: backup_client.protected_item_operation_results.
        get(
            az_recovery_services_vault_name,
            az_resource_group_name,
            fabric_name,
            container_name,
            protected_item_name,
            operation_id,
            raw=True,
        ),
        lambda operation_id: backup_client.protected_item_operation_statuses.
        get(
            az_recovery_services_vault_name,
            az_resource_group_name,
            fabric_name,
            container_name,
            protected_item_name,
            operation_id,
        ),
    )

    wait_for_job_completion(job_response.job_id)

    print('Backup enabled for {}'.format(az_vm_name))
    exit(0)