Skip to content

Commit 80f1460

Browse files
authored
Merge pull request #5534 from maddieclayton/AzureRM.Compute.4.3.1
Merge AzureRM.Compute.4.3.1 into master
2 parents 9d9cc62 + 0999201 commit 80f1460

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+721
-585
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.ManagedService/AzureRM.Compute.ManagedService.psd1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@{
1010

1111
# Script module or binary module file associated with this manifest.
12-
RootModule = '.\ConvertTo-AzureRmVhd.psm1'
12+
RootModule = '.\AzureRM.Compute.ManagedService.psm1'
1313

1414
# Version number of this module.
1515
ModuleVersion = '0.1.0'
@@ -66,13 +66,13 @@ TypesToProcess = @()
6666
FormatsToProcess = @()
6767

6868
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
69-
NestedModules = @('.\Microsoft.Azure.Commands.Compute.ManagedService.dll')
69+
NestedModules = @()
7070

7171
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
72-
FunctionsToExport = @()
72+
FunctionsToExport = 'ConvertTo-AzureRmVhd'
7373

7474
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
75-
CmdletsToExport = @('ConvertTo-AzureRmVhd')
75+
CmdletsToExport = 'ConvertTo-AzureRmVhd'
7676

7777
# Variables to export from this module
7878
# VariablesToExport = @()

src/ResourceManager/Compute.ManagedService/Commands.Compute.ManagedService/ConvertTo-AzureRmVhd.psm1 renamed to src/ResourceManager/Compute.ManagedService/Commands.Compute.ManagedService/AzureRM.Compute.ManagedService.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ This module requires Hyper-V version 1.1. Please follow the instructions below t
1212
1) https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v
1313
2) https://docs.microsoft.com/en-us/windows-server/virtualization/hyper-v/get-started/install-the-hyper-v-role-on-windows-server
1414
"@;
15-
Write-Error $instructions -ErrorAction Stop;
15+
Write-Error $instructions -ErrorAction Stop
1616
}
1717
else
1818
{
19-
. $PSScriptRoot\Tools\ConvertTo-AzureRmVhd.ps1;
19+
Import-Module Hyper-V -MinimumVersion 1.1 -Scope Global
20+
. $PSScriptRoot\Tools\ConvertTo-AzureRmVhd.ps1
2021
}
21-

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,13 @@
9696
<Project>{3819d8a7-c62c-4c47-8ddd-0332d9ce1252}</Project>
9797
<Name>Commands.ResourceManager.Common</Name>
9898
</ProjectReference>
99-
<ProjectReference Include="..\..\Compute\Commands.Compute\Commands.Compute.csproj">
100-
<Project>{52643bd5-6378-49bd-9f6e-dac9dd8a867b}</Project>
101-
<Name>Commands.Compute</Name>
102-
</ProjectReference>
10399
</ItemGroup>
104100
<ItemGroup>
105101
<None Include="..\AzureRM.Compute.ManagedService.psd1">
106102
<Link>AzureRM.Compute.ManagedService.psd1</Link>
107103
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
108104
</None>
109-
<None Include="ConvertTo-AzureRmVhd.psm1">
105+
<None Include="AzureRM.Compute.ManagedService.psm1">
110106
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
111107
</None>
112108
<None Include="Tools\ConvertTo-AzureRmVhd.ps1">

src/ResourceManager/Compute.ManagedService/Commands.Compute.ManagedService/Tools/ConvertTo-AzureRmVhd.ps1

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,6 @@ function ConvertTo-AzureRmVhd
3838
[switch]$AsJob
3939
)
4040

41-
$module = Get-Module Hyper-V;
42-
if ($module -ne $null -and $module.Version.ToString().CompareTo("1.1") -lt 0)
43-
{
44-
$instructions =
45-
@"
46-
This module requires Hyper-V version 1.1. Please follow the instructions below to enable Hyper-V on your Windows System:
47-
1) https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v
48-
2) https://docs.microsoft.com/en-us/windows-server/virtualization/hyper-v/get-started/install-the-hyper-v-role-on-windows-server
49-
"@;
50-
Write-Error $instructions -ErrorAction Stop;
51-
}
52-
elseif ($module -eq $null)
53-
{
54-
Import-Module Hyper-V -MinimumVersion 1.1 -Scope Global;
55-
}
56-
5741
if ($AsJob)
5842
{
5943
Start-Job -ScriptBlock ${function:ExecuteCmdlet} -Argumentlist $HyperVVMName,$ExportPath,$HyperVServer,$Force;
@@ -158,7 +142,7 @@ function ExecuteCmdlet($HyperVVMName, $ExportPath, $HyperVServer, $Force)
158142
}
159143
}
160144

161-
if ($PSCmdlet.ShouldProcess($Name, "Converting a Hyper-V VM to Azure supported VHD file(s)..."))
145+
if ($PSCmdlet.ShouldProcess($HyperVVMName, "Converting a Hyper-V VM to Azure supported VHD file(s)..."))
162146
{
163147
$vhdFiles = Export-DiskFiles $HyperVServer $HyperVVMName $ExportPath;
164148

src/ResourceManager/Compute/AzureRM.Compute.psd1

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# RootModule = ''
1313

1414
# Version number of this module.
15-
ModuleVersion = '4.3.0'
15+
ModuleVersion = '4.3.1'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()
@@ -210,12 +210,7 @@ PrivateData = @{
210210
# IconUri = ''
211211

212212
# ReleaseNotes of this module
213-
ReleaseNotes = '* Added ''AvailabilitySetName'' parameter to the simplified parameterset of ''New-AzureRmVm''.
214-
* Corrected usage of ''Login-AzureRmAccount'' to use ''Connect-AzureRmAccount''
215-
* User assigned identity support for VM and VM scale set
216-
- IdentityType and IdentityId parameters are added to New-AzureRmVMConfig, New-AzureRmVmssConfig, Update-AzureRmVM and Update-AzureRmVmss
217-
* Added EnableIPForwarding parameter to Add-AzureRmVmssNetworkInterfaceConfig
218-
* Added Priority parameter to New-AzureRmVmssConfig'
213+
ReleaseNotes = '* Query image details for OS Version for New-AzureRmVm, New-AzureRmVMSS'
219214

220215
# Prerelease string of this module
221216
# Prerelease = ''

src/ResourceManager/Compute/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
-->
2020
## Current Release
2121

22+
## Version 4.3.1
23+
* `New-AzureRmVm` and `New-AzureRmVmss` get information about an image from Azure.
24+
2225
## Version 4.3.0
2326
* Added 'AvailabilitySetName' parameter to the simplified parameterset of 'New-AzureRmVm'.
2427
* Corrected usage of 'Login-AzureRmAccount' to use 'Connect-AzureRmAccount'

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)