Skip to content

Commit c29396f

Browse files
authored
Merge pull request #3584 from MSSedusch/dev
Set-AzureRMVMAEMExtension - Add initial support for Managed Disks
2 parents 777c28c + 30ed57f commit c29396f

File tree

6 files changed

+5902
-40
lines changed

6 files changed

+5902
-40
lines changed

src/ResourceManager/Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Updated Set-AzureRmVMAEMExtension and Test-AzureRmVMAEMExtension cmdlets to support managed disks
2122

2223
## Version 2.7.0
2324
* Updated Set-AzureRmVMDscExtension cmdlet WmfVersion parameter to support "5.1"

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AEMExtensionTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,11 @@ public void TestAEMExtensionAdvancedLinux()
7070
{
7171
ComputeTestController.NewInstance.RunPsTest("Test-AEMExtensionAdvancedLinux");
7272
}
73+
74+
[Fact]
75+
public void TestAEMExtensionAdvancedWindowsMD()
76+
{
77+
ComputeTestController.NewInstance.RunPsTest("Test-AEMExtensionAdvancedWindowsMD");
78+
}
7379
}
7480
}

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AEMExtensionTests.ps1

Lines changed: 97 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,73 @@ function Test-AEMExtensionAdvancedWindows
243243
}
244244
}
245245

246+
function Test-AEMExtensionAdvancedWindowsMD
247+
{
248+
$rgname = Get-ComputeTestResourceName
249+
$loc = Get-ComputeVMLocation
250+
251+
try
252+
{
253+
Write-Verbose "Start the test Test-AEMExtensionAdvancedWindows"
254+
# Setup
255+
$vm = Create-AdvancedVM -rgname $rgname -loc $loc -vmsize 'Standard_DS2' -stotype 'Premium_LRS' -nicCount 2 -useMD
256+
$vmname = $vm.Name
257+
Write-Verbose "Test-AEMExtensionAdvancedWindows: VM created"
258+
259+
# Get with not extension
260+
Write-Verbose "Test-AEMExtensionAdvancedWindows: Get with no extension"
261+
$extension = Get-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
262+
Assert-Null $extension
263+
264+
# Test with not extension
265+
Write-Verbose "Test-AEMExtensionAdvancedWindows: Test with no extension"
266+
$res = Test-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname -SkipStorageCheck
267+
Assert-False { $res.Result }
268+
Write-Verbose "Test-AEMExtensionAdvancedWindows: Test done"
269+
270+
$stoname = 'sto' + $rgname + "2";
271+
New-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type 'Standard_LRS';
272+
273+
# Set and Get command.
274+
Write-Verbose "Test-AEMExtensionAdvancedWindows: Set with no extension"
275+
Set-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname -WADStorageAccountName $stoname -SkipStorage
276+
Write-Verbose "Test-AEMExtensionAdvancedWindows: Set done"
277+
Write-Verbose "Test-AEMExtensionAdvancedWindows: Get with extension"
278+
$extension = Get-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
279+
280+
281+
Assert-NotNull $extension
282+
Assert-AreEqual $extension.Publisher 'Microsoft.AzureCAT.AzureEnhancedMonitoring'
283+
Assert-AreEqual $extension.ExtensionType 'AzureCATExtensionHandler'
284+
Assert-AreEqual $extension.Name 'AzureCATExtensionHandler'
285+
$settings = $extension.PublicSettings | ConvertFrom-Json
286+
Assert-NotNull $settings.cfg
287+
Write-Verbose "Test-AEMExtensionAdvancedWindows: Get done"
288+
289+
# Test command.
290+
Write-Verbose "Test-AEMExtensionAdvancedWindows: Test with extension"
291+
$res = Test-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname -SkipStorageCheck
292+
Assert-True { $res.Result }
293+
Assert-True { ($res.PartialResults.Count -gt 0) }
294+
Write-Verbose "Test-AEMExtensionAdvancedWindows: Test done"
295+
296+
# Remove command.
297+
Write-Verbose "Test-AEMExtensionAdvancedWindows: Remove with extension"
298+
Remove-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
299+
Write-Verbose "Test-AEMExtensionAdvancedWindows: Remove done"
300+
301+
Write-Verbose "Test-AEMExtensionAdvancedWindows: Get after remove"
302+
$extension = Get-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
303+
Assert-Null $extension
304+
Write-Verbose "Test-AEMExtensionAdvancedWindows: Get after remove done"
305+
}
306+
finally
307+
{
308+
# Cleanup
309+
Clean-ResourceGroup $rgname
310+
}
311+
}
312+
246313
function Test-AEMExtensionBasicLinuxWAD
247314
{
248315
$rgname = Get-ComputeTestResourceName
@@ -471,7 +538,7 @@ function Test-AEMExtensionAdvancedLinux
471538
}
472539
}
473540

474-
function Create-AdvancedVM($rgname, $vmname, $loc, $vmsize, $stotype, $nicCount, [Switch] $linux)
541+
function Create-AdvancedVM($rgname, $vmname, $loc, $vmsize, $stotype, $nicCount, [Switch] $linux, [Switch] $useMD)
475542
{
476543
# Initialize parameters
477544
$rgname = if ([string]::IsNullOrEmpty($rgname)) { Get-ComputeTestResourceName } else { $rgname }
@@ -528,25 +595,47 @@ function Create-AdvancedVM($rgname, $vmname, $loc, $vmsize, $stotype, $nicCount,
528595
$dataDiskVhdUri2 = "https://$stoname.blob.core.windows.net/test/data2.vhd";
529596
$dataDiskVhdUri3 = "https://$stoname.blob.core.windows.net/test/data3.vhd";
530597

531-
$p = Set-AzureRmVMOSDisk -VM $p -Name $osDiskName -VhdUri $osDiskVhdUri -Caching $osDiskCaching -CreateOption FromImage;
598+
$osURI = @{}
599+
$disk1Uri = @{}
600+
$disk2Uri = @{}
601+
$disk3Uri = @{}
602+
603+
if (-not $useMD)
604+
{
605+
$osURI = @{"VhdUri"=$osDiskVhdUri}
606+
$disk1Uri = @{"VhdUri"=$dataDiskVhdUri1}
607+
$disk2Uri = @{"VhdUri"=$dataDiskVhdUri2}
608+
$disk3Uri = @{"VhdUri"=$dataDiskVhdUri3}
609+
}
610+
611+
$p = Set-AzureRmVMOSDisk -VM $p -Name $osDiskName @osURI -Caching $osDiskCaching -CreateOption FromImage;
532612

533-
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 1 -VhdUri $dataDiskVhdUri1 -CreateOption Empty;
534-
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 2 -VhdUri $dataDiskVhdUri2 -CreateOption Empty;
535-
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk3' -Caching 'ReadOnly' -DiskSizeInGB 12 -Lun 3 -VhdUri $dataDiskVhdUri3 -CreateOption Empty;
613+
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 1 @disk1Uri -CreateOption Empty;
614+
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 2 @disk2Uri -CreateOption Empty;
615+
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk3' -Caching 'ReadOnly' -DiskSizeInGB 12 -Lun 3 @disk3Uri -CreateOption Empty;
536616
$p = Remove-AzureRmVMDataDisk -VM $p -Name 'testDataDisk3';
537617

538618
Assert-AreEqual $p.StorageProfile.OsDisk.Caching $osDiskCaching;
539619
Assert-AreEqual $p.StorageProfile.OsDisk.Name $osDiskName;
540-
Assert-AreEqual $p.StorageProfile.OsDisk.Vhd.Uri $osDiskVhdUri;
620+
if (-not $useMD)
621+
{
622+
Assert-AreEqual $p.StorageProfile.OsDisk.Vhd.Uri $osDiskVhdUri;
623+
}
541624
Assert-AreEqual $p.StorageProfile.DataDisks.Count 2;
542625
Assert-AreEqual $p.StorageProfile.DataDisks[0].Caching 'ReadOnly';
543626
Assert-AreEqual $p.StorageProfile.DataDisks[0].DiskSizeGB 10;
544627
Assert-AreEqual $p.StorageProfile.DataDisks[0].Lun 1;
545-
Assert-AreEqual $p.StorageProfile.DataDisks[0].Vhd.Uri $dataDiskVhdUri1;
628+
if (-not $useMD)
629+
{
630+
Assert-AreEqual $p.StorageProfile.DataDisks[0].Vhd.Uri $dataDiskVhdUri1;
631+
}
546632
Assert-AreEqual $p.StorageProfile.DataDisks[1].Caching 'ReadOnly';
547633
Assert-AreEqual $p.StorageProfile.DataDisks[1].DiskSizeGB 11;
548634
Assert-AreEqual $p.StorageProfile.DataDisks[1].Lun 2;
549-
Assert-AreEqual $p.StorageProfile.DataDisks[1].Vhd.Uri $dataDiskVhdUri2;
635+
if (-not $useMD)
636+
{
637+
Assert-AreEqual $p.StorageProfile.DataDisks[1].Vhd.Uri $dataDiskVhdUri2;
638+
}
550639

551640
# OS & Image
552641
$user = "Foo12";

src/ResourceManager/Compute/Commands.Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.AEMExtensionTests/TestAEMExtensionAdvancedWindowsMD.json

Lines changed: 5720 additions & 0 deletions
Large diffs are not rendered by default.

src/ResourceManager/Compute/Commands.Compute/Extension/AEM/SetAzureRmVMAEMExtension.cs

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -179,45 +179,58 @@ public override void ExecuteCmdlet()
179179

180180
// Get Disks
181181
var accounts = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
182-
var accountName = this._Helper.GetStorageAccountFromUri(osdisk.Vhd.Uri);
183-
var storageKey = this._Helper.GetAzureStorageKeyFromCache(accountName);
184-
accounts.Add(accountName, storageKey);
182+
if (osdisk.ManagedDisk == null)
183+
{
184+
var accountName = this._Helper.GetStorageAccountFromUri(osdisk.Vhd.Uri);
185+
var storageKey = this._Helper.GetAzureStorageKeyFromCache(accountName);
186+
accounts.Add(accountName, storageKey);
185187

186-
this._Helper.WriteHost("[INFO] Adding configuration for OS disk");
188+
this._Helper.WriteHost("[INFO] Adding configuration for OS disk");
187189

188-
var caching = osdisk.Caching;
189-
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.name", Value = this._Helper.GetDiskName(osdisk.Vhd.Uri) });
190-
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.caching", Value = caching });
191-
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.account", Value = accountName });
192-
if (this._Helper.IsPremiumStorageAccount(accountName))
193-
{
194-
WriteVerbose("OS Disk Storage Account is a premium account - adding SLAs for OS disk");
195-
var sla = this._Helper.GetDiskSLA(osdisk);
196-
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.type", Value = AEMExtensionConstants.DISK_TYPE_PREMIUM });
197-
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.sla.throughput", Value = sla.TP });
198-
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.sla.iops", Value = sla.IOPS });
190+
var caching = osdisk.Caching;
191+
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.name", Value = this._Helper.GetDiskName(osdisk.Vhd.Uri) });
192+
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.caching", Value = caching });
193+
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.account", Value = accountName });
194+
if (this._Helper.IsPremiumStorageAccount(accountName))
195+
{
196+
WriteVerbose("OS Disk Storage Account is a premium account - adding SLAs for OS disk");
197+
var sla = this._Helper.GetDiskSLA(osdisk);
198+
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.type", Value = AEMExtensionConstants.DISK_TYPE_PREMIUM });
199+
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.sla.throughput", Value = sla.TP });
200+
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.sla.iops", Value = sla.IOPS });
201+
}
202+
else
203+
{
204+
WriteVerbose("OS Disk Storage Account is a standard account");
205+
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.type", Value = AEMExtensionConstants.DISK_TYPE_STANDARD });
206+
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.connminute", Value = (accountName + ".minute") });
207+
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.connhour", Value = (accountName + ".hour") });
208+
}
199209
}
200210
else
201211
{
202-
WriteVerbose("OS Disk Storage Account is a standard account");
203-
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.type", Value = AEMExtensionConstants.DISK_TYPE_STANDARD });
204-
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.connminute", Value = (accountName + ".minute") });
205-
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.connhour", Value = (accountName + ".hour") });
212+
this._Helper.WriteWarning("[WARN] Managed Disks are not yet supported. Extension will be installed but no disk metrics will be available.");
206213
}
207214

208215
// Get Storage accounts from disks
209216
var diskNumber = 1;
210217
foreach (var disk in disks)
211218
{
212-
accountName = this._Helper.GetStorageAccountFromUri(disk.Vhd.Uri);
219+
if (disk.ManagedDisk != null)
220+
{
221+
this._Helper.WriteWarning("[WARN] Managed Disks are not yet supported. Extension will be installed but no disk metrics will be available.");
222+
continue;
223+
}
224+
225+
var accountName = this._Helper.GetStorageAccountFromUri(disk.Vhd.Uri);
213226
if (!accounts.ContainsKey(accountName))
214227
{
215-
storageKey = this._Helper.GetAzureStorageKeyFromCache(accountName);
228+
var storageKey = this._Helper.GetAzureStorageKeyFromCache(accountName);
216229
accounts.Add(accountName, storageKey);
217230
}
218231

219232
this._Helper.WriteHost("[INFO] Adding configuration for data disk {0}", disk.Name);
220-
caching = disk.Caching;
233+
var caching = disk.Caching;
221234
sapmonPublicConfig.Add(new KeyValuePair() { Key = "disk.lun." + diskNumber, Value = disk.Lun });
222235
sapmonPublicConfig.Add(new KeyValuePair() { Key = "disk.name." + diskNumber, Value = this._Helper.GetDiskName(disk.Vhd.Uri) });
223236
sapmonPublicConfig.Add(new KeyValuePair() { Key = "disk.caching." + diskNumber, Value = caching });

src/ResourceManager/Compute/Commands.Compute/Extension/AEM/TestAzureRmVMAEMExtension.cs

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Microsoft.Azure.Management.Compute;
2121
using Microsoft.Azure.Management.Compute.Models;
2222
using Microsoft.Azure.Management.Storage;
23+
using Microsoft.Azure.Management.Storage.Models;
2324
using Newtonsoft.Json;
2425
using Newtonsoft.Json.Linq;
2526
using System;
@@ -182,13 +183,27 @@ public override void ExecuteCmdlet()
182183
var accounts = new List<string>();
183184
//var osdisk = selectedVM.StorageProfile.OsDisk;
184185

186+
var osaccountName = String.Empty;
187+
if (osdisk.ManagedDisk == null)
188+
{
189+
var accountName = this._Helper.GetStorageAccountFromUri(osdisk.Vhd.Uri);
190+
osaccountName = accountName;
191+
accounts.Add(accountName);
192+
}
193+
else
194+
{
195+
this._Helper.WriteWarning("[WARN] Managed Disks are not yet supported. Extension will be installed but no disk metrics will be available.");
196+
}
197+
185198
var dataDisks = selectedVM.StorageProfile.DataDisks;
186-
var accountName = this._Helper.GetStorageAccountFromUri(osdisk.Vhd.Uri);
187-
var osaccountName = accountName;
188-
accounts.Add(accountName);
189199
foreach (var disk in dataDisks)
190200
{
191-
accountName = this._Helper.GetStorageAccountFromUri(disk.Vhd.Uri);
201+
if (disk.ManagedDisk != null)
202+
{
203+
this._Helper.WriteWarning("[WARN] Managed Disks are not yet supported. Extension will be installed but no disk metrics will be available.");
204+
continue;
205+
}
206+
var accountName = this._Helper.GetStorageAccountFromUri(disk.Vhd.Uri);
192207
if (!accounts.Contains(accountName))
193208
{
194209
accounts.Add(accountName);
@@ -277,8 +292,13 @@ public override void ExecuteCmdlet()
277292

278293
sapmonPublicConfig = JsonConvert.DeserializeObject(monPublicConfig) as JObject;
279294

280-
var storage = this._Helper.GetStorageAccountFromCache(osaccountName);
281-
var osaccountIsPremium = this._Helper.IsPremiumStorageAccount(osaccountName);
295+
StorageAccount storage = null;
296+
var osaccountIsPremium = false;
297+
if (!String.IsNullOrEmpty(osaccountName))
298+
{
299+
storage = this._Helper.GetStorageAccountFromCache(osaccountName);
300+
osaccountIsPremium = this._Helper.IsPremiumStorageAccount(osaccountName);
301+
}
282302

283303
var vmSize = selectedVM.HardwareProfile.VmSize;
284304
this._Helper.CheckMonitoringProperty("Azure Enhanced Monitoring Extension for SAP public configuration check: VM Size", "vmsize", sapmonPublicConfig, vmSize, aemConfigResult);
@@ -315,7 +335,7 @@ public override void ExecuteCmdlet()
315335
this._Helper.WriteHost("NOT OK ", ConsoleColor.Red);
316336
}
317337

318-
if (!osaccountIsPremium)
338+
if (!osaccountIsPremium && storage != null)
319339
{
320340
var endpoint = this._Helper.GetAzureSAPTableEndpoint(storage);
321341
var minuteUri = endpoint + "$MetricsMinutePrimaryTransactionsBlob";
@@ -327,22 +347,35 @@ public override void ExecuteCmdlet()
327347
this._Helper.CheckMonitoringProperty("Azure Enhanced Monitoring Extension for SAP public configuration check: VM OS Disk Type", "osdisk.type", sapmonPublicConfig, AEMExtensionConstants.DISK_TYPE_STANDARD, aemConfigResult);
328348

329349
}
330-
else
350+
else if (storage != null)
331351
{
332352
var sla = this._Helper.GetDiskSLA(osdisk);
333353

334354
this._Helper.CheckMonitoringProperty("Azure Enhanced Monitoring Extension for SAP public configuration check: VM OS Disk Type", "osdisk.type", sapmonPublicConfig, AEMExtensionConstants.DISK_TYPE_PREMIUM, aemConfigResult);
335355
this._Helper.CheckMonitoringProperty("Azure Enhanced Monitoring Extension for SAP public configuration check: VM OS Disk SLA IOPS", "osdisk.sla.throughput", sapmonPublicConfig, sla.TP, aemConfigResult);
336356
this._Helper.CheckMonitoringProperty("Azure Enhanced Monitoring Extension for SAP public configuration check: VM OS Disk SLA Throughput", "osdisk.sla.iops", sapmonPublicConfig, sla.IOPS, aemConfigResult);
337357

358+
} else
359+
{
360+
this._Helper.WriteWarning("[WARN] Managed Disks are not yet supported. Extension will be installed but no disk metrics will be available.");
361+
}
362+
363+
if (osdisk.ManagedDisk == null)
364+
{
365+
this._Helper.CheckMonitoringProperty("Azure Enhanced Monitoring Extension for SAP public configuration check: VM OS disk name", "osdisk.name", sapmonPublicConfig, this._Helper.GetDiskName(osdisk.Vhd.Uri), aemConfigResult);
338366
}
339-
this._Helper.CheckMonitoringProperty("Azure Enhanced Monitoring Extension for SAP public configuration check: VM OS disk name", "osdisk.name", sapmonPublicConfig, this._Helper.GetDiskName(osdisk.Vhd.Uri), aemConfigResult);
340367

341368

342369
var diskNumber = 1;
343370
foreach (var disk in dataDisks)
344371
{
345-
accountName = this._Helper.GetStorageAccountFromUri(disk.Vhd.Uri);
372+
if (disk.ManagedDisk != null)
373+
{
374+
this._Helper.WriteWarning("[WARN] Managed Disks are not yet supported. Extension will be installed but no disk metrics will be available.");
375+
continue;
376+
}
377+
378+
var accountName = this._Helper.GetStorageAccountFromUri(disk.Vhd.Uri);
346379
storage = this._Helper.GetStorageAccountFromCache(accountName);
347380
var accountIsPremium = this._Helper.IsPremiumStorageAccount(storage);
348381

0 commit comments

Comments
 (0)