diff --git a/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs b/src/Compute/Compute.AlcWrapper/PSPageBlobClient.cs index d2bc1bd287e2..c50020bda175 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 tokenCredential = null ) { - _pageBlobClient = new PageBlobClient(blobUri, null); + _pageBlobClient = tokenCredential == null ? new PageBlobClient(blobUri, null) : new PageBlobClient(blobUri, tokenCredential); } public Uri Uri { get { return _pageBlobClient.Uri; } } 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/ChangeLog.md b/src/Compute/Compute/ChangeLog.md index 18fc53893c27..7c0cf612cc05 100644 --- a/src/Compute/Compute/ChangeLog.md +++ b/src/Compute/Compute/ChangeLog.md @@ -20,6 +20,8 @@ --> ## Upcoming Release +* 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. diff --git a/src/Compute/Compute/Common/ComputeTokenCredential.cs b/src/Compute/Compute/Common/ComputeTokenCredential.cs new file mode 100644 index 000000000000..679119e2e5d9 --- /dev/null +++ b/src/Compute/Compute/Common/ComputeTokenCredential.cs @@ -0,0 +1,73 @@ +// ---------------------------------------------------------------------------------- +// +// 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; +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 Context, string customAudience) + { + + if (Context == null || Context.Account == null) + { + throw new InvalidOperationException(); + } + + accessToken = AzureSession.Instance.AuthenticationFactory.Authenticate( + Context.Account, + EnsureCustomAudienceSet(Context.Environment, customAudience), + Context.Tenant.Id, + null, + ShowDialog.Never, + null, + customAudience); + + } + + public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken) + { + AccessToken token = new AccessToken(accessToken.AccessToken, DateTimeOffset.UtcNow); + //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..19ec95f1cce6 100644 --- a/src/Compute/Compute/Compute.csproj +++ b/src/Compute/Compute/Compute.csproj @@ -14,7 +14,7 @@ - + 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/StorageServices/AddAzureVhdCommand.cs b/src/Compute/Compute/StorageServices/AddAzureVhdCommand.cs index 9fb4e53b4aab..ea2b08e7116b 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")] + 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 tokenCredential = null; + if (this.DataAccessAuthMode == "AzureActiveDirectory") + { + // get token + tokenCredential = new ComputeTokenCredential(DefaultContext, "https://disk.azure.com/"); + } + 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()) + if (synchronizer.Synchronize(tokenCredential)) { 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..69a169436b4d 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 tokenCredential) { 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, tokenCredential), (dwr, b) => { using (dwr) 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( 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 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 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 @@ - + 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