Skip to content
Draft
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 @@ -37,5 +37,12 @@ public void TestAvailabilitySetVM()
{
TestRunner.RunTestScript("Test-AvailabilitySetVM");
}

[Fact]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
public void TestAvailabilitySetMigration()
{
TestRunner.RunTestScript("Test-AvailabilitySetMigration");
}
}
}
47 changes: 47 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/AvailabilitySetTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,50 @@ function Test-AvailabilitySetVM
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Test Availability Set Migration to VMSS Flex
Note: This test requires the subscription to be enabled for the feature flag Microsoft.Compute/MigrateToVmssFlex
#>
function Test-AvailabilitySetMigration
{
# Setup
$rgname = Get-ComputeTestResourceName

try
{
# Common
$loc = Get-ComputeVMLocation;
New-AzResourceGroup -Name $rgname -Location $loc -Force;

# Create Availability Set
$asetName = 'aset' + $rgname;
New-AzAvailabilitySet -ResourceGroupName $rgname -Name $asetName -Location $loc -Sku 'Aligned' -PlatformFaultDomainCount 2 -PlatformUpdateDomainCount 5;
$aset = Get-AzAvailabilitySet -ResourceGroupName $rgname -Name $asetName;
Assert-NotNull $aset;

# Create a Flexible VMSS for migration target
$vmssName = 'vmss' + $rgname;
$vmssConfig = New-AzVmssConfig -Location $loc -OrchestrationMode 'Flexible' -PlatformFaultDomainCount 2;
$vmss = New-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName -VirtualMachineScaleSet $vmssConfig;
Assert-NotNull $vmss;
$vmssId = $vmss.Id;

# Test Validate Migration cmdlet
$validateResult = Test-AzAvailabilitySetMigration -ResourceGroupName $rgname -Name $asetName -VirtualMachineScaleSetFlexibleId $vmssId;
Assert-NotNull $validateResult;

# Test Convert cmdlet (creates a new VMSS)
$newVmssName = 'vmss2' + $rgname;
$convertResult = Convert-AzAvailabilitySet -ResourceGroupName $rgname -Name $asetName -VirtualMachineScaleSetName $newVmssName;
Assert-NotNull $convertResult;

Write-Host "Availability Set Migration cmdlets test completed successfully";
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// ----------------------------------------------------------------------------------
//
// 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;
using System.Management.Automation;
using Microsoft.Azure.Commands.Compute.Common;
using Microsoft.Azure.Commands.Compute.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;

namespace Microsoft.Azure.Commands.Compute
{
[Cmdlet("Convert", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "AvailabilitySet", SupportsShouldProcess = true)]
[OutputType(typeof(PSComputeLongRunningOperation), typeof(PSAzureOperationResponse))]
public class ConvertAzureAvailabilitySetCommand : AvailabilitySetBaseCmdlet
{
[Parameter(
Mandatory = true,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource group name.")]
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Alias("AvailabilitySetName")]
[Parameter(
Mandatory = true,
Position = 1,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The availability set name.")]
[ResourceNameCompleter("Microsoft.Compute/availabilitySets", "ResourceGroupName")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(
Mandatory = true,
Position = 2,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The name of the Virtual Machine Scale Set to create.")]
[ValidateNotNullOrEmpty]
public string VirtualMachineScaleSetName { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Starts the operation and returns immediately, before the operation is completed. In order to determine if the operation has successfully been completed, use some other mechanism.")]
public SwitchParameter NoWait { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();

if (this.ShouldProcess(Name, "Convert Availability Set to Virtual Machine Scale Set"))
{
ExecuteClientAction(() =>
{
if (NoWait.IsPresent)
{
var op = this.AvailabilitySetClient.BeginConvertToVirtualMachineScaleSetWithHttpMessagesAsync(
this.ResourceGroupName,
this.Name,
this.VirtualMachineScaleSetName).GetAwaiter().GetResult();
var result = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op);
WriteObject(result);
}
else
{
var op = this.AvailabilitySetClient.ConvertToVirtualMachineScaleSetWithHttpMessagesAsync(
this.ResourceGroupName,
this.Name,
this.VirtualMachineScaleSetName).GetAwaiter().GetResult();
var result = ComputeAutoMapperProfile.Mapper.Map<PSComputeLongRunningOperation>(op);
result.StartTime = this.StartTime;
result.EndTime = DateTime.Now;
WriteObject(result);
}
});
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// ----------------------------------------------------------------------------------
//
// 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;
using System.Management.Automation;
using Microsoft.Azure.Commands.Compute.Common;
using Microsoft.Azure.Commands.Compute.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Compute.Models;

namespace Microsoft.Azure.Commands.Compute
{
[Cmdlet("Start", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "AvailabilitySetMigration", SupportsShouldProcess = true)]
[OutputType(typeof(PSComputeLongRunningOperation), typeof(PSAzureOperationResponse))]
public class StartAzureAvailabilitySetMigrationCommand : AvailabilitySetBaseCmdlet
{
[Parameter(
Mandatory = true,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource group name.")]
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Alias("AvailabilitySetName")]
[Parameter(
Mandatory = true,
Position = 1,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The availability set name.")]
[ResourceNameCompleter("Microsoft.Compute/availabilitySets", "ResourceGroupName")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(
Mandatory = true,
Position = 2,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource ID of the Flexible Virtual Machine Scale Set to migrate to.")]
[ValidateNotNullOrEmpty]
public string VirtualMachineScaleSetFlexibleId { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();

if (this.ShouldProcess(Name, "Start Availability Set Migration to Virtual Machine Scale Set"))
{
ExecuteClientAction(() =>
{
var vmssReference = new SubResource(this.VirtualMachineScaleSetFlexibleId);

var op = this.AvailabilitySetClient.StartMigrationToVirtualMachineScaleSetWithHttpMessagesAsync(
this.ResourceGroupName,
this.Name,
vmssReference).GetAwaiter().GetResult();
var result = ComputeAutoMapperProfile.Mapper.Map<PSComputeLongRunningOperation>(op);
result.StartTime = this.StartTime;
result.EndTime = DateTime.Now;
WriteObject(result);
});
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// ----------------------------------------------------------------------------------
//
// 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;
using System.Management.Automation;
using Microsoft.Azure.Commands.Compute.Common;
using Microsoft.Azure.Commands.Compute.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;

namespace Microsoft.Azure.Commands.Compute
{
[Cmdlet("Stop", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "AvailabilitySetMigration", SupportsShouldProcess = true)]
[OutputType(typeof(PSComputeLongRunningOperation), typeof(PSAzureOperationResponse))]
public class StopAzureAvailabilitySetMigrationCommand : AvailabilitySetBaseCmdlet
{
[Parameter(
Mandatory = true,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource group name.")]
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Alias("AvailabilitySetName")]
[Parameter(
Mandatory = true,
Position = 1,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The availability set name.")]
[ResourceNameCompleter("Microsoft.Compute/availabilitySets", "ResourceGroupName")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();

if (this.ShouldProcess(Name, "Cancel Availability Set Migration"))
{
ExecuteClientAction(() =>
{
var op = this.AvailabilitySetClient.CancelMigrationToVirtualMachineScaleSetWithHttpMessagesAsync(
this.ResourceGroupName,
this.Name).GetAwaiter().GetResult();
var result = ComputeAutoMapperProfile.Mapper.Map<PSComputeLongRunningOperation>(op);
result.StartTime = this.StartTime;
result.EndTime = DateTime.Now;
WriteObject(result);
});
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// ----------------------------------------------------------------------------------
//
// 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;
using System.Management.Automation;
using Microsoft.Azure.Commands.Compute.Common;
using Microsoft.Azure.Commands.Compute.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Compute.Models;

namespace Microsoft.Azure.Commands.Compute
{
[Cmdlet("Test", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "AvailabilitySetMigration", SupportsShouldProcess = true)]
[OutputType(typeof(PSComputeLongRunningOperation), typeof(PSAzureOperationResponse))]
public class TestAzureAvailabilitySetMigrationCommand : AvailabilitySetBaseCmdlet
{
[Parameter(
Mandatory = true,
Position = 0,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource group name.")]
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
public string ResourceGroupName { get; set; }

[Alias("AvailabilitySetName")]
[Parameter(
Mandatory = true,
Position = 1,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The availability set name.")]
[ResourceNameCompleter("Microsoft.Compute/availabilitySets", "ResourceGroupName")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(
Mandatory = true,
Position = 2,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource ID of the Flexible Virtual Machine Scale Set to validate migration to.")]
[ValidateNotNullOrEmpty]
public string VirtualMachineScaleSetFlexibleId { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();

if (this.ShouldProcess(Name, "Validate Availability Set Migration to Virtual Machine Scale Set"))
{
ExecuteClientAction(() =>
{
var vmssReference = new SubResource(this.VirtualMachineScaleSetFlexibleId);

var op = this.AvailabilitySetClient.ValidateMigrationToVirtualMachineScaleSetWithHttpMessagesAsync(
this.ResourceGroupName,
this.Name,
vmssReference).GetAwaiter().GetResult();
var result = ComputeAutoMapperProfile.Mapper.Map<PSComputeLongRunningOperation>(op);
result.StartTime = this.StartTime;
result.EndTime = DateTime.Now;
WriteObject(result);
});
}
}
}
}
Loading