From 628767c3c2a63e5b71d2a10d871832c00717ef26 Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Tue, 26 Apr 2022 18:29:20 -0500 Subject: [PATCH 01/20] add -DataAccessAuthMode to Snaptshot/Disk config/updateConfig --- .../Disk/Config/NewAzureRmDiskConfigCommand.cs | 10 +++++++++- .../Disk/Config/NewAzureRmDiskUpdateConfigCommand.cs | 10 +++++++++- src/Compute/Compute/Generated/Models/PSDisk.cs | 11 +---------- src/Compute/Compute/Generated/Models/PSDiskUpdate.cs | 1 + src/Compute/Compute/Generated/Models/PSSnapshot.cs | 2 +- .../Compute/Generated/Models/PSSnapshotUpdate.cs | 1 + .../Config/NewAzureRmSnapshotConfigCommand.cs | 10 +++++++++- .../Config/NewAzureRmSnapshotUpdateConfigCommand.cs | 10 +++++++++- 8 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskConfigCommand.cs b/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskConfigCommand.cs index 775953754fd2..49e8340bd18f 100644 --- a/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskConfigCommand.cs +++ b/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskConfigCommand.cs @@ -228,6 +228,13 @@ public partial class NewAzureRmDiskConfigCommand : Microsoft.Azure.Commands.Reso HelpMessage = "True if the image from which the OS disk is created supports accelerated networking.")] public bool? AcceleratedNetwork { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Additional authentication requirements when exporting or uploading to a disk or snapshot.")] + [PSArgumentCompleter("AzureActiveDirectory", "None")] + public string DataAccessAuthMode { get; set; } + protected override void ProcessRecord() { if (ShouldProcess("Disk", "New")) @@ -443,7 +450,8 @@ private void Run() PurchasePlan = this.IsParameterBound(c => c.PurchasePlan) ? this.PurchasePlan : null, SupportsHibernation = this.IsParameterBound(c => c.SupportsHibernation) ? SupportsHibernation : null, SupportedCapabilities = vSupportedCapabilities, - PublicNetworkAccess = this.IsParameterBound(c => c.PublicNetworkAccess) ? PublicNetworkAccess : null + PublicNetworkAccess = this.IsParameterBound(c => c.PublicNetworkAccess) ? PublicNetworkAccess : null, + DataAccessAuthMode = this.IsParameterBound(c => c.DataAccessAuthMode) ? DataAccessAuthMode : null }; WriteObject(vDisk); diff --git a/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskUpdateConfigCommand.cs b/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskUpdateConfigCommand.cs index 9339cc8b7805..3869c03a8844 100644 --- a/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskUpdateConfigCommand.cs +++ b/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskUpdateConfigCommand.cs @@ -161,6 +161,13 @@ public partial class NewAzureRmDiskUpdateConfigCommand : Microsoft.Azure.Command HelpMessage = "True if the image from which the OS disk is created supports accelerated networking.")] public bool? AcceleratedNetwork { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Additional authentication requirements when exporting or uploading to a disk or snapshot.")] + [PSArgumentCompleter("AzureActiveDirectory", "None")] + public string DataAccessAuthMode { get; set; } + protected override void ProcessRecord() { @@ -294,7 +301,8 @@ private void Run() PurchasePlan = this.IsParameterBound(c => c.PurchasePlan) ? this.PurchasePlan : null, SupportsHibernation = this.IsParameterBound(c => c.SupportsHibernation) ? SupportsHibernation : null, SupportedCapabilities = vSupportedCapabilities, - PublicNetworkAccess = this.IsParameterBound(c => c.PublicNetworkAccess) ? PublicNetworkAccess : null + PublicNetworkAccess = this.IsParameterBound(c => c.PublicNetworkAccess) ? PublicNetworkAccess : null, + DataAccessAuthMode = this.IsParameterBound(c => c.DataAccessAuthMode) ? DataAccessAuthMode : null }; WriteObject(vDiskUpdate); diff --git a/src/Compute/Compute/Generated/Models/PSDisk.cs b/src/Compute/Compute/Generated/Models/PSDisk.cs index be823bb4ac0c..da4ab0879975 100644 --- a/src/Compute/Compute/Generated/Models/PSDisk.cs +++ b/src/Compute/Compute/Generated/Models/PSDisk.cs @@ -67,7 +67,6 @@ public string ResourceGroupName public string Location { get; set; } public ExtendedLocation ExtendedLocation { get; set; } public IDictionary Tags { get; set; } - // Gets or sets possible values include: 'AllowAll', 'AllowPrivate', 'DenyAll' public string NetworkAccessPolicy { get; set; } public string DiskAccessId { get; set; } public string Tier { get; set; } @@ -75,16 +74,8 @@ public string ResourceGroupName public PSPurchasePlan PurchasePlan { get; set; } public bool? SupportsHibernation { get; set; } public DiskSecurityProfile SecurityProfile { get; set; } - - // - // Summary: - // Gets or sets possible values include: 'Enabled', 'Disabled' public string PublicNetworkAccess { get; set; } - - // - // Summary: - // Gets or sets list of supported capabilities for the image from which the OS disk - // was created. public SupportedCapabilities SupportedCapabilities { get; set; } + public string DataAccessAuthMode { get; set; } } } diff --git a/src/Compute/Compute/Generated/Models/PSDiskUpdate.cs b/src/Compute/Compute/Generated/Models/PSDiskUpdate.cs index ad15201aa264..b8869c26d86c 100644 --- a/src/Compute/Compute/Generated/Models/PSDiskUpdate.cs +++ b/src/Compute/Compute/Generated/Models/PSDiskUpdate.cs @@ -56,5 +56,6 @@ public partial class PSDiskUpdate // Summary: // Gets or sets possible values include: 'Enabled', 'Disabled' public string PublicNetworkAccess { get; set; } + public string DataAccessAuthMode { get; set; } } } diff --git a/src/Compute/Compute/Generated/Models/PSSnapshot.cs b/src/Compute/Compute/Generated/Models/PSSnapshot.cs index dd0064e57011..bf0bcbfe93d7 100644 --- a/src/Compute/Compute/Generated/Models/PSSnapshot.cs +++ b/src/Compute/Compute/Generated/Models/PSSnapshot.cs @@ -81,6 +81,6 @@ public string ResourceGroupName // Gets or sets percentage complete for the background copy when a resource is created // via the CopyStart operation. public double? CompletionPercent { get; set; } - + public string DataAccessAuthMode { get; set; } } } diff --git a/src/Compute/Compute/Generated/Models/PSSnapshotUpdate.cs b/src/Compute/Compute/Generated/Models/PSSnapshotUpdate.cs index 517bd8ab0157..687392126c33 100644 --- a/src/Compute/Compute/Generated/Models/PSSnapshotUpdate.cs +++ b/src/Compute/Compute/Generated/Models/PSSnapshotUpdate.cs @@ -39,5 +39,6 @@ public partial class PSSnapshotUpdate // Summary: // Gets or sets possible values include: 'Enabled', 'Disabled' public string PublicNetworkAccess { get; set; } + public string DataAccessAuthMode { get; set; } } } diff --git a/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotConfigCommand.cs b/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotConfigCommand.cs index 7e1efda74034..6ffb2f573bbf 100644 --- a/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotConfigCommand.cs +++ b/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotConfigCommand.cs @@ -173,6 +173,13 @@ public partial class NewAzureRmSnapshotConfigCommand : Microsoft.Azure.Commands. HelpMessage = "True if the image from which the OS disk is created supports accelerated networking.")] public bool? AcceleratedNetwork { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Additional authentication requirements when exporting or uploading to a disk or snapshot.")] + [PSArgumentCompleter("AzureActiveDirectory", "None")] + public string DataAccessAuthMode { get; set; } + protected override void ProcessRecord() { if (ShouldProcess("Snapshot", "New")) @@ -354,7 +361,8 @@ private void Run() PurchasePlan = this.IsParameterBound(c => c.PurchasePlan) ? this.PurchasePlan : null, SupportsHibernation = this.IsParameterBound(c => c.SupportsHibernation) ? SupportsHibernation : null, SupportedCapabilities = vSupportedCapabilities, - PublicNetworkAccess = this.IsParameterBound(c => c.PublicNetworkAccess) ? PublicNetworkAccess : null + PublicNetworkAccess = this.IsParameterBound(c => c.PublicNetworkAccess) ? PublicNetworkAccess : null, + DataAccessAuthMode = this.IsParameterBound(c => c.DataAccessAuthMode) ? DataAccessAuthMode : null }; WriteObject(vSnapshot); diff --git a/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotUpdateConfigCommand.cs b/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotUpdateConfigCommand.cs index 7275d2602a14..f2fe5b25b331 100644 --- a/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotUpdateConfigCommand.cs +++ b/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotUpdateConfigCommand.cs @@ -101,6 +101,13 @@ public partial class NewAzureRmSnapshotUpdateConfigCommand : Microsoft.Azure.Com [PSArgumentCompleter("Enabled", "Disabled")] public string PublicNetworkAccess { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Additional authentication requirements when exporting or uploading to a disk or snapshot.")] + [PSArgumentCompleter("AzureActiveDirectory", "None")] + public string DataAccessAuthMode { get; set; } + protected override void ProcessRecord() { if (ShouldProcess("SnapshotUpdate", "New")) @@ -202,7 +209,8 @@ private void Run() Encryption = vEncryption, Sku = vSku, SupportsHibernation = this.IsParameterBound(c => c.SupportsHibernation) ? SupportsHibernation : null, - PublicNetworkAccess = this.IsParameterBound(c => c.PublicNetworkAccess) ? PublicNetworkAccess : null + PublicNetworkAccess = this.IsParameterBound(c => c.PublicNetworkAccess) ? PublicNetworkAccess : null, + DataAccessAuthMode = this.IsParameterBound(c => c.DataAccessAuthMode) ? DataAccessAuthMode : null }; WriteObject(vSnapshotUpdate); From b0c2ae164fce13228c513d7240bb43fe8776be50 Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Wed, 27 Apr 2022 18:52:01 -0500 Subject: [PATCH 02/20] trying DataAuth in Add-AzVhd --- .../AzureSessionCredential.cs | 121 ++++++++++++++++++ .../Compute.AlcWrapper/AzureStorageService.cs | 11 ++ .../Compute.AlcWrapper/PSPageBlobClient.cs | 13 ++ .../StorageServices/AddAzureVhdCommand.cs | 54 +++++++- 4 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 src/Compute/Compute.AlcWrapper/AzureSessionCredential.cs diff --git a/src/Compute/Compute.AlcWrapper/AzureSessionCredential.cs b/src/Compute/Compute.AlcWrapper/AzureSessionCredential.cs new file mode 100644 index 000000000000..f4629e6d448d --- /dev/null +++ b/src/Compute/Compute.AlcWrapper/AzureSessionCredential.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Microsoft.Azure.Commands.Common.Authentication; +using Microsoft.Azure.Commands.Common.Authentication.Abstractions; + +namespace Microsoft.Azure.Commands.Compute +{ + public delegate void DebugLogWriter(string log); + public class AzureSessionCredential : TokenCredential + { + public AzureSessionCredential(IAzureContext DefaultContext, DebugLogWriter logWriter = null, string customAudience = null) + { + if (DefaultContext == null || DefaultContext.Account == null) + { + throw new InvalidOperationException(); + } + if (logWriter != null) + { + this.debugLogWriter = logWriter; + } + + if (customAudience != null) + { + IAccessToken accessToken1 = AzureSession.Instance.AuthenticationFactory.Authenticate( + DefaultContext.Account, + EnsureCustomAudienceSet(DefaultContext.Environment, customAudience), + DefaultContext.Tenant.Id, + null, + ShowDialog.Never, + null, + customAudience); + accessToken = accessToken1; + } + else + { + IAccessToken accessToken1 = AzureSession.Instance.AuthenticationFactory.Authenticate( + DefaultContext.Account, + EnsureStorageOAuthAudienceSet(DefaultContext.Environment), + DefaultContext.Tenant.Id, + null, + ShowDialog.Never, + null, + StorageOAuthEndpointResourceKey); + accessToken = accessToken1; + } + } + + public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken) + { + AccessToken token; + accessToken.AuthorizeRequest((tokenType, tokenValue) => + { + token = new AccessToken(tokenValue, DateTimeOffset.UtcNow); + }); + if (this.debugLogWriter != null) + { + this.debugLogWriter("[" + DateTime.Now.ToString() + "] GetToken: " + token.Token); + } + return token; + } + + public override ValueTask GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken) + { + AccessToken token; + accessToken.AuthorizeRequest((tokenType, tokenValue) => + { + token = new AccessToken(tokenValue, DateTimeOffset.UtcNow); + }); + + if (this.debugLogWriter != null) + { + this.debugLogWriter("[" + DateTime.Now.ToString() + "] GetTokenAsync: " + token.Token); + } + return new ValueTask(token); + } + + private IAzureEnvironment EnsureStorageOAuthAudienceSet(IAzureEnvironment environment) + { + if (environment != null) + { + if (!environment.IsPropertySet(StorageOAuthEndpointResourceKey)) + { + environment.SetProperty(StorageOAuthEndpointResourceKey, StorageOAuthEndpointResourceValue); + } + } + + return environment; + } + + private IAzureEnvironment EnsureCustomAudienceSet(IAzureEnvironment environment, string customAudience) + { + if (environment != null) + { + if (!environment.IsPropertySet(customAudience)) + { + environment.SetProperty(customAudience, customAudience); + } + } + + return environment; + } + + /// + /// The extension key to use for the storage token audience value + /// + public const string StorageOAuthEndpointResourceKey = "StorageOAuthEndpointResourceId"; + + /// + /// Default resourceId for storage OAuth tokens + /// + public const string StorageOAuthEndpointResourceValue = "https://storage.azure.com"; + + private IAccessToken accessToken; + private DebugLogWriter debugLogWriter = null; + } + +} diff --git a/src/Compute/Compute.AlcWrapper/AzureStorageService.cs b/src/Compute/Compute.AlcWrapper/AzureStorageService.cs index 7094b193416b..43f2b25088ed 100644 --- a/src/Compute/Compute.AlcWrapper/AzureStorageService.cs +++ b/src/Compute/Compute.AlcWrapper/AzureStorageService.cs @@ -57,4 +57,15 @@ internal PSBlobDownloadInfo(BlobDownloadInfo info) public string ContentType { get { return _blobDownloadInfo.ContentType; } } } + + public class PSBlobProperties + { + private BlobProperties _blobProperties; + + internal PSBlobProperties(BlobProperties blobProperties) + { + _blobProperties = blobProperties; + } + + } } diff --git a/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs b/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs index d2bc1bd287e2..31fd85246c76 100644 --- a/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs +++ b/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs @@ -17,6 +17,7 @@ using System.Text; using Azure.Storage.Blobs.Specialized; using System.IO; +using Microsoft.Azure.Commands.Common.Authentication.Abstractions; namespace Microsoft.Azure.Commands.Compute { @@ -33,11 +34,23 @@ public PSPageBlobClient(Uri blobUri) _pageBlobClient = new PageBlobClient(blobUri, null); } + public PSPageBlobClient(Uri blobUri, IAzureContext DefaultContext, string audience) + { + AzureSessionCredential customerToken = new AzureSessionCredential(DefaultContext, customAudience: audience); + _pageBlobClient = new PageBlobClient(blobUri, customerToken); + } + public Uri Uri { get { return _pageBlobClient.Uri; } } public void UploadPages(Stream content, long offset) { _pageBlobClient.UploadPagesAsync(content, offset).ConfigureAwait(false).GetAwaiter().GetResult(); } + + public PSBlobProperties GetProperties() + { + var blobProperties = new PSBlobProperties(_pageBlobClient.GetProperties()); + return blobProperties; + } } } diff --git a/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs b/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs index 65dabad7a4d1..b13967341765 100644 --- a/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs +++ b/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs @@ -36,6 +36,7 @@ using Microsoft.Samples.HyperV.Storage; using Microsoft.Samples.HyperV.Common; using System.Threading; +using Azure.Core; namespace Microsoft.Azure.Commands.Compute.StorageServices @@ -178,6 +179,13 @@ public class AddAzureVhdCommand : ComputeClientBaseCmdlet HelpMessage = "Skips the resizing of VHD")] public SwitchParameter SkipResizing { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "Additional authentication requirements when exporting or uploading to a disk or snapshot.")] + [PSArgumentCompleter("AzureActiveDirectory", "None")] + public string DataAccessAuthMode { get; set; } + [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] public SwitchParameter AsJob { get; set; } @@ -225,6 +233,27 @@ public override void ExecuteCmdlet() Uri sasUri = new Uri(accessUri.AccessSAS); WriteVerbose("SAS generated: " + accessUri.AccessSAS); + var pageBlobClient = new PSPageBlobClient(sasUri); + PSBlobProperties blobProperties; + try + { + blobProperties = pageBlobClient.GetProperties(); + } + catch (global::Azure.RequestFailedException e) when (e.Status == 401) // need diskRP bearer token + { + string audience = GetAudienceFrom401ExceptionMessage(e.Message); + if (audience != null) + { + Console.WriteLine(string.Format("Need bearer token with audience {0} to access the blob, so will generate bearer token and resend the request.", audience)); + pageBlobClient = new PSPageBlobClient(sasUri, DefaultContext, audience); + } + else + { + throw e; + } + } + blobProperties = pageBlobClient.GetProperties(); + // 3-4: UPLOAD WriteVerbose("Preparing for Upload"); @@ -281,6 +310,28 @@ public override void ExecuteCmdlet() } + public static string GetAudienceFrom401ExceptionMessage(string exceptionMessage) + { + string authenticateHeaderName = "WWW-Authenticate"; + string audienceName = "resource_id="; + string[] exceptionMessageTexts = exceptionMessage.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); + foreach (string messageText in exceptionMessageTexts) + { + if (messageText.StartsWith(authenticateHeaderName)) + { + string[] authTexts = messageText.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); + foreach (string authText in authTexts) + { + if (authText.StartsWith(audienceName)) + { + return authText.Substring(audienceName.Length); + } + } + } + } + return null; + } + public UploadParameters ValidateParameters() { BlobUri destinationUri; @@ -378,7 +429,8 @@ private PSDisk CreateDiskConfig() EncryptionSettingsCollection = null, Encryption = null, NetworkAccessPolicy = null, - DiskAccessId = null + DiskAccessId = null, + DataAccessAuthMode = this.IsParameterBound(c => c.DataAccessAuthMode) ? this.DataAccessAuthMode : null }; return vDisk; } From bb1643176acee5e30bf35c3f7364335a14d8fe3e Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Wed, 11 May 2022 21:11:02 +0100 Subject: [PATCH 03/20] progress save for Add-AzVhd --- src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs | 10 +++++++--- .../Compute/StorageServices/AddAzureVhdCommand.cs | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs b/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs index 31fd85246c76..04e50640bb4b 100644 --- a/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs +++ b/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs @@ -36,7 +36,7 @@ public PSPageBlobClient(Uri blobUri) public PSPageBlobClient(Uri blobUri, IAzureContext DefaultContext, string audience) { - AzureSessionCredential customerToken = new AzureSessionCredential(DefaultContext, customAudience: audience); + AzureSessionCredential customerToken = new AzureSessionCredential(DefaultContext, customAudience: audience); _pageBlobClient = new PageBlobClient(blobUri, customerToken); } @@ -47,10 +47,14 @@ public void UploadPages(Stream content, long offset) _pageBlobClient.UploadPagesAsync(content, offset).ConfigureAwait(false).GetAwaiter().GetResult(); } + /* public PSBlobProperties GetProperties() { - var blobProperties = new PSBlobProperties(_pageBlobClient.GetProperties()); + + var test = _pageBlobClient.GetProperties(); + var testValue = test.Value; + var blobProperties = new PSBlobProperties(testValue); return blobProperties; - } + }*/ } } diff --git a/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs b/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs index b13967341765..474b0732c9ae 100644 --- a/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs +++ b/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs @@ -233,7 +233,10 @@ public override void ExecuteCmdlet() Uri sasUri = new Uri(accessUri.AccessSAS); WriteVerbose("SAS generated: " + accessUri.AccessSAS); + /* var pageBlobClient = new PSPageBlobClient(sasUri); + + PSBlobProperties blobProperties; try { @@ -245,7 +248,7 @@ public override void ExecuteCmdlet() if (audience != null) { Console.WriteLine(string.Format("Need bearer token with audience {0} to access the blob, so will generate bearer token and resend the request.", audience)); - pageBlobClient = new PSPageBlobClient(sasUri, DefaultContext, audience); + pageBlobClient = new PSPageBlobClient(sasUri, DefaultContext, "https://disk.compute.azure.com/"); } else { @@ -253,7 +256,7 @@ public override void ExecuteCmdlet() } } blobProperties = pageBlobClient.GetProperties(); - + */ // 3-4: UPLOAD WriteVerbose("Preparing for Upload"); From 54291b6dd1dac4176c562f3618326b7e5c6a2956 Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Wed, 11 May 2022 21:43:06 +0100 Subject: [PATCH 04/20] updates to cmdlets --- .../Config/NewAzureRmDiskConfigCommand.cs | 16 ++++++++++++++ .../NewAzureRmDiskUpdateConfigCommand.cs | 16 ++++++++++++++ .../GalleryImageCreateOrUpdateMethod.cs | 12 +++++++++++ .../Generated/Models/PSGalleryImage.cs | 1 + .../Generated/Models/PSSnapshotUpdate.cs | 1 + .../Config/NewAzureRmSnapshotConfigCommand.cs | 16 ++++++++++++++ .../NewAzureRmSnapshotUpdateConfigCommand.cs | 21 ++++++++++++++++++- .../Compute/Models/PSVirtualMachineImage.cs | 2 ++ 8 files changed, 84 insertions(+), 1 deletion(-) diff --git a/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskConfigCommand.cs b/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskConfigCommand.cs index 775953754fd2..bbd4168cb81f 100644 --- a/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskConfigCommand.cs +++ b/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskConfigCommand.cs @@ -228,6 +228,13 @@ public partial class NewAzureRmDiskConfigCommand : Microsoft.Azure.Commands.Reso HelpMessage = "True if the image from which the OS disk is created supports accelerated networking.")] public bool? AcceleratedNetwork { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "CPU architecture supported by an OS disk. Possible values are \"X64\" and \"Arm64\".")] + [PSArgumentCompleter("X64", "Arm64")] + public string Architecture { get; set; } + protected override void ProcessRecord() { if (ShouldProcess("Disk", "New")) @@ -418,6 +425,15 @@ private void Run() vSupportedCapabilities.AcceleratedNetwork = AcceleratedNetwork; } + if (this.IsParameterBound(c => c.Architecture)) + { + if (vSupportedCapabilities == null) + { + vSupportedCapabilities = new SupportedCapabilities(); + } + vSupportedCapabilities.Architecture = this.Architecture; + } + var vDisk = new PSDisk { Zones = this.IsParameterBound(c => c.Zone) ? this.Zone : null, diff --git a/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskUpdateConfigCommand.cs b/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskUpdateConfigCommand.cs index 9339cc8b7805..7764bebafe73 100644 --- a/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskUpdateConfigCommand.cs +++ b/src/Compute/Compute/Generated/Disk/Config/NewAzureRmDiskUpdateConfigCommand.cs @@ -161,6 +161,13 @@ public partial class NewAzureRmDiskUpdateConfigCommand : Microsoft.Azure.Command HelpMessage = "True if the image from which the OS disk is created supports accelerated networking.")] public bool? AcceleratedNetwork { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "CPU architecture supported by an OS disk. Possible values are \"X64\" and \"Arm64\".")] + [PSArgumentCompleter("X64", "Arm64")] + public string Architecture { get; set; } + protected override void ProcessRecord() { @@ -274,6 +281,15 @@ private void Run() vSupportedCapabilities.AcceleratedNetwork = AcceleratedNetwork; } + if (this.IsParameterBound(c => c.Architecture)) + { + if (vSupportedCapabilities == null) + { + vSupportedCapabilities = new SupportedCapabilities(); + } + vSupportedCapabilities.Architecture = this.Architecture; + } + var vDiskUpdate = new PSDiskUpdate { OsType = this.IsParameterBound(c => c.OsType) ? this.OsType : (OperatingSystemTypes?)null, diff --git a/src/Compute/Compute/Generated/GalleryImage/GalleryImageCreateOrUpdateMethod.cs b/src/Compute/Compute/Generated/GalleryImage/GalleryImageCreateOrUpdateMethod.cs index 0160ba86226e..bf1cf8a0fedd 100644 --- a/src/Compute/Compute/Generated/GalleryImage/GalleryImageCreateOrUpdateMethod.cs +++ b/src/Compute/Compute/Generated/GalleryImage/GalleryImageCreateOrUpdateMethod.cs @@ -403,6 +403,11 @@ public override void ExecuteCmdlet() galleryImage.Tags = this.Tag.Cast().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value); } + if (this.IsParameterBound(c => c.Architecture)) + { + galleryImage.Architecture = this.Architecture; + } + if (this.IsParameterBound(c => c.MinimumVCPU)) { if (galleryImage.Recommended == null) @@ -605,6 +610,13 @@ public override void ExecuteCmdlet() ValueFromPipelineByPropertyName = true)] public string ReleaseNoteUri { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "CPU architecture supported by an OS disk. Possible values are \"X64\" and \"Arm64\".")] + [PSArgumentCompleter("X64", "Arm64")] + public string Architecture { get; set; } + [Parameter( Mandatory = false, ValueFromPipelineByPropertyName = true)] diff --git a/src/Compute/Compute/Generated/Models/PSGalleryImage.cs b/src/Compute/Compute/Generated/Models/PSGalleryImage.cs index e3a9f8a7b744..018b4df25dd4 100644 --- a/src/Compute/Compute/Generated/Models/PSGalleryImage.cs +++ b/src/Compute/Compute/Generated/Models/PSGalleryImage.cs @@ -59,6 +59,7 @@ public string ResourceGroupName public string Location { get; set; } public IDictionary Tags { get; set; } public IList Features { get; set; } + public string Architecture { get; set; } } } diff --git a/src/Compute/Compute/Generated/Models/PSSnapshotUpdate.cs b/src/Compute/Compute/Generated/Models/PSSnapshotUpdate.cs index 517bd8ab0157..68c7327cff02 100644 --- a/src/Compute/Compute/Generated/Models/PSSnapshotUpdate.cs +++ b/src/Compute/Compute/Generated/Models/PSSnapshotUpdate.cs @@ -34,6 +34,7 @@ public partial class PSSnapshotUpdate public IDictionary Tags { get; set; } public SnapshotSku Sku { get; set; } public bool? SupportsHibernation { get; set; } + public SupportedCapabilities SupportedCapabilities { get; set; } // // Summary: diff --git a/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotConfigCommand.cs b/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotConfigCommand.cs index 7e1efda74034..ffb38ca25e08 100644 --- a/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotConfigCommand.cs +++ b/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotConfigCommand.cs @@ -173,6 +173,13 @@ public partial class NewAzureRmSnapshotConfigCommand : Microsoft.Azure.Commands. HelpMessage = "True if the image from which the OS disk is created supports accelerated networking.")] public bool? AcceleratedNetwork { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "CPU architecture supported by an OS disk. Possible values are \"X64\" and \"Arm64\".")] + [PSArgumentCompleter("X64", "Arm64")] + public string Architecture { get; set; } + protected override void ProcessRecord() { if (ShouldProcess("Snapshot", "New")) @@ -336,6 +343,15 @@ private void Run() vSupportedCapabilities.AcceleratedNetwork = AcceleratedNetwork; } + if (this.IsParameterBound(c => c.Architecture)) + { + if (vSupportedCapabilities == null) + { + vSupportedCapabilities = new SupportedCapabilities(); + } + vSupportedCapabilities.Architecture = this.Architecture; + } + var vSnapshot = new PSSnapshot { OsType = this.IsParameterBound(c => c.OsType) ? this.OsType : (OperatingSystemTypes?)null, diff --git a/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotUpdateConfigCommand.cs b/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotUpdateConfigCommand.cs index 7275d2602a14..1c9c1aa2cd80 100644 --- a/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotUpdateConfigCommand.cs +++ b/src/Compute/Compute/Generated/Snapshot/Config/NewAzureRmSnapshotUpdateConfigCommand.cs @@ -101,6 +101,13 @@ public partial class NewAzureRmSnapshotUpdateConfigCommand : Microsoft.Azure.Com [PSArgumentCompleter("Enabled", "Disabled")] public string PublicNetworkAccess { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "CPU architecture supported by an OS disk. Possible values are \"X64\" and \"Arm64\".")] + [PSArgumentCompleter("X64", "Arm64")] + public string Architecture { get; set; } + protected override void ProcessRecord() { if (ShouldProcess("SnapshotUpdate", "New")) @@ -120,6 +127,8 @@ private void Run() // Sku SnapshotSku vSku = null; + SupportedCapabilities vSupportedCapabilities = null; + if (this.IsParameterBound(c => c.EncryptionSettingsEnabled)) { if (vEncryptionSettingsCollection == null) @@ -193,6 +202,15 @@ private void Run() vSku.Name = this.SkuName; } + if (this.IsParameterBound(c => c.Architecture)) + { + if (vSupportedCapabilities == null) + { + vSupportedCapabilities = new SupportedCapabilities(); + } + vSupportedCapabilities.Architecture = this.Architecture; + } + var vSnapshotUpdate = new PSSnapshotUpdate { OsType = this.IsParameterBound(c => c.OsType) ? this.OsType : (OperatingSystemTypes?)null, @@ -202,7 +220,8 @@ private void Run() Encryption = vEncryption, Sku = vSku, SupportsHibernation = this.IsParameterBound(c => c.SupportsHibernation) ? SupportsHibernation : null, - PublicNetworkAccess = this.IsParameterBound(c => c.PublicNetworkAccess) ? PublicNetworkAccess : null + PublicNetworkAccess = this.IsParameterBound(c => c.PublicNetworkAccess) ? PublicNetworkAccess : null, + SupportedCapabilities = vSupportedCapabilities }; WriteObject(vSnapshotUpdate); diff --git a/src/Compute/Compute/Models/PSVirtualMachineImage.cs b/src/Compute/Compute/Models/PSVirtualMachineImage.cs index ed2fee8e2b60..f7bc1a3c33d4 100644 --- a/src/Compute/Compute/Models/PSVirtualMachineImage.cs +++ b/src/Compute/Compute/Models/PSVirtualMachineImage.cs @@ -81,5 +81,7 @@ public string DataDiskImagesText } public AutomaticOSUpgradeProperties AutomaticOSUpgradeProperties { get; set; } + + public string Architecture { get; set; } } } From bb5b5513be58f140e0a65db968fe5dd596acf679 Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Wed, 11 May 2022 21:58:29 +0100 Subject: [PATCH 05/20] fix NewGalleryImage instead of update, add md files, update changelog --- src/Compute/Compute/ChangeLog.md | 6 +++++ .../GalleryImageCreateOrUpdateMethod.cs | 24 +++++++++---------- src/Compute/Compute/help/New-AzDiskConfig.md | 19 +++++++++++++-- .../Compute/help/New-AzDiskUpdateConfig.md | 17 ++++++++++++- .../Compute/help/New-AzSnapshotConfig.md | 17 ++++++++++++- .../help/New-AzSnapshotUpdateConfig.md | 17 ++++++++++++- 6 files changed, 83 insertions(+), 17 deletions(-) diff --git a/src/Compute/Compute/ChangeLog.md b/src/Compute/Compute/ChangeLog.md index 9e7a0994a067..f17ce8b09e2f 100644 --- a/src/Compute/Compute/ChangeLog.md +++ b/src/Compute/Compute/ChangeLog.md @@ -21,6 +21,12 @@ --> ## Upcoming Release * Edited `New-AzVm` cmdlet internal logic to use the `PlatformFaultDomain` value in the `PSVirtualMachine` object passed to it in the new virtual machine. +* Added `-Architecture` parameter to the following cmdlets: + - New-AzDiskConfig`` + - New-AzDiskUpdateConfig + - New-AzSnapshotConfig + - New-AzSnapshotUpdateConfig + - New-AzGalleryImageDefinition ## Version 4.26.0 * Added `-ImageReferenceId` parameter to following cmdlets: `New-AzVm`, `New-AzVmConfig`, `New-AzVmss`, `Set-AzVmssStorageProfile` diff --git a/src/Compute/Compute/Generated/GalleryImage/GalleryImageCreateOrUpdateMethod.cs b/src/Compute/Compute/Generated/GalleryImage/GalleryImageCreateOrUpdateMethod.cs index bf1cf8a0fedd..99d419e0775d 100644 --- a/src/Compute/Compute/Generated/GalleryImage/GalleryImageCreateOrUpdateMethod.cs +++ b/src/Compute/Compute/Generated/GalleryImage/GalleryImageCreateOrUpdateMethod.cs @@ -83,6 +83,11 @@ public override void ExecuteCmdlet() galleryImage.EndOfLifeDate = this.EndOfLifeDate; } + if (this.IsParameterBound(c => c.Architecture)) + { + galleryImage.Architecture = this.Architecture; + } + if (this.IsParameterBound(c => c.Tag)) { galleryImage.Tags = this.Tag.Cast().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value); @@ -327,6 +332,13 @@ public override void ExecuteCmdlet() Mandatory = false, ValueFromPipelineByPropertyName = true)] public GalleryImageFeature[] Feature { get; set; } + + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + HelpMessage = "CPU architecture supported by an OS disk. Possible values are \"X64\" and \"Arm64\".")] + [PSArgumentCompleter("X64", "Arm64")] + public string Architecture { get; set; } } [Cmdlet(VerbsData.Update, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "GalleryImageDefinition", DefaultParameterSetName = "DefaultParameter", SupportsShouldProcess = true)] @@ -403,11 +415,6 @@ public override void ExecuteCmdlet() galleryImage.Tags = this.Tag.Cast().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value); } - if (this.IsParameterBound(c => c.Architecture)) - { - galleryImage.Architecture = this.Architecture; - } - if (this.IsParameterBound(c => c.MinimumVCPU)) { if (galleryImage.Recommended == null) @@ -610,13 +617,6 @@ public override void ExecuteCmdlet() ValueFromPipelineByPropertyName = true)] public string ReleaseNoteUri { get; set; } - [Parameter( - Mandatory = false, - ValueFromPipelineByPropertyName = true, - HelpMessage = "CPU architecture supported by an OS disk. Possible values are \"X64\" and \"Arm64\".")] - [PSArgumentCompleter("X64", "Arm64")] - public string Architecture { get; set; } - [Parameter( Mandatory = false, ValueFromPipelineByPropertyName = true)] diff --git a/src/Compute/Compute/help/New-AzDiskConfig.md b/src/Compute/Compute/help/New-AzDiskConfig.md index de47c57e25fa..6a846124fef7 100644 --- a/src/Compute/Compute/help/New-AzDiskConfig.md +++ b/src/Compute/Compute/help/New-AzDiskConfig.md @@ -24,8 +24,8 @@ New-AzDiskConfig [[-SkuName] ] [-Tier ] [-LogicalSectorSize ] [-KeyEncryptionKey ] [-DiskEncryptionSetId ] [-EncryptionType ] [-DiskAccessId ] [-NetworkAccessPolicy ] [-BurstingEnabled ] [-PublicNetworkAccess ] - [-AcceleratedNetwork ] [-DefaultProfile ] [-WhatIf] [-Confirm] - [] + [-AcceleratedNetwork ] [-Architecture ] [-DefaultProfile ] [-WhatIf] + [-Confirm] [] ``` ## DESCRIPTION @@ -97,6 +97,21 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -Architecture +CPU architecture supported by an OS disk. Possible values are "X64" and "Arm64". + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### -BurstingEnabled Enables bursting beyond the provisioned performance target of the disk. Bursting is disabled by default. Does not apply to Ultra disks. diff --git a/src/Compute/Compute/help/New-AzDiskUpdateConfig.md b/src/Compute/Compute/help/New-AzDiskUpdateConfig.md index 6031a2b6419b..280e3d9a052a 100644 --- a/src/Compute/Compute/help/New-AzDiskUpdateConfig.md +++ b/src/Compute/Compute/help/New-AzDiskUpdateConfig.md @@ -20,7 +20,7 @@ New-AzDiskUpdateConfig [[-SkuName] ] [-Tier ] [-DiskIOPSReadOnly [-EncryptionSettingsEnabled ] [-DiskEncryptionKey ] [-KeyEncryptionKey ] [-DiskEncryptionSetId ] [-EncryptionType ] [-BurstingEnabled ] [-PublicNetworkAccess ] [-AcceleratedNetwork ] - [-DefaultProfile ] [-WhatIf] [-Confirm] [] + [-Architecture ] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -70,6 +70,21 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -Architecture +CPU architecture supported by an OS disk. Possible values are "X64" and "Arm64". + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### -BurstingEnabled Enables bursting beyond the provisioned performance target of the disk. Bursting is disabled by default. Does not apply to Ultra disks. diff --git a/src/Compute/Compute/help/New-AzSnapshotConfig.md b/src/Compute/Compute/help/New-AzSnapshotConfig.md index 1d7e11e904d4..dd8dcac7e817 100644 --- a/src/Compute/Compute/help/New-AzSnapshotConfig.md +++ b/src/Compute/Compute/help/New-AzSnapshotConfig.md @@ -21,7 +21,7 @@ New-AzSnapshotConfig [[-SkuName] ] [[-OsType] ] [[ [-DiskEncryptionKey ] [-KeyEncryptionKey ] [-DiskEncryptionSetId ] [-EncryptionType ] [-DiskAccessId ] [-NetworkAccessPolicy ] [-PublicNetworkAccess ] [-AcceleratedNetwork ] - [-DefaultProfile ] [-WhatIf] [-Confirm] [] + [-Architecture ] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -71,6 +71,21 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -Architecture +CPU architecture supported by an OS disk. Possible values are "X64" and "Arm64". + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### -CreateOption Specifies whether this cmdlet creates a disk in the virtual machine from a platform or user image, creates an empty disk, or attaches an existing disk. diff --git a/src/Compute/Compute/help/New-AzSnapshotUpdateConfig.md b/src/Compute/Compute/help/New-AzSnapshotUpdateConfig.md index 51ca31d63ee7..ee4741603b39 100644 --- a/src/Compute/Compute/help/New-AzSnapshotUpdateConfig.md +++ b/src/Compute/Compute/help/New-AzSnapshotUpdateConfig.md @@ -17,7 +17,7 @@ New-AzSnapshotUpdateConfig [[-SkuName] ] [[-OsType] ] [-SupportsHibernation ] [-EncryptionSettingsEnabled ] [-DiskEncryptionKey ] [-KeyEncryptionKey ] [-DiskEncryptionSetId ] [-EncryptionType ] [-PublicNetworkAccess ] - [-DefaultProfile ] [-WhatIf] [-Confirm] [] + [-Architecture ] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -53,6 +53,21 @@ This command updates an existing snapshot with name 'Snapshot01' in resource gro ## PARAMETERS +### -Architecture +CPU architecture supported by an OS disk. Possible values are "X64" and "Arm64". + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### -DefaultProfile The credentials, account, tenant, and subscription used for communication with azure. From aef512138b5ac7facb0b569823fc966c57c2f140 Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Wed, 11 May 2022 22:06:20 +0100 Subject: [PATCH 06/20] update last md --- .../help/New-AzGalleryImageDefinition.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Compute/Compute/help/New-AzGalleryImageDefinition.md b/src/Compute/Compute/help/New-AzGalleryImageDefinition.md index 8f82c2914729..99dfd0b392ef 100644 --- a/src/Compute/Compute/help/New-AzGalleryImageDefinition.md +++ b/src/Compute/Compute/help/New-AzGalleryImageDefinition.md @@ -20,7 +20,7 @@ New-AzGalleryImageDefinition [-ResourceGroupName] [-GalleryName] ] [-Eula ] [-HyperVGeneration ] [-MinimumMemory ] [-MinimumVCPU ] [-MaximumMemory ] [-MaximumVCPU ] [-PrivacyStatementUri ] [-PurchasePlanName ] [-PurchasePlanProduct ] [-PurchasePlanPublisher ] - [-ReleaseNoteUri ] [-Tag ] [-Feature ] + [-ReleaseNoteUri ] [-Tag ] [-Feature ] [-Architecture ] [-DefaultProfile ] [-WhatIf] [-Confirm] [] ``` @@ -78,7 +78,7 @@ New-AzGalleryImageDefinition -ResourceGroupName $rgName -GalleryName $galleryNam Creates a gallery image definition to contain image versions for specialized windows images. -### Example 4: Create an image definition for generalized windows images and set features. +### Example 4: Create an image definition for generalized windows images and set features. ```powershell $rgName = "myResourceGroup" @@ -186,6 +186,21 @@ Creates a gallery image definition for linux generalized images and specify eith ## PARAMETERS +### -Architecture +CPU architecture supported by an OS disk. Possible values are "X64" and "Arm64". + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### -AsJob Run cmdlet in the background From 558edabfc815682b3710cc2e34d20ac13358f0ad Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Thu, 12 May 2022 16:02:02 +0100 Subject: [PATCH 07/20] remove add-azvhd stuff --- .../AzureSessionCredential.cs | 121 ------------------ .../Compute.AlcWrapper/AzureStorageService.cs | 11 -- .../Compute.AlcWrapper/PSPageBlobClient.cs | 17 --- .../StorageServices/AddAzureVhdCommand.cs | 63 +-------- 4 files changed, 4 insertions(+), 208 deletions(-) delete mode 100644 src/Compute/Compute.AlcWrapper/AzureSessionCredential.cs diff --git a/src/Compute/Compute.AlcWrapper/AzureSessionCredential.cs b/src/Compute/Compute.AlcWrapper/AzureSessionCredential.cs deleted file mode 100644 index f4629e6d448d..000000000000 --- a/src/Compute/Compute.AlcWrapper/AzureSessionCredential.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using Azure.Core; -using Microsoft.Azure.Commands.Common.Authentication; -using Microsoft.Azure.Commands.Common.Authentication.Abstractions; - -namespace Microsoft.Azure.Commands.Compute -{ - public delegate void DebugLogWriter(string log); - public class AzureSessionCredential : TokenCredential - { - public AzureSessionCredential(IAzureContext DefaultContext, DebugLogWriter logWriter = null, string customAudience = null) - { - if (DefaultContext == null || DefaultContext.Account == null) - { - throw new InvalidOperationException(); - } - if (logWriter != null) - { - this.debugLogWriter = logWriter; - } - - if (customAudience != null) - { - IAccessToken accessToken1 = AzureSession.Instance.AuthenticationFactory.Authenticate( - DefaultContext.Account, - EnsureCustomAudienceSet(DefaultContext.Environment, customAudience), - DefaultContext.Tenant.Id, - null, - ShowDialog.Never, - null, - customAudience); - accessToken = accessToken1; - } - else - { - IAccessToken accessToken1 = AzureSession.Instance.AuthenticationFactory.Authenticate( - DefaultContext.Account, - EnsureStorageOAuthAudienceSet(DefaultContext.Environment), - DefaultContext.Tenant.Id, - null, - ShowDialog.Never, - null, - StorageOAuthEndpointResourceKey); - accessToken = accessToken1; - } - } - - public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken) - { - AccessToken token; - accessToken.AuthorizeRequest((tokenType, tokenValue) => - { - token = new AccessToken(tokenValue, DateTimeOffset.UtcNow); - }); - if (this.debugLogWriter != null) - { - this.debugLogWriter("[" + DateTime.Now.ToString() + "] GetToken: " + token.Token); - } - return token; - } - - public override ValueTask GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken) - { - AccessToken token; - accessToken.AuthorizeRequest((tokenType, tokenValue) => - { - token = new AccessToken(tokenValue, DateTimeOffset.UtcNow); - }); - - if (this.debugLogWriter != null) - { - this.debugLogWriter("[" + DateTime.Now.ToString() + "] GetTokenAsync: " + token.Token); - } - return new ValueTask(token); - } - - private IAzureEnvironment EnsureStorageOAuthAudienceSet(IAzureEnvironment environment) - { - if (environment != null) - { - if (!environment.IsPropertySet(StorageOAuthEndpointResourceKey)) - { - environment.SetProperty(StorageOAuthEndpointResourceKey, StorageOAuthEndpointResourceValue); - } - } - - return environment; - } - - private IAzureEnvironment EnsureCustomAudienceSet(IAzureEnvironment environment, string customAudience) - { - if (environment != null) - { - if (!environment.IsPropertySet(customAudience)) - { - environment.SetProperty(customAudience, customAudience); - } - } - - return environment; - } - - /// - /// The extension key to use for the storage token audience value - /// - public const string StorageOAuthEndpointResourceKey = "StorageOAuthEndpointResourceId"; - - /// - /// Default resourceId for storage OAuth tokens - /// - public const string StorageOAuthEndpointResourceValue = "https://storage.azure.com"; - - private IAccessToken accessToken; - private DebugLogWriter debugLogWriter = null; - } - -} diff --git a/src/Compute/Compute.AlcWrapper/AzureStorageService.cs b/src/Compute/Compute.AlcWrapper/AzureStorageService.cs index 43f2b25088ed..7094b193416b 100644 --- a/src/Compute/Compute.AlcWrapper/AzureStorageService.cs +++ b/src/Compute/Compute.AlcWrapper/AzureStorageService.cs @@ -57,15 +57,4 @@ internal PSBlobDownloadInfo(BlobDownloadInfo info) public string ContentType { get { return _blobDownloadInfo.ContentType; } } } - - public class PSBlobProperties - { - private BlobProperties _blobProperties; - - internal PSBlobProperties(BlobProperties blobProperties) - { - _blobProperties = blobProperties; - } - - } } diff --git a/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs b/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs index 04e50640bb4b..d2bc1bd287e2 100644 --- a/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs +++ b/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs @@ -17,7 +17,6 @@ using System.Text; using Azure.Storage.Blobs.Specialized; using System.IO; -using Microsoft.Azure.Commands.Common.Authentication.Abstractions; namespace Microsoft.Azure.Commands.Compute { @@ -34,27 +33,11 @@ public PSPageBlobClient(Uri blobUri) _pageBlobClient = new PageBlobClient(blobUri, null); } - public PSPageBlobClient(Uri blobUri, IAzureContext DefaultContext, string audience) - { - AzureSessionCredential customerToken = new AzureSessionCredential(DefaultContext, customAudience: audience); - _pageBlobClient = new PageBlobClient(blobUri, customerToken); - } - public Uri Uri { get { return _pageBlobClient.Uri; } } public void UploadPages(Stream content, long offset) { _pageBlobClient.UploadPagesAsync(content, offset).ConfigureAwait(false).GetAwaiter().GetResult(); } - - /* - public PSBlobProperties GetProperties() - { - - var test = _pageBlobClient.GetProperties(); - var testValue = test.Value; - var blobProperties = new PSBlobProperties(testValue); - return blobProperties; - }*/ } } diff --git a/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs b/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs index 474b0732c9ae..9fb4e53b4aab 100644 --- a/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs +++ b/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs @@ -36,7 +36,6 @@ using Microsoft.Samples.HyperV.Storage; using Microsoft.Samples.HyperV.Common; using System.Threading; -using Azure.Core; namespace Microsoft.Azure.Commands.Compute.StorageServices @@ -103,7 +102,7 @@ public class AddAzureVhdCommand : ComputeClientBaseCmdlet public string DiskName { get; set; } [Parameter( - Mandatory = true, + Mandatory = true, Position = 1, ParameterSetName = DirectUploadToManagedDiskSet, ValueFromPipelineByPropertyName = true, @@ -179,13 +178,6 @@ public class AddAzureVhdCommand : ComputeClientBaseCmdlet HelpMessage = "Skips the resizing of VHD")] public SwitchParameter SkipResizing { get; set; } - [Parameter( - Mandatory = false, - ValueFromPipelineByPropertyName = true, - HelpMessage = "Additional authentication requirements when exporting or uploading to a disk or snapshot.")] - [PSArgumentCompleter("AzureActiveDirectory", "None")] - public string DataAccessAuthMode { get; set; } - [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] public SwitchParameter AsJob { get; set; } @@ -233,30 +225,6 @@ public override void ExecuteCmdlet() Uri sasUri = new Uri(accessUri.AccessSAS); WriteVerbose("SAS generated: " + accessUri.AccessSAS); - /* - var pageBlobClient = new PSPageBlobClient(sasUri); - - - PSBlobProperties blobProperties; - try - { - blobProperties = pageBlobClient.GetProperties(); - } - catch (global::Azure.RequestFailedException e) when (e.Status == 401) // need diskRP bearer token - { - string audience = GetAudienceFrom401ExceptionMessage(e.Message); - if (audience != null) - { - Console.WriteLine(string.Format("Need bearer token with audience {0} to access the blob, so will generate bearer token and resend the request.", audience)); - pageBlobClient = new PSPageBlobClient(sasUri, DefaultContext, "https://disk.compute.azure.com/"); - } - else - { - throw e; - } - } - blobProperties = pageBlobClient.GetProperties(); - */ // 3-4: UPLOAD WriteVerbose("Preparing for Upload"); @@ -313,28 +281,6 @@ public override void ExecuteCmdlet() } - public static string GetAudienceFrom401ExceptionMessage(string exceptionMessage) - { - string authenticateHeaderName = "WWW-Authenticate"; - string audienceName = "resource_id="; - string[] exceptionMessageTexts = exceptionMessage.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); - foreach (string messageText in exceptionMessageTexts) - { - if (messageText.StartsWith(authenticateHeaderName)) - { - string[] authTexts = messageText.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); - foreach (string authText in authTexts) - { - if (authText.StartsWith(audienceName)) - { - return authText.Substring(audienceName.Length); - } - } - } - } - return null; - } - public UploadParameters ValidateParameters() { BlobUri destinationUri; @@ -432,8 +378,7 @@ private PSDisk CreateDiskConfig() EncryptionSettingsCollection = null, Encryption = null, NetworkAccessPolicy = null, - DiskAccessId = null, - DataAccessAuthMode = this.IsParameterBound(c => c.DataAccessAuthMode) ? this.DataAccessAuthMode : null + DiskAccessId = null }; return vDisk; } @@ -516,7 +461,7 @@ private void CheckForInvalidVhd() try { bool resizeNeeded = false; - long resizeTo=0; + long resizeTo = 0; using (VirtualDiskStream vds = new VirtualDiskStream(filePath.FullName)) { if (vds.Length < 20971520 || vds.Length > 4396972769280) @@ -695,4 +640,4 @@ private void resizeVhdFile(long FileSize) } } } -} +} \ No newline at end of file From d0772ffee29853a669be7da45fee1e085c9f1cec Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Thu, 12 May 2022 16:12:37 +0100 Subject: [PATCH 08/20] md files --- src/Compute/Compute/ChangeLog.md | 5 +++++ src/Compute/Compute/help/New-AzDiskConfig.md | 19 +++++++++++++++++-- .../Compute/help/New-AzDiskUpdateConfig.md | 18 +++++++++++++++++- .../Compute/help/New-AzSnapshotConfig.md | 18 +++++++++++++++++- .../help/New-AzSnapshotUpdateConfig.md | 18 +++++++++++++++++- 5 files changed, 73 insertions(+), 5 deletions(-) diff --git a/src/Compute/Compute/ChangeLog.md b/src/Compute/Compute/ChangeLog.md index 9e7a0994a067..03167def8686 100644 --- a/src/Compute/Compute/ChangeLog.md +++ b/src/Compute/Compute/ChangeLog.md @@ -21,6 +21,11 @@ --> ## Upcoming Release * Edited `New-AzVm` cmdlet internal logic to use the `PlatformFaultDomain` value in the `PSVirtualMachine` object passed to it in the new virtual machine. +* Add `-DataAccessAuthMode` parameter to the following cmdlets: + - New-AzDiskConfig + - New-AzDiskUpdateConfig + - New-AzSnapshotConfig + - New-AzSnapshotUpdateConfig ## Version 4.26.0 * Added `-ImageReferenceId` parameter to following cmdlets: `New-AzVm`, `New-AzVmConfig`, `New-AzVmss`, `Set-AzVmssStorageProfile` diff --git a/src/Compute/Compute/help/New-AzDiskConfig.md b/src/Compute/Compute/help/New-AzDiskConfig.md index de47c57e25fa..226cf345ab59 100644 --- a/src/Compute/Compute/help/New-AzDiskConfig.md +++ b/src/Compute/Compute/help/New-AzDiskConfig.md @@ -24,8 +24,8 @@ New-AzDiskConfig [[-SkuName] ] [-Tier ] [-LogicalSectorSize ] [-KeyEncryptionKey ] [-DiskEncryptionSetId ] [-EncryptionType ] [-DiskAccessId ] [-NetworkAccessPolicy ] [-BurstingEnabled ] [-PublicNetworkAccess ] - [-AcceleratedNetwork ] [-DefaultProfile ] [-WhatIf] [-Confirm] - [] + [-AcceleratedNetwork ] [-DataAccessAuthMode ] [-DefaultProfile ] + [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -128,6 +128,21 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -DataAccessAuthMode +Additional authentication requirements when exporting or uploading to a disk or snapshot. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### -DefaultProfile The credentials, account, tenant, and subscription used for communication with azure. diff --git a/src/Compute/Compute/help/New-AzDiskUpdateConfig.md b/src/Compute/Compute/help/New-AzDiskUpdateConfig.md index 6031a2b6419b..d3fd1e2eb21e 100644 --- a/src/Compute/Compute/help/New-AzDiskUpdateConfig.md +++ b/src/Compute/Compute/help/New-AzDiskUpdateConfig.md @@ -20,7 +20,8 @@ New-AzDiskUpdateConfig [[-SkuName] ] [-Tier ] [-DiskIOPSReadOnly [-EncryptionSettingsEnabled ] [-DiskEncryptionKey ] [-KeyEncryptionKey ] [-DiskEncryptionSetId ] [-EncryptionType ] [-BurstingEnabled ] [-PublicNetworkAccess ] [-AcceleratedNetwork ] - [-DefaultProfile ] [-WhatIf] [-Confirm] [] + [-DataAccessAuthMode ] [-DefaultProfile ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -85,6 +86,21 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -DataAccessAuthMode +Additional authentication requirements when exporting or uploading to a disk or snapshot. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### -DefaultProfile The credentials, account, tenant, and subscription used for communication with azure. diff --git a/src/Compute/Compute/help/New-AzSnapshotConfig.md b/src/Compute/Compute/help/New-AzSnapshotConfig.md index 1d7e11e904d4..753a26add5c5 100644 --- a/src/Compute/Compute/help/New-AzSnapshotConfig.md +++ b/src/Compute/Compute/help/New-AzSnapshotConfig.md @@ -21,7 +21,8 @@ New-AzSnapshotConfig [[-SkuName] ] [[-OsType] ] [[ [-DiskEncryptionKey ] [-KeyEncryptionKey ] [-DiskEncryptionSetId ] [-EncryptionType ] [-DiskAccessId ] [-NetworkAccessPolicy ] [-PublicNetworkAccess ] [-AcceleratedNetwork ] - [-DefaultProfile ] [-WhatIf] [-Confirm] [] + [-DataAccessAuthMode ] [-DefaultProfile ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -86,6 +87,21 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -DataAccessAuthMode +Additional authentication requirements when exporting or uploading to a disk or snapshot. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### -DefaultProfile The credentials, account, tenant, and subscription used for communication with azure. diff --git a/src/Compute/Compute/help/New-AzSnapshotUpdateConfig.md b/src/Compute/Compute/help/New-AzSnapshotUpdateConfig.md index 51ca31d63ee7..eb1d63b51871 100644 --- a/src/Compute/Compute/help/New-AzSnapshotUpdateConfig.md +++ b/src/Compute/Compute/help/New-AzSnapshotUpdateConfig.md @@ -17,7 +17,8 @@ New-AzSnapshotUpdateConfig [[-SkuName] ] [[-OsType] ] [-SupportsHibernation ] [-EncryptionSettingsEnabled ] [-DiskEncryptionKey ] [-KeyEncryptionKey ] [-DiskEncryptionSetId ] [-EncryptionType ] [-PublicNetworkAccess ] - [-DefaultProfile ] [-WhatIf] [-Confirm] [] + [-DataAccessAuthMode ] [-DefaultProfile ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -53,6 +54,21 @@ This command updates an existing snapshot with name 'Snapshot01' in resource gro ## PARAMETERS +### -DataAccessAuthMode +Additional authentication requirements when exporting or uploading to a disk or snapshot. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### -DefaultProfile The credentials, account, tenant, and subscription used for communication with azure. From b436af7a23c21548a0140ba89f4f1d73ed838b22 Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Fri, 27 May 2022 20:09:32 -0500 Subject: [PATCH 09/20] add update for Add-AzVhd DataAccessAuthMode --- .../Compute.AlcWrapper/PSPageBlobClient.cs | 5 +- src/Compute/Compute/ChangeLog.md | 1 + .../Compute/Common/ComputeTokenCredential.cs | 60 +++++++++++++++++++ src/Compute/Compute/Compute.csproj | 2 +- .../StorageServices/AddAzureVhdCommand.cs | 23 ++++++- .../Compute/Sync/Upload/DiskSynchronizer.cs | 5 +- src/Compute/Compute/help/Add-AzVhd.md | 33 +++++----- 7 files changed, 106 insertions(+), 23 deletions(-) create mode 100644 src/Compute/Compute/Common/ComputeTokenCredential.cs diff --git a/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs b/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs index d2bc1bd287e2..aad9348d13f5 100644 --- a/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs +++ b/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs @@ -17,6 +17,7 @@ using System.Text; using Azure.Storage.Blobs.Specialized; using System.IO; +using Azure.Core; namespace Microsoft.Azure.Commands.Compute { @@ -28,9 +29,9 @@ internal PSPageBlobClient(PageBlobClient pageblobclient) { _pageBlobClient = pageblobclient; } - public PSPageBlobClient(Uri blobUri) + public PSPageBlobClient(Uri blobUri, TokenCredential token = null ) { - _pageBlobClient = new PageBlobClient(blobUri, null); + _pageBlobClient = token == null ? new PageBlobClient(blobUri, null) : new PageBlobClient(blobUri, token); } public Uri Uri { get { return _pageBlobClient.Uri; } } diff --git a/src/Compute/Compute/ChangeLog.md b/src/Compute/Compute/ChangeLog.md index b9ac7bba315c..f29cb4e82cb7 100644 --- a/src/Compute/Compute/ChangeLog.md +++ b/src/Compute/Compute/ChangeLog.md @@ -20,6 +20,7 @@ --> ## Upcoming Release +* Add `-DataAccessAuthMode` parameter to Add-AzVhd DirectUploadToManagedDisk parameter set. * Edited `New-AzVm` cmdlet internal logic to use the `PlatformFaultDomain` value in the `PSVirtualMachine` object passed to it in the new virtual machine. * Add `-DataAccessAuthMode` parameter to the following cmdlets: - New-AzDiskConfig diff --git a/src/Compute/Compute/Common/ComputeTokenCredential.cs b/src/Compute/Compute/Common/ComputeTokenCredential.cs new file mode 100644 index 000000000000..1ebb57ce0611 --- /dev/null +++ b/src/Compute/Compute/Common/ComputeTokenCredential.cs @@ -0,0 +1,60 @@ +using Azure.Core; +using System; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Azure.Commands.Common.Authentication; +using Microsoft.Azure.Commands.Common.Authentication.Abstractions; + +namespace Microsoft.Azure.Commands.Compute.Common +{ + public class ComputeTokenCredential : TokenCredential + { + public IAccessToken accessToken { get; set; } + public ComputeTokenCredential(IAzureContext DefaultContext, string customAudience) + { + + if (DefaultContext == null || DefaultContext.Account == null) + { + throw new InvalidOperationException(); + } + + IAccessToken accessToken1 = AzureSession.Instance.AuthenticationFactory.Authenticate( + DefaultContext.Account, + EnsureCustomAudienceSet(DefaultContext.Environment, customAudience), + DefaultContext.Tenant.Id, + null, + ShowDialog.Never, + null, + customAudience); + + accessToken = accessToken1; + } + + public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken) + { + AccessToken token; + accessToken.AuthorizeRequest((tokenType, tokenValue) => + { + token = new AccessToken(tokenValue, DateTimeOffset.UtcNow); + }); + return token; + } + + public override ValueTask GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken) + { + return new ValueTask(this.GetToken(requestContext, cancellationToken)); + } + + private IAzureEnvironment EnsureCustomAudienceSet(IAzureEnvironment environment, string customAudience) + { + if (environment != null) + { + if (!environment.IsPropertySet(customAudience)) + { + environment.SetProperty(customAudience, customAudience); + } + } + return environment; + } + } +} \ No newline at end of file diff --git a/src/Compute/Compute/Compute.csproj b/src/Compute/Compute/Compute.csproj index 7f8c888ec5a0..fb6b7470518d 100644 --- a/src/Compute/Compute/Compute.csproj +++ b/src/Compute/Compute/Compute.csproj @@ -1,4 +1,4 @@ - + Compute diff --git a/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs b/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs index 9fb4e53b4aab..51e056766032 100644 --- a/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs +++ b/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs @@ -36,6 +36,8 @@ using Microsoft.Samples.HyperV.Storage; using Microsoft.Samples.HyperV.Common; using System.Threading; +using Azure.Core; +using Microsoft.Azure.Commands.Compute.Common; namespace Microsoft.Azure.Commands.Compute.StorageServices @@ -178,6 +180,14 @@ public class AddAzureVhdCommand : ComputeClientBaseCmdlet HelpMessage = "Skips the resizing of VHD")] public SwitchParameter SkipResizing { get; set; } + [Parameter( + Mandatory = false, + ValueFromPipelineByPropertyName = true, + ParameterSetName = DirectUploadToManagedDiskSet, + HelpMessage = "Additional authentication requirements when exporting or uploading to a disk or snapshot. Possible options are: \"AzureActiveDirectory\" and \"None\".")] + [PSArgumentCompleter("AzureActiveDirectory", "None")] + public string DataAccessAuthMode { get; set; } + [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] public SwitchParameter AsJob { get; set; } @@ -228,13 +238,19 @@ public override void ExecuteCmdlet() // 3-4: UPLOAD WriteVerbose("Preparing for Upload"); - PSPageBlobClient managedDisk = new PSPageBlobClient(sasUri); + ComputeTokenCredential token = null; + if (this.DataAccessAuthMode == "AzureActiveDirectory") + { + // get token + token = new ComputeTokenCredential(DefaultContext, "https://disk.compute.azure.com/"); + } + PSPageBlobClient managedDisk = new PSPageBlobClient(sasUri, token); DiskUploadCreator diskUploadCreator = new DiskUploadCreator(); var uploadContext = diskUploadCreator.Create(this.LocalFilePath, managedDisk, false); var synchronizer = new DiskSynchronizer(uploadContext, this.NumberOfUploaderThreads ?? DefaultNumberOfUploaderThreads); WriteVerbose("Uploading"); - if (synchronizer.Synchronize()) + if (synchronizer.Synchronize(token)) { var result = new VhdUploadContext { LocalFilePath = this.LocalFilePath, DestinationUri = sasUri }; WriteObject(result); @@ -378,7 +394,8 @@ private PSDisk CreateDiskConfig() EncryptionSettingsCollection = null, Encryption = null, NetworkAccessPolicy = null, - DiskAccessId = null + DiskAccessId = null, + DataAccessAuthMode = this.IsParameterBound(c => c.DataAccessAuthMode) ? this.DataAccessAuthMode : null }; return vDisk; } diff --git a/src/Compute/Compute/Sync/Upload/DiskSynchronizer.cs b/src/Compute/Compute/Sync/Upload/DiskSynchronizer.cs index 11515052cef9..9242c3d96b12 100644 --- a/src/Compute/Compute/Sync/Upload/DiskSynchronizer.cs +++ b/src/Compute/Compute/Sync/Upload/DiskSynchronizer.cs @@ -23,6 +23,7 @@ using Microsoft.WindowsAzure.Commands.Sync.Upload; using Microsoft.WindowsAzure.Commands.Sync; using System.Threading.Tasks; +using Microsoft.Azure.Commands.Compute.Common; namespace Microsoft.Azure.Commands.Compute.Sync.Upload { @@ -47,7 +48,7 @@ public DiskSynchronizer(UploadContextDisk context, int maxParallelism) this.maxParallelism = maxParallelism; } - public bool Synchronize() + public bool Synchronize(ComputeTokenCredential token) { var uploadStatus = new ProgressStatus(alreadyUploadedData, alreadyUploadedData + dataToUpload, new ComputeStats()); @@ -57,7 +58,7 @@ public bool Synchronize() Task task = Task.Factory.StartNew(() => { return Threading.Parallel.ForEach(dataWithRanges, - () => new PSPageBlobClient(pageBlob.Uri), + () => new PSPageBlobClient(pageBlob.Uri, token), (dwr, b) => { using (dwr) diff --git a/src/Compute/Compute/help/Add-AzVhd.md b/src/Compute/Compute/help/Add-AzVhd.md index 8ecd69323e41..1371fe26593b 100644 --- a/src/Compute/Compute/help/Add-AzVhd.md +++ b/src/Compute/Compute/help/Add-AzVhd.md @@ -24,8 +24,8 @@ Add-AzVhd [-ResourceGroupName] [-Destination] [-LocalFilePath] [-LocalFilePath] -DiskName [-Location] [-DiskSku ] [-DiskZone ] [-DiskHyperVGeneration ] - [-DiskOsType ] [[-NumberOfUploaderThreads] ] [-AsJob] - [-DefaultProfile ] [] + [-DiskOsType ] [[-NumberOfUploaderThreads] ] [-DataAccessAuthMode ] + [-AsJob] [-DefaultProfile ] [] ``` ## DESCRIPTION @@ -127,6 +127,21 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` +### -DataAccessAuthMode +Additional authentication requirements when exporting or uploading to a disk or snapshot. Possible options are: "AzureActiveDirectory" and "None". + +```yaml +Type: System.String +Parameter Sets: DirectUploadToManagedDiskSet +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + ### -DefaultProfile The credentials, account, tenant, and subscription used for communication with azure. @@ -299,19 +314,7 @@ Specifies the name of the resource group of the virtual machine. ```yaml Type: System.String -Parameter Sets: DefaultParameterSet -Aliases: - -Required: False -Position: 0 -Default value: None -Accept pipeline input: True (ByPropertyName) -Accept wildcard characters: False -``` - -```yaml -Type: System.String -Parameter Sets: DirectUploadToManagedDiskSet +Parameter Sets: (All) Aliases: Required: True From 16257dd8ff45ec6e01a85ab88c3319cfdbb73e65 Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Tue, 31 May 2022 18:09:30 -0500 Subject: [PATCH 10/20] add veryEarly's comments --- .../Compute.AlcWrapper/PSPageBlobClient.cs | 4 ++-- .../Compute/Common/ComputeTokenCredential.cs | 19 ++++++++++++++++--- .../StorageServices/AddAzureVhdCommand.cs | 8 ++++---- .../Compute/Sync/Upload/DiskSynchronizer.cs | 4 ++-- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs b/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs index aad9348d13f5..c50020bda175 100644 --- a/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs +++ b/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs @@ -29,9 +29,9 @@ internal PSPageBlobClient(PageBlobClient pageblobclient) { _pageBlobClient = pageblobclient; } - public PSPageBlobClient(Uri blobUri, TokenCredential token = null ) + public PSPageBlobClient(Uri blobUri, TokenCredential tokenCredential = null ) { - _pageBlobClient = token == null ? new PageBlobClient(blobUri, null) : new PageBlobClient(blobUri, token); + _pageBlobClient = tokenCredential == null ? new PageBlobClient(blobUri, null) : new PageBlobClient(blobUri, tokenCredential); } public Uri Uri { get { return _pageBlobClient.Uri; } } diff --git a/src/Compute/Compute/Common/ComputeTokenCredential.cs b/src/Compute/Compute/Common/ComputeTokenCredential.cs index 1ebb57ce0611..bc9fa12fb084 100644 --- a/src/Compute/Compute/Common/ComputeTokenCredential.cs +++ b/src/Compute/Compute/Common/ComputeTokenCredential.cs @@ -1,4 +1,18 @@ -using Azure.Core; +// ---------------------------------------------------------------------------------- +// +// 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 Azure.Core; using System; using System.Threading; using System.Threading.Tasks; @@ -18,7 +32,7 @@ public ComputeTokenCredential(IAzureContext DefaultContext, string customAudienc throw new InvalidOperationException(); } - IAccessToken accessToken1 = AzureSession.Instance.AuthenticationFactory.Authenticate( + accessToken = AzureSession.Instance.AuthenticationFactory.Authenticate( DefaultContext.Account, EnsureCustomAudienceSet(DefaultContext.Environment, customAudience), DefaultContext.Tenant.Id, @@ -27,7 +41,6 @@ public ComputeTokenCredential(IAzureContext DefaultContext, string customAudienc null, customAudience); - accessToken = accessToken1; } public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken) diff --git a/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs b/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs index 51e056766032..b8c3dea529e8 100644 --- a/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs +++ b/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs @@ -238,19 +238,19 @@ public override void ExecuteCmdlet() // 3-4: UPLOAD WriteVerbose("Preparing for Upload"); - ComputeTokenCredential token = null; + ComputeTokenCredential tokenCredential = null; if (this.DataAccessAuthMode == "AzureActiveDirectory") { // get token - token = new ComputeTokenCredential(DefaultContext, "https://disk.compute.azure.com/"); + tokenCredential = new ComputeTokenCredential(DefaultContext, "https://disk.compute.azure.com/"); } - PSPageBlobClient managedDisk = new PSPageBlobClient(sasUri, token); + PSPageBlobClient managedDisk = new PSPageBlobClient(sasUri, tokenCredential); DiskUploadCreator diskUploadCreator = new DiskUploadCreator(); var uploadContext = diskUploadCreator.Create(this.LocalFilePath, managedDisk, false); var synchronizer = new DiskSynchronizer(uploadContext, this.NumberOfUploaderThreads ?? DefaultNumberOfUploaderThreads); WriteVerbose("Uploading"); - if (synchronizer.Synchronize(token)) + if (synchronizer.Synchronize(tokenCredential)) { var result = new VhdUploadContext { LocalFilePath = this.LocalFilePath, DestinationUri = sasUri }; WriteObject(result); diff --git a/src/Compute/Compute/Sync/Upload/DiskSynchronizer.cs b/src/Compute/Compute/Sync/Upload/DiskSynchronizer.cs index 9242c3d96b12..69a169436b4d 100644 --- a/src/Compute/Compute/Sync/Upload/DiskSynchronizer.cs +++ b/src/Compute/Compute/Sync/Upload/DiskSynchronizer.cs @@ -48,7 +48,7 @@ public DiskSynchronizer(UploadContextDisk context, int maxParallelism) this.maxParallelism = maxParallelism; } - public bool Synchronize(ComputeTokenCredential token) + public bool Synchronize(ComputeTokenCredential tokenCredential) { var uploadStatus = new ProgressStatus(alreadyUploadedData, alreadyUploadedData + dataToUpload, new ComputeStats()); @@ -58,7 +58,7 @@ public bool Synchronize(ComputeTokenCredential token) Task task = Task.Factory.StartNew(() => { return Threading.Parallel.ForEach(dataWithRanges, - () => new PSPageBlobClient(pageBlob.Uri, token), + () => new PSPageBlobClient(pageBlob.Uri, tokenCredential), (dwr, b) => { using (dwr) From 1b0281626be535907a652a52412f75752f481f80 Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Thu, 9 Jun 2022 12:10:13 -0500 Subject: [PATCH 11/20] update --- src/Compute/Compute/Common/ComputeTokenCredential.cs | 10 +++++----- .../Compute/StorageServices/AddAzureVhdCommand.cs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Compute/Compute/Common/ComputeTokenCredential.cs b/src/Compute/Compute/Common/ComputeTokenCredential.cs index bc9fa12fb084..6b53300a6b33 100644 --- a/src/Compute/Compute/Common/ComputeTokenCredential.cs +++ b/src/Compute/Compute/Common/ComputeTokenCredential.cs @@ -24,18 +24,18 @@ namespace Microsoft.Azure.Commands.Compute.Common public class ComputeTokenCredential : TokenCredential { public IAccessToken accessToken { get; set; } - public ComputeTokenCredential(IAzureContext DefaultContext, string customAudience) + public ComputeTokenCredential(IAzureContext Context, string customAudience) { - if (DefaultContext == null || DefaultContext.Account == null) + if (Context == null || Context.Account == null) { throw new InvalidOperationException(); } accessToken = AzureSession.Instance.AuthenticationFactory.Authenticate( - DefaultContext.Account, - EnsureCustomAudienceSet(DefaultContext.Environment, customAudience), - DefaultContext.Tenant.Id, + Context.Account, + EnsureCustomAudienceSet(Context.Environment, customAudience), + Context.Tenant.Id, null, ShowDialog.Never, null, diff --git a/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs b/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs index b8c3dea529e8..ea2b08e7116b 100644 --- a/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs +++ b/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs @@ -185,7 +185,7 @@ public class AddAzureVhdCommand : ComputeClientBaseCmdlet ValueFromPipelineByPropertyName = true, ParameterSetName = DirectUploadToManagedDiskSet, HelpMessage = "Additional authentication requirements when exporting or uploading to a disk or snapshot. Possible options are: \"AzureActiveDirectory\" and \"None\".")] - [PSArgumentCompleter("AzureActiveDirectory", "None")] + [PSArgumentCompleter("AzureActiveDirectory")] public string DataAccessAuthMode { get; set; } [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] @@ -242,7 +242,7 @@ public override void ExecuteCmdlet() if (this.DataAccessAuthMode == "AzureActiveDirectory") { // get token - tokenCredential = new ComputeTokenCredential(DefaultContext, "https://disk.compute.azure.com/"); + tokenCredential = new ComputeTokenCredential(DefaultContext, "https://disk.azure.com/"); } PSPageBlobClient managedDisk = new PSPageBlobClient(sasUri, tokenCredential); DiskUploadCreator diskUploadCreator = new DiskUploadCreator(); From fe517ac4f1a6abe700ad93ee866bfbc97e9677d3 Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Thu, 9 Jun 2022 12:20:57 -0500 Subject: [PATCH 12/20] update sdk package to 55.0.0 --- src/Compute/Compute.Test/Compute.Test.csproj | 2 +- src/Compute/Compute/Compute.csproj | 4 ++-- src/Network/Network.Test/Network.Test.csproj | 2 +- .../RecoveryServices.Backup.Test.csproj | 2 +- .../RecoveryServices.SiteRecovery.Test.csproj | 2 +- src/Security/Security.Test/Security.Test.csproj | 2 +- .../SqlVirtualMachine.Test/SqlVirtualMachine.Test.csproj | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Compute/Compute.Test/Compute.Test.csproj b/src/Compute/Compute.Test/Compute.Test.csproj index 7ca0751bc13d..681347dedd4b 100644 --- a/src/Compute/Compute.Test/Compute.Test.csproj +++ b/src/Compute/Compute.Test/Compute.Test.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/Compute/Compute/Compute.csproj b/src/Compute/Compute/Compute.csproj index fb6b7470518d..19ec95f1cce6 100644 --- a/src/Compute/Compute/Compute.csproj +++ b/src/Compute/Compute/Compute.csproj @@ -1,4 +1,4 @@ - + Compute @@ -14,7 +14,7 @@ - + diff --git a/src/Network/Network.Test/Network.Test.csproj b/src/Network/Network.Test/Network.Test.csproj index 692cda21fc4c..c020c31ddb81 100644 --- a/src/Network/Network.Test/Network.Test.csproj +++ b/src/Network/Network.Test/Network.Test.csproj @@ -18,7 +18,7 @@ - + diff --git a/src/RecoveryServices/RecoveryServices.Backup.Test/RecoveryServices.Backup.Test.csproj b/src/RecoveryServices/RecoveryServices.Backup.Test/RecoveryServices.Backup.Test.csproj index a435a1f0c779..f93a690c1a79 100644 --- a/src/RecoveryServices/RecoveryServices.Backup.Test/RecoveryServices.Backup.Test.csproj +++ b/src/RecoveryServices/RecoveryServices.Backup.Test/RecoveryServices.Backup.Test.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/RecoveryServices/RecoveryServices.SiteRecovery.Test/RecoveryServices.SiteRecovery.Test.csproj b/src/RecoveryServices/RecoveryServices.SiteRecovery.Test/RecoveryServices.SiteRecovery.Test.csproj index 51e477d595bb..5338e6668c83 100644 --- a/src/RecoveryServices/RecoveryServices.SiteRecovery.Test/RecoveryServices.SiteRecovery.Test.csproj +++ b/src/RecoveryServices/RecoveryServices.SiteRecovery.Test/RecoveryServices.SiteRecovery.Test.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Security/Security.Test/Security.Test.csproj b/src/Security/Security.Test/Security.Test.csproj index 368363504036..b2d6d99795ef 100644 --- a/src/Security/Security.Test/Security.Test.csproj +++ b/src/Security/Security.Test/Security.Test.csproj @@ -42,7 +42,7 @@ Always - + \ No newline at end of file diff --git a/src/SqlVirtualMachine/SqlVirtualMachine.Test/SqlVirtualMachine.Test.csproj b/src/SqlVirtualMachine/SqlVirtualMachine.Test/SqlVirtualMachine.Test.csproj index 190cc9c5cddb..85c2d00f063e 100644 --- a/src/SqlVirtualMachine/SqlVirtualMachine.Test/SqlVirtualMachine.Test.csproj +++ b/src/SqlVirtualMachine/SqlVirtualMachine.Test/SqlVirtualMachine.Test.csproj @@ -15,7 +15,7 @@ - + From 4692130f4e12ffcc3fc84eeb5fe87028d1dc4991 Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Thu, 9 Jun 2022 12:37:46 -0500 Subject: [PATCH 13/20] add -enableUltraSSD to New-AzHostGroup --- src/Compute/Compute/ChangeLog.md | 1 + .../DedicatedHostGroupCreateOrUpdateMethod.cs | 14 +++++ src/Compute/Compute/help/New-AzHostGroup.md | 63 ++++++++++++------- 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/Compute/Compute/ChangeLog.md b/src/Compute/Compute/ChangeLog.md index 8735911ac795..8c37dc7b43fe 100644 --- a/src/Compute/Compute/ChangeLog.md +++ b/src/Compute/Compute/ChangeLog.md @@ -21,6 +21,7 @@ --> ## Upcoming Release * Add `-DataAccessAuthMode` parameter to Add-AzVhd DirectUploadToManagedDisk parameter set. +* Add `-EnabldUltraSSD` parameter to New-AzHostGroup. ## Version 4.27.0 * Edited `New-AzVm` cmdlet internal logic to use the `PlatformFaultDomain` value in the `PSVirtualMachine` object passed to it in the new virtual machine. diff --git a/src/Compute/Compute/Generated/DedicatedHostGroup/DedicatedHostGroupCreateOrUpdateMethod.cs b/src/Compute/Compute/Generated/DedicatedHostGroup/DedicatedHostGroupCreateOrUpdateMethod.cs index 526385248788..53710391eeb8 100644 --- a/src/Compute/Compute/Generated/DedicatedHostGroup/DedicatedHostGroupCreateOrUpdateMethod.cs +++ b/src/Compute/Compute/Generated/DedicatedHostGroup/DedicatedHostGroupCreateOrUpdateMethod.cs @@ -63,6 +63,15 @@ public override void ExecuteCmdlet() parameters.Tags = this.Tag.Cast().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value); } + if (this.EnableUltraSSD.IsPresent) + { + if (parameters.AdditionalCapabilities == null) + { + parameters.AdditionalCapabilities = new DedicatedHostGroupPropertiesAdditionalCapabilities(); + } + parameters.AdditionalCapabilities.UltraSSDEnabled = true; + } + var result = DedicatedHostGroupsClient.CreateOrUpdate(resourceGroupName, hostGroupName, parameters); var psObject = new PSHostGroup(); ComputeAutomationAutoMapperProfile.Mapper.Map(result, psObject); @@ -109,6 +118,11 @@ public override void ExecuteCmdlet() Mandatory = false)] public Hashtable Tag { get; set; } + [Parameter( + Mandatory = false, + HelpMessage = "The flag that enables or disables a capability to have UltraSSD Enabled Virtual Machines on Dedicated Hosts of the Dedicated Host Group. For the Virtual Machines to be UltraSSD Enabled, UltraSSDEnabled flag for the resource needs to be set true as well. Please refer to https://docs.microsoft.com/en-us/azure/virtual-machines/disks-enable-ultra-ssd for more details on Ultra SSD feature. The ultraSSDEnabled setting can only be enabled for Host Groups that are created as zonal.")] + public SwitchParameter EnableUltraSSD { get; set; } + [Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")] public SwitchParameter AsJob { get; set; } } diff --git a/src/Compute/Compute/help/New-AzHostGroup.md b/src/Compute/Compute/help/New-AzHostGroup.md index 213777cf2dac..ab94eecc1662 100644 --- a/src/Compute/Compute/help/New-AzHostGroup.md +++ b/src/Compute/Compute/help/New-AzHostGroup.md @@ -14,8 +14,9 @@ Creates a host group. ``` New-AzHostGroup [-ResourceGroupName] [-Name] [-Location] - -PlatformFaultDomain [-Zone ] [-SupportAutomaticPlacement ] [-Tag ] [-AsJob] - [-DefaultProfile ] [-WhatIf] [-Confirm] [] + -PlatformFaultDomain [-Zone ] [-SupportAutomaticPlacement ] [-Tag ] + [-EnableUltraSSD] [-AsJob] [-DefaultProfile ] [-WhatIf] [-Confirm] + [] ``` ## DESCRIPTION @@ -47,7 +48,7 @@ This command creates a host group in the given location and zone. Run cmdlet in the background ```yaml -Type: System.Management.Automation.SwitchParameter +Type: SwitchParameter Parameter Sets: (All) Aliases: @@ -62,7 +63,7 @@ Accept wildcard characters: False The credentials, account, tenant, and subscription used for communication with Azure. ```yaml -Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer +Type: IAzureContextContainer Parameter Sets: (All) Aliases: AzContext, AzureRmContext, AzureCredential @@ -73,11 +74,26 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -EnableUltraSSD +The flag that enables or disables a capability to have UltraSSD Enabled Virtual Machines on Dedicated Hosts of the Dedicated Host Group. For the Virtual Machines to be UltraSSD Enabled, UltraSSDEnabled flag for the resource needs to be set true as well. Please refer to https://docs.microsoft.com/en-us/azure/virtual-machines/disks-enable-ultra-ssd for more details on Ultra SSD feature. The ultraSSDEnabled setting can only be enabled for Host Groups that are created as zonal. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Location Specifies location. ```yaml -Type: System.String +Type: String Parameter Sets: (All) Aliases: @@ -92,7 +108,7 @@ Accept wildcard characters: False Specifies the name of the host group. ```yaml -Type: System.String +Type: String Parameter Sets: (All) Aliases: HostGroupName @@ -107,7 +123,7 @@ Accept wildcard characters: False Specifies the number of fault domains that the host group can span. The minimum value is 1 and the maximum value is 3. ```yaml -Type: System.Int32 +Type: Int32 Parameter Sets: (All) Aliases: @@ -122,7 +138,7 @@ Accept wildcard characters: False The name of the resource group. ```yaml -Type: System.String +Type: String Parameter Sets: (All) Aliases: @@ -133,26 +149,28 @@ Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ``` -### -Tag -Specifies Tags +### -SupportAutomaticPlacement +Specifies if HostGroup will enable automatic placement of vm's. +Automatic placement means these VMs are placed on dedicated hosts, chosen by Azure, under the dedicated host group. +If not specified, default value will be false. ```yaml -Type: System.Collections.Hashtable +Type: Boolean Parameter Sets: (All) Aliases: Required: False Position: Named -Default value: None +Default value: True Accept pipeline input: False Accept wildcard characters: False ``` -### -Zone -Specifies Zones of the host group. +### -Tag +Specifies Tags ```yaml -Type: System.String[] +Type: Hashtable Parameter Sets: (All) Aliases: @@ -163,29 +181,26 @@ Accept pipeline input: False Accept wildcard characters: False ``` -### -SupportAutomaticPlacement -Specifies if HostGroup will enable automatic placement of vm's. -Automatic placement means these VMs are placed on dedicated hosts, chosen by Azure, under the dedicated host group. -If not specified, default value will be false. +### -Zone +Specifies Zones of the host group. ```yaml -Type: bool +Type: String[] Parameter Sets: (All) Aliases: Required: False Position: Named -Default value: True +Default value: None Accept pipeline input: False Accept wildcard characters: False ``` - ### -Confirm Prompts you for confirmation before running the cmdlet. ```yaml -Type: System.Management.Automation.SwitchParameter +Type: SwitchParameter Parameter Sets: (All) Aliases: cf @@ -201,7 +216,7 @@ Shows what would happen if the cmdlet runs. The cmdlet is not run. ```yaml -Type: System.Management.Automation.SwitchParameter +Type: SwitchParameter Parameter Sets: (All) Aliases: wi From d52ccc78230faa3a02dbfdcc17779506cbfa4275 Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Fri, 10 Jun 2022 13:43:20 -0500 Subject: [PATCH 14/20] update token. removing uneccesary "authorizerequest" --- src/Compute/Compute/Common/ComputeTokenCredential.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Compute/Compute/Common/ComputeTokenCredential.cs b/src/Compute/Compute/Common/ComputeTokenCredential.cs index 6b53300a6b33..679119e2e5d9 100644 --- a/src/Compute/Compute/Common/ComputeTokenCredential.cs +++ b/src/Compute/Compute/Common/ComputeTokenCredential.cs @@ -45,11 +45,11 @@ public ComputeTokenCredential(IAzureContext Context, string customAudience) public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken) { - AccessToken token; - accessToken.AuthorizeRequest((tokenType, tokenValue) => - { - token = new AccessToken(tokenValue, DateTimeOffset.UtcNow); - }); + AccessToken token = new AccessToken(accessToken.AccessToken, DateTimeOffset.UtcNow); + //accessToken.AuthorizeRequest((tokenType, tokenValue) => + //{ + // token = new AccessToken(tokenValue, DateTimeOffset.UtcNow); + //}); return token; } From f3ded60b3fe193f6f755ac77ae1e00e958a3b9ea Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Mon, 13 Jun 2022 12:02:16 -0500 Subject: [PATCH 15/20] suppress nonbreaking change --- .../Exceptions/Az.Compute/BreakingChangeIssues.csv | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tools/StaticAnalysis/Exceptions/Az.Compute/BreakingChangeIssues.csv diff --git a/tools/StaticAnalysis/Exceptions/Az.Compute/BreakingChangeIssues.csv b/tools/StaticAnalysis/Exceptions/Az.Compute/BreakingChangeIssues.csv new file mode 100644 index 000000000000..37cb900f2665 --- /dev/null +++ b/tools/StaticAnalysis/Exceptions/Az.Compute/BreakingChangeIssues.csv @@ -0,0 +1,2 @@ +"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation" +"Az.Compute","Microsoft.Azure.Commands.Compute.Automation.GetAzureRestorePoint","Get-AzRestorePoint","0","3000","The type of property 'ReplicationStatus' of type 'Microsoft.Azure.Management.Compute.Models.DiskRestorePointInstanceView' has changed from 'System.Object' to 'Microsoft.Azure.Management.Compute.Models.DiskRestorePointReplicationStatus'.","Change the type of property 'ReplicationStatus' back to 'System.Object'." \ No newline at end of file From f745a5b13e741f07b3581298541f1a3e34b40b43 Mon Sep 17 00:00:00 2001 From: Yabo Hu Date: Wed, 15 Jun 2022 16:33:21 +0800 Subject: [PATCH 16/20] Update ChangeLog.md --- src/Compute/Compute/ChangeLog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compute/Compute/ChangeLog.md b/src/Compute/Compute/ChangeLog.md index 8c37dc7b43fe..7c0cf612cc05 100644 --- a/src/Compute/Compute/ChangeLog.md +++ b/src/Compute/Compute/ChangeLog.md @@ -20,8 +20,8 @@ --> ## Upcoming Release -* Add `-DataAccessAuthMode` parameter to Add-AzVhd DirectUploadToManagedDisk parameter set. -* Add `-EnabldUltraSSD` parameter to New-AzHostGroup. +* Added `-DataAccessAuthMode` parameter to Add-AzVhd DirectUploadToManagedDisk parameter set. +* Added `-EnabldUltraSSD` parameter to New-AzHostGroup. ## Version 4.27.0 * Edited `New-AzVm` cmdlet internal logic to use the `PlatformFaultDomain` value in the `PSVirtualMachine` object passed to it in the new virtual machine. From 40c8941a720a58ab45a7a9f9eee5d27790af457a Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Wed, 15 Jun 2022 13:26:10 -0500 Subject: [PATCH 17/20] a --- src/Compute/Compute/Compute.Automation.generated.format.ps1xml | 2 +- .../Compute/Generated/ResourceSku/ResourceSkuListMethod.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compute/Compute/Compute.Automation.generated.format.ps1xml b/src/Compute/Compute/Compute.Automation.generated.format.ps1xml index 3a64904ad5d1..8ee644823663 100644 --- a/src/Compute/Compute/Compute.Automation.generated.format.ps1xml +++ b/src/Compute/Compute/Compute.Automation.generated.format.ps1xml @@ -485,7 +485,7 @@ Right - + Right diff --git a/src/Compute/Compute/Generated/ResourceSku/ResourceSkuListMethod.cs b/src/Compute/Compute/Generated/ResourceSku/ResourceSkuListMethod.cs index 14b44c6af412..d378e0f95f8e 100644 --- a/src/Compute/Compute/Generated/ResourceSku/ResourceSkuListMethod.cs +++ b/src/Compute/Compute/Generated/ResourceSku/ResourceSkuListMethod.cs @@ -33,7 +33,7 @@ namespace Microsoft.Azure.Commands.Compute.Automation { [Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ComputeResourceSku", DefaultParameterSetName = "DefaultParameter")] - [OutputType(typeof(PSResourceSku))] + [OutputType(typeof(List))] public partial class GetAzureRmComputeResourceSku : ComputeAutomationBaseCmdlet { [Parameter( From eef7f6330b03c7741655ffc2aff11f34d22d71dc Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Thu, 16 Jun 2022 11:19:10 -0500 Subject: [PATCH 18/20] update to resolve failing tests. small object updated from swagger to address bug --- .../Compute/VirtualMachine/Operation/NewAzureVMCommand.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compute/Compute/VirtualMachine/Operation/NewAzureVMCommand.cs b/src/Compute/Compute/VirtualMachine/Operation/NewAzureVMCommand.cs index 77c2ccc01717..f81b684fc789 100644 --- a/src/Compute/Compute/VirtualMachine/Operation/NewAzureVMCommand.cs +++ b/src/Compute/Compute/VirtualMachine/Operation/NewAzureVMCommand.cs @@ -882,9 +882,9 @@ public void DefaultExecuteCmdlet() AutoUpgradeMinorVersion = true, }; - typeof(CM.Resource).GetRuntimeProperty("Name") + typeof(CM.ResourceWithOptionalLocation).GetRuntimeProperty("Name") .SetValue(extensionParameters, VirtualMachineBGInfoExtensionContext.ExtensionDefaultName); - typeof(CM.Resource).GetRuntimeProperty("Type") + typeof(CM.ResourceWithOptionalLocation).GetRuntimeProperty("Type") .SetValue(extensionParameters, VirtualMachineExtensionType); var op2 = ComputeClient.ComputeManagementClient.VirtualMachineExtensions.CreateOrUpdateWithHttpMessagesAsync( From 4f1cb1ee2af2528a0d6908a88e7e12b77bed770d Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Thu, 16 Jun 2022 12:35:27 -0500 Subject: [PATCH 19/20] Update Compute.Automation.generated.format.ps1xml --- src/Compute/Compute/Compute.Automation.generated.format.ps1xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compute/Compute/Compute.Automation.generated.format.ps1xml b/src/Compute/Compute/Compute.Automation.generated.format.ps1xml index 8ee644823663..3a64904ad5d1 100644 --- a/src/Compute/Compute/Compute.Automation.generated.format.ps1xml +++ b/src/Compute/Compute/Compute.Automation.generated.format.ps1xml @@ -485,7 +485,7 @@ Right - + Right From 1381282e2e03e80174ec75a973c0d673ffb272e7 Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Thu, 16 Jun 2022 12:36:00 -0500 Subject: [PATCH 20/20] Update ResourceSkuListMethod.cs --- .../Compute/Generated/ResourceSku/ResourceSkuListMethod.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compute/Compute/Generated/ResourceSku/ResourceSkuListMethod.cs b/src/Compute/Compute/Generated/ResourceSku/ResourceSkuListMethod.cs index d378e0f95f8e..14b44c6af412 100644 --- a/src/Compute/Compute/Generated/ResourceSku/ResourceSkuListMethod.cs +++ b/src/Compute/Compute/Generated/ResourceSku/ResourceSkuListMethod.cs @@ -33,7 +33,7 @@ namespace Microsoft.Azure.Commands.Compute.Automation { [Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ComputeResourceSku", DefaultParameterSetName = "DefaultParameter")] - [OutputType(typeof(List))] + [OutputType(typeof(PSResourceSku))] public partial class GetAzureRmComputeResourceSku : ComputeAutomationBaseCmdlet { [Parameter(