Skip to content

Commit f4007db

Browse files
authored
Merge branch 'AzureRM.Compute.4.3.1' into cmp-managed
2 parents fa3279f + be3453c commit f4007db

33 files changed

+645
-516
lines changed

src/ResourceManager/Common/Commands.Common.Strategies.UnitTest/Commands.Common.Strategies.UnitTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
</Reference>
5757
</ItemGroup>
5858
<ItemGroup>
59+
<Compile Include="Compute\ImageVersionTest.cs" />
5960
<Compile Include="Properties\AssemblyInfo.cs" />
6061
<Compile Include="TimeSlotTest.cs" />
6162
</ItemGroup>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Common.Strategies.Compute;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Xunit;
18+
19+
namespace Microsoft.Azure.Commands.Common.Strategies.UnitTest.Compute
20+
{
21+
public class ImageVersionTest
22+
{
23+
[Fact]
24+
[Trait(Category.AcceptanceType, Category.CheckIn)]
25+
public void CompareToTest()
26+
{
27+
var a = ImageVersion.Parse("1.23.456");
28+
var b = ImageVersion.Parse("1.23");
29+
var c = ImageVersion.Parse("01.023");
30+
var d = ImageVersion.Parse("1.23.457");
31+
Assert.Equal(1, a.CompareTo(b));
32+
Assert.Equal(-1, b.CompareTo(a));
33+
Assert.Equal(0, b.CompareTo(c));
34+
Assert.Equal(-1, a.CompareTo(d));
35+
Assert.Equal(1, d.CompareTo(a));
36+
}
37+
}
38+
}

src/ResourceManager/Common/Commands.Common.Strategies/Commands.Common.Strategies.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<Reference Include="System.Xml" />
5656
</ItemGroup>
5757
<ItemGroup>
58+
<Compile Include="Compute\ImageVersion.cs" />
5859
<Compile Include="IResourceConfig.cs" />
5960
<Compile Include="IResourceConfigVisitor.cs" />
6061
<Compile Include="IResourceStrategy.cs" />
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Linq;
16+
17+
namespace Microsoft.Azure.Commands.Common.Strategies.Compute
18+
{
19+
public sealed class ImageVersion
20+
{
21+
public string Original { get; }
22+
23+
public ulong[] Parts { get; }
24+
25+
ImageVersion(string original, ulong[] parts)
26+
{
27+
Original = original;
28+
Parts = parts;
29+
}
30+
31+
public int CompareTo(ImageVersion version)
32+
{
33+
var sign = Parts
34+
.Zip(version.Parts, (a, b) => a.CompareTo(b))
35+
.FirstOrDefault(s => s != 0);
36+
return sign == 0 ? Parts.Length.CompareTo(version.Parts.Length) : sign;
37+
}
38+
39+
public static ImageVersion Parse(string version)
40+
=> new ImageVersion(version, version.Split('.').Select(ulong.Parse).ToArray());
41+
42+
public override string ToString()
43+
=> Original;
44+
}
45+
}

src/ResourceManager/Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* `New-AzureRmVm` and `New-AzureRmVmss` get information about an image from Azure.
2122

2223
## Version 4.3.0
2324
* Added 'AvailabilitySetName' parameter to the simplified parameterset of 'New-AzureRmVm'.

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/StrategiesVirtualMachineTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.Compute.Test.ScenarioTests;
1615
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1716
using Xunit;
1817

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/StrategiesVmssTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Commands.Compute.Test.ScenarioTests;
1615
using Microsoft.WindowsAzure.Commands.ScenarioTest;
1716
using Xunit;
1817

@@ -22,7 +21,8 @@ public class StrategiesVmssTests
2221
{
2322
public StrategiesVmssTests(Xunit.Abstractions.ITestOutputHelper output)
2423
{
25-
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
24+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(
25+
new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
2626
}
2727

2828
[Fact]

src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,19 @@
272272
<Compile Include="StorageServices\StorageCredentialsFactory.cs" />
273273
<Compile Include="Strategies\AsyncCmdletExtensions.cs" />
274274
<Compile Include="Strategies\Client.cs" />
275-
<Compile Include="Strategies\Compute\AvailabilitySetStrategy.cs" />
276-
<Compile Include="Strategies\Compute\ComputeStrategy.cs" />
277-
<Compile Include="Strategies\Compute\Image.cs" />
278-
<Compile Include="Strategies\Compute\Images.cs" />
279-
<Compile Include="Strategies\Compute\VirtualMachineScaleSetStrategy.cs" />
280-
<Compile Include="Strategies\Compute\VirtualMachineStrategy.cs" />
275+
<Compile Include="Strategies\ComputeRp\AvailabilitySetStrategy.cs" />
276+
<Compile Include="Strategies\ComputeRp\ComputeStrategy.cs" />
277+
<Compile Include="Strategies\ComputeRp\ImageAndOsType.cs" />
278+
<Compile Include="Strategies\ComputeRp\ImageEx.cs" />
279+
<Compile Include="Strategies\ComputeRp\Images.cs" />
280+
<Compile Include="Strategies\ComputeRp\VirtualMachineScaleSetStrategy.cs" />
281+
<Compile Include="Strategies\ComputeRp\VirtualMachineStrategy.cs" />
281282
<Compile Include="Strategies\IAsyncCmdlet.cs" />
283+
<Compile Include="Strategies\Location.cs" />
282284
<Compile Include="Strategies\Network\BackendAddressPoolStrategy.cs" />
283285
<Compile Include="Strategies\Network\FrontendIPConfigurationStrategy.cs" />
284286
<Compile Include="Strategies\Network\LoadBalancerStrategy.cs" />
285-
<Compile Include="Strategies\Compute\ManagedDiskStrategy.cs" />
287+
<Compile Include="Strategies\ComputeRp\ManagedDiskStrategy.cs" />
286288
<Compile Include="Strategies\Network\NetworkInterfaceStrategy.cs" />
287289
<Compile Include="Strategies\Network\NetworkSecurityGroupPolicy.cs" />
288290
<Compile Include="Strategies\Network\NetworkStrategy.cs" />
@@ -400,7 +402,7 @@
400402
</ItemGroup>
401403
<ItemGroup>
402404
<EmbeddedResource Include="Properties\Resources.resx">
403-
<Generator>PublicResXFileCodeGenerator</Generator>
405+
<Generator>ResXFileCodeGenerator</Generator>
404406
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
405407
<SubType>Designer</SubType>
406408
</EmbeddedResource>

src/ResourceManager/Compute/Commands.Compute/Generated/VirtualMachineScaleSet/VirtualMachineScaleSetCreateOrUpdateMethod.cs

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,15 @@
2020
// code is regenerated.
2121

2222
using Microsoft.Azure.Commands.Common.Strategies;
23-
using Microsoft.Azure.Commands.Common.Strategies.Compute;
24-
using Microsoft.Azure.Commands.Common.Strategies.Network;
25-
using Microsoft.Azure.Commands.Common.Strategies.ResourceManager;
2623
using Microsoft.Azure.Commands.Compute.Automation.Models;
2724
using Microsoft.Azure.Commands.Compute.Strategies;
25+
using Microsoft.Azure.Commands.Compute.Strategies.ComputeRp;
26+
using Microsoft.Azure.Commands.Compute.Strategies.Network;
27+
using Microsoft.Azure.Commands.Compute.Strategies.ResourceManager;
2828
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
2929
using Microsoft.Azure.Management.Compute;
3030
using Microsoft.Azure.Management.Compute.Models;
31-
using System;
32-
using System.Collections;
3331
using System.Collections.Generic;
34-
using System.Linq;
3532
using System.Management.Automation;
3633
using System.Net;
3734
using System.Threading;
@@ -164,45 +161,8 @@ async Task SimpleParameterSetExecuteCmdlet(IAsyncCmdlet asyncCmdlet)
164161
FrontendPoolName = FrontendPoolName ?? VMScaleSetName;
165162
BackendPoolName = BackendPoolName ?? VMScaleSetName;
166163

167-
// get image
168-
bool isWindows;
169-
Commands.Common.Strategies.Compute.Image image;
170-
if (ImageName.Contains(':'))
171-
{
172-
var imageArray = ImageName.Split(':');
173-
if (imageArray.Length != 4)
174-
{
175-
throw new Exception("Invalid ImageName");
176-
}
177-
image = new Commands.Common.Strategies.Compute.Image
178-
{
179-
publisher = imageArray[0],
180-
offer = imageArray[1],
181-
sku = imageArray[2],
182-
version = imageArray[3],
183-
};
184-
isWindows = image.publisher.ToLower() == "MicrosoftWindowsServer".ToLower();
185-
}
186-
else
187-
{
188-
// get image
189-
var osTypeAndImage = Images
190-
.Instance
191-
.SelectMany(osAndMap => osAndMap
192-
.Value
193-
.Where(nameAndImage => nameAndImage.Key.ToLower() == ImageName.ToLower())
194-
.Select(nameAndImage => new
195-
{
196-
OsType = osAndMap.Key,
197-
Image = nameAndImage.Value
198-
}))
199-
.FirstOrDefault();
200-
image = osTypeAndImage.Image;
201-
isWindows = osTypeAndImage.OsType == "Windows";
202-
}
203-
204-
BackendPort = BackendPort ?? (isWindows ? new[] { 3389, 5985 } : new[] { 22 });
205-
164+
var imageAndOsType = new ImageAndOsType(OperatingSystemTypes.Windows, null);
165+
206166
var resourceGroup = ResourceGroupStrategy.CreateResourceGroupConfig(ResourceGroupName);
207167

208168
var publicIpAddress = resourceGroup.CreatePublicIPAddressConfig(
@@ -237,13 +197,12 @@ async Task SimpleParameterSetExecuteCmdlet(IAsyncCmdlet asyncCmdlet)
237197
subnet: subnet,
238198
frontendIpConfigurations: new[] { frontendIpConfiguration },
239199
backendAdressPool: backendAddressPool,
240-
isWindows: isWindows,
200+
getImageAndOsType: () => imageAndOsType,
241201
adminUsername: Credential.UserName,
242202
adminPassword: new NetworkCredential(string.Empty, Credential.Password).Password,
243-
image: image,
244203
vmSize: VmSize,
245204
instanceCount: InstanceCount,
246-
upgradeMode: (MyInvocation.BoundParameters.ContainsKey("UpgradePolicyMode") == true )
205+
upgradeMode: MyInvocation.BoundParameters.ContainsKey("UpgradePolicyMode")
247206
? UpgradePolicyMode
248207
: (UpgradeMode?) null);
249208

@@ -252,14 +211,9 @@ async Task SimpleParameterSetExecuteCmdlet(IAsyncCmdlet asyncCmdlet)
252211
// get current Azure state
253212
var current = await virtualMachineScaleSet.GetStateAsync(client, new CancellationToken());
254213

255-
if (Location == null)
256-
{
257-
Location = current.GetLocation(virtualMachineScaleSet);
258-
if (Location == null)
259-
{
260-
Location = "eastus";
261-
}
262-
}
214+
Location = current.UpdateLocation(Location, virtualMachineScaleSet);
215+
216+
imageAndOsType = await client.UpdateImageAndOsTypeAsync(ImageName, Location);
263217

264218
// generate a domain name label if it's not specified.
265219
DomainNameLabel = await PublicIPAddressStrategy.UpdateDomainNameLabelAsync(

0 commit comments

Comments
 (0)