Skip to content

Commit ea30075

Browse files
authored
Update windows_userData.ps1
Fix lint issue Fix mount disk after restart Fix lun size to 90% of vol size
1 parent e9be514 commit ea30075

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

Management-Utilities/ec2-user-data-iscsi-create-and-mount/windows_userData.ps1

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ $volName="Fsx volume name, e.g. iscsiVol"
77
$volSize="volume size in GB, e.g 100"
88
$drive_letter="drive letter to use, e.g. d"
99

10+
# Default value is fsxnIscsi1, but you can change it to any other value according to yours FSx for ONTAP defintion
11+
$user="fsxadmin"
1012
# Default value is fsx, but you can change it to any other value according to yours FSx for ONTAP SVM name
1113
$svm_name="fsx"
1214

@@ -24,15 +26,16 @@ function unInstall {
2426
}
2527

2628
# default values
27-
# All FSxN instances are created with the user 'fsxadmin' which can't be changed
2829
# The script will create a log file in the Administrator home directory
2930
# The script will create an uninstall script in the Administrator home directory
30-
$user="fsxadmin"
3131
$currentLogPath="C:\Users\Administrator\install.log"
3232
$uninstallFile="C:\Users\Administrator\uninstall.ps1"
3333

3434
$password=Get-SECSecretValue -SecretId "$secretId" -Select "SecretString"
3535

36+
if (Test-Path $currentLogPath){
37+
Remove-Item -Path $currentLogPath -Force
38+
}
3639

3740
if( $null -eq $password -or $password -eq "" ) {
3841
Write-Output "Failed to get data from Secrets Manager, exiting..." >> $currentLogPath
@@ -49,14 +52,14 @@ $m = "NetApp.ONTAP"
4952
$path= "HKLM:\Software\UserData"
5053
$itemName = "FSXnRunStep"
5154

52-
if(!(Get-Item $Path -ErrorAction SilentlyContinue)) {
53-
New-Item $Path
54-
New-ItemProperty -Path $Path -Name $itemName -Value 0 -PropertyType dword
55+
if(!(Get-Item $path -ErrorAction SilentlyContinue)) {
56+
New-Item $path
57+
New-ItemProperty -Path $path -Name $itemName -Value 0 -PropertyType dword
5558
}
5659

5760
$runStep = Get-ItemProperty -Path $path -Name $itemName -ErrorAction SilentlyContinue | Select-Object -ExpandProperty $itemName
5861

59-
if($runStep -eq 0 -or (Get-Module | Where-Object {$_.Name -ne $m})) {
62+
if($runStep -eq 0) {
6063
Write-Output "Write-Host ""Uninstall FSxn configuration""" >> $uninstallFile
6164
Write-Output "# FSXn uninstall:" >> $uninstallFile
6265
Write-Output "Installing/ Import ONTAP module" >> $currentLogPath
@@ -192,20 +195,21 @@ if($runStep -eq 1) {
192195
catch {
193196
Write-Output "Failed create volume, due to: $_" >> $currentLogPath
194197
Write-Host "Failed create volume, due to: $_" -ForegroundColor Red
195-
unInstall $printUninstallConnect $ip $credntials $svm_name
198+
unInstall -printUninstallConnect $printUninstallConnect -ip $ip -credntials $credntials -svm_name $svm_name
196199
break
197200
}
198201

199202
Write-Output "Creating LUN" >> $currentLogPath
200203
Write-Host "Creating LUN" -ForegroundColor Yellow
201204
try {
202-
New-NcLun -Size $volSize'g' -OsType windows -Path /vol/$vol_name/$lun_name -Unreserved -ErrorAction stop
205+
$lunSize=0.9*$volSize
206+
New-NcLun -Size $lunSize'g' -OsType windows -Path /vol/$vol_name/$lun_name -Unreserved -ErrorAction stop
203207
@("Remove-NcLun $lun_name -force") + (Get-Content $uninstallFile) | Set-Content $uninstallFile
204208
}
205209
catch {
206210
Write-Output "Failed create LUN, due to: $_" >> $currentLogPath
207211
Write-Host "Failed create LUN, due to: $_" -ForegroundColor Red
208-
unInstall $printUninstallConnect $ip $credntials $svm_name
212+
unInstall -printUninstallConnect $printUninstallConnect -ip $ip -credntials $credntials -svm_name $svm_name
209213
break
210214
}
211215

@@ -218,7 +222,7 @@ if($runStep -eq 1) {
218222
catch {
219223
Write-Output "Failed create Igroup, due to: $_" >> $currentLogPath
220224
Write-Host "Failed create Igroup, due to: $_" -ForegroundColor Red
221-
unInstall $printUninstallConnect $ip $credntials $svm_name
225+
unInstall -printUninstallConnect $printUninstallConnect -ip $ip -credntials $credntials -svm_name $svm_name
222226
break
223227
}
224228

@@ -235,7 +239,7 @@ if($runStep -eq 1) {
235239
catch {
236240
Write-Output "Failed to add igroup initiator, due to: $_" >> $currentLogPath
237241
Write-Host "Failed to add igroup initiator, due to: $_" -ForegroundColor Red
238-
unInstall $printUninstallConnect
242+
unInstall -printUninstallConnect $printUninstallConnect
239243
break
240244
}
241245

@@ -248,7 +252,7 @@ if($runStep -eq 1) {
248252
catch {
249253
Write-Output "Failed mapping LUN to igroup, due to: $_" >> $currentLogPath
250254
Write-Host "Failed mapping LUN to igroup, due to: $_" -ForegroundColor Red
251-
unInstall $printUninstallConnect
255+
unInstall -printUninstallConnect $printUninstallConnect
252256
break
253257
}
254258

@@ -266,19 +270,19 @@ if($runStep -eq 1) {
266270
catch {
267271
Write-Output "Failed to add new target, due to: $_" >> $currentLogPath
268272
Write-Host "Failed to add new target, due to: $_" -ForegroundColor Red
269-
unInstall $printUninstallConnect
273+
unInstall -printUninstallConnect$printUninstallConnect
270274
break
271275
}
272276

273277
Write-Output "Connect to the new target" >> $currentLogPath
274278
try {
275-
Get-IscsiTarget | Connect-IscsiTarget -IsMultipathEnabled $true -ErrorAction stop
279+
Get-IscsiTarget | Connect-IscsiTarget -IsMultipathEnabled $true -ErrorAction stop -IsPersistent $true
276280
@("Get-IscsiTarget | Disconnect-IscsiTarget") + (Get-Content $uninstallFile) | Set-Content $uninstallFile
277281
}
278282
catch {
279283
Write-Output "Failed to connect to the new target, due to: $_" >> $currentLogPath
280284
Write-Host "Failed to connect to the new target, due to: $_" -ForegroundColor Red
281-
unInstall $printUninstallConnect
285+
unInstall -printUninstallConnect$printUninstallConnect
282286
break
283287
}
284288
@("Connect-NcController $ip -Credential $credntials -Vserver $svm_name -ErrorAction Stop") + (Get-Content $uninstallFile) | Set-Content $uninstallFile
@@ -338,5 +342,10 @@ else {
338342
Write-Output "FSx disk already created" >> $currentLogPath
339343
Write-Host "FSx disk already created" -ForegroundColor Green
340344
}
341-
Remove-Item -Path $uninstallFile -Force
345+
if (Test-Path $uninstallFile){
346+
Remove-Item -Path $uninstallFile -Force
347+
Write-Output "Uninstall script removed" >> $currentLogPath
348+
Write-Host "Uninstall script removed" -ForegroundColor Green
349+
}
342350
</powershell>
351+
<persist>true</persist>

0 commit comments

Comments
 (0)