19
19
// Changes to this file may cause incorrect behavior and will be lost if the
20
20
// code is regenerated.
21
21
22
- using Microsoft . Azure . Commands . Common . Strategies . Compute ;
23
22
using Microsoft . Azure . Commands . Compute . Automation . Models ;
24
23
using Microsoft . Azure . Management . Compute ;
25
24
using Microsoft . Azure . Management . Compute . Models ;
29
28
using System . Collections . Generic ;
30
29
using System . Linq ;
31
30
using System . Management . Automation ;
32
- using Microsoft . Azure . Commands . Common . Strategies ;
33
- using Microsoft . Azure . Commands . Common . Strategies . ResourceManager ;
34
- using System . Threading ;
35
- using Microsoft . Azure . Commands . ResourceManager . Common . ArgumentCompleters ;
36
- using Microsoft . Azure . Commands . Common . Strategies . Network ;
37
- using Microsoft . Azure . Commands . Compute . Common ;
38
- using System . Net ;
39
- using Microsoft . Azure . Commands . Compute . Strategies ;
40
- using System . Threading . Tasks ;
41
31
42
32
namespace Microsoft . Azure . Commands . Compute . Automation
43
33
{
@@ -126,114 +116,23 @@ protected PSArgument[] CreateVirtualMachineScaleSetCreateOrUpdateParameters()
126
116
[ OutputType ( typeof ( PSVirtualMachineScaleSet ) ) ]
127
117
public partial class NewAzureRmVmss : ComputeAutomationBaseCmdlet
128
118
{
129
- public const string SimpleParameterSet = "SimpleParameterSet" ;
130
-
131
119
public override void ExecuteCmdlet ( )
132
120
{
133
- switch ( ParameterSetName )
121
+ ExecuteClientAction ( ( ) =>
134
122
{
135
- case SimpleParameterSet :
136
- this . StartAndWait ( SimpleParameterSetExecuteCmdlet ) ;
137
- break ;
138
- default :
139
- ExecuteClientAction ( ( ) =>
140
- {
141
- if ( ShouldProcess ( this . VMScaleSetName , VerbsCommon . New ) )
142
- {
143
- string resourceGroupName = this . ResourceGroupName ;
144
- string vmScaleSetName = this . VMScaleSetName ;
145
- VirtualMachineScaleSet parameters = new VirtualMachineScaleSet ( ) ;
146
- ComputeAutomationAutoMapperProfile . Mapper . Map < PSVirtualMachineScaleSet , VirtualMachineScaleSet > ( this . VirtualMachineScaleSet , parameters ) ;
147
-
148
- var result = VirtualMachineScaleSetsClient . CreateOrUpdate ( resourceGroupName , vmScaleSetName , parameters ) ;
149
- var psObject = new PSVirtualMachineScaleSet ( ) ;
150
- ComputeAutomationAutoMapperProfile . Mapper . Map < VirtualMachineScaleSet , PSVirtualMachineScaleSet > ( result , psObject ) ;
151
- WriteObject ( psObject ) ;
152
- }
153
- } ) ;
154
- break ;
155
- }
156
- }
157
-
158
- async Task SimpleParameterSetExecuteCmdlet ( IAsyncCmdlet asyncCmdlet )
159
- {
160
- ResourceGroupName = ResourceGroupName ?? VMScaleSetName ;
161
- VirtualNetworkName = VirtualNetworkName ?? VMScaleSetName ;
162
- SubnetName = SubnetName ?? VMScaleSetName ;
163
- PublicIpAddressName = PublicIpAddressName ?? VMScaleSetName ;
164
- DomainNameLabel = DomainNameLabel ?? ( VMScaleSetName + ResourceGroupName ) . ToLower ( ) ;
165
- SecurityGroupName = SecurityGroupName ?? VMScaleSetName ;
166
- LoadBalancerName = LoadBalancerName ?? VMScaleSetName ;
167
-
168
- // get image
169
- var image = Images
170
- . Instance
171
- . Select ( osAndMap =>
172
- new { OsType = osAndMap . Key , Image = osAndMap . Value . GetOrNull ( ImageName ) } )
173
- . First ( osAndImage => osAndImage . Image != null ) ;
174
-
175
- BackendPorts = BackendPorts
176
- ?? ( image . OsType == "Windows" ? new [ ] { 3389 , 5985 } : new [ ] { 22 } ) ;
177
-
178
- var resourceGroup = ResourceGroupStrategy . CreateResourceGroupConfig ( ResourceGroupName ) ;
179
-
180
- var publicIpAddress = resourceGroup . CreatePublicIPAddressConfig (
181
- name : PublicIpAddressName ,
182
- domainNameLabel : DomainNameLabel ,
183
- allocationMethod : AllocationMethod ) ;
184
-
185
- var loadBalancer = resourceGroup . CreateLoadBalancerConfig (
186
- name : LoadBalancerName ) ;
187
-
188
- var virtualNetwork = resourceGroup . CreateVirtualNetworkConfig (
189
- name : VirtualNetworkName , addressPrefix : VnetAddressPrefix ) ;
190
-
191
- var subnet = virtualNetwork . CreateSubnet ( SubnetName , SubnetAddressPrefix ) ;
192
-
193
- /*
194
- var networkSecurityGroup = resourceGroup.CreateNetworkSecurityGroupConfig(
195
- name: SecurityGroupName,
196
- openPorts: OpenPorts);
197
-
198
- var networkInterface = resourceGroup.CreateNetworkInterfaceConfig(
199
- Name, subnet, publicIpAddress, networkSecurityGroup);*/
200
-
201
- var virtualMachineScaleSet = resourceGroup . CreateVirtualMachineScaleSetConfig (
202
- name : VMScaleSetName ,
203
- adminUsername : Credential . UserName ,
204
- adminPassword : new NetworkCredential ( string . Empty , Credential . Password ) . Password ,
205
- image : image . Image ) ;
206
-
207
- var client = new Client ( DefaultProfile . DefaultContext ) ;
208
-
209
- var current = virtualMachineScaleSet
210
- . GetStateAsync ( client , new CancellationToken ( ) )
211
- . GetAwaiter ( )
212
- . GetResult ( ) ;
213
-
214
- if ( Location == null )
215
- {
216
- Location = current . GetLocation ( virtualMachineScaleSet ) ;
217
- if ( Location == null )
123
+ if ( ShouldProcess ( this . VMScaleSetName , VerbsCommon . New ) )
218
124
{
219
- Location = "eastus" ;
125
+ string resourceGroupName = this . ResourceGroupName ;
126
+ string vmScaleSetName = this . VMScaleSetName ;
127
+ VirtualMachineScaleSet parameters = new VirtualMachineScaleSet ( ) ;
128
+ ComputeAutomationAutoMapperProfile . Mapper . Map < PSVirtualMachineScaleSet , VirtualMachineScaleSet > ( this . VirtualMachineScaleSet , parameters ) ;
129
+
130
+ var result = VirtualMachineScaleSetsClient . CreateOrUpdate ( resourceGroupName , vmScaleSetName , parameters ) ;
131
+ var psObject = new PSVirtualMachineScaleSet ( ) ;
132
+ ComputeAutomationAutoMapperProfile . Mapper . Map < VirtualMachineScaleSet , PSVirtualMachineScaleSet > ( result , psObject ) ;
133
+ WriteObject ( psObject ) ;
220
134
}
221
- }
222
-
223
- var target = virtualMachineScaleSet . GetTargetState ( current , client . SubscriptionId , Location ) ;
224
-
225
- if ( ShouldProcess ( VMScaleSetName , VerbsCommon . New ) )
226
- {
227
- var result = await virtualMachineScaleSet
228
- . UpdateStateAsync (
229
- client ,
230
- target ,
231
- new CancellationToken ( ) ,
232
- new ShouldProcess ( asyncCmdlet ) ,
233
- new ProgressReport ( asyncCmdlet ) ) ;
234
-
235
- asyncCmdlet . WriteObject ( result ) ;
236
- }
135
+ } ) ;
237
136
}
238
137
239
138
[ Parameter ( Mandatory = false , HelpMessage = "Run cmdlet in the background" ) ]
@@ -247,9 +146,6 @@ async Task SimpleParameterSetExecuteCmdlet(IAsyncCmdlet asyncCmdlet)
247
146
ValueFromPipeline = false ) ]
248
147
[ AllowNull ]
249
148
[ ResourceManager . Common . ArgumentCompleters . ResourceGroupCompleter ( ) ]
250
- [ Parameter (
251
- ParameterSetName = SimpleParameterSet ,
252
- Mandatory = false ) ]
253
149
public string ResourceGroupName { get ; set ; }
254
150
255
151
[ Parameter (
@@ -260,9 +156,6 @@ async Task SimpleParameterSetExecuteCmdlet(IAsyncCmdlet asyncCmdlet)
260
156
ValueFromPipeline = false ) ]
261
157
[ Alias ( "Name" ) ]
262
158
[ AllowNull ]
263
- [ Parameter (
264
- ParameterSetName = SimpleParameterSet ,
265
- Mandatory = true ) ]
266
159
public string VMScaleSetName { get ; set ; }
267
160
268
161
[ Parameter (
@@ -273,58 +166,5 @@ async Task SimpleParameterSetExecuteCmdlet(IAsyncCmdlet asyncCmdlet)
273
166
ValueFromPipeline = true ) ]
274
167
[ AllowNull ]
275
168
public PSVirtualMachineScaleSet VirtualMachineScaleSet { get ; set ; }
276
-
277
- // SimpleParameterSet
278
-
279
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = true ) ]
280
- public string ImageName { get ; set ; } //= "Win2016Datacenter";
281
-
282
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = true ) ]
283
- public PSCredential Credential { get ; set ; }
284
-
285
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = false ) ]
286
- public int InstanceCount { get ; set ; } = 2 ;
287
-
288
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = false ) ]
289
- public string VirtualNetworkName { get ; set ; }
290
-
291
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = false ) ]
292
- public string SubnetName { get ; set ; }
293
-
294
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = false ) ]
295
- public string PublicIpAddressName { get ; set ; }
296
-
297
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = false ) ]
298
- public string DomainNameLabel { get ; set ; }
299
-
300
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = false ) ]
301
- public string SecurityGroupName { get ; set ; }
302
-
303
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = false ) ]
304
- public string LoadBalancerName { get ; set ; }
305
-
306
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = false ) ]
307
- public int [ ] BackendPorts { get ; set ; }
308
-
309
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = false ) ]
310
- [ LocationCompleter ]
311
- public string Location { get ; set ; }
312
-
313
- // this corresponds to VmSku in the Azure CLI
314
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = false ) ]
315
- public string VmSize { get ; set ; } = "Standard_DS1_v2" ;
316
-
317
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = false ) ]
318
- public UpgradeMode UpgradePolicyMode { get ; set ; }
319
-
320
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = false ) ]
321
- [ ValidateSet ( "Static" , "Dynamic" ) ]
322
- public string AllocationMethod { get ; set ; } = "Static" ;
323
-
324
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = false ) ]
325
- public string VnetAddressPrefix { get ; set ; } = "192.168.0.0/16" ;
326
-
327
- [ Parameter ( ParameterSetName = SimpleParameterSet , Mandatory = false ) ]
328
- public string SubnetAddressPrefix { get ; set ; } = "192.168.1.0/24" ;
329
169
}
330
- }
170
+ }
0 commit comments