diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/A2ATestsHelper.ps1 b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/A2ATestsHelper.ps1 index d34cd10bcd42..4cf969b920a4 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/A2ATestsHelper.ps1 +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/A2ATestsHelper.ps1 @@ -198,3 +198,31 @@ Function WaitForIRCompletion $IRjobs WaitForJobCompletion -JobId $IRjobs[0].Name -JobQueryWaitTimeInSeconds $JobQueryWaitTimeInSeconds -Message $("Finalize IR in Progress...") } + +Function WaitForAddDisksIRCompletion +{ + param( + [PSObject] $affectedObjectId, + [int] $JobQueryWaitTimeInSeconds = 10 + ) + $isProcessingLeft = $true + $IRjobs = $null + + Write-Host $("Add-Disk IR in Progress...") -ForegroundColor Yellow + do + { + $IRjobs = Get-AzureRmRecoveryServicesAsrJob -TargetObjectId $affectedObjectId | Sort-Object StartTime -Descending | select -First 2 | Where-Object{$_.JobType -eq "AddDisksIrCompletion"} + $isProcessingLeft = ($IRjobs -eq $null -or $IRjobs.Count -ne 1) + + if($isProcessingLeft) + { + Write-Host $("Adddisk IR in Progress...") -ForegroundColor Yellow + Write-Host $("Waiting for: " + $JobQueryWaitTimeInSeconds.ToString + " Seconds") -ForegroundColor Yellow + [Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait($JobQueryWaitTimeInSeconds * 1000) + } + }While($isProcessingLeft) + + Write-Host $("Finalize Add disk IR jobs:") -ForegroundColor Green + $IRjobs + WaitForJobCompletion -JobId $IRjobs[0].Name -JobQueryWaitTimeInSeconds $JobQueryWaitTimeInSeconds -Message $("Finalize IR in Progress...") +} diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.cs index 2fc9b966ea94..bac19156915a 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.cs @@ -76,5 +76,49 @@ public void A2ATestNewContainer() { this.RunPowerShellTest(_logger, Constants.NewModel, "Test-NewContainer"); } + +#if NETSTANDARD + [Fact(Skip = "Needs investigation, TestManagementClientHelper class wasn't initialized with the ResourceManagementClient client.")] +#else + [Fact] +#endif + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void A2ANewReplicationProtectedItemDisk() + { + this.RunPowerShellTest(_logger, Constants.NewModel, "Test-NewReplicationProtectedItem"); + } + +#if NETSTANDARD + [Fact(Skip = "Needs investigation, TestManagementClientHelper class wasn't initialized with the ResourceManagementClient client.")] +#else + [Fact] +#endif + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void A2AAddReplicationProtectedItemDisk() + { + this.RunPowerShellTest(_logger, Constants.NewModel, "Test-AddReplicationProtectedItemDisk"); + } + +#if NETSTANDARD + [Fact(Skip = "Needs investigation, TestManagementClientHelper class wasn't initialized with the ResourceManagementClient client.")] +#else + [Fact] +#endif + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void A2ARemoveReplicationProtectedItemDisk() + { + this.RunPowerShellTest(_logger, Constants.NewModel, "Test-RemoveReplicationProtectedItemDisk"); + } + +#if NETSTANDARD + [Fact(Skip = "Needs investigation, TestManagementClientHelper class wasn't initialized with the ResourceManagementClient client.")] +#else + [Fact] +#endif + [Trait(Category.AcceptanceType, Category.CheckIn)] + public void A2ARemoveReplicationProtectedItemHealthError() + { + this.RunPowerShellTest(_logger, Constants.NewModel, "Test-ResolveHealthError"); + } } } diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.ps1 b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.ps1 index c0fe04fe010d..c63c6c7aba62 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.ps1 +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery.Test/ScenarioTests/A2A/AsrA2ATests.ps1 @@ -90,11 +90,72 @@ function Test-NewAsrFabric { Assert-AreEqual $fab.FabricSpecificDetails.Location $primaryLocation } +<# +.SYNOPSIS + Test GetAsrFabric new parametersets +#> +function Test-NewContainer { + #variables + $seed = 33; + $primaryPolicyName = getPrimaryPolicy + $recoveryPolicyName = getRecoveryPolicy + + $primaryContainerMappingName = getPrimaryContainerMapping + $recoveryContainerMappingName = getRecoveryContainerMapping + $primaryContainerName = getPrimaryContainer + $recoveryContainerName = getRecoveryContainer + $vaultRgLocation = getVaultRgLocation + $vaultName = getVaultName + $vaultLocation = getVaultLocation + $vaultRg = getVaultRg + $primaryLocation = getPrimaryLocation + $recoveryLocation = getRecoveryLocation + $primaryFabricName = getPrimaryFabric + $recoveryFabricName = getRecoveryFabric + $RecoveryReplicaDiskAccountType = "Premium_LRS" + $RecoveryTargetDiskAccountType = "Premium_LRS" -function Test-NewContainer{ + New-AzureRmResourceGroup -name $vaultRg -location $vaultRgLocation -force + [Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000) + # vault Creation + New-azureRmRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName -Location $vaultLocation + [Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000) + $Vault = Get-AzureRMRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName + Set-ASRVaultContext -Vault $Vault + # fabric Creation + ### AzureToAzure New paramset + $fabJob= New-AzureRmRecoveryServicesAsrFabric -Azure -Name $primaryFabricName -Location $primaryLocation + WaitForJobCompletion -JobId $fabJob.Name + $fab = Get-AzureRmRecoveryServicesAsrFabric -Name $primaryFabricName + Assert-true { $fab.name -eq $primaryFabricName } + Assert-AreEqual $fab.FabricSpecificDetails.Location $primaryLocation - $seed = 33; - $primaryPolicyName = getPrimaryPolicy + #recovery fabric + $fabJob= New-AzureRmRecoveryServicesAsrFabric -Azure -Name $recoveryFabricName -Location $recoveryLocation + WaitForJobCompletion -JobId $fabJob.Name + $fab = Get-AzureRmRecoveryServicesAsrFabric -Name $recoveryFabricName + Assert-true { $fab.name -eq $recoveryFabricName } + Assert-AreEqual $fab.FabricSpecificDetails.Location $recoveryLocation + $pf = get-asrFabric -Name $primaryFabricName + $rf = get-asrFabric -Name $recoveryFabricName + + ### AzureToAzure (Default) + $job = New-AzureRmRecoveryServicesAsrProtectionContainer -Name $primaryContainerName -Fabric $pf + WaitForJobCompletion -JobId $Job.Name + $pc = Get-asrProtectionContainer -name $primaryContainerName -Fabric $pf + Assert-NotNull($pc) + Assert-AreEqual $pc.Name $primaryContainerName +} + +<# +.SYNOPSIS + Test-NewReplicationProtectedItem new parametersets +#> + +function Test-NewReplicationProtectedItem{ + #variables + $seed = 336; + $primaryPolicyName = getPrimaryPolicy $recoveryPolicyName = getRecoveryPolicy $primaryContainerMappingName = getPrimaryContainerMapping @@ -106,16 +167,27 @@ function Test-NewContainer{ $vaultName = getVaultName $vaultLocation = getVaultLocation $vaultRg = getVaultRg - $primaryLocation = getPrimaryLocation - $recoveryLocation = getRecoveryLocation + $primaryLocation = getRecoveryLocation + $recoveryLocation = getPrimaryLocation $primaryFabricName = getPrimaryFabric $recoveryFabricName = getRecoveryFabric $RecoveryReplicaDiskAccountType = "Premium_LRS" $RecoveryTargetDiskAccountType = "Premium_LRS" + $policyName = getPrimaryPolicy + $mappingName = getPrimaryContainerMapping + $primaryNetMapping = getPrimaryNetworkMapping + + $logStg = "/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourcegroups/pstest1/providers/Microsoft.Storage/storageAccounts/cachestgpstest1" + $v2VmId ="/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstest1/providers/Microsoft.Compute/virtualMachines/linux-vm1" + $PrimaryAzureNetworkId ="/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstest1/providers/Microsoft.Network/virtualNetworks/pstest1-vnet" + $RecoveryAzureNetworkId ="/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstest1-asr/providers/Microsoft.Network/virtualNetworks/rec-pstests1" + $recRg = "/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstest1-asr" + $vmName ="linux-vm1" + $vhdid ="/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstest1/providers/Microsoft.Compute/disks/linux-vm1_OsDisk_1_3d376317b0d6463bb344da9fab7d56f3" New-AzureRmResourceGroup -name $vaultRg -location $vaultRgLocation -force [Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000) - # vault Creation + # vault Creation New-azureRmRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName -Location $vaultLocation [Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000) $Vault = Get-AzureRMRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName @@ -136,11 +208,223 @@ function Test-NewContainer{ $pf = get-asrFabric -Name $primaryFabricName $rf = get-asrFabric -Name $recoveryFabricName - ### AzureToAzure (Default) + ### AzureToAzure (Default) $job = New-AzureRmRecoveryServicesAsrProtectionContainer -Name $primaryContainerName -Fabric $pf WaitForJobCompletion -JobId $Job.Name $pc = Get-asrProtectionContainer -name $primaryContainerName -Fabric $pf - Assert-NotNull($pc) - Assert-AreEqual $pc.Name $primaryContainerName + $job = New-AzureRmRecoveryServicesAsrProtectionContainer -Name $recoveryContainerName -Fabric $rf + WaitForJobCompletion -JobId $Job.Name + $rc = Get-asrProtectionContainer -name $recoveryContainerName -Fabric $rf + #create policy + $job = New-AzureRmRecoveryServicesAsrPolicy -Name $policyName -RecoveryPointRetentionInHours 12 -AzureToAzure + WaitForJobCompletion -JobId $job.Name + $policy = Get-AzureRmRecoveryServicesAsrPolicy -Name $policyName + $job = New-AzureRmRecoveryServicesAsrProtectionContainerMapping -Name $mappingName -Policy $policy -PrimaryProtectionContainer $pc -RecoveryProtectionContainer $rc + WaitForJobCompletion -JobId $job.Name + $mapping = Get-AzureRmRecoveryServicesAsrProtectionContainerMapping -Name $mappingName -ProtectionContainer $pc + + #network mapping + $job = New-AzureRmRecoveryServicesAsrNetworkMapping -AzureToAzure -Name $primaryNetMapping -PrimaryFabric $pf -PrimaryAzureNetworkId $PrimaryAzureNetworkId -RecoveryFabric $rf -RecoveryAzureNetworkId $RecoveryAzureNetworkId + WaitForJobCompletion -JobId $job.Name + + $disk1= New-AzureRmRecoveryServicesAsrAzureToAzureDiskReplicationConfig -DiskId $vhdid -LogStorageAccountId $logStg -ManagedDisk -RecoveryReplicaDiskAccountType $RecoveryReplicaDiskAccountType -RecoveryResourceGroupId $recRg -RecoveryTargetDiskAccountType $RecoveryTargetDiskAccountType + $enableDRjob = New-AzureRmRecoveryServicesAsrReplicationProtectedItem -AzureToAzure -AzureVmId $v2VmId -Name $vmName -ProtectionContainerMapping $mapping -RecoveryResourceGroupId $recrg -AzureToAzureDiskReplicationConfiguration $disk1 + WaitForJobCompletion -JobId $enableDRjob.Name + WaitForIRCompletion -affectedObjectId $enableDRjob.TargetObjectId +} + +<# +.SYNOPSIS + Test AddReplicationProtectedItemDisk new parametersets +#> + +function Test-AddReplicationProtectedItemDisk{ + #variables + $seed = 336; + $vaultName = getVaultName + $vaultLocation = getVaultLocation + $vaultRg = getVaultRg + $primaryLocation = getPrimaryLocation + $recoveryLocation = getRecoveryLocation + $RecoveryReplicaDiskAccountType = "Premium_LRS" + $RecoveryTargetDiskAccountType = "Premium_LRS" + + $v2VmId ="/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstests/providers/Microsoft.Compute/virtualMachines/Vm1" + $vmName ="vm1" + $vmRg = "pstests" + $diskName = "A2ADisk0"+ $seed + + # vault + $Vault = Get-AzureRMRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName + Set-ASRVaultContext -Vault $Vault + # fabric + $pf = Get-ASRFabric | where-object {$_.FabricSpecificDetails.Location -eq $primaryLocation} + Assert-NotNull($pf) + $rf = Get-ASRFabric | where-object {$_.FabricSpecificDetails.Location -eq $recoveryLocation} + Assert-NotNull($rf) + + ### AzureToAzure (Default) + $pc = Get-asrProtectionContainer -name $primaryContainerName -Fabric $pf + $rc = Get-asrProtectionContainer -name $recoveryContainerName -Fabric $rf + Assert-NotNull($pc) + Assert-NotNull($rc) + + #add diskId + $pe = Get-AzureRmRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName + Assert-NotNull($pe) + + #create disk and attach + $vm = get-azureRmVm -ResourceGroupName $vmRg -Name $vmName + $newDiskConfig = New-AzurermDiskConfig -Location $vm.Location -CreateOption Empty -DiskSizeGB 5 + $newDisk = New-AzurermDisk -ResourceGroupName $vm.ResourceGroupName -DiskName $diskName -Disk $newDiskConfig + $vm = Add-AzureRmVMDataDisk -VM $vm -Name $diskName -CreateOption Attach -ManagedDiskId $newDisk.Id -Lun 5 + Update-azureRmVm -ResourceGroupName $vmRg -VM $vm + + #wait for the add-disk health warning to appear + Write-Host $("Waiting for Add-Disk health warning...") -ForegroundColor Yellow + $HealthQueryWaitTimeInSeconds = 10 + do + { + $pe = Get-AzureRmRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName + $healthError = $pe.ReplicationHealthErrors | where-object {$_.ErrorCode -eq 153039} + + if($healthError -eq $null) + { + Write-Host $("Waiting for Add-Disk health warning...") -ForegroundColor Yellow + Write-Host $("Waiting for: " + $HealthQueryWaitTimeInSeconds.ToString + " Seconds") -ForegroundColor Yellow + [Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait($HealthQueryWaitTimeInSeconds * 1000) + } + }While($healthError -eq $null) + + #add disks + $disk2= New-AzureRmRecoveryServicesAsrAzureToAzureDiskReplicationConfig -DiskId $newDisk.Id -LogStorageAccountId $pe.ProviderSpecificDetails.A2ADiskDetails[0].PrimaryStagingAzureStorageAccountId -ManagedDisk -RecoveryReplicaDiskAccountType $RecoveryReplicaDiskAccountType -RecoveryResourceGroupId $pe.ProviderSpecificDetails.A2ADiskDetails[0].RecoveryResourceGroupId -RecoveryTargetDiskAccountType $RecoveryTargetDiskAccountType + $addDRjob = Add-AzureRmRecoveryServicesAsrReplicationProtectedItemDisk -ReplicationProtectedItem $pe -AzureToAzureDiskReplicationConfiguration $disk2 + WaitForJobCompletion -JobId $addDRjob.Name + WaitForAddDisksIRCompletion -affectedObjectId $addDRjob.TargetObjectId + + $pe = Get-AzureRmRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName + Assert-NotNull($pe) +} + +<# +.SYNOPSIS + Test AddReplicationProtectedItemDisk new parametersets +#> + +function Test-RemoveReplicationProtectedItemDisk{ + #variables + $seed = 336; + $vaultName = getVaultName + $vaultLocation = getVaultLocation + $vaultRg = getVaultRg + $primaryLocation = getPrimaryLocation + $recoveryLocation = getRecoveryLocation + $RecoveryReplicaDiskAccountType = "Premium_LRS" + $RecoveryTargetDiskAccountType = "Premium_LRS" + + $v2VmId ="/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstests/providers/Microsoft.Compute/virtualMachines/Vm1" + $vmName ="vm1" + $vmRg = "pstests" + $diskName = "A2ADisk0"+ $seed + + # vault + $Vault = Get-AzureRMRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName + Set-ASRVaultContext -Vault $Vault + # fabric + $pf = Get-ASRFabric | where-object {$_.FabricSpecificDetails.Location -eq $primaryLocation} + Assert-NotNull($pf) + $rf = Get-ASRFabric | where-object {$_.FabricSpecificDetails.Location -eq $recoveryLocation} + Assert-NotNull($rf) + + ### AzureToAzure (Default) + $pc = Get-asrProtectionContainer -name $primaryContainerName -Fabric $pf + $rc = Get-asrProtectionContainer -name $recoveryContainerName -Fabric $rf + Assert-NotNull($pc) + Assert-NotNull($rc) + + #add diskId + $pe = Get-AzureRmRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName + Assert-NotNull($pe) + + #get disk to deattach + | $removeDisk = $pe.ProviderSpecificDetails.A2ADiskDetails | where-object {$_.AllowedDiskLevelOperation.Count -eq 1} + Assert-NotNull($removeDisk) + + $vm = get-azureRmVm -ResourceGroupName $vmRg -Name $vmName + $removeDiskId = $vm.StorageProfile.DataDisks | Where-Object {$_.ManagedDisk.Name -eq $removeDisk.DiskName} + + $removeDRjob = Remove-AzureRmRecoveryServicesAsrReplicationProtectedItemDisk -ReplicationProtectedItem $pe -DiskId $removeDiskId.ManagedDisk.Id + WaitForJobCompletion -JobId $removeDRjob.Name + + $pe = Get-AzureRmRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName + Assert-NotNull($pe) +} + +<# +.SYNOPSIS + Test AddReplicationProtectedItemDisk new parametersets +#> + +function Test-ResolveHealthError{ + #variables + $seed = 336; + $vaultName = getVaultName + $vaultLocation = getVaultLocation + $vaultRg = getVaultRg + $primaryLocation = getPrimaryLocation + $recoveryLocation = getRecoveryLocation + $RecoveryReplicaDiskAccountType = "Premium_LRS" + $RecoveryTargetDiskAccountType = "Premium_LRS" + + $v2VmId ="/subscriptions/509099b2-9d2c-4636-b43e-bd5cafb6be69/resourceGroups/pstests/providers/Microsoft.Compute/virtualMachines/Vm1" + $vmName ="vm1" + $vmRg = "pstests" + $diskName = "A2ADisk0"+ $seed + + # vault + $Vault = Get-AzureRMRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName + Set-ASRVaultContext -Vault $Vault + # fabric + $pf = Get-ASRFabric | where-object {$_.FabricSpecificDetails.Location -eq $primaryLocation} + Assert-NotNull($pf) + $rf = Get-ASRFabric | where-object {$_.FabricSpecificDetails.Location -eq $recoveryLocation} + Assert-NotNull($rf) + + ### AzureToAzure (Default) + $pc = Get-asrProtectionContainer -name $primaryContainerName -Fabric $pf + $rc = Get-asrProtectionContainer -name $recoveryContainerName -Fabric $rf + Assert-NotNull($pc) + Assert-NotNull($rc) + + #add diskId + $pe = Get-AzureRmRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName + Assert-NotNull($pe) + + #create disk and attach + $vm = get-azureRmVm -ResourceGroupName $vmRg -Name $vmName + $newDiskConfig = New-AzurermDiskConfig -Location $vm.Location -CreateOption Empty -DiskSizeGB 5 + $newDisk = New-AzurermDisk -ResourceGroupName $vm.ResourceGroupName -DiskName $diskName -Disk $newDiskConfig + $vm = Add-AzureRmVMDataDisk -VM $vm -Name $diskName -CreateOption Attach -ManagedDiskId $newDisk.Id -Lun 5 + Update-azureRmVm -ResourceGroupName $vmRg -VM $vm + + #wait for the add-disk health warning to appear + Write-Host $("Waiting for Add-Disk health warning...") -ForegroundColor Yellow + $HealthQueryWaitTimeInSeconds = 10 + do + { + $pe = Get-AzureRmRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName + $healthError = $pe.ReplicationHealthErrors | where-object {$_.ErrorCode -eq 153039} + + if($healthError -eq $null) + { + Write-Host $("Waiting for Add-Disk health warning...") -ForegroundColor Yellow + Write-Host $("Waiting for: " + $HealthQueryWaitTimeInSeconds.ToString + " Seconds") -ForegroundColor Yellow + [Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait($HealthQueryWaitTimeInSeconds * 1000) + } + }While($healthError -eq $null) + + #resolve health error + $addDRjob = Remove-AzureRmRecoveryServicesAsrReplicationProtectedItemHealthError -ReplicationProtectedItem $pe -ErrorIds $healthError.ErrorId + WaitForJobCompletion -JobId $addDRjob.Name } diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 index fdd394a44d34..81e73abc7c1e 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/AzureRM.RecoveryServices.SiteRecovery.psd1 @@ -116,6 +116,8 @@ CmdletsToExport = 'Remove-AzureRmRecoveryServicesAsrProtectionContainerMapping', 'Remove-AzureRmRecoveryServicesAsrRecoveryPlan', 'Remove-AzureRmRecoveryServicesAsrReplicationProtectedItem', + 'Remove-AzureRmRecoveryServicesAsrReplicationProtectedItemDisk', + 'RecoveryServicesAsrReplicationProtectedItemHealthError', 'Remove-AzureRmRecoveryServicesAsrServicesProvider', 'Remove-AzureRmRecoveryServicesAsrStorageClassificationMapping', 'Remove-AzureRmRecoveryServicesAsrvCenter', @@ -162,8 +164,9 @@ AliasesToExport = 'Add-ASRReplicationProtectedItemDisk', 'Edit-ASRRP', 'Edit-ASR 'New-ASRRecoveryPlan', 'New-ASRReplicationProtectedItem', 'New-ASRStorageClassificationMapping', 'New-ASRvCenter', 'Remove-ASRFabric', 'Remove-ASRNetworkMapping', 'Remove-ASRPolicy', - 'Remove-ASRProtectionContainerMapping', 'Remove-ASRRP', - 'Remove-ASRRecoveryPlan', 'Remove-ASRReplicationProtectedItem', + 'Remove-ASRProtectionContainerMapping', 'Remove-ASRRP', + 'Remove-ASRRecoveryPlan', 'Remove-ASRReplicationProtectedItem', + 'Remove-ASRReplicationProtectedItemDisk', 'Remove-ASRReplicationProtectedItemHealthError', 'Remove-ASRServicesProvider', 'Remove-ASRStorageClassificationMapping', 'Remove-ASRvCenter', 'Restart-ASRJob', 'Resume-ASRJob', 'Set-ASRAlertSetting', diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj index cf0314e61c08..8a1177ef914c 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery.csproj @@ -44,14 +44,14 @@ ..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.4.2.1-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.dll True - - ..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.1.3.0-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.dll + + ..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.2.0.1-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.dll - ..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.18\lib\net452\Microsoft.Rest.ClientRuntime.dll + ..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.19\lib\net452\Microsoft.Rest.ClientRuntime.dll - ..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.18\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll + ..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.19\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll ..\..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll @@ -118,6 +118,8 @@ + + @@ -196,4 +198,4 @@ - + \ No newline at end of file diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs index bfb1da1b9dc9..274cc477d222 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Common/PSAsrReplicationProtectedItemsClient.cs @@ -28,8 +28,8 @@ public partial class PSRecoveryServicesClient /// Removes Replicated Protected Item. /// /// Fabric Name - /// Protection Container ID - /// Virtual Machine ID or Replication group Id + /// Protection Container Name + /// Replication Protected Item Name /// Disable protection input. /// Job response public PSSiteRecoveryLongRunningOperation DisableProtection( @@ -56,8 +56,8 @@ public PSSiteRecoveryLongRunningOperation DisableProtection( /// Creates Replicated Protected Item. /// /// Fabric Name - /// Protection Container ID - /// Virtual Machine ID or Replication group Id + /// Protection Container Name + /// Replication Protected Item Name /// Enable protection input. /// Job response public PSSiteRecoveryLongRunningOperation EnableProtection( @@ -81,11 +81,11 @@ public PSSiteRecoveryLongRunningOperation EnableProtection( } /// - /// Add disks to replicated protected item. + /// Add disks to replication protected item. /// /// Fabric Name - /// Protection Container ID - /// Virtual Machine ID or Replication group Id + /// Protection Container Name + /// Replication Protected Item Name /// Add disks input. /// Job response public PSSiteRecoveryLongRunningOperation AddDisks( @@ -108,6 +108,62 @@ public PSSiteRecoveryLongRunningOperation AddDisks( return result; } + /// + /// Remove disks from replication protected item. + /// + /// Fabric Name + /// Protection Container Name + /// Replication Protected Item Name + /// Remove disks input. + /// Job response + public PSSiteRecoveryLongRunningOperation RemoveDisks( + string fabricName, + string protectionContainerName, + string replicationProtectedItemName, + RemoveDisksInput input) + { + var op = this.GetSiteRecoveryClient() + .ReplicationProtectedItems.BeginRemoveDisksWithHttpMessagesAsync( + fabricName, + protectionContainerName, + replicationProtectedItemName, + input, + this.GetRequestHeaders(true)) + .GetAwaiter() + .GetResult(); + + var result = SiteRecoveryAutoMapperProfile.Mapper.Map(op); + return result; + } + + /// + /// Removes the Health error from replication protected item. + /// + /// Fabric Name + /// Protection Container Name + /// Replication Protected Item Name + /// Remove disks input. + /// Job response + public PSSiteRecoveryLongRunningOperation ResolveHealthError( + string fabricName, + string protectionContainerName, + string replicationProtectedItemName, + ResolveHealthInput input) + { + var op = this.GetSiteRecoveryClient() + .ReplicationProtectedItems.BeginResolveHealthErrorsWithHttpMessagesAsync( + fabricName, + protectionContainerName, + replicationProtectedItemName, + input, + this.GetRequestHeaders(true)) + .GetAwaiter() + .GetResult(); + + var result = SiteRecoveryAutoMapperProfile.Mapper.Map(op); + return result; + } + /// /// Retrieves Replicated Protected Item. /// diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/2016-08-10/ASRPSObjects.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/2016-08-10/ASRPSObjects.cs index 02d50e18fbd5..272e904e0b86 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/2016-08-10/ASRPSObjects.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/2016-08-10/ASRPSObjects.cs @@ -46,6 +46,8 @@ public ASRHealthError_2016_08_10(HealthError healthError) this.PossibleCauses = healthError.PossibleCauses; this.RecommendedAction = healthError.RecommendedAction; this.RecoveryProviderErrorMessage = healthError.RecoveryProviderErrorMessage; + this.ErrorId = healthError.ErrorId; + this.CustomerResolvability = healthError.CustomerResolvability; this.childError = new List(); if (healthError.InnerHealthErrors != null) { @@ -121,6 +123,16 @@ public ASRHealthError_2016_08_10(InnerHealthError healthError) /// public string ErrorMessage { get; set; } + /// + /// Id of error. + /// + public string ErrorId { get; set; } + + /// + /// CustomerResolvability of error. + /// + public string CustomerResolvability { get; set; } + /// /// Possible causes of error. /// diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSFabricDetails.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSFabricDetails.cs index e5440c200859..b7969992ed17 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSFabricDetails.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSFabricDetails.cs @@ -1183,6 +1183,7 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details) this.RecoveryAzureCloudService = details.RecoveryCloudService; this.RecoveryFabricLocation = details.RecoveryFabricLocation; this.RecoveryAvailabilitySet = details.RecoveryAvailabilitySet; + this.RecoveryAvailabilityZone = details.RecoveryAvailabilityZone; this.TestFailoverRecoveryFabricObjectId = details.TestFailoverRecoveryFabricObjectId; this.MonitoringJobType = details.MonitoringJobType; this.MonitoringPercentageCompletion = details.MonitoringPercentageCompletion; @@ -1214,7 +1215,7 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details) .ConvertAll(disk => new ASRAzureToAzureProtectedDiskDetails(disk))); } - if (details.UnprotectedDisks != null && details.UnprotectedDisks.Count > 0) + if (details.UnprotectedDisks != null && details.UnprotectedDisks.Count > 0) { this.A2AUnprotectedDiskDetails = new List(); foreach (var unprotectedDisk in details.UnprotectedDisks) @@ -1281,6 +1282,11 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details) /// public string RecoveryAvailabilitySet { get; set; } + /// + /// Recovery availability zone. + /// + public string RecoveryAvailabilityZone { get; set; } + /// /// Synced configuration details of the virtual machine. /// diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSObjects.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSObjects.cs index a940102e80b3..aa64da99cd2f 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSObjects.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/Models/PSObjects.cs @@ -2261,6 +2261,7 @@ public ASRAzureToAzureProtectedDiskDetails(A2AProtectedDiskDetails disk) this.DiskName = disk.DiskName; this.DiskType = disk.DiskType; this.DiskState = disk.DiskState; + this.AllowedDiskLevelOperation = disk.AllowedDiskLevelOperation; this.Managed = false; } @@ -2280,6 +2281,7 @@ public ASRAzureToAzureProtectedDiskDetails(A2AProtectedManagedDiskDetails disk) this.DiskName = disk.DiskName; this.DiskType = disk.DiskType; this.DiskState = disk.DiskState; + this.AllowedDiskLevelOperation = disk.AllowedDiskLevelOperation; this.RecoveryReplicaDiskAccountType = disk.RecoveryReplicaDiskAccountType; this.RecoveryReplicaDiskId = disk.RecoveryReplicaDiskId; this.RecoveryResourceGroupId = disk.RecoveryResourceGroupId; @@ -2360,6 +2362,11 @@ public ASRAzureToAzureProtectedDiskDetails(A2AProtectedManagedDiskDetails disk) /// public string DiskState { get; set; } + /// + /// Gets or sets the Allowed Disk Level Operation. + /// + public IList AllowedDiskLevelOperation { get; set; } + /// /// Gets or sets recovery disk uri. /// diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/NewAzureRmRecoveryServicesAsrReplicationProtectedItem.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/NewAzureRmRecoveryServicesAsrReplicationProtectedItem.cs index c85ac8b08805..a835b7401685 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/NewAzureRmRecoveryServicesAsrReplicationProtectedItem.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/NewAzureRmRecoveryServicesAsrReplicationProtectedItem.cs @@ -216,6 +216,8 @@ public class NewAzureRmRecoveryServicesAsrReplicationProtectedItem : SiteRecover /// [Parameter(ParameterSetName = ASRParameterSets.VMwareToAzure)] [Parameter(ParameterSetName = ASRParameterSets.HyperVSiteToAzure)] + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzure)] + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzureWithoutDiskDetails)] [ValidateNotNullOrEmpty] public string RecoveryAzureNetworkId { get; set; } @@ -225,6 +227,8 @@ public class NewAzureRmRecoveryServicesAsrReplicationProtectedItem : SiteRecover /// [Parameter(ParameterSetName = ASRParameterSets.VMwareToAzure)] [Parameter(ParameterSetName = ASRParameterSets.HyperVSiteToAzure)] + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzure)] + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzureWithoutDiskDetails)] [ValidateNotNullOrEmpty] public string RecoveryAzureSubnetName { get; set; } @@ -261,6 +265,14 @@ public class NewAzureRmRecoveryServicesAsrReplicationProtectedItem : SiteRecover [ValidateNotNullOrEmpty] public string RecoveryAvailabilitySetId { get; set; } + /// + /// Gets or sets ID of the AvailabilityZone to recover the machine to in the event of a failover. + /// + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzure)] + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzureWithoutDiskDetails)] + [ValidateNotNullOrEmpty] + public string RecoveryAvailabilityZone { get; set; } + /// /// Gets or sets BootDiagnosticStorageAccountId. /// @@ -604,7 +616,10 @@ private void AzureToAzureReplication(EnableProtectionInput input) RecoveryResourceGroupId = this.RecoveryResourceGroupId, RecoveryCloudServiceId = this.RecoveryCloudServiceId, RecoveryAvailabilitySetId = this.RecoveryAvailabilitySetId, - RecoveryBootDiagStorageAccountId = this.RecoveryBootDiagStorageAccountId + RecoveryBootDiagStorageAccountId = this.RecoveryBootDiagStorageAccountId, + RecoveryAvailabilityZone = this.RecoveryAvailabilityZone, + RecoveryAzureNetworkId = this.RecoveryAzureNetworkId, + RecoverySubnetName = this.RecoveryAzureSubnetName }; if (!string.IsNullOrEmpty(this.RecoveryCloudServiceId)) @@ -612,6 +627,12 @@ private void AzureToAzureReplication(EnableProtectionInput input) providerSettings.RecoveryResourceGroupId = null; } + if (!string.IsNullOrEmpty(this.RecoveryAvailabilityZone) && + !string.IsNullOrEmpty(this.RecoveryAvailabilitySetId)) + { + throw new Exception("RecoveryAvailabilityZone and RecoveryAvailabilitySetId cannot be set together for a VM"); + } + if (this.AzureToAzureDiskReplicationConfiguration == null) { if (this.AzureVmId.ToLower().Contains(ARMResourceTypeConstants.Compute.ToLower())) diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs new file mode 100644 index 000000000000..abfcdfd652fd --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs @@ -0,0 +1,136 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Management.Automation; +using System.Collections.Generic; +using Microsoft.Azure.Management.RecoveryServices.SiteRecovery.Models; +using Job = Microsoft.Azure.Management.RecoveryServices.SiteRecovery.Models.Job; + +namespace Microsoft.Azure.Commands.RecoveryServices.SiteRecovery +{ + /// + /// Removes disks to replication protected item. + /// + [Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RecoveryServicesAsrReplicationProtectedItemDisk", DefaultParameterSetName = ASRParameterSets.AzureToAzure, SupportsShouldProcess = true)] + [Alias("Remove-ASRReplicationProtectedItemDisk")] + [OutputType(typeof(ASRJob))] + public class RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk : SiteRecoveryCmdletBase + { + [ValidateNotNullOrEmpty] + [Parameter(Mandatory = true)] + public ASRReplicationProtectedItem ReplicationProtectedItem { get; set; } + + /// + /// Gets or sets the disk uri. + /// + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzure, Mandatory = true)] + [ValidateNotNullOrEmpty] + public string[] VhdUri { get; set; } + + /// + /// Gets or sets the disk Id. + /// + [Parameter(ParameterSetName = ASRParameterSets.AzureToAzureManagedDisk, Mandatory = true)] + [ValidateNotNullOrEmpty] + public string[] DiskId { get; set; } + + [Parameter] + public SwitchParameter WaitForCompletion { get; set; } + + /// + /// ProcessRecord of the command. + /// + public override void ExecuteSiteRecoveryCmdlet() + { + base.ExecuteSiteRecoveryCmdlet(); + + // check for A2A protected item - if providerSpecificDetails is A2AReplicationDetails. + + var removeDisksProviderSpecificInput = new RemoveDisksProviderSpecificInput(); + var inputProperties = new RemoveDisksInputProperties + { + ProviderSpecificDetails = removeDisksProviderSpecificInput + }; + var input = new RemoveDisksInput { Properties = inputProperties }; + FillRemoveDiskInputForAzureToAzureReplication(input); + + this.response = this.RecoveryServicesClient.RemoveDisks( + Utilities.GetValueFromArmId( + this.ReplicationProtectedItem.ID, + ARMResourceTypeConstants.ReplicationFabrics), + Utilities.GetValueFromArmId( + this.ReplicationProtectedItem.ID, + ARMResourceTypeConstants.ReplicationProtectionContainers), + this.ReplicationProtectedItem.Name, + input); + + this.jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( + PSRecoveryServicesClient.GetJobIdFromReponseLocation(this.response.Location)); + + this.WriteObject(new ASRJob(this.jobResponse)); + + if (this.WaitForCompletion.IsPresent) + { + this.WaitForJobCompletion(this.jobResponse.Name); + + this.jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( + PSRecoveryServicesClient + .GetJobIdFromReponseLocation(this.response.Location)); + + this.WriteObject(new ASRJob(this.jobResponse)); + } + } + + /// + /// Helper method to fill in input details. + /// + private void FillRemoveDiskInputForAzureToAzureReplication(RemoveDisksInput input) + { + var providerSettings = new A2ARemoveDisksInput() + { + VmDisksUris = new List(), + VmManagedDisksIds = new List() + }; + + switch (this.ParameterSetName) + { + case ASRParameterSets.AzureToAzure: + providerSettings.VmDisksUris = this.VhdUri; + break; + case ASRParameterSets.AzureToAzureManagedDisk: + providerSettings.VmManagedDisksIds = this.DiskId; + break; + } + + input.Properties.ProviderSpecificDetails = providerSettings; + } + + /// + /// Writes Job. + /// + /// Job object. + private void WriteJob( + Job job) + { + this.WriteObject(new ASRJob(job)); + } + + private Job jobResponse; + + /// + /// Job response. + /// + private PSSiteRecoveryLongRunningOperation response; + } +} diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemHealthError.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemHealthError.cs new file mode 100644 index 000000000000..a3efa9869089 --- /dev/null +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemHealthError.cs @@ -0,0 +1,111 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Management.Automation; +using System.Collections.Generic; +using Microsoft.Azure.Management.RecoveryServices.SiteRecovery.Models; +using Job = Microsoft.Azure.Management.RecoveryServices.SiteRecovery.Models.Job; + +namespace Microsoft.Azure.Commands.RecoveryServices.SiteRecovery +{ + /// + /// Removes health error for the replication protected item. + /// + [Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RecoveryServicesAsrReplicationProtectedItemHealthError", DefaultParameterSetName = ASRParameterSets.AzureToAzure, SupportsShouldProcess = true)] + [Alias("Remove-ASRReplicationProtectedItemHealthError")] + [OutputType(typeof(ASRJob))] + public class RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemHealthError : SiteRecoveryCmdletBase + { + [ValidateNotNullOrEmpty] + [Parameter(Mandatory = true)] + public ASRReplicationProtectedItem ReplicationProtectedItem { get; set; } + + /// + /// Gets or sets the errro id. + /// + [Parameter(Mandatory = true)] + [ValidateNotNullOrEmpty] + public string[] ErrorIds { get; set; } + + [Parameter] + public SwitchParameter WaitForCompletion { get; set; } + + /// + /// ProcessRecord of the command. + /// + public override void ExecuteSiteRecoveryCmdlet() + { + base.ExecuteSiteRecoveryCmdlet(); + + var input = new ResolveHealthInput { Properties = new ResolveHealthInputProperties()}; + FillResolveHealthErrorInput(input); + + this.response = this.RecoveryServicesClient.ResolveHealthError( + Utilities.GetValueFromArmId( + this.ReplicationProtectedItem.ID, + ARMResourceTypeConstants.ReplicationFabrics), + Utilities.GetValueFromArmId( + this.ReplicationProtectedItem.ID, + ARMResourceTypeConstants.ReplicationProtectionContainers), + this.ReplicationProtectedItem.Name, + input); + + this.jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( + PSRecoveryServicesClient.GetJobIdFromReponseLocation(this.response.Location)); + + this.WriteObject(new ASRJob(this.jobResponse)); + + if (this.WaitForCompletion.IsPresent) + { + this.WaitForJobCompletion(this.jobResponse.Name); + + this.jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( + PSRecoveryServicesClient + .GetJobIdFromReponseLocation(this.response.Location)); + + this.WriteObject(new ASRJob(this.jobResponse)); + } + } + + /// + /// Helper method to fill in input details. + /// + private void FillResolveHealthErrorInput(ResolveHealthInput input) + { + input.Properties.HealthErrors = new List(); + + foreach (string errorId in ErrorIds) + { + input.Properties.HealthErrors.Add(new ResolveHealthError(errorId)); + } + } + + /// + /// Writes Job. + /// + /// Job object. + private void WriteJob( + Job job) + { + this.WriteObject(new ASRJob(job)); + } + + private Job jobResponse; + + /// + /// Job response. + /// + private PSSiteRecoveryLongRunningOperation response; + } +} diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/UpdateAzureRmRecoveryServicesAsrProtectionDirection.cs b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/UpdateAzureRmRecoveryServicesAsrProtectionDirection.cs index d8fa1582934b..c2cad12dcea4 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/UpdateAzureRmRecoveryServicesAsrProtectionDirection.cs +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/ReplicationProtectedItem/UpdateAzureRmRecoveryServicesAsrProtectionDirection.cs @@ -635,7 +635,7 @@ private void populateManagedDiskInputDetails( RecoveryResourceGroupId = disk.RecoveryResourceGroupId, RecoveryReplicaDiskAccountType = disk.RecoveryReplicaDiskAccountType, RecoveryTargetDiskAccountType = disk.RecoveryTargetDiskAccountType, - PrimaryStagingAzureStorageAccountId = this.LogStorageAccountId, + PrimaryStagingAzureStorageAccountId = disk.LogStorageAccountId, }); } } diff --git a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/packages.config b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/packages.config index 83a4456eb24e..7d7c692f1c24 100644 --- a/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/packages.config +++ b/src/ResourceManager/RecoveryServices/Commands.RecoveryServices.SiteRecovery/packages.config @@ -2,8 +2,9 @@ - - - + + + - + + \ No newline at end of file