/
Get-ImportServerConfigurationProfilePreviewREDFISH.psm1
543 lines (485 loc) · 17.2 KB
/
Get-ImportServerConfigurationProfilePreviewREDFISH.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
<#
_author_ = Texas Roemer <Texas_Roemer@Dell.com>
_version_ = 9.0
Copyright (c) 2017, Dell, Inc.
This software is licensed to you under the GNU General Public License,
version 2 (GPLv2). There is NO WARRANTY for this software, express or
implied, including the implied warranties of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
along with this software; if not, see
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
#>
<#
.Synopsis
iDRAC cmdlet using Redfish OEM extension to preview Server Configuration Profile (SCP) file located on supported network share.
.DESCRIPTION
iDRAC cmdlet using Redfish OEM extension to preview Server Configuration Profile (SCP) file located on supported network share. Recommended to use this action before attempting to import the SCP file. This preview action will validate the SCP file format is correct and attribute values are valid.
- idrac_ip (iDRAC IP) REQUIRED
- idrac_username (iDRAC user name)
- idrac_password (iDRAC user name password)
- x_auth_token: Pass in iDRAC X-Auth token session to execute cmdlet instead of username / password (recommended)
- network_share_IPAddress (Supported value: IP address of your network share)
- ShareName (Supported value: Name of your network share)
- ShareType (Supported values: NFS, CIFS, HTTP and HTTPS)
- FileName (Supported value: Pass in a name of the exported or imported file)
- Username (Supported value: Name of your username that has access to CIFS share) REQUIRED only for CIFS
- Password (Supported value: Name of your user password that has access to CIFS share) REQUIRED only for CIFS
.EXAMPLE
Get-ImportServerConfigurationProfilePreviewREDFISH -idrac_ip 192.168.0.120 -idrac_username root -idrac_password calvin -IPAddress 192.168.0.130 -ShareType NFS -ShareName /nfs -FileName export_SCP_R640.xml
This example shows executing import preview command using a SCP file located on NFS share.
.EXAMPLE
Get-ImportServerConfigurationProfilePreviewREDFISH -idrac_ip 192.168.0.120 -IPAddress 192.168.0.130 -ShareType NFS -ShareName /nfs -FileName export_SCP_R640.xml
This example will first prompt to enter iDRAC username and password using Get-Credential, then execute import preview command using a SCP file located on NFS share.
.EXAMPLE
Get-ImportServerConfigurationProfilePreviewREDFISH -idrac_ip 192.168.0.120 -IPAddress 192.168.0.130 -ShareType NFS -ShareName /nfs -FileName export_SCP_R640.xml -x_auth_token 7bd9bb9a8727ec366a9cef5bc83b2708
This example shows using iDRAC X-auth token session, execute import preview command using a SCP file located on NFS share.
#>
function Get-ImportServerConfigurationProfilePreviewREDFISH {
param(
[Parameter(Mandatory=$True)]
$idrac_ip,
[Parameter(Mandatory=$False)]
$idrac_username,
[Parameter(Mandatory=$False)]
$idrac_password,
[Parameter(Mandatory=$False)]
[string]$x_auth_token,
[Parameter(Mandatory=$True)]
[string]$ShareType,
[Parameter(Mandatory=$True)]
[string]$ShareName,
[Parameter(Mandatory=$True)]
[string]$network_share_IPAddress,
[Parameter(Mandatory=$True)]
[string]$FileName,
[Parameter(Mandatory=$False)]
[string]$cifs_username,
[Parameter(Mandatory=$False)]
[string]$cifs_password
)
$share_info = @{"ShareParameters"=@{}}
$share_info["ShareParameters"]["Target"]="ALL"
if ($ShareType)
{
$share_info["ShareParameters"]["ShareType"]=$ShareType
}
if ($network_share_IPAddress)
{
$share_info["ShareParameters"]["IPAddress"]=$network_share_IPAddress
}
if ($ShareName)
{
$share_info["ShareParameters"]["ShareName"]=$ShareName
}
if ($FileName)
{
$share_info["ShareParameters"]["FileName"]=$FileName
}
if ($cifs_password)
{
$share_info["ShareParameters"]["Password"]=$cifs_password
}
if ($cifs_username)
{
if ($cifs_username -and $fw_version -gt 316 -and $server_generation -eq "14G" -or $server_generation -eq "15G" -or $server_generation -eq "16G" -or $server_generation -eq "17G")
{
$share_info["ShareParameters"]["Username"]=$cifs_username
}
elseif ($cifs_username -and $fw_version -gt 264 -and $server_generation -eq "13G" -or $server_generation -eq "12G")
{
$share_info["ShareParameters"]["Username"]=$cifs_username
}
else
{
$share_info["ShareParameters"]["UserName"]=$cifs_username
}
}
Write-Host "`n- INFO, parameter details for $Method operation"
$share_info
Write-Host "`nShareParameters details:`n"
$share_info.ShareParameters
$JsonBody = $share_info | ConvertTo-Json -Compress
function Ignore-SSLCertificates
{
$Provider = New-Object Microsoft.CSharp.CSharpCodeProvider
$Compiler = $Provider.CreateCompiler()
$Params = New-Object System.CodeDom.Compiler.CompilerParameters
$Params.GenerateExecutable = $false
$Params.GenerateInMemory = $true
$Params.IncludeDebugInformation = $false
$Params.ReferencedAssemblies.Add("System.DLL") > $null
$TASource=@'
namespace Local.ToolkitExtensions.Net.CertificatePolicy
{
public class TrustAll : System.Net.ICertificatePolicy
{
public bool CheckValidationResult(System.Net.ServicePoint sp,System.Security.Cryptography.X509Certificates.X509Certificate cert, System.Net.WebRequest req, int problem)
{
return true;
}
}
}
'@
$TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
$TAAssembly=$TAResults.CompiledAssembly
$TrustAll = $TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
[System.Net.ServicePointManager]::CertificatePolicy = $TrustAll
}
# Function get Powershell version
$global:get_powershell_version = $null
function get_powershell_version
{
$get_host_info = Get-Host
$major_number = $get_host_info.Version.Major
$global:get_powershell_version = $major_number
}
get_powershell_version
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12
if ($idrac_username -and $idrac_password)
{
$user = $idrac_username
$pass= $idrac_password
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($user, $secpasswd)
}
elseif ($x_auth_token)
{
$global:x_auth_token = $x_auth_token
}
else
{
$get_creds = Get-Credential
$credential = New-Object System.Management.Automation.PSCredential($get_creds.UserName, $get_creds.Password)
}
$uri = "https://$idrac_ip/redfish/v1/Systems/System.Embedded.1"
if ($x_auth_token)
{
try
{
if ($global:get_powershell_version -gt 5)
{
$result = Invoke-WebRequest -SkipCertificateCheck -SkipHeaderValidation -Uri $uri -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept" = "application/json"; "X-Auth-Token" = $x_auth_token}
}
else
{
Ignore-SSLCertificates
$result = Invoke-WebRequest -Uri $uri -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept"="application/json"; "X-Auth-Token" = $x_auth_token}
}
}
catch
{
$RespErr
return
}
}
else
{
try
{
if ($global:get_powershell_version -gt 5)
{
$result = Invoke-WebRequest -SkipCertificateCheck -SkipHeaderValidation -Uri $uri -Credential $credential -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept"="application/json"}
}
else
{
Ignore-SSLCertificates
$result = Invoke-WebRequest -Uri $uri -Credential $credential -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept"="application/json"}
}
}
catch
{
$RespErr
return
}
}
$uri = "https://$idrac_ip/redfish/v1/Managers/iDRAC.Embedded.1"
if ($x_auth_token)
{
try
{
if ($global:get_powershell_version -gt 5)
{
$result = Invoke-WebRequest -SkipCertificateCheck -SkipHeaderValidation -Uri $uri -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept" = "application/json"; "X-Auth-Token" = $x_auth_token}
}
else
{
Ignore-SSLCertificates
$result = Invoke-WebRequest -Uri $uri -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept"="application/json"; "X-Auth-Token" = $x_auth_token}
}
}
catch
{
$RespErr
return
}
}
else
{
try
{
if ($global:get_powershell_version -gt 5)
{
$result = Invoke-WebRequest -SkipCertificateCheck -SkipHeaderValidation -Uri $uri -Credential $credential -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept"="application/json"}
}
else
{
Ignore-SSLCertificates
$result = Invoke-WebRequest -Uri $uri -Credential $credential -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept"="application/json"}
}
}
catch
{
Write-Host
$RespErr
return
}
}
if ($result.StatusCode -ne 200)
{
"`n- FAIL, GET request failed, status code {0} returned" -f $result.StatusCode
return
}
$get_result=$result.Content | ConvertFrom-Json
$server_generation = $get_result.Model.Split(" ")[0]
$fw_version = $get_result.FirmwareVersion.Split(".")[0]+$get_result.FirmwareVersion.Split(".")[1]
$fw_version = [int]$fw_version
$full_method_name="EID_674_Manager.ImportSystemConfigurationPreview"
$uri = "https://$idrac_ip/redfish/v1/Managers/iDRAC.Embedded.1/Actions/Oem/$full_method_name"
# POST command to import preview configuration file
if ($x_auth_token)
{
try
{
if ($global:get_powershell_version -gt 5)
{
$result1 = Invoke-WebRequest -UseBasicParsing -SkipHeaderValidation -SkipCertificateCheck -Uri $uri -Body $JsonBody -Method Post -ContentType 'application/json' -Headers @{"Accept" = "application/json"; "X-Auth-Token" = $x_auth_token} -ErrorVariable RespErr
}
else
{
Ignore-SSLCertificates
$result1 = Invoke-WebRequest -UseBasicParsing -Uri $uri -Method Post -ContentType 'application/json' -Headers @{"Accept" = "application/json"; "X-Auth-Token" = $x_auth_token} -Body $JsonBody -ErrorVariable RespErr
}
}
catch
{
Write-Host
$RespErr
return
}
}
else
{
try
{
if ($global:get_powershell_version -gt 5)
{
$result1 = Invoke-WebRequest -UseBasicParsing -SkipHeaderValidation -SkipCertificateCheck -Uri $uri -Credential $credential -Body $JsonBody -Method Post -ContentType 'application/json' -Headers @{"Accept"="application/json"} -ErrorVariable RespErr
}
else
{
Ignore-SSLCertificates
$result1 = Invoke-WebRequest -UseBasicParsing -Uri $uri -Credential $credential -Method Post -ContentType 'application/json' -Headers @{"Accept"="application/json"} -Body $JsonBody -ErrorVariable RespErr
}
}
catch
{
Write-Host
$RespErr
return
}
}
$raw_content=$result1.RawContent | ConvertTo-Json -Compress
$job_id_search=[regex]::Match($raw_content, "JID_.+?r").captures.groups[0].value
$job_id=$job_id_search.Replace("\r","")
if ($result1.StatusCode -eq 202)
{
Write-Host
[String]::Format("- PASS, statuscode {0} returned to successfully create job: {1}",$result1.StatusCode,$job_id)
Write-Host
Start-Sleep 5
}
else
{
[String]::Format("- FAIL, statuscode {0} returned",$result1.StatusCode)
return
}
$overall_job_output=""
$get_time_old=Get-Date -DisplayHint Time
$start_time = Get-Date
$end_time = $start_time.AddMinutes(10)
# While loop to query the job status until marked completed
while ($overall_job_output.JobState -ne "Completed")
{
$loop_time = Get-Date
$uri ="https://$idrac_ip/redfish/v1/Managers/iDRAC.Embedded.1/Jobs/$job_id"
if ($x_auth_token)
{
try
{
if ($global:get_powershell_version -gt 5)
{
$result = Invoke-WebRequest -SkipCertificateCheck -SkipHeaderValidation -Uri $uri -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept" = "application/json"; "X-Auth-Token" = $x_auth_token}
}
else
{
Ignore-SSLCertificates
$result = Invoke-WebRequest -Uri $uri -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept"="application/json"; "X-Auth-Token" = $x_auth_token}
}
}
catch
{
$RespErr
return
}
}
else
{
try
{
if ($global:get_powershell_version -gt 5)
{
$result = Invoke-WebRequest -SkipCertificateCheck -SkipHeaderValidation -Uri $uri -Credential $credential -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept"="application/json"}
}
else
{
Ignore-SSLCertificates
$result = Invoke-WebRequest -Uri $uri -Credential $credential -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept"="application/json"}
}
}
catch
{
$RespErr
return
}
}
$overall_job_output=$result.Content | ConvertFrom-Json
if ($overall_job_output.JobState -eq "Failed") {
Write-Host
[String]::Format("- FAIL, final job status is: {0}, no configuration changes were applied",$overall_job_output.JobState)
if ($overall_job_output.Message -eq "The system could not be shut down within the specified time.")
{
[String]::Format("- FAIL, 10 minute default shutdown timeout reached, final job message is: {0}",$overall_job_output.Message)
return
}
else
{
[String]::Format("- FAIL, final job message is: {0}",$overall_job_output.Message)
return
}
}
elseif ($loop_time -gt $end_time)
{
Write-Host "- FAIL, timeout of 30 minutes has been reached before marking the job completed"
return
}
elseif ($overall_job_output.Message -eq "Import of Server Configuration Profile operation completed with errors.") {
Write-Host
[String]::Format("- WARNING, final job status is: {0}",$overall_job_output.Message)
$uri ="https://$idrac_ip/redfish/v1/TaskService/Tasks/$job_id"
if ($x_auth_token)
{
try
{
if ($global:get_powershell_version -gt 5)
{
$result = Invoke-WebRequest -SkipCertificateCheck -SkipHeaderValidation -Uri $uri -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept" = "application/json"; "X-Auth-Token" = $x_auth_token}
}
else
{
Ignore-SSLCertificates
$result = Invoke-WebRequest -Uri $uri -Credential $credential -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept"="application/json"; "X-Auth-Token" = $x_auth_token}
}
}
catch
{
$RespErr
return
}
}
else
{
try
{
if ($global:get_powershell_version -gt 5)
{
$result = Invoke-WebRequest -SkipCertificateCheck -SkipHeaderValidation -Uri $uri -Credential $credential -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept"="application/json"}
}
else
{
Ignore-SSLCertificates
$result = Invoke-WebRequest -Uri $uri -Credential $credential -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept"="application/json"}
}
}
catch
{
$RespErr
return
}
}
Write-Host "`n- Detailed final job status and configuration results for import job ID '$job_id' -`n"
$get_final_results = [string]$result.Content
$get_final_results.Split(",")
return
}
else {
[String]::Format("- WARNING, import job ID not marked completed, current job status: {0}",$overall_job_output.Message)
Start-Sleep 10
}
}
Write-Host
[String]::Format("- PASS, {0} job ID marked as completed!",$job_id)
$final_message = $overall_job_output.Message
if ($final_message.Contains("No changes were applied"))
{
[String]::Format("`n- Final job status is: {0}",$overall_job_output.Message)
return
}
$get_current_time=Get-Date -DisplayHint Time
$final_time=$get_current_time-$get_time_old
$final_completion_time=$final_time | select Minutes,Seconds
Write-Host " Job completed in $final_completion_time"
$uri ="https://$idrac_ip/redfish/v1/TaskService/Tasks/$job_id"
if ($x_auth_token)
{
try
{
if ($global:get_powershell_version -gt 5)
{
$result = Invoke-WebRequest -SkipCertificateCheck -SkipHeaderValidation -Uri $uri -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept" = "application/json"; "X-Auth-Token" = $x_auth_token}
}
else
{
Ignore-SSLCertificates
$result = Invoke-WebRequest -Uri $uri -Credential $credential -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept"="application/json"; "X-Auth-Token" = $x_auth_token}
}
}
catch
{
$RespErr
return
}
}
else
{
try
{
if ($global:get_powershell_version -gt 5)
{
$result = Invoke-WebRequest -SkipCertificateCheck -SkipHeaderValidation -Uri $uri -Credential $credential -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept"="application/json"}
}
else
{
Ignore-SSLCertificates
$result = Invoke-WebRequest -Uri $uri -Credential $credential -Method Get -UseBasicParsing -ErrorVariable RespErr -Headers @{"Accept"="application/json"}
}
}
catch
{
$RespErr
return
}
}
Write-Host "`n- Detailed final job status and configuration results for import job ID '$job_id' -`n"
$get_final_results = [string]$result.Content
$get_final_results.Split(",")
}