@@ -26,17 +26,17 @@ SOFTWARE.
26
26
#>
27
27
28
28
param (
29
- [string ]$basevhd = $ (throw " please specify a base vhd" ),
30
- [int ]$vms = $ (throw " please specify a number of vms per node csv" ),
31
- [string []]$groups = @ (),
32
- [string ]$adminpass = $ (throw " need admin password for autologin" ),
33
- [string ]$admin = ' administrator' ,
34
- [string ]$connectpass = $ (throw " need password for loopback host connection" ),
35
- [string ]$connectuser = $ (throw " need username for loopback host connection" ),
36
- [validateset (" CreateVMSwitch" , " CopyVHD" , " CreateVM" , " CreateVMGroup" , " AssertComplete" )][string ]$stopafter ,
37
- [validateset (" Force" , " Auto" , " None" )][string ]$specialize = " Auto" ,
38
- [switch ]$fixedvhd = $true ,
39
- [string []]$nodes = @ ()
29
+ [string ]$BaseVHD = $ (throw " please specify a base vhd" ),
30
+ [int ]$VMs = $ (throw " please specify a number of vms per node csv" ),
31
+ [string []]$Groups = @ (),
32
+ [string ]$AdminPass = $ (throw ' need admin password for autologin' ),
33
+ [string ]$Admin = ' administrator' ,
34
+ [string ]$ConnectPass = $ (throw ' need password for loopback host connection' ),
35
+ [string ]$ConnectUser = $ (throw ' need username for loopback host connection' ),
36
+ [validateset (' CreateVMSwitch' , ' CopyVHD' , ' CreateVM' , ' CreateVMGroup' , ' AssertComplete' )][string ]$StopAfter ,
37
+ [validateset (' Force' , ' Auto' , ' None' )][string ]$Specialize = ' Auto' ,
38
+ [switch ]$FixedVHD = $true ,
39
+ [string []]$Nodes = @ ()
40
40
)
41
41
42
42
function Stop-After ($step )
@@ -48,6 +48,13 @@ function Stop-After($step)
48
48
return $false
49
49
}
50
50
51
+ # #################
52
+
53
+ # validate existence of basevhd
54
+ if (! (test-path - path $BaseVHD )) {
55
+ throw " Base VHD $BaseVHD not found"
56
+ }
57
+
51
58
if (Get-ClusterNode | ? State -ne Up) {
52
59
throw " not all cluster nodes are up; please address before creating vmfleet"
53
60
}
@@ -97,17 +104,9 @@ if (Stop-After "CreateVMSwitch") {
97
104
# create $vms vms per each csv named as <nodename><group prefix>
98
105
# vm name is vm-<group prefix><$group>-<hostname>-<number>
99
106
100
- icm $nodes - ArgumentList $basevhd , $vms , $groups , $admin , $adminpass , $connectpass , $connectuser , $stopafter , $specialize , (Get-Command Stop-After ) {
101
-
102
- param ( [string []]$basevhd ,
103
- [int ]$vms ,
104
- [string []]$groups ,
105
- [string ]$admin ,
106
- [string ]$adminpass ,
107
- [string ]$connectpass ,
108
- [string ]$connectuser ,
109
- [string ]$stopafter ,
110
- [string ]$specialize ,
107
+ icm $nodes - ArgumentList $stopafter , (Get-Command Stop-After ) {
108
+
109
+ param ( [string ]$stopafter ,
111
110
$fn )
112
111
113
112
set-item - Path function:\$ ($fn.name ) - Value $fn.definition
@@ -134,9 +133,9 @@ icm $nodes -ArgumentList $basevhd,$vms,$groups,$admin,$adminpass,$connectpass,$c
134
133
# autologon
135
134
$null = reg load ' HKLM\tmp' z:\windows\system32\config\software
136
135
$ok = $ok -band $?
137
- $null = reg add ' HKLM\tmp\Microsoft\Windows NT\CurrentVersion\WinLogon' / f / v DefaultUserName / t REG_SZ / d $admin
136
+ $null = reg add ' HKLM\tmp\Microsoft\Windows NT\CurrentVersion\WinLogon' / f / v DefaultUserName / t REG_SZ / d $using : admin
138
137
$ok = $ok -band $?
139
- $null = reg add ' HKLM\tmp\Microsoft\Windows NT\CurrentVersion\WinLogon' / f / v DefaultPassword / t REG_SZ / d $adminpass
138
+ $null = reg add ' HKLM\tmp\Microsoft\Windows NT\CurrentVersion\WinLogon' / f / v DefaultPassword / t REG_SZ / d $using : adminpass
140
139
$ok = $ok -band $?
141
140
$null = reg add ' HKLM\tmp\Microsoft\Windows NT\CurrentVersion\WinLogon' / f / v AutoAdminLogon / t REG_DWORD / d 1
142
141
$ok = $ok -band $?
@@ -161,7 +160,7 @@ icm $nodes -ArgumentList $basevhd,$vms,$groups,$admin,$adminpass,$connectpass,$c
161
160
}
162
161
163
162
del - Force z:\users\administrator\launch.ps1 - ErrorAction SilentlyContinue
164
- gc C:\ClusterStorage\collect\control\launch- template.ps1 | % { $_ -replace ' __CONNECTUSER__' , $connectuser -replace ' __CONNECTPASS__' , $connectpass } > z:\users\administrator\launch.ps1
163
+ gc C:\ClusterStorage\collect\control\launch- template.ps1 | % { $_ -replace ' __CONNECTUSER__' , $using : connectuser -replace ' __CONNECTPASS__' , $using : connectpass } > z:\users\administrator\launch.ps1
165
164
$ok = $ok -band $?
166
165
if (-not $ok ) {
167
166
Write-Error " failed injection of launch.ps1 for $vhdpath "
@@ -213,32 +212,52 @@ icm $nodes -ArgumentList $basevhd,$vms,$groups,$admin,$adminpass,$connectpass,$c
213
212
return $ok
214
213
}
215
214
216
- foreach ($csv in get-clustersharedvolume ) {
215
+ $csvs = Get-ClusterSharedVolume
216
+
217
+ # handle restore cases by mapping the csv to the friendly name of the volume
218
+ # don't rely on the csv name to contain this data
219
+
220
+ $vh = @ {}
221
+ Get-Volume | ? FileSystem -eq CSVFS | % { $vh [$_.Path ] = $_ }
222
+
223
+ $csvs | % {
224
+ $v = $vh [$_.SharedVolumeInfo.Partition.Name ]
225
+ if ($v -ne $null ) {
226
+ $_ | Add-Member - NotePropertyName VDName - NotePropertyValue $v.FileSystemLabel
227
+ }
228
+ }
229
+
230
+ foreach ($csv in $csvs ) {
217
231
218
- if ($groups.Length -eq 0 ) {
232
+ if ($ ( $ using : groups) .Length -eq 0 ) {
219
233
$groups = @ ( ' base' )
234
+ } else {
235
+ $groups = $using :groups
220
236
}
221
237
222
238
# identify the CSvs for which this node should create its VMs
223
239
# the trailing characters (if any) are the group prefix
224
- if ($csv.Name -match " \(( $env: COMPUTERNAME ) " ) {
240
+ if ($csv.VDName -match " ^ $env: COMPUTERNAME (?:-.+){0,1} " ) {
225
241
226
242
foreach ($group in $groups ) {
227
243
228
- if ($csv.Name -match " \(( $env: COMPUTERNAME ) -([^-]+)?\) " ) {
229
- $g = $group + $matches [2 ]
244
+ if ($csv.VDName -match " ^ $env: COMPUTERNAME -([^-]+)$ " ) {
245
+ $g = $group + $matches [1 ]
230
246
} else {
231
247
$g = $group
232
248
}
233
249
234
- foreach ($vm in 1 .. $vms ) {
250
+ foreach ($vm in 1 .. $using : vms ) {
235
251
236
252
$stop = $false
237
253
238
254
$newvm = $false
239
255
$name = " vm-$g -$env: COMPUTERNAME -$vm "
240
256
$path = Join-Path $csv.SharedVolumeInfo.FriendlyVolumeName $name
241
- $vhd = $path + " .vhdx"
257
+
258
+ # place vhdx in subdirectory, per scvmm layout defaults
259
+ # $vhd = $path+".vhdx"
260
+ $vhd = join-path $path " $name .vhdx"
242
261
243
262
# if the vm cluster group exists, we are already deployed
244
263
if (-not (Get-ClusterGroup - Name $name - ErrorAction SilentlyContinue)) {
@@ -267,7 +286,7 @@ icm $nodes -ArgumentList $basevhd,$vms,$groups,$admin,$adminpass,$connectpass,$c
267
286
$null = mkdir - ErrorAction SilentlyContinue $path
268
287
269
288
if (-not (gi $vhd - ErrorAction SilentlyContinue)) {
270
- cp $basevhd $vhd
289
+ cp $using : basevhd $vhd
271
290
} else {
272
291
write-host " vm vhd $vhd already exists"
273
292
}
@@ -280,6 +299,9 @@ icm $nodes -ArgumentList $basevhd,$vms,$groups,$admin,$adminpass,$connectpass,$c
280
299
if (-not $stop ) {
281
300
$o = new-vm - VHDPath $vhd - Generation 2 - SwitchName Internal - Path $path - Name $name
282
301
302
+ # create A1 VM. use set-vmfleet to alter fleet sizing post-creation.
303
+ $o | set-vm - ProcessorCount 1 - MemoryStartupBytes 1.75 GB - StaticMemory
304
+
283
305
# do not monitor the internal switch connection; this allows live migration
284
306
$o | Get-VMNetworkAdapter | Set-VMNetworkAdapter - NotMonitoredInCluster $true
285
307
}
@@ -307,10 +329,10 @@ icm $nodes -ArgumentList $basevhd,$vms,$groups,$admin,$adminpass,$connectpass,$c
307
329
$stop = Stop-After " CreateVMGroup"
308
330
}
309
331
310
- if (-not $stop -or ($specialize -eq ' Force' )) {
332
+ if (-not $stop -or ($using : specialize -eq ' Force' )) {
311
333
# specialize as needed
312
334
# auto only specializes new vms; force always; none skips it
313
- if (($specialize -eq ' Auto' -and $newvm ) -or ($specialize -eq ' Force' )) {
335
+ if (($using : specialize -eq ' Auto' -and $newvm ) -or ($using : specialize -eq ' Force' )) {
314
336
write-host - fore yellow specialize $vhd
315
337
if (-not (specialize- vhd $vhd )) {
316
338
write-host - fore red " Failed specialize of $vhd , halting."
0 commit comments