Skip to content

Get-AzVMBootDiagnostics api change to use RetrieveBootDiagnosticsData() #13233

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 30 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3cab948
initial dev
Sandido Oct 15, 2020
5d5cf99
intermediate work
Sandido Oct 16, 2020
098ad0a
get-azvmbootdiagnosticsdata dev, testing (maybe) , and changelog. No …
Sandido Oct 26, 2020
815bce1
Merge branch 'master' into SandidoBootDiagDataAPI
Sandido Oct 26, 2020
74db1b3
test if removing file path and cmd in test removes CI failures
Sandido Oct 27, 2020
9e58e2a
Merge branch 'SandidoBootDiagDataAPI' of https://github.com/Azure/azu…
Sandido Oct 27, 2020
ee3bd37
updating to 12.7.0
Sandido Oct 27, 2020
3617ec2
adding test with local file path back in
Sandido Oct 27, 2020
a05341e
remove get cmd from test
Sandido Oct 27, 2020
71895f8
back to 12.6.0
Sandido Oct 27, 2020
f7df32e
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Sandido Oct 27, 2020
d87df8c
12.7.0-preview.1
Sandido Oct 29, 2020
d94a6df
Update Compute.csproj
Sandido Oct 29, 2020
706ef09
attempt 12.5.0
Sandido Oct 29, 2020
549dce9
12.7.0-preview
Sandido Oct 29, 2020
580ef1c
12.7.0-preview.1
Sandido Oct 29, 2020
5fdd422
added back in local file path test
Sandido Oct 30, 2020
de9e881
commented out boot
Sandido Nov 2, 2020
a74f174
to parity
Sandido Nov 2, 2020
4b876ad
Merge branch 'SandidoBootDiagDataAPI' of https://github.com/Azure/azu…
Sandido Nov 2, 2020
9c8f9cf
adding required assemblies
Sandido Nov 2, 2020
068a7f9
removed last test cmd recorded
Sandido Nov 2, 2020
9241848
Update Az.Compute.psd1
Sandido Nov 3, 2020
ca7afe2
try 12.6.0 with required assemblies.
Sandido Nov 3, 2020
fcfedbd
12.7.0-preview.1
Sandido Nov 3, 2020
ddebc1a
simplified to CloudBlob
Sandido Nov 5, 2020
5bc321c
removed unnecessary assmblies
Sandido Nov 5, 2020
bd15aea
test updates, LivOnly.
Sandido Nov 5, 2020
33ade74
fix linux
Sandido Nov 5, 2020
ee6bb60
windows serial log
Sandido Nov 6, 2020
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
7 changes: 7 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,5 +346,12 @@ public void TestVirtualMachineImageListTopOrderExpand()
{
TestRunner.RunTestScript("Test-VirtualMachineImageListTopOrderExpand");
}

[Fact]
[Trait(Category.AcceptanceType, Category.LiveOnly)]
public void TestVirtualMachineBootDiagnostics()
{
TestRunner.RunTestScript("Test-VirtualMachineBootDiagnostics");
}
}
}
66 changes: 66 additions & 0 deletions src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4412,3 +4412,69 @@ function Test-VirtualMachineImageListTopOrderExpand

}

<#
.SYNOPSIS
This test can only run in Record mode. SEveral lines need to be uncommented for it to test the cmdlet.
Downloads the managed boot diagnostics of a Windows machine to a local file path.
#>
function Test-VirtualMachineBootDiagnostics
{
# Setup
$rgname = Get-ComputeTestResourceName;
$loc = Get-ComputeVMLocation;

try
{
New-AzResourceGroup -Name $rgname -Location $loc -Force;

# VM Profile & Hardware
$vmsize = 'Standard_DS1_v2';
$vmname = 'vm' + $rgname;
# Create the file path on your machine, then set this variable to it.
# $localPath = "C:\Users\adsandor\Documents\bootDiags"

$p = New-AzVMConfig -VMName $vmname -VMSize $vmsize;

# NRP
$subnet = New-AzVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
$vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
$vnet = Get-AzVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
$subnetId = $vnet.Subnets[0].Id;
#1
$pubip = New-AzPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
$pubip = Get-AzPublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
$pubipId = $pubip.Id;
$nic = New-AzNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
$nic = Get-AzNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname;
$nicId = $nic.Id;

$p = Add-AzVMNetworkInterface -VM $p -Id $nicId;

# OS & Image
$user = "Foo2";
$password = $PLACEHOLDER;
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
$computerName = 'test';

# Windows OS test case.
$p = Set-AzVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred;

$imgRef = Get-DefaultCRPImage -loc $loc;
$p = ($imgRef | Set-AzVMSourceImage -VM $p);

# Virtual Machine
$vm = New-AzVM -ResourceGroupName $rgname -Location $loc -VM $p;
Assert-NotNull $vm;

# Get Managed Boot Diagnostics
# uncomment this when running locally.
# Get-AzVmBootDiagnosticsData -ResourceGroupName $rgname -Name $vmname -Windows -LocalPath $localPath;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Compute/Compute/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* New cmdlet `Get-AzDiskEncryptionSetAssociatedResource`
* Added `Tier` and `LogicalSectorSize` optional parameters to the New-AzDiskConfig cmdlet.
* Added `Tier`, `MaxSharesCount`, `DiskIOPSReadOnly`, and `DiskMBpsReadOnly` optional parameters to the `New-AzDiskUpdateConfig` cmdlet.
* Modified `Get-AzVmBootDiagnostics` cmdlet to use the new RetrieveBootDiagnosticsData API instead of directly accessing the BootDiagnostics properties on the virtual machine.

## Version 4.5.0
* Fixed issue in `Update-ASRRecoveryPlan` by populating FailoverTypes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
using Microsoft.Azure.Commands.Compute.Common;
using Microsoft.Azure.Commands.Compute.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Compute;
using Microsoft.Azure.Management.Storage.Version2017_10_01;
using Microsoft.WindowsAzure.Commands.Sync.Download;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Blob;


namespace Microsoft.Azure.Commands.Compute
{
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VMBootDiagnosticsData", DefaultParameterSetName = WindowsParamSet)]
Expand Down Expand Up @@ -107,7 +109,7 @@ public override void ExecuteCmdlet()
|| result.Body.DiagnosticsProfile.BootDiagnostics == null
|| result.Body.DiagnosticsProfile.BootDiagnostics.Enabled == null
|| !result.Body.DiagnosticsProfile.BootDiagnostics.Enabled.Value
|| result.Body.DiagnosticsProfile.BootDiagnostics.StorageUri == null)
)
{
ThrowTerminatingError
(new ErrorRecord(
Expand All @@ -130,25 +132,26 @@ public override void ExecuteCmdlet()
null));
}

//console log
if (this.Windows.IsPresent
|| (this.Linux.IsPresent && !string.IsNullOrEmpty(this.LocalPath)))
{
var screenshotUri = new Uri(result.Body.InstanceView.BootDiagnostics.ConsoleScreenshotBlobUri);
var localFile = this.LocalPath + screenshotUri.Segments[2];
DownloadFromBlobUri(screenshotUri, localFile);
}
var bootDiagnostics = this.VirtualMachineClient.RetrieveBootDiagnosticsData(this.ResourceGroupName, this.Name);
var localPathTest = this.LocalPath;
var localFile = this.LocalPath + new Uri(bootDiagnostics.ConsoleScreenshotBlobUri).Segments[2];

DownloadFromBlobUri(new Uri(bootDiagnostics.ConsoleScreenshotBlobUri), localFile);
}

//serial log
var bootDiagnosticsSerial = this.VirtualMachineClient.RetrieveBootDiagnosticsData(this.ResourceGroupName, this.Name);
var logUri = new Uri(bootDiagnosticsSerial.SerialConsoleLogBlobUri);
var localFileSerial = (this.LocalPath ?? Path.GetTempPath()) + logUri.Segments[2];
DownloadFromBlobUri(logUri, localFileSerial);
if (this.Linux.IsPresent)
{
var logUri = new Uri(result.Body.InstanceView.BootDiagnostics.SerialConsoleLogBlobUri);

var localFile = (this.LocalPath ?? Path.GetTempPath()) + logUri.Segments[2];

DownloadFromBlobUri(logUri, localFile);

var sb = new StringBuilder();
using (var reader = new StreamReader(localFile))
using (var reader = new StreamReader(localFileSerial))
{
string line;
while ((line = reader.ReadLine()) != null)
Expand All @@ -165,25 +168,12 @@ public override void ExecuteCmdlet()
private void DownloadFromBlobUri(Uri sourceUri, string localFileInfo)
{
BlobUri blobUri;
string storagekey = "";
if (!BlobUri.TryParseUri(sourceUri, out blobUri))
{
throw new ArgumentOutOfRangeException("Source", sourceUri.ToString());
}

var storageClient = AzureSession.Instance.ClientFactory.CreateArmClient<StorageManagementClient>(
DefaultProfile.DefaultContext, AzureEnvironment.Endpoint.ResourceManager);


var storageService = storageClient.StorageAccounts.GetProperties(this.ResourceGroupName, blobUri.StorageAccountName);
if (storageService != null)
{
var storageKeys = storageClient.StorageAccounts.ListKeys(this.ResourceGroupName, storageService.Name);
storagekey = storageKeys.GetKey1();
}

StorageCredentials storagecred = new StorageCredentials(blobUri.StorageAccountName, storagekey);
var blob = new CloudBlob(sourceUri, storagecred);
var blob = new CloudBlob(sourceUri);

blob.DownloadToFileAsync(localFileInfo, FileMode.Create).ConfigureAwait(false).GetAwaiter().GetResult();
}
Expand Down