Skip to content

[Compute] Update VMSS VM feature #6170

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 3 commits into from
May 24, 2018
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
3 changes: 2 additions & 1 deletion src/ResourceManager/Compute/AzureRM.Compute.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ CmdletsToExport = 'Remove-AzureRmAvailabilitySet', 'Get-AzureRmAvailabilitySet',
'Get-AzureRmVmssDiskEncryption', 'Get-AzureRmVmssVMDiskEncryption',
'Export-AzureRmLogAnalyticRequestRateByInterval',
'Export-AzureRmLogAnalyticThrottledRequests',
'Repair-AzureRmVmssServiceFabricUpdateDomain'
'Repair-AzureRmVmssServiceFabricUpdateDomain',
'New-AzureRmVMDataDisk', 'Update-AzureRmVmssVM'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
3 changes: 3 additions & 0 deletions src/ResourceManager/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
- Additional information about change #1
-->
## Current Release
* VMSS VM Update feature
- Added `Update-AzureRmVmssVM` and `New-AzureRmVMDataDisk` cmdlets
- Add VirtualMachineScaleSetVM parameter to `Add-AzureRmVMDataDisk` cmdlet to support adding a data disk to Vmss VM.

## Version 5.0.0
* `New-AzureRmVm` and `New-AzureRmVmss` support verbose output of parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ function Test-VirtualMachineProfile
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 1 -VhdUri $dataDiskVhdUri2 -CreateOption Empty;

# Managed data disk setting
$managedDataDiskId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rggroup/providers/Microsoft.Compute/disks/dataDisk";
$managedDataDiskId = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rggroup/providers/Microsoft.Compute/disks/testDataDisk3";
Assert-ThrowsContains `
{ Add-AzureRmVMDataDisk -VM $p -Name 'dataDisk' -Caching 'ReadOnly' -DiskSizeInGB $null -Lun 2 -CreateOption Empty -ManagedDiskId $managedDataDiskId -StorageAccountType Standard_LRS; } `
"does not match with given managed disk ID";

$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk3' -Caching 'ReadOnly' -DiskSizeInGB $null -Lun 2 -CreateOption Empty -ManagedDiskId $managedDataDiskId -StorageAccountType Standard_LRS;
Assert-AreEqual $managedDataDiskId $p.StorageProfile.DataDisks[2].ManagedDisk.Id;
Assert-AreEqual "Standard_LRS" $p.StorageProfile.DataDisks[2].ManagedDisk.StorageAccountType;
Expand All @@ -88,13 +92,13 @@ function Test-VirtualMachineProfile
Assert-AreEqual $p.StorageProfile.DataDisks[0].DiskSizeGB 10;
Assert-AreEqual $p.StorageProfile.DataDisks[0].Lun 0;
Assert-AreEqual $p.StorageProfile.DataDisks[0].Vhd.Uri $dataDiskVhdUri1;
Assert-AreEqual $false $p.StorageProfile.DataDisks[0].WriteAcceleratorEnabled;
Assert-Null $p.StorageProfile.DataDisks[0].WriteAcceleratorEnabled;

Assert-AreEqual $p.StorageProfile.DataDisks[1].Caching 'ReadOnly';
Assert-AreEqual $p.StorageProfile.DataDisks[1].DiskSizeGB 11;
Assert-AreEqual $p.StorageProfile.DataDisks[1].Lun 1;
Assert-AreEqual $p.StorageProfile.DataDisks[1].Vhd.Uri $dataDiskVhdUri2;
Assert-AreEqual $false $p.StorageProfile.DataDisks[1].WriteAcceleratorEnabled;
Assert-Null $p.StorageProfile.DataDisks[1].WriteAcceleratorEnabled;

# Remove all data disks
$p = $p | Remove-AzureRmVMDataDisk;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,12 @@ public void TestVirtualMachineScaleSetRedeploy()
{
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachineScaleSetRedeploy");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestVirtualMachineScaleSetVMUpdate()
{
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachineScaleSetVMUpdate");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1715,4 +1715,159 @@ function Test-VirtualMachineScaleSetRedeploy
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Test Virtual Machine Scale Set VM Update
#>
function Test-VirtualMachineScaleSetVMUpdate
{
# Setup
$rgname = Get-ComputeTestResourceName

try
{
# Common
$loc = Get-Location "Microsoft.Compute" "virtualMachines" "East US 2";
New-AzureRMResourceGroup -Name $rgname -Location $loc -Force;

# SRP
$stoname = 'sto' + $rgname;
$stotype = 'Standard_GRS';
New-AzureRMStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
$stoaccount = Get-AzureRMStorageAccount -ResourceGroupName $rgname -Name $stoname;

# NRP
$subnet = New-AzureRMVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
$vnet = New-AzureRMVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
$vnet = Get-AzureRMVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
$subnetId = $vnet.Subnets[0].Id;

# New VMSS Parameters
$vmssName = 'vmss' + $rgname;
$vmssType = 'Microsoft.Compute/virtualMachineScaleSets';

$adminUsername = 'Foo12';
$adminPassword = Get-PasswordForVM;

$imgRef = Get-DefaultCRPImage -loc $loc;

# Create VMSS with managed disk
$ipCfg = New-AzureRmVmssIPConfig -Name 'test' -SubnetId $subnetId;
$vmss = New-AzureRmVmssConfig -Location $loc -SkuCapacity 2 -SkuName 'Standard_A1_v2' -UpgradePolicyMode 'Automatic' `
| Add-AzureRmVmssNetworkInterfaceConfiguration -Name 'test' -Primary $true -IPConfiguration $ipCfg `
| Set-AzureRmVmssOSProfile -ComputerNamePrefix 'test' -AdminUsername $adminUsername -AdminPassword $adminPassword `
| Set-AzureRmVmssStorageProfile -OsDiskCreateOption 'FromImage' -OsDiskCaching 'None' `
-ImageReferenceOffer $imgRef.Offer -ImageReferenceSku $imgRef.Skus -ImageReferenceVersion $imgRef.Version `
-ImageReferencePublisher $imgRef.PublisherName;

$result = New-AzureRmVmss -ResourceGroupName $rgname -Name $vmssName -VirtualMachineScaleSet $vmss;

Assert-AreEqual $loc.ToLowerInvariant().Replace(" ", "") $result.Location;
Assert-AreEqual 2 $result.Sku.Capacity;
Assert-AreEqual 'Standard_A1_v2' $result.Sku.Name;
Assert-AreEqual 'Automatic' $result.UpgradePolicy.Mode;

# Validate Network Profile
Assert-AreEqual 'test' $result.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].Name;
Assert-AreEqual $true $result.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].Primary;
Assert-AreEqual $subnetId `
$result.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].Subnet.Id;

# Validate OS Profile
Assert-AreEqual 'test' $result.VirtualMachineProfile.OsProfile.ComputerNamePrefix;
Assert-AreEqual $adminUsername $result.VirtualMachineProfile.OsProfile.AdminUsername;
Assert-Null $result.VirtualMachineProfile.OsProfile.AdminPassword;

# Validate Storage Profile
Assert-AreEqual 'FromImage' $result.VirtualMachineProfile.StorageProfile.OsDisk.CreateOption;
Assert-AreEqual 'None' $result.VirtualMachineProfile.StorageProfile.OsDisk.Caching;
Assert-AreEqual $imgRef.Offer $result.VirtualMachineProfile.StorageProfile.ImageReference.Offer;
Assert-AreEqual $imgRef.Skus $result.VirtualMachineProfile.StorageProfile.ImageReference.Sku;
Assert-AreEqual $imgRef.Version $result.VirtualMachineProfile.StorageProfile.ImageReference.Version;
Assert-AreEqual $imgRef.PublisherName $result.VirtualMachineProfile.StorageProfile.ImageReference.Publisher;

$vmss = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
$vmssVMs = Get-AzureRmVmssVM -ResourceGroupName $rgname -VMScaleSetName $vmssName;

# Add a data disk to VMSS VM using VMSS VM object (with piping)
$diskname0 = 'datadisk0';
New-AzureRmDiskConfig -Location $loc -DiskSizeGB 5 -AccountType Standard_LRS -OsType Windows -CreateOption Empty `
| New-AzureRmDisk -ResourceGroupName $rgname -DiskName $diskname0;
$disk0 = Get-AzureRmDisk -ResourceGroupName $rgname -DiskName $diskname0;

$result = $vmssVMs[0] `
| Add-AzureRmVmDataDisk -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 1 -CreateOption Attach -StorageAccountType Standard_LRS -ManagedDiskId $disk0.Id `
| Update-AzureRmVmssVM;

$vmss = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
$vmssVMs = Get-AzureRmVmssVM -ResourceGroupName $rgname -VMScaleSetName $vmssName;
Assert-AreEqual 1 $vmssVMs[0].StorageProfile.DataDisks[0].Lun;
Assert-AreEqual $diskname0 $vmssVMs[0].StorageProfile.DataDisks[0].Name;
Assert-AreEqual 10 $vmssVMs[0].StorageProfile.DataDisks[0].DiskSizeGB;
Assert-AreEqual "Attach" $vmssVMs[0].StorageProfile.DataDisks[0].CreateOption;
Assert-AreEqual "Standard_LRS" $vmssVMs[0].StorageProfile.DataDisks[0].ManagedDisk.StorageAccountType;
Assert-AreEqual $disk0.Id $vmssVMs[0].StorageProfile.DataDisks[0].ManagedDisk.Id;

# Adding a data disk to a VMSS VM using resource group name, VMSS name and instance ID..
$instance_id = $vmssVMs[0].InstanceId;
$diskname1 = 'datadisk1';
New-AzureRmDiskConfig -Location $loc -DiskSizeGB 5 -AccountType Standard_LRS -OsType Windows -CreateOption Empty `
| New-AzureRmDisk -ResourceGroupName $rgname -DiskName $diskname1;
$disk1 = Get-AzureRmDisk -ResourceGroupName $rgname -DiskName $diskname1;

$diskname2 = 'datadisk2';
New-AzureRmDiskConfig -Location $loc -DiskSizeGB 5 -AccountType Standard_LRS -OsType Windows -CreateOption Empty `
| New-AzureRmDisk -ResourceGroupName $rgname -DiskName $diskname2;
$disk2 = Get-AzureRmDisk -ResourceGroupName $rgname -DiskName $diskname2;

Assert-ThrowsContains { New-AzureRmVMDataDisk -Name 'wrongdiskname' -Caching 'ReadOnly' -Lun 2 -CreateOption Attach -StorageAccountType Standard_LRS -ManagedDiskId $disk1.Id; } `
"does not match with given managed disk ID";

$datadisk1 = New-AzureRmVMDataDisk -Caching 'ReadOnly' -Lun 2 -CreateOption Attach -StorageAccountType Standard_LRS -ManagedDiskId $disk1.Id;
$datadisk2 = New-AzureRmVMDataDisk -Caching 'ReadOnly' -Lun 3 -CreateOption Attach -StorageAccountType Standard_LRS -ManagedDiskId $disk2.Id;
$result = Update-AzureRmVmssVM -ResourceGroupName $rgname -VMScaleSetName $vmssName -InstanceId $instance_id -DataDisk $datadisk1,$datadisk2

$vmss = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
$vmssVMs = Get-AzureRmVmssVM -ResourceGroupName $rgname -VMScaleSetName $vmssName;

Assert-AreEqual 2 $vmssVMs[0].StorageProfile.DataDisks[1].Lun;
Assert-AreEqual $diskname1 $vmssVMs[0].StorageProfile.DataDisks[1].Name;
Assert-AreEqual 5 $vmssVMs[0].StorageProfile.DataDisks[1].DiskSizeGB;
Assert-AreEqual "Attach" $vmssVMs[0].StorageProfile.DataDisks[1].CreateOption;
Assert-AreEqual "Standard_LRS" $vmssVMs[0].StorageProfile.DataDisks[1].ManagedDisk.StorageAccountType;
Assert-AreEqual $disk1.Id $vmssVMs[0].StorageProfile.DataDisks[1].ManagedDisk.Id;

Assert-AreEqual 3 $vmssVMs[0].StorageProfile.DataDisks[2].Lun;
Assert-AreEqual $diskname2 $vmssVMs[0].StorageProfile.DataDisks[2].Name;
Assert-AreEqual 5 $vmssVMs[0].StorageProfile.DataDisks[2].DiskSizeGB;
Assert-AreEqual "Attach" $vmssVMs[0].StorageProfile.DataDisks[2].CreateOption;
Assert-AreEqual "Standard_LRS" $vmssVMs[0].StorageProfile.DataDisks[2].ManagedDisk.StorageAccountType;
Assert-AreEqual $disk2.Id $vmssVMs[0].StorageProfile.DataDisks[2].ManagedDisk.Id;

# Adding a data disk to a VMSS VM using resource ID.
$resource_id = $vmssVMs[0].Id;
$diskname3 = 'datadisk3';
$diskconfig = New-AzureRmDiskConfig -Location $loc -DiskSizeGB 5 -AccountType Standard_LRS -OsType Windows -CreateOption Empty;
New-AzureRmDisk -ResourceGroupName $rgname -DiskName $diskname3 -Disk $diskconfig
$disk3 = Get-AzureRmDisk -ResourceGroupName $rgname -DiskName $diskname3;

$datadisk3 = New-AzureRmVMDataDisk -Caching 'ReadOnly' -Lun 4 -CreateOption Attach -StorageAccountType Standard_LRS -ManagedDiskId $disk3.Id;
$result = Update-AzureRmVmssVM -ResourceId $resource_id -DataDisk $datadisk3

$vmss = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
$vmssVMs = Get-AzureRmVmssVM -ResourceGroupName $rgname -VMScaleSetName $vmssName;
Assert-AreEqual 4 $vmssVMs[0].StorageProfile.DataDisks[3].Lun;
Assert-AreEqual $diskname3 $vmssVMs[0].StorageProfile.DataDisks[3].Name;
Assert-AreEqual 5 $vmssVMs[0].StorageProfile.DataDisks[3].DiskSizeGB;
Assert-AreEqual "Attach" $vmssVMs[0].StorageProfile.DataDisks[3].CreateOption;
Assert-AreEqual "Standard_LRS" $vmssVMs[0].StorageProfile.DataDisks[3].ManagedDisk.StorageAccountType;
Assert-AreEqual $disk3.Id $vmssVMs[0].StorageProfile.DataDisks[3].ManagedDisk.Id;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@
<Compile Include="VirtualMachine\VirtualMachineBaseCmdlet.cs" />
<Compile Include="Common\ConstantStringTypes.cs" />
<Compile Include="Models\PSVirtualMachine.cs" />
<Compile Include="Models\PSVirtualMachineDataDisk.cs" />
<Compile Include="VirtualMachine\Operation\NewAzureVMCommand.cs" />
<Compile Include="VirtualMachine\Action\StartAzureVMCommand.cs" />
<Compile Include="VirtualMachine\Action\StopAzureVMCommand.cs" />
Expand All @@ -334,6 +335,7 @@
</Compile>
<Compile Include="VirtualMachine\Config\SetAzureVMOperatingSystemCommand.cs" />
<Compile Include="VirtualMachine\Config\AddAzureVMDataDiskCommand.cs" />
<Compile Include="VirtualMachine\Config\NewAzureVMDataDiskCommand.cs" />
<Compile Include="VirtualMachine\Config\AddAzureVMNetworkInterfaceCommand.cs" />
<Compile Include="VirtualMachine\VirtualMachineCmdletHelper.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Globalization;
using System.Management.Automation;
using Microsoft.Azure.Commands.Compute.Common;
using Microsoft.Azure.Commands.ResourceManager.Common;
using System;

namespace Microsoft.Azure.Commands.Compute
{
Expand Down Expand Up @@ -68,6 +70,22 @@ protected void ExecuteClientAction(Action action)
throw new ComputeCloudException(ex);
}
}

protected void ThrowInvalidArgumentError(string errorMessage, string arg)
{
ThrowTerminatingError
(new ErrorRecord(
new ArgumentException(string.Format(CultureInfo.InvariantCulture,
errorMessage, arg)),
"InvalidArgument",
ErrorCategory.InvalidArgument,
null));
}

protected string GetDiskNameFromId(string Id)
{
return Id.Substring(Id.LastIndexOf('/') + 1);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace Microsoft.Azure.Commands.Compute.Common
public static class HelpMessages
{
public const string VMProfile = "The virtual machine profile.";
public const string VmssVMProfile = "The virtual machine scale set VM profile.";
public const string VMSize = "The virtual machine size.";
public const string VMComputerName = "The virtual machine's omputer name.";
public const string VMCredential = "The virtual machine's credential.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,5 @@ protected string GetVolumeType(string VolumeType, VirtualMachineScaleSetStorageP
return VolumeType;
}
}

protected void ThrowInvalidArgumentError(string errorMessage, string arg)
{
ThrowTerminatingError
(new ErrorRecord(
new ArgumentException(string.Format(CultureInfo.InvariantCulture,
errorMessage, arg)),
"InvalidArgument",
ErrorCategory.InvalidArgument,
null));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//
//
// Copyright (c) Microsoft and contributors. All rights reserved.
//
//
// 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.
//
//

// Warning: This code was generated by a tool.
//
//
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//
//
// Copyright (c) Microsoft and contributors. All rights reserved.
//
//
// 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.
//
//

// Warning: This code was generated by a tool.
//
//
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//
//
// Copyright (c) Microsoft and contributors. All rights reserved.
//
//
// 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.
//
//

// Warning: This code was generated by a tool.
//
//
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.

Expand Down
Loading