Skip to content

VMSS powerShell changes to common branch #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.3.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="4.1.5-preview" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="14.3.0" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.SiteRecovery" Version="2.1.2-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.SiteRecovery" Version="2.1.3-preview" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,12 @@ public void A2ARecoveryPlanReplication()
{
this.RunPowerShellTest(_logger, Constants.NewModel, "Test-RecoveryPlanReplication");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void A2AVMSSReplication()
{
this.RunPowerShellTest(_logger, Constants.NewModel, "Test-VMSSReplication");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -924,4 +924,154 @@ function Test-RecoveryPlanReplication {
#Failover
$failoverjob = Start-AzRecoveryServicesAsrUnPlannedFailoverJob -RecoveryPlan $RecoveryPlan -Direction PrimaryToRecovery -PerformSourceSideAction
WaitForJobCompletion -JobId $failoverjob.Name
}

<#
.SYNOPSIS
Test VMSS replication new parametersets
#>

function Test-VMSSReplication {
param([string] $seed = '1227')
$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"
$policyName = getPrimaryPolicy
$mappingName = getPrimaryContainerMapping
$recMappingName = getRecoveryContainerMapping
$primaryNetMapping = getPrimaryNetworkMapping
$recoveryNetMapping = getRecoveryNetworkMapping

#create recovery side resources
$recRgName = getRecoveryResourceGroupName
New-AzResourceGroup -name $recRgName -location $recoveryLocation -force
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000)
$RecoveryAzureNetworkId = createRecoveryNetworkId
$index = $RecoveryAzureNetworkId.IndexOf("/providers/")
$recRg = $RecoveryAzureNetworkId.Substring(0, $index)
#create virtual Machine scale set
$vmssConfig = New-AzVmssConfig -Location $recoveryLocation -PlatformFaultDomainCount 1 -SinglePlacementGroup 0
$recVmss = new-azvmss -resourcegroupname $recRgName -vmscalesetname 'vmss-asr' -virtualmachinescaleset $vmssConfig
$recVmss1 = new-azvmss -resourcegroupname $recRgName -vmscalesetname 'vmss1-asr' -virtualmachinescaleset $vmssConfig

#create primary
$vmName = getAzureVmName
New-AzResourceGroup -name $vmName -location $primaryLocation -force
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000)
$logStg = createCacheStorageAccount
$recLogStg = createRecoveryCacheStorageAccount

$v2VmId = createAzureVm
$vm = get-azVm -ResourceGroupName $vmName -Name $vmName
$vhdid = $vm.StorageProfile.OSDisk.ManagedDisk.Id
$index = $vm.Id.IndexOf("/providers/")
$Rg = $vm.Id.Substring(0, $index)
$PrimaryAzureNetworkId = $Rg + "/providers/Microsoft.Network/virtualNetworks/" + $vmName

# vault Creation
New-AzResourceGroup -name $vaultRg -location $vaultRgLocation -force
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000)
New-AzRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName -Location $vaultLocation
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(20 * 1000)
$Vault = Get-AzRecoveryServicesVault -ResourceGroupName $vaultRg -Name $vaultName
Set-ASRVaultContext -Vault $Vault

# fabric Creation
$fabJob = New-AzRecoveryServicesAsrFabric -Azure -Name $primaryFabricName -Location $primaryLocation
WaitForJobCompletion -JobId $fabJob.Name
$fab = Get-AzRecoveryServicesAsrFabric -Name $primaryFabricName
Assert-true { $fab.name -eq $primaryFabricName }
Assert-AreEqual $fab.FabricSpecificDetails.Location $primaryLocation

$fabJob = New-AzRecoveryServicesAsrFabric -Azure -Name $recoveryFabricName -Location $recoveryLocation
WaitForJobCompletion -JobId $fabJob.Name
$fab = Get-AzRecoveryServicesAsrFabric -Name $recoveryFabricName
Assert-true { $fab.name -eq $recoveryFabricName }
Assert-AreEqual $fab.FabricSpecificDetails.Location $recoveryLocation
$pf = get-asrFabric -Name $primaryFabricName
$rf = get-asrFabric -Name $recoveryFabricName

#Container creation
$job = New-AzRecoveryServicesAsrProtectionContainer -Name $primaryContainerName -Fabric $pf
WaitForJobCompletion -JobId $Job.Name
$pc = Get-asrProtectionContainer -name $primaryContainerName -Fabric $pf
Assert-NotNull($pc)
$job = New-AzRecoveryServicesAsrProtectionContainer -Name $recoveryContainerName -Fabric $rf
WaitForJobCompletion -JobId $Job.Name
$rc = Get-asrProtectionContainer -name $recoveryContainerName -Fabric $rf
Assert-NotNull($rc)

#create policy and mapping
$job = New-AzRecoveryServicesAsrPolicy -Name $policyName -RecoveryPointRetentionInHours 12 -AzureToAzure
WaitForJobCompletion -JobId $job.Name
$policy = Get-AzRecoveryServicesAsrPolicy -Name $policyName
$job = New-AzRecoveryServicesAsrProtectionContainerMapping -Name $mappingName -Policy $policy -PrimaryProtectionContainer $pc -RecoveryProtectionContainer $rc
WaitForJobCompletion -JobId $job.Name
$mapping = Get-AzRecoveryServicesAsrProtectionContainerMapping -Name $mappingName -ProtectionContainer $pc

#network mapping
$job = New-AzRecoveryServicesAsrNetworkMapping -AzureToAzure -Name $primaryNetMapping -PrimaryFabric $pf -PrimaryAzureNetworkId $PrimaryAzureNetworkId -RecoveryFabric $rf -RecoveryAzureNetworkId $RecoveryAzureNetworkId
WaitForJobCompletion -JobId $job.Name

#Reverse Conatiner mapping
$job = New-AzRecoveryServicesAsrProtectionContainerMapping -Name $recMappingName -Policy $policy -PrimaryProtectionContainer $rc -RecoveryProtectionContainer $pc
WaitForJobCompletion -JobId $job.Name
$revMapping = Get-AzRecoveryServicesAsrProtectionContainerMapping -Name $recMappingName -ProtectionContainer $rc

#Reverse network mapping
$job = New-AzRecoveryServicesAsrNetworkMapping -AzureToAzure -Name $recoveryNetMapping -PrimaryFabric $rf -PrimaryAzureNetworkId $RecoveryAzureNetworkId -RecoveryFabric $pf -RecoveryAzureNetworkId $PrimaryAzureNetworkId
WaitForJobCompletion -JobId $job.Name

#enable Replication
$v = New-AzRecoveryServicesAsrAzureToAzureDiskReplicationConfig -managed -LogStorageAccountId $logStg `
-DiskId $vhdid -RecoveryResourceGroupId $recRg -RecoveryReplicaDiskAccountType $RecoveryReplicaDiskAccountType `
-RecoveryTargetDiskAccountType $RecoveryTargetDiskAccountType
$enableDRjob = New-AzRecoveryServicesAsrReplicationProtectedItem -AzureToAzure -AzureVmId $vm.Id -Name $vmName -ProtectionContainerMapping $mapping -RecoveryResourceGroupId $recRg -AzureToAzureDiskReplicationConfiguration $v -RecoveryVirtualMachineScaleSetId $recVmss.Id
WaitForJobCompletion -JobId $enableDRjob.Name
WaitForIRCompletion -affectedObjectId $enableDRjob.TargetObjectId

#Validate vmss Set in replicated vm properties
$pe = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName
Assert-NotNull($pe.providerSpecificDetails.RecoveryVirtualMachineScaleSetId)

#Update Vmpropertie
$updateDRjob = Set-AzRecoveryServicesAsrReplicationProtectedItem -InputObject $pe -RecoveryVirtualMachineScaleSetId $recVmss1.Id
WaitForJobCompletion -JobId $updateDRjob.Name
$pe = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $pc -Name $vmName
Assert-NotNull($pe.providerSpecificDetails.RecoveryVirtualMachineScaleSetId)

#Failover
$failoverjob = Start-AzRecoveryServicesAsrUnPlannedFailoverJob -ReplicationProtectedItem $pe -Direction PrimaryToRecovery -PerformSourceSideAction
WaitForJobCompletion -JobId $failoverjob.Name
#Get recovery vm and verify
$recvm = get-azVm -ResourceGroupName $recRgName -Name $vmName
Assert-NotNull($recvm.virtualmachinescaleset.Id);

#Switch replication
$vm = get-azVm -ResourceGroupName $vmName -Name $vmName
$vhdid = $recvm.StorageProfile.OSDisk.ManagedDisk.Id
$v = New-AzRecoveryServicesAsrAzureToAzureDiskReplicationConfig -managed -LogStorageAccountId $recLogStg `
-DiskId $vhdid -RecoveryResourceGroupId $Rg -RecoveryReplicaDiskAccountType $RecoveryReplicaDiskAccountType `
-RecoveryTargetDiskAccountType $RecoveryTargetDiskAccountType
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(600 * 1000)
$Switchjob = Update-AzureRmRecoveryServicesAsrProtectionDirection -AzureToAzure -ProtectionContainerMapping $revMapping[0] -RecoveryResourceGroupId $Rg -ReplicationProtectedItem $pe -RecoveryVirtualMachineScaleSetId $vm.virtualmachinescaleset.Id -AzureToAzureDiskReplicationConfiguration $v
WaitForJobCompletion -JobId $Switchjob.Name

$pe = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $rc -Name $vmName
Assert-NotNull($pe.providerSpecificDetails.RecoveryVirtualMachineScaleSetId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,7 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details)
this.RecoveryFabricLocation = details.RecoveryFabricLocation;
this.RecoveryAvailabilitySet = details.RecoveryAvailabilitySet;
this.RecoveryProximityPlacementGroupId = details.RecoveryProximityPlacementGroupId;
this.RecoveryVirtualMachineScaleSetId = details.RecoveryVirtualMachineScaleSetId;
this.TestFailoverRecoveryFabricObjectId = details.TestFailoverRecoveryFabricObjectId;
this.MonitoringJobType = details.MonitoringJobType;
this.MonitoringPercentageCompletion = details.MonitoringPercentageCompletion;
Expand Down Expand Up @@ -1393,6 +1394,11 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details)
/// </summary>
public string RecoveryProximityPlacementGroupId { get; set; }

/// <summary>
/// Recovery virtual machine scale set Id.
/// </summary>
public string RecoveryVirtualMachineScaleSetId { get; set; }

/// <summary>
/// Synced configuration details of the virtual machine.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="6.2.2" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.3.1-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.SiteRecovery" Version="2.1.2-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.SiteRecovery" Version="2.1.3-preview" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ public class NewAzureRmRecoveryServicesAsrReplicationProtectedItem : SiteRecover
[ValidateNotNullOrEmpty]
public string RecoveryProximityPlacementGroupId { get; set; }

/// <summary>
/// Gets or sets the resource ID of virtual machine scale set to failover this virtual machine to.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzure, HelpMessage = "Specify the virtual machine scale set Id to be used by the failover Vm in target recovery region.")]
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzureWithoutDiskDetails, HelpMessage = "Specify the virtual machine scale set Id to be used by the failover Vm in target recovery region.")]
[ValidateNotNullOrEmpty]
public string RecoveryVirtualMachineScaleSetId { get; set; }

/// <summary>
/// Gets or sets ID of the AvailabilitySet to recover the machine to in the event of a failover.
/// </summary>
Expand Down Expand Up @@ -715,7 +723,8 @@ private void AzureToAzureReplication(EnableProtectionInput input)
RecoveryAzureNetworkId = this.RecoveryAzureNetworkId,
RecoverySubnetName = this.RecoveryAzureSubnetName,
RecoveryAvailabilityZone = this.RecoveryAvailabilityZone,
RecoveryProximityPlacementGroupId = this.RecoveryProximityPlacementGroupId
RecoveryProximityPlacementGroupId = this.RecoveryProximityPlacementGroupId,
RecoveryVirtualMachineScaleSetId = this.RecoveryVirtualMachineScaleSetId
};

if (!string.IsNullOrEmpty(this.ReplicationGroupName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ public class SetAzureRmRecoveryServicesAsrReplicationProtectedItem : SiteRecover
[Parameter]
public string RecoveryProximityPlacementGroupId { get; set; }

/// <summary>
/// Gets or sets the virtual machine scale set Id for replication protected item after failover.
/// </summary>
[Parameter]
public string RecoveryVirtualMachineScaleSetId { get; set; }

/// <summary>
/// Gets or sets the availability set for replication protected item after failover.
/// </summary>
Expand Down Expand Up @@ -285,6 +291,7 @@ public override void ExecuteSiteRecoveryCmdlet()
this.IsParameterBound(c => c.RecoveryAvailabilitySet) &&
this.IsParameterBound(c => c.RecoveryAvailabilityZone) &&
this.IsParameterBound(c => c.RecoveryProximityPlacementGroupId) &&
this.IsParameterBound(c => c.RecoveryVirtualMachineScaleSetId) &&
string.IsNullOrEmpty(this.RecoveryCloudServiceId) &&
string.IsNullOrEmpty(this.RecoveryResourceGroupId) &&
string.IsNullOrEmpty(this.LicenseType) &&
Expand Down Expand Up @@ -339,6 +346,7 @@ public override void ExecuteSiteRecoveryCmdlet()
var useManagedDisk = this.UseManagedDisk;
var availabilitySetId = this.RecoveryAvailabilitySet;
var proximityPlacementGroupId = this.RecoveryProximityPlacementGroupId;
var virtualMachineScaleSetId = this.RecoveryVirtualMachineScaleSetId;
var availabilityZone = this.RecoveryAvailabilityZone;
var primaryNic = this.PrimaryNic;
var diskIdToDiskEncryptionMap = this.DiskIdToDiskEncryptionSetMap;
Expand Down Expand Up @@ -540,6 +548,10 @@ public override void ExecuteSiteRecoveryCmdlet()
? this.RecoveryProximityPlacementGroupId
: providerSpecificDetails.RecoveryProximityPlacementGroupId;

virtualMachineScaleSetId = this.IsParameterBound(c => c.RecoveryVirtualMachineScaleSetId)
? this.RecoveryVirtualMachineScaleSetId
: providerSpecificDetails.RecoveryVirtualMachineScaleSetId;

if (!this.MyInvocation.BoundParameters.ContainsKey(
Utilities.GetMemberName(() => this.RecoveryCloudServiceId)))
{
Expand Down Expand Up @@ -607,6 +619,7 @@ public override void ExecuteSiteRecoveryCmdlet()
RecoveryCloudServiceId = this.RecoveryCloudServiceId,
RecoveryResourceGroupId = this.RecoveryResourceGroupId,
RecoveryProximityPlacementGroupId = this.RecoveryProximityPlacementGroupId,
RecoveryVirtualMachineScaleSetId = this.RecoveryVirtualMachineScaleSetId,
RecoveryBootDiagStorageAccountId = this.RecoveryBootDiagStorageAccountId,
ManagedDiskUpdateDetails = managedDiskUpdateDetails,
TfoAzureVMName = this.TfoAzureVMName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ public class UpdateAzureRmRecoveryServicesAsrProtection : SiteRecoveryCmdletBase
[ValidateNotNullOrEmpty]
public string RecoveryProximityPlacementGroupId { get; set; }

/// <summary>
/// Gets or sets virtual machine scale set Id for protected Vm.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzure)]
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzureWithMultipleStorageAccount)]
[ValidateNotNullOrEmpty]
public string RecoveryVirtualMachineScaleSetId { get; set; }

/// <summary>
/// Gets or sets BootDiagnosticStorageAccountId.
/// </summary>
Expand Down Expand Up @@ -592,7 +600,8 @@ private void A2ARPIReprotect()
RecoveryCloudServiceId = this.RecoveryCloudServiceId,
RecoveryAvailabilitySetId = this.RecoveryAvailabilitySetId,
RecoveryBootDiagStorageAccountId = this.RecoveryBootDiagStorageAccountId,
RecoveryProximityPlacementGroupId = this.RecoveryProximityPlacementGroupId
RecoveryProximityPlacementGroupId = this.RecoveryProximityPlacementGroupId,
RecoveryVirtualMachineScaleSetId = this.RecoveryVirtualMachineScaleSetId
};

// Fetch the latest Protected item objects
Expand Down
1 change: 1 addition & 0 deletions src/RecoveryServices/RecoveryServices/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Azure Site Recovery support for Virtual Machine Scale Set for Azure to Azure provider.

## Version 3.5.0
* Added Cross Zonal Restore for managed virtual machines.
Expand Down
Loading