Exemple #1
0
        private void AzureToAzureReplication(EnableProtectionInput input)
        {
            var providerSettings = new A2AEnableProtectionInput()
            {
                FabricObjectId      = this.AzureVmId,
                RecoveryContainerId =
                    this.ProtectionContainerMapping.TargetProtectionContainerId,
                VmDisks = new List <A2AVmDiskInputDetails>(),
                RecoveryResourceGroupId   = this.RecoveryResourceGroupId,
                RecoveryCloudServiceId    = this.RecoveryCloudServiceId,
                RecoveryAvailabilitySetId = this.RecoveryAvailabilitySetId
            };

            // If azureVmDisk Details are null add disk to protect
            // TODO:: item for other parameterset when customer can pass AzureVmId targetStorageAccount and RecoveryStorageAccount.
            // will add support when compute dependency is added in common library.
            foreach (ASRAzuretoAzureDiskReplicationConfig disk in this.AzureToAzureDiskReplicationConfiguration)
            {
                providerSettings.VmDisks.Add(new A2AVmDiskInputDetails
                {
                    DiskUri = disk.VhdUri,
                    RecoveryAzureStorageAccountId =
                        disk.RecoveryAzureStorageAccountId,
                    PrimaryStagingAzureStorageAccountId =
                        disk.LogStorageAccountId,
                });
            }

            input.Properties.ProviderSpecificDetails = providerSettings;
        }
        /// <summary>
        ///     Helper method for Azure to Azure replication scenario.
        /// </summary>
        private void AzureToAzureReplication(EnableProtectionInput input)
        {
            var providerSettings = new A2AEnableProtectionInput()
            {
                FabricObjectId      = this.AzureVmId,
                RecoveryContainerId =
                    this.ProtectionContainerMapping.TargetProtectionContainerId,
                VmDisks                          = new List <A2AVmDiskInputDetails>(),
                VmManagedDisks                   = new List <A2AVmManagedDiskInputDetails>(),
                RecoveryResourceGroupId          = this.RecoveryResourceGroupId,
                RecoveryCloudServiceId           = this.RecoveryCloudServiceId,
                RecoveryAvailabilitySetId        = this.RecoveryAvailabilitySetId,
                RecoveryBootDiagStorageAccountId = this.RecoveryBootDiagStorageAccountId,
                RecoveryAzureNetworkId           = this.RecoveryAzureNetworkId,
                RecoverySubnetName               = this.RecoveryAzureSubnetName,
                RecoveryAvailabilityZone         = this.RecoveryAvailabilityZone
            };

            if (!string.IsNullOrEmpty(this.ReplicationGroupName))
            {
                providerSettings.MultiVmGroupName = this.ReplicationGroupName;
            }

            if (!string.IsNullOrEmpty(this.RecoveryCloudServiceId))
            {
                providerSettings.RecoveryResourceGroupId = null;
            }

            if (this.AzureToAzureDiskReplicationConfiguration == null)
            {
                if (this.AzureVmId.ToLower().Contains(ARMResourceTypeConstants.Compute.ToLower()))
                {
                    var vmName             = Utilities.GetValueFromArmId(this.AzureVmId, ARMResourceTypeConstants.VirtualMachine);
                    var vmRg               = Utilities.GetValueFromArmId(this.AzureVmId, ARMResourceTypeConstants.ResourceGroups);
                    var subscriptionId     = Utilities.GetValueFromArmId(this.AzureVmId, ARMResourceTypeConstants.Subscriptions);
                    var tempSubscriptionId = this.ComputeManagementClient.GetComputeManagementClient.SubscriptionId;
                    this.ComputeManagementClient.GetComputeManagementClient.SubscriptionId = subscriptionId;
                    var virtualMachine = this.ComputeManagementClient.GetComputeManagementClient.
                                         VirtualMachines.GetWithHttpMessagesAsync(vmRg, vmName).GetAwaiter().GetResult().Body;
                    this.ComputeManagementClient.GetComputeManagementClient.SubscriptionId = tempSubscriptionId;

                    if (virtualMachine == null)
                    {
                        throw new Exception("Azure Vm not found");
                    }

                    // if managed disk
                    if (virtualMachine.StorageProfile.OsDisk.ManagedDisk != null)
                    {
                        if (this.RecoveryAzureStorageAccountId != null)
                        {
                            throw new Exception("Recovery Storage account is not required for managed disk vm to protect");
                        }
                        var osDisk = virtualMachine.StorageProfile.OsDisk;
                        providerSettings.VmManagedDisks.Add(new A2AVmManagedDiskInputDetails
                        {
                            DiskId = osDisk.ManagedDisk.Id,
                            RecoveryResourceGroupId             = this.RecoveryResourceGroupId,
                            PrimaryStagingAzureStorageAccountId = this.LogStorageAccountId,
                            RecoveryReplicaDiskAccountType      = osDisk.ManagedDisk.StorageAccountType,
                            RecoveryTargetDiskAccountType       = osDisk.ManagedDisk.StorageAccountType
                        });
                        if (virtualMachine.StorageProfile.DataDisks != null)
                        {
                            foreach (var dataDisk in virtualMachine.StorageProfile.DataDisks)
                            {
                                providerSettings.VmManagedDisks.Add(new A2AVmManagedDiskInputDetails
                                {
                                    DiskId = dataDisk.ManagedDisk.Id,
                                    RecoveryResourceGroupId             = this.RecoveryResourceGroupId,
                                    PrimaryStagingAzureStorageAccountId = LogStorageAccountId,
                                    RecoveryReplicaDiskAccountType      = dataDisk.ManagedDisk.StorageAccountType,
                                    RecoveryTargetDiskAccountType       = dataDisk.ManagedDisk.StorageAccountType
                                });
                            }
                        }
                    }
                    else
                    {
                        if (this.RecoveryAzureStorageAccountId == null)
                        {
                            throw new Exception("Recovery Storage account is required for non-managed disk vm to protect");
                        }

                        var osDisk = virtualMachine.StorageProfile.OsDisk;
                        providerSettings.VmDisks.Add(new A2AVmDiskInputDetails
                        {
                            DiskUri = osDisk.Vhd.Uri,
                            RecoveryAzureStorageAccountId       = this.RecoveryAzureStorageAccountId,
                            PrimaryStagingAzureStorageAccountId = LogStorageAccountId
                        });
                        if (virtualMachine.StorageProfile.DataDisks != null)
                        {
                            foreach (var dataDisk in virtualMachine.StorageProfile.DataDisks)
                            {
                                providerSettings.VmDisks.Add(new A2AVmDiskInputDetails
                                {
                                    DiskUri = dataDisk.Vhd.Uri,
                                    RecoveryAzureStorageAccountId       = this.RecoveryAzureStorageAccountId,
                                    PrimaryStagingAzureStorageAccountId = LogStorageAccountId
                                });
                            }
                        }
                    }
                }
                else
                {
                    throw new Exception("Pass Disk details for Classic VMs");
                }
            }
            else
            {
                foreach (ASRAzuretoAzureDiskReplicationConfig disk in this.AzureToAzureDiskReplicationConfiguration)
                {
                    if (disk.IsManagedDisk)
                    {
                        providerSettings.VmManagedDisks.Add(new A2AVmManagedDiskInputDetails
                        {
                            DiskId = disk.DiskId,
                            RecoveryResourceGroupId             = disk.RecoveryResourceGroupId,
                            PrimaryStagingAzureStorageAccountId = disk.LogStorageAccountId,
                            RecoveryReplicaDiskAccountType      = disk.RecoveryReplicaDiskAccountType,
                            RecoveryTargetDiskAccountType       = disk.RecoveryTargetDiskAccountType,
                            DiskEncryptionInfo =
                                Utilities.A2AEncryptionDetails(
                                    disk.DiskEncryptionSecretUrl,
                                    disk.DiskEncryptionVaultId,
                                    disk.KeyEncryptionKeyUrl,
                                    disk.KeyEncryptionVaultId)
                        });
                    }
                    else
                    {
                        providerSettings.VmDisks.Add(new A2AVmDiskInputDetails
                        {
                            DiskUri = disk.VhdUri,
                            RecoveryAzureStorageAccountId =
                                disk.RecoveryAzureStorageAccountId,
                            PrimaryStagingAzureStorageAccountId =
                                disk.LogStorageAccountId,
                        });
                    }
                }
            }

            providerSettings.DiskEncryptionInfo =
                Utilities.A2AEncryptionDetails(
                    this.DiskEncryptionSecretUrl,
                    this.DiskEncryptionVaultId,
                    this.KeyEncryptionKeyUrl,
                    this.KeyEncryptionVaultId);

            input.Properties.ProviderSpecificDetails = providerSettings;
        }