From dba029cafaba65530358ab049a04818f07d8109a Mon Sep 17 00:00:00 2001 From: Sergey Shandar Date: Wed, 29 Nov 2017 11:50:10 -0800 Subject: [PATCH] imagename case insensetive --- .../Network/VirtualNetworkStrategy.cs | 1 - .../Common/ComputeClientBaseCmdlet.cs | 5 +---- .../VirtualMachine/Operation/NewAzureVMCommand.cs | 12 ++++++++---- .../VirtualMachine/VirtualMachineBaseCmdlet.cs | 9 ++------- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/ResourceManager/Common/Commands.Common.Strategies/Network/VirtualNetworkStrategy.cs b/src/ResourceManager/Common/Commands.Common.Strategies/Network/VirtualNetworkStrategy.cs index 976f3b390a3c..0737b6da2d15 100644 --- a/src/ResourceManager/Common/Commands.Common.Strategies/Network/VirtualNetworkStrategy.cs +++ b/src/ResourceManager/Common/Commands.Common.Strategies/Network/VirtualNetworkStrategy.cs @@ -15,7 +15,6 @@ using Microsoft.Azure.Management.Network; using Microsoft.Azure.Management.Network.Models; using Microsoft.Azure.Management.ResourceManager.Models; -using System; namespace Microsoft.Azure.Commands.Common.Strategies.Network { diff --git a/src/ResourceManager/Compute/Commands.Compute/Common/ComputeClientBaseCmdlet.cs b/src/ResourceManager/Compute/Commands.Compute/Common/ComputeClientBaseCmdlet.cs index 9cc3b9e1e3c0..eb2743428ff3 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Common/ComputeClientBaseCmdlet.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Common/ComputeClientBaseCmdlet.cs @@ -21,10 +21,7 @@ public abstract class ComputeClientBaseCmdlet : Microsoft.Azure.Commands.Resourc { protected const string VirtualMachineExtensionType = "Microsoft.Compute/virtualMachines/extensions"; - protected override bool IsUsageMetricEnabled - { - get { return true; } - } + protected override bool IsUsageMetricEnabled => true; private ComputeClient computeClient; diff --git a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs index 3430757419f2..198e89d1422b 100644 --- a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs +++ b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Operation/NewAzureVMCommand.cs @@ -210,7 +210,6 @@ public ProgressReportType(Cmdlet cmdlet) public void Report(ResourceConfig config, double progress) where TModel : class { - } /* => _Cmdlet.WriteVerbose( @@ -231,9 +230,11 @@ public void StrategyExecuteCmdlet() // get image var image = Images .Instance - .Select(osAndMap => - new { OsType = osAndMap.Key, Image = osAndMap.Value.GetOrNull(ImageName) }) - .First(osAndImage => osAndImage.Image != null); + .SelectMany(osAndMap => osAndMap + .Value + .Where(nameAndImage => nameAndImage.Key.ToLower() == ImageName.ToLower()) + .Select(nameAndImage => new { OsType = osAndMap.Key, Image = nameAndImage.Value })) + .FirstOrDefault(); OpenPorts = OpenPorts ?? (image.OsType == "Windows" ? new[] { 3389, 5985 } : new[] { 22 }); @@ -258,6 +259,7 @@ public void StrategyExecuteCmdlet() adminPassword: new NetworkCredential(string.Empty, Credential.Password).Password, image: image.Image); + // get state var client = new Client(DefaultProfile.DefaultContext); var current = virtualMachine .GetStateAsync(client, new CancellationToken()) @@ -273,8 +275,10 @@ public void StrategyExecuteCmdlet() } } + // create target state var target = virtualMachine.GetTargetState(current, client.SubscriptionId, Location); + // apply target state var result = virtualMachine .UpdateStateAsync( client, diff --git a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/VirtualMachineBaseCmdlet.cs b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/VirtualMachineBaseCmdlet.cs index 4fd31f40451d..e6b0662c84e5 100644 --- a/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/VirtualMachineBaseCmdlet.cs +++ b/src/ResourceManager/Compute/Commands.Compute/VirtualMachine/VirtualMachineBaseCmdlet.cs @@ -28,13 +28,8 @@ public abstract class VirtualMachineBaseCmdlet : ComputeClientBaseCmdlet { protected const InstanceViewTypes InstanceViewExpand = InstanceViewTypes.InstanceView; - public IVirtualMachinesOperations VirtualMachineClient - { - get - { - return ComputeClient.ComputeManagementClient.VirtualMachines; - } - } + public IVirtualMachinesOperations VirtualMachineClient + => ComputeClient.ComputeManagementClient.VirtualMachines; public static string FormatObject(Object obj) {