Skip to content

Commit 5821259

Browse files
authored
Merge pull request #5315 from markcowl/vmsssimple
Simplified Parameter set for VM ScaleSet Creation
2 parents a7a5677 + f0b3113 commit 5821259

File tree

20 files changed

+4394
-140756
lines changed

20 files changed

+4394
-140756
lines changed

src/ResourceManager/Common/Commands.Common.Strategies/NestedResourceConfig.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public sealed class NestedResourceConfig<TModel, TParenModel> : IEntityConfig<TM
3636
/// </summary>
3737
public IEntityConfig<TParenModel> Parent { get; }
3838

39-
public Func<TModel> CreateModel { get; }
39+
public Func<string, TModel> CreateModel { get; }
4040

4141
public IResourceConfig Resource => Parent.Resource;
4242

@@ -46,7 +46,7 @@ public NestedResourceConfig(
4646
NestedResourceStrategy<TModel, TParenModel> strategy,
4747
IEntityConfig<TParenModel> parent,
4848
string name,
49-
Func<TModel> createModel)
49+
Func<string, TModel> createModel)
5050
{
5151
Strategy = strategy;
5252
Name = name;

src/ResourceManager/Common/Commands.Common.Strategies/NestedResourceConfigExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static NestedResourceConfig<TModel, TParenModel> CreateConfig<TModel, TPa
2222
this NestedResourceStrategy<TModel, TParenModel> strategy,
2323
IEntityConfig<TParenModel> parent,
2424
string name,
25-
Func<TModel> createModel)
25+
Func<string, TModel> createModel)
2626
where TModel : class
2727
where TParenModel : class
2828
=> new NestedResourceConfig<TModel, TParenModel>(strategy, parent, name, createModel);

src/ResourceManager/Common/Commands.Common.Strategies/NestedResourceStrategy.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using System;
1616
using System.Collections.Generic;
17+
using System.Linq;
1718

1819
namespace Microsoft.Azure.Commands.Common.Strategies
1920
{
@@ -48,5 +49,37 @@ public static NestedResourceStrategy<TModel, TParentModel> Create<TModel, TParen
4849
name => new[] { provider, name},
4950
get,
5051
createOrUpdate);
52+
53+
public static NestedResourceStrategy<TModel, TParentModel> Create<TModel, TParentModel>(
54+
string provider,
55+
Func<TParentModel, IList<TModel>> getList,
56+
Action<TParentModel, IList<TModel>> setList,
57+
Func<TModel, string> getName,
58+
Action<TModel, string> setName)
59+
where TModel : class
60+
where TParentModel : class
61+
=> Create<TModel, TParentModel>(
62+
provider,
63+
(parentModel, name) => getList(parentModel)?.FirstOrDefault(model => getName(model) == name),
64+
(parentModel, name, model) =>
65+
{
66+
setName(model, name);
67+
var list = getList(parentModel);
68+
if (list == null)
69+
{
70+
list = new List<TModel> { model };
71+
setList(parentModel, list);
72+
return;
73+
}
74+
var modelAndIndex = list
75+
.Select((m, i) => new { m, i })
76+
.FirstOrDefault(mi => getName(mi.m) == name);
77+
if (modelAndIndex != null)
78+
{
79+
list[modelAndIndex.i] = model;
80+
return;
81+
}
82+
list.Add(model);
83+
});
5184
}
5285
}

src/ResourceManager/Common/Commands.Common.Strategies/TargetStateExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ sealed class Context
4545

4646
public string Location { get; }
4747

48-
public Context(IState current, string subscription, string location)
48+
public Context(IState current, string subscriptionId, string location)
4949
{
5050
Current = current;
51-
Subscription = subscription;
51+
Subscription = subscriptionId;
5252
Location = location;
5353
}
5454

@@ -84,7 +84,7 @@ public TModel GetOrAdd<TModel, TParentModel>(
8484
var model = config.Strategy.Get(parentModel, config.Name);
8585
if (model == null)
8686
{
87-
model = config.CreateModel();
87+
model = config.CreateModel(Subscription);
8888
config.Strategy.CreateOrUpdate(parentModel, config.Name, model);
8989
}
9090
return model;

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/Mocks/MockClientFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ public TClient CreateCustomArmClient<TClient>(params object[] parameters) where
255255
}
256256
}
257257

258-
if (TestMockSupport.RunningMocked)
258+
if (TestMockSupport.RunningMocked && HttpMockServer.GetCurrentMode() != HttpRecorderMode.Record)
259259
{
260260
IAzureClient azureClient = client as IAzureClient;
261261
if (azureClient != null)

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+
* Added simplified parameter set to New-AzureRmVmss, which creates a Virtual Machine Scale Set and all required resources using smart defaults
2122
* Added Location Completer to -Location parameters allowing tab completion through valid Locations
2223
* Added ResourceGroup Completer to -ResourceGroup parameters allowing tab completion through resource groups in current subscription
2324
* Obsoleted -Tags in favor of -Tag for New-AzureRmVm and Update-AzureRmVm

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
</Compile>
180180
<Compile Include="ScenarioTests\DscExtensionTests.cs" />
181181
<Compile Include="ScenarioTests\RunnerTests.cs" />
182+
<Compile Include="ScenarioTests\StrategiesVmssTests.cs" />
182183
<Compile Include="ScenarioTests\VirtualMachineBootDiagnosticsTests.cs" />
183184
<Compile Include="ScenarioTests\VirtualMachineRunCommandTests.cs" />
184185
<Compile Include="ScenarioTests\VirtualMachineScaleSetExtensionTests.cs" />
@@ -318,6 +319,9 @@
318319
<None Include="ScenarioTests\SqlIaaSExtensionTests.ps1">
319320
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
320321
</None>
322+
<None Include="ScenarioTests\StrategiesVmssTests.ps1">
323+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
324+
</None>
321325
<None Include="ScenarioTests\test.ps1">
322326
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
323327
</None>
@@ -371,6 +375,7 @@
371375
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
372376
</None>
373377
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.StrategiesVirtualMachineTests\TestSimpleNewVm.json" />
378+
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.StrategiesVmssTests\TestSimpleNewVmss.json" />
374379
<None Include="Templates\azuredeploy.json">
375380
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
376381
</None>

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
using Microsoft.Azure.Commands.Compute.Test.ScenarioTests;
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.Compute.Test.ScenarioTests;
216
using Microsoft.WindowsAzure.Commands.ScenarioTest;
317
using Xunit;
418

@@ -11,8 +25,8 @@ public StrategiesVirtualMachineTests(Xunit.Abstractions.ITestOutputHelper output
1125
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
1226
}
1327

14-
[Fact(/*Skip = "TODO: only works for live mode"*/)]
15-
[Trait(Category.RunType, Category.LiveOnly)]
28+
[Fact]
29+
[Trait(Category.RunType, Category.CheckIn)]
1630
public void TestSimpleNewVm()
1731
{
1832
ComputeTestController.NewInstance.RunPsTest("Test-SimpleNewVm");
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.Compute.Test.ScenarioTests;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Xunit;
18+
19+
namespace Microsoft.Azure.Commands.Compute.Test.ScenarioTests
20+
{
21+
public class StrategiesVmssTests
22+
{
23+
public StrategiesVmssTests(Xunit.Abstractions.ITestOutputHelper output)
24+
{
25+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
26+
}
27+
28+
[Fact]
29+
[Trait(Category.RunType, Category.CheckIn)]
30+
public void TestSimpleNewVmss()
31+
{
32+
ComputeTestController.NewInstance.RunPsTest("Test-SimpleNewVmss");
33+
}
34+
}
35+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
<#
16+
.SYNOPSIS
17+
Test Simple Paremeter Set for New Vm
18+
#>
19+
function Test-SimpleNewVmss
20+
{
21+
# Setup
22+
$vmssname = Get-ResourceName
23+
24+
try
25+
{
26+
$username = "admin01"
27+
$password = "werWER345#%^" | ConvertTo-SecureString -AsPlainText -Force
28+
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
29+
30+
# Common
31+
$x = New-AzureRmVmss -Name $vmssname -Credential $cred
32+
33+
Assert-AreEqual $vmssname $x.Name;
34+
Assert-AreEqual $vmssname $x.ResourceGroupName;
35+
Assert-AreEqual $vmssname $x.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].Name;
36+
Assert-AreEqual $vmssname $x.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].Name;
37+
Assert-AreEqual "Standard_DS1_v2" $x.Sku.Name
38+
Assert-AreEqual $username $x.VirtualMachineProfile.OsProfile.AdminUsername
39+
Assert-AreEqual "2016-Datacenter" $x.VirtualMachineProfile.StorageProfile.ImageReference.Sku
40+
Assert-NotNull $x.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].LoadBalancerBackendAddressPools;
41+
Assert-NotNull $x.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations[0].IpConfigurations[0].Subnet
42+
}
43+
finally
44+
{
45+
# Cleanup
46+
Clean-ResourceGroup $vmssname
47+
}
48+
}

0 commit comments

Comments
 (0)