Skip to content

Commit

Permalink
Merge pull request Azure#3865 from MSSedusch/preview
Browse files Browse the repository at this point in the history
Set-AzureRMVMAEMExtension - Improve support for Managed Disks
  • Loading branch information
markcowl authored May 3, 2017
2 parents 9d3498a + 4a6fde2 commit 938bfe9
Show file tree
Hide file tree
Showing 9 changed files with 7,775 additions and 1,096 deletions.
1 change: 1 addition & 0 deletions src/ResourceManager/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->
## Current Release

* Updated Set-AzureRmVMAEMExtension and Test-AzureRmVMAEMExtension cmdlets to support Premium managed disks
* Backup encryption settings for IaaS VMs and restore on failure
* ChefServiceInterval option is renamed to ChefDaemonInterval now. Old one will continue to work however.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,11 @@ public void TestAEMExtensionAdvancedWindowsMD()
{
ComputeTestController.NewInstance.RunPsTest("Test-AEMExtensionAdvancedWindowsMD");
}

[Fact]
public void TestAEMExtensionAdvancedLinuxMD()
{
ComputeTestController.NewInstance.RunPsTest("Test-AEMExtensionAdvancedLinuxMD");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,31 +250,31 @@ function Test-AEMExtensionAdvancedWindowsMD

try
{
Write-Verbose "Start the test Test-AEMExtensionAdvancedWindows"
Write-Verbose "Start the test Test-AEMExtensionAdvancedWindowsMD"
# Setup
$vm = Create-AdvancedVM -rgname $rgname -loc $loc -vmsize 'Standard_DS2' -stotype 'Premium_LRS' -nicCount 2 -useMD
$vmname = $vm.Name
Write-Verbose "Test-AEMExtensionAdvancedWindows: VM created"
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: VM created"

# Get with not extension
Write-Verbose "Test-AEMExtensionAdvancedWindows: Get with no extension"
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Get with no extension"
$extension = Get-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
Assert-Null $extension

# Test with not extension
Write-Verbose "Test-AEMExtensionAdvancedWindows: Test with no extension"
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Test with no extension"
$res = Test-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname -SkipStorageCheck
Assert-False { $res.Result }
Write-Verbose "Test-AEMExtensionAdvancedWindows: Test done"
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Test done"

$stoname = 'sto' + $rgname + "2";
New-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type 'Standard_LRS';

# Set and Get command.
Write-Verbose "Test-AEMExtensionAdvancedWindows: Set with no extension"
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Set with no extension"
Set-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname -WADStorageAccountName $stoname -SkipStorage
Write-Verbose "Test-AEMExtensionAdvancedWindows: Set done"
Write-Verbose "Test-AEMExtensionAdvancedWindows: Get with extension"
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Set done"
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Get with extension"
$extension = Get-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname


Expand All @@ -284,24 +284,95 @@ function Test-AEMExtensionAdvancedWindowsMD
Assert-AreEqual $extension.Name 'AzureCATExtensionHandler'
$settings = $extension.PublicSettings | ConvertFrom-Json
Assert-NotNull $settings.cfg
Write-Verbose "Test-AEMExtensionAdvancedWindows: Get done"
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Get done"

# Test command.
Write-Verbose "Test-AEMExtensionAdvancedWindows: Test with extension"
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Test with extension"
$res = Test-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname -SkipStorageCheck
Assert-True { $res.Result }
Assert-True { ($res.PartialResults.Count -gt 0) }
Write-Verbose "Test-AEMExtensionAdvancedWindows: Test done"
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Test done"

# Remove command.
Write-Verbose "Test-AEMExtensionAdvancedWindows: Remove with extension"
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Remove with extension"
Remove-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
Write-Verbose "Test-AEMExtensionAdvancedWindows: Remove done"
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Remove done"

Write-Verbose "Test-AEMExtensionAdvancedWindows: Get after remove"
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Get after remove"
$extension = Get-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
Assert-Null $extension
Write-Verbose "Test-AEMExtensionAdvancedWindows: Get after remove done"
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Get after remove done"
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

function Test-AEMExtensionAdvancedLinuxMD
{
$rgname = Get-ComputeTestResourceName
$loc = Get-ComputeVMLocation

try
{
Write-Host "Start the test Test-AEMExtensionAdvancedLinuxMD"
# Setup
$vm = Create-AdvancedVM -rgname $rgname -loc $loc -vmsize 'Standard_DS2' -stotype 'Premium_LRS' -nicCount 2 -useMD -linux
$vmname = $vm.Name
$vm = Get-AzureRmVM -ResourceGroupName $rgname -Name $vmname
Add-AzureRmVMDataDisk -VM $vm -StorageAccountType StandardLRS -Lun (($vm.StorageProfile.DataDisks | select -ExpandProperty Lun | Measure-Object -Maximum).Maximum + 1) -CreateOption Empty -DiskSizeInGB 10 | Update-AzureRmVM


Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: VM created"

# Get with not extension
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Get with no extension"
$extension = Get-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
Assert-Null $extension

# Test with not extension
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Test with no extension"
$res = Test-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname -SkipStorageCheck
Assert-False { $res.Result }
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Test done"

$stoname = 'sto' + $rgname + "2";
New-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type 'Standard_LRS';

# Set and Get command.
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Set with no extension"
Set-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname -WADStorageAccountName $stoname -SkipStorage
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Set done"
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Get with extension"
$extension = Get-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname


Assert-NotNull $extension
Assert-AreEqual $extension.Publisher 'Microsoft.OSTCExtensions'
Assert-AreEqual $extension.ExtensionType 'AzureEnhancedMonitorForLinux'
Assert-AreEqual $extension.Name 'AzureEnhancedMonitorForLinux'
$settings = $extension.PublicSettings | ConvertFrom-Json
Assert-NotNull $settings.cfg
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Get done"

# Test command.
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Test with extension"
$res = Test-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname -SkipStorageCheck
Assert-True { $res.Result }
Assert-True { ($res.PartialResults.Count -gt 0) }
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Test done"

# Remove command.
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Remove with extension"
Remove-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Remove done"

Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Get after remove"
$extension = Get-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
Assert-Null $extension
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Get after remove done"
}
finally
{
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static class AEMExtensionConstants

public const string DISK_TYPE_STANDARD = "Standard";
public const string DISK_TYPE_PREMIUM = "Premium";
public const string DISK_TYPE_PREMIUM_MD = "PremiumMD";
public const string WadTableName = "WADPerformanceCountersTable";
public const string AzureEndpoint = "core.windows.net";
public const int ContentAgeInMinutes = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,30 @@ internal string GetResourceGroupFromId(string id)
return result.Groups[2].Value;
}

internal string GetResourceNameFromId(string id)
{
var matcher = new Regex("/subscriptions/([^/]+)/resourceGroups/([^/]+)/providers/([^/]+)/([^/]+)/([^/]+)(/\\w+)?");
var result = matcher.Match(id);
if (!result.Success || result.Groups == null || result.Groups.Count < 3)
{
throw new InvalidOperationException(string.Format("Cannot find resource group name and storage account name from resource identity {0}", id));
}

return result.Groups[5].Value;
}

internal bool IsPremiumStorageAccount(string accountName)
{
return IsPremiumStorageAccount(this.GetStorageAccountFromCache(accountName));
}

internal int? GetDiskSizeGbFromBlobUri(string sBlobUri)
{
if (String.IsNullOrEmpty(sBlobUri))
{
return null;
}

var blobMatch = Regex.Match(sBlobUri, "https?://(\\S*?)\\..*?/(.*)");
if (!blobMatch.Success)
{
Expand Down Expand Up @@ -321,7 +338,7 @@ internal bool IsPremiumStorageAccount(StorageAccount account)
{
if (account.AccountType.HasValue)
{
return (account.AccountType.Value.ToString().StartsWith("Premium"));
return (account.AccountType.Value == AccountType.PremiumLRS);
}

WriteError("No AccountType for storage account {0} found", account.Name);
Expand All @@ -330,19 +347,19 @@ internal bool IsPremiumStorageAccount(StorageAccount account)

internal AzureSLA GetDiskSLA(OSDisk osdisk)
{
return this.GetDiskSLA(osdisk.DiskSizeGB, osdisk.Vhd.Uri);
return this.GetDiskSLA(osdisk.DiskSizeGB, osdisk.Vhd);
}

internal AzureSLA GetDiskSLA(DataDisk datadisk)
{
return this.GetDiskSLA(datadisk.DiskSizeGB, datadisk.Vhd.Uri);
return this.GetDiskSLA(datadisk.DiskSizeGB, datadisk.Vhd);
}

internal AzureSLA GetDiskSLA(int? diskSize, string vhdUri)
internal AzureSLA GetDiskSLA(int? diskSize, VirtualHardDisk vhd)
{
if (!diskSize.HasValue)
if (!diskSize.HasValue && vhd != null)
{
diskSize = this.GetDiskSizeGbFromBlobUri(vhdUri);
diskSize = this.GetDiskSizeGbFromBlobUri(vhd.Uri);
}
if (!diskSize.HasValue)
{
Expand All @@ -363,7 +380,7 @@ internal AzureSLA GetDiskSLA(int? diskSize, string vhdUri)
sla.IOPS = 2300;
sla.TP = 150;
}
else if (diskSize > 0 && diskSize < 1025)
else if (diskSize > 0 && diskSize < 1024)
{
// P30
sla.IOPS = 5000;
Expand Down Expand Up @@ -812,4 +829,4 @@ internal bool CheckDiagnosticsTable(string storageAccountName, string resId, str
return tableExists;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,20 @@ public override void ExecuteCmdlet()
}
else
{
this._Helper.WriteWarning("[WARN] Managed Disks are not yet supported. Extension will be installed but no disk metrics will be available.");
var osDiskMD = ComputeClient.ComputeManagementClient.Disks.Get(this._Helper.GetResourceGroupFromId(osdisk.ManagedDisk.Id),
this._Helper.GetResourceNameFromId(osdisk.ManagedDisk.Id));
if (osDiskMD.AccountType == StorageAccountTypes.PremiumLRS)
{
WriteVerbose("OS Disk Storage Account is a premium account - adding SLAs for OS disk");
var sla = this._Helper.GetDiskSLA(osDiskMD.DiskSizeGB, null);
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.type", Value = AEMExtensionConstants.DISK_TYPE_PREMIUM_MD });
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.sla.throughput", Value = sla.TP });
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.sla.iops", Value = sla.IOPS });
}
else
{
this._Helper.WriteWarning("[WARN] Standard Managed Disks are not supported. Extension will be installed but no disk metrics will be available.");
}
}

// Get Storage accounts from disks
Expand All @@ -218,7 +231,23 @@ public override void ExecuteCmdlet()
{
if (disk.ManagedDisk != null)
{
this._Helper.WriteWarning("[WARN] Managed Disks are not yet supported. Extension will be installed but no disk metrics will be available.");
var diskMD = ComputeClient.ComputeManagementClient.Disks.Get(this._Helper.GetResourceGroupFromId(disk.ManagedDisk.Id),
this._Helper.GetResourceNameFromId(disk.ManagedDisk.Id));

if (diskMD.AccountType == StorageAccountTypes.PremiumLRS)
{
this._Helper.WriteVerbose("Data Disk {0} is a Premium Managed Disk - adding SLAs for disk", diskNumber.ToString());
var sla = this._Helper.GetDiskSLA(diskMD.DiskSizeGB, null);
sapmonPublicConfig.Add(new KeyValuePair() { Key = "disk.type." + diskNumber, Value = AEMExtensionConstants.DISK_TYPE_PREMIUM_MD });
sapmonPublicConfig.Add(new KeyValuePair() { Key = "disk.sla.throughput." + diskNumber, Value = sla.TP });
sapmonPublicConfig.Add(new KeyValuePair() { Key = "disk.sla.iops." + diskNumber, Value = sla.IOPS });
this._Helper.WriteVerbose("Done - Data Disk {0} is a Premium Managed Disk - adding SLAs for disk", diskNumber.ToString());
}
else
{
this._Helper.WriteWarning("[WARN] Standard Managed Disks are not supported. Extension will be installed but no disk metrics will be available.");

}
continue;
}

Expand Down
Loading

0 comments on commit 938bfe9

Please sign in to comment.