idrac 0.1.91 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/idrac +754 -4
- data/lib/idrac/boot.rb +357 -0
- data/lib/idrac/client.rb +167 -72
- data/lib/idrac/core_ext.rb +100 -0
- data/lib/idrac/lifecycle.rb +86 -189
- data/lib/idrac/session.rb +134 -85
- data/lib/idrac/storage.rb +374 -0
- data/lib/idrac/system.rb +383 -0
- data/lib/idrac/version.rb +1 -1
- data/lib/idrac/virtual_media.rb +285 -0
- data/lib/idrac.rb +16 -11
- metadata +7 -2
data/lib/idrac/session.rb
CHANGED
@@ -50,24 +50,24 @@ module IDRAC
|
|
50
50
|
|
51
51
|
# Force clear all sessions by directly using Basic Auth
|
52
52
|
def force_clear_sessions
|
53
|
-
debug "Attempting to force clear all sessions...",
|
53
|
+
debug "Attempting to force clear all sessions...", 1
|
54
54
|
|
55
55
|
max_retries = 3
|
56
56
|
retry_count = 0
|
57
57
|
|
58
58
|
while retry_count < max_retries
|
59
59
|
if delete_all_sessions_with_basic_auth
|
60
|
-
debug "Successfully cleared sessions using Basic Auth",
|
60
|
+
debug "Successfully cleared sessions using Basic Auth", 1, :green
|
61
61
|
return true
|
62
62
|
else
|
63
63
|
retry_count += 1
|
64
64
|
if retry_count < max_retries
|
65
65
|
# Exponential backoff
|
66
66
|
sleep_time = 2 ** retry_count
|
67
|
-
debug "Retrying session clear after #{sleep_time} seconds (attempt #{retry_count+1}/#{max_retries})",
|
67
|
+
debug "Retrying session clear after #{sleep_time} seconds (attempt #{retry_count+1}/#{max_retries})", 1, :light_yellow
|
68
68
|
sleep(sleep_time)
|
69
69
|
else
|
70
|
-
debug "Failed to clear sessions after #{max_retries} attempts",
|
70
|
+
debug "Failed to clear sessions after #{max_retries} attempts", 1, :red
|
71
71
|
return false
|
72
72
|
end
|
73
73
|
end
|
@@ -78,7 +78,7 @@ module IDRAC
|
|
78
78
|
|
79
79
|
# Delete all sessions using Basic Authentication
|
80
80
|
def delete_all_sessions_with_basic_auth
|
81
|
-
debug "Attempting to delete all sessions using Basic Authentication...",
|
81
|
+
debug "Attempting to delete all sessions using Basic Authentication...", 1
|
82
82
|
|
83
83
|
# First, get the list of sessions
|
84
84
|
sessions_url = determine_session_endpoint
|
@@ -88,10 +88,10 @@ module IDRAC
|
|
88
88
|
response = request_with_basic_auth(:get, sessions_url, nil, 'application/json')
|
89
89
|
|
90
90
|
if response.status != 200
|
91
|
-
debug "Failed to get sessions list: #{response.status} - #{response.body}",
|
91
|
+
debug "Failed to get sessions list: #{response.status} - #{response.body}", 1, :red
|
92
92
|
# If we received HTML error, assume we can't get sessions and try direct session deletion
|
93
93
|
if response.headers['content-type']&.include?('text/html') || response.body.to_s.include?('DOCTYPE html')
|
94
|
-
debug "Received HTML error response, trying direct session deletion",
|
94
|
+
debug "Received HTML error response, trying direct session deletion", 1, :light_yellow
|
95
95
|
return try_delete_latest_sessions
|
96
96
|
end
|
97
97
|
return false
|
@@ -102,7 +102,7 @@ module IDRAC
|
|
102
102
|
sessions_data = JSON.parse(response.body)
|
103
103
|
|
104
104
|
if sessions_data['Members'] && sessions_data['Members'].any?
|
105
|
-
debug "Found #{sessions_data['Members'].count} active sessions",
|
105
|
+
debug "Found #{sessions_data['Members'].count} active sessions", 1, :light_yellow
|
106
106
|
|
107
107
|
# Delete each session
|
108
108
|
success = true
|
@@ -118,7 +118,7 @@ module IDRAC
|
|
118
118
|
if delete_response.status == 200 || delete_response.status == 204
|
119
119
|
debug "Successfully deleted session: #{session_url}", 1, :green
|
120
120
|
else
|
121
|
-
debug "Failed to delete session #{session_url}: #{delete_response.status}",
|
121
|
+
debug "Failed to delete session #{session_url}: #{delete_response.status}", 1, :red
|
122
122
|
success = false
|
123
123
|
end
|
124
124
|
|
@@ -128,17 +128,17 @@ module IDRAC
|
|
128
128
|
|
129
129
|
return success
|
130
130
|
else
|
131
|
-
debug "No active sessions found",
|
131
|
+
debug "No active sessions found", 1, :light_yellow
|
132
132
|
return true
|
133
133
|
end
|
134
134
|
rescue JSON::ParserError => e
|
135
|
-
debug "Error parsing sessions response: #{e.message}",
|
136
|
-
debug "Trying direct session deletion",
|
135
|
+
debug "Error parsing sessions response: #{e.message}", 1, :red
|
136
|
+
debug "Trying direct session deletion", 1, :light_yellow
|
137
137
|
return try_delete_latest_sessions
|
138
138
|
end
|
139
139
|
rescue => e
|
140
|
-
debug "Error during session deletion with Basic Auth: #{e.message}",
|
141
|
-
debug "Trying direct session deletion",
|
140
|
+
debug "Error during session deletion with Basic Auth: #{e.message}", 1, :red
|
141
|
+
debug "Trying direct session deletion", 1, :light_yellow
|
142
142
|
return try_delete_latest_sessions
|
143
143
|
end
|
144
144
|
end
|
@@ -146,7 +146,7 @@ module IDRAC
|
|
146
146
|
# Try to delete sessions by direct URL when we can't list sessions
|
147
147
|
def try_delete_latest_sessions
|
148
148
|
# Try to delete sessions by direct URL when we can't list sessions
|
149
|
-
debug "Attempting to delete recent sessions directly...",
|
149
|
+
debug "Attempting to delete recent sessions directly...", 1
|
150
150
|
base_url = determine_session_endpoint
|
151
151
|
success = false
|
152
152
|
|
@@ -177,7 +177,7 @@ module IDRAC
|
|
177
177
|
def create
|
178
178
|
# Skip if we're in direct mode
|
179
179
|
if @direct_mode
|
180
|
-
debug "Skipping Redfish session creation (direct mode)",
|
180
|
+
debug "Skipping Redfish session creation (direct mode)", 1, :light_yellow
|
181
181
|
return false
|
182
182
|
end
|
183
183
|
|
@@ -186,7 +186,7 @@ module IDRAC
|
|
186
186
|
|
187
187
|
payload = { "UserName" => username, "Password" => password }
|
188
188
|
|
189
|
-
debug "Attempting to create Redfish session at #{base_url}#{session_endpoint}",
|
189
|
+
debug "Attempting to create Redfish session at #{base_url}#{session_endpoint}", 1
|
190
190
|
debug "SSL verification: #{verify_ssl ? 'Enabled' : 'Disabled'}", 1
|
191
191
|
print_connection_debug_info if @verbosity >= 2
|
192
192
|
|
@@ -203,29 +203,78 @@ module IDRAC
|
|
203
203
|
|
204
204
|
# Delete the Redfish session
|
205
205
|
def delete
|
206
|
-
return unless @x_auth_token
|
206
|
+
return false unless @x_auth_token || @session_location
|
207
207
|
|
208
208
|
begin
|
209
|
-
debug "Deleting Redfish session...",
|
209
|
+
debug "Deleting Redfish session...", 1
|
210
210
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
211
|
+
if @session_location
|
212
|
+
# Use the X-Auth-Token for authentication
|
213
|
+
headers = { 'X-Auth-Token' => @x_auth_token }
|
214
|
+
|
215
|
+
begin
|
216
|
+
response = connection.delete(@session_location) do |req|
|
217
|
+
req.headers.merge!(headers)
|
218
|
+
end
|
219
|
+
|
220
|
+
if response.status == 200 || response.status == 204
|
221
|
+
debug "Redfish session deleted successfully", 1, :green
|
222
|
+
@x_auth_token = nil
|
223
|
+
@session_location = nil
|
224
|
+
return true
|
225
|
+
end
|
226
|
+
rescue => session_e
|
227
|
+
debug "Error during session deletion via location: #{session_e.message}", 1, :yellow
|
228
|
+
# Continue to try basic auth method
|
229
|
+
end
|
216
230
|
end
|
217
231
|
|
218
|
-
|
219
|
-
|
232
|
+
# If deleting via session location fails or there's no session location,
|
233
|
+
# try to delete by using the basic auth method
|
234
|
+
if @x_auth_token
|
235
|
+
# Try to determine session ID from the X-Auth-Token or session_location
|
236
|
+
session_id = nil
|
237
|
+
|
238
|
+
# Extract session ID from location if available
|
239
|
+
if @session_location
|
240
|
+
if @session_location =~ /\/([^\/]+)$/
|
241
|
+
session_id = $1
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
# If we have an extracted session ID
|
246
|
+
if session_id
|
247
|
+
debug "Trying to delete session by ID #{session_id}", 1
|
248
|
+
|
249
|
+
begin
|
250
|
+
endpoint = determine_session_endpoint
|
251
|
+
delete_url = "#{endpoint}/#{session_id}"
|
252
|
+
|
253
|
+
delete_response = request_with_basic_auth(:delete, delete_url, nil)
|
254
|
+
|
255
|
+
if delete_response.status == 200 || delete_response.status == 204
|
256
|
+
debug "Successfully deleted session via ID", 1, :green
|
257
|
+
@x_auth_token = nil
|
258
|
+
@session_location = nil
|
259
|
+
return true
|
260
|
+
end
|
261
|
+
rescue => id_e
|
262
|
+
debug "Error during session deletion via ID: #{id_e.message}", 1, :yellow
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
# Last resort: clear the token variable even if we couldn't properly delete it
|
267
|
+
debug "Clearing session token internally", 1, :yellow
|
220
268
|
@x_auth_token = nil
|
221
269
|
@session_location = nil
|
222
|
-
return true
|
223
|
-
else
|
224
|
-
debug "Failed to delete Redfish session: #{response.status} - #{response.body}", 0, :red
|
225
|
-
return false
|
226
270
|
end
|
271
|
+
|
272
|
+
return false
|
227
273
|
rescue => e
|
228
|
-
debug "Error during Redfish session deletion: #{e.message}",
|
274
|
+
debug "Error during Redfish session deletion: #{e.message}", 1, :red
|
275
|
+
# Clear token variable anyway
|
276
|
+
@x_auth_token = nil
|
277
|
+
@session_location = nil
|
229
278
|
return false
|
230
279
|
end
|
231
280
|
end
|
@@ -315,12 +364,12 @@ module IDRAC
|
|
315
364
|
debug "Request headers: #{req.headers.reject { |k,v| k =~ /auth/i }.to_json}", 2
|
316
365
|
end
|
317
366
|
rescue Faraday::SSLError => e
|
318
|
-
debug "SSL Error in Basic Auth request: #{e.message}",
|
367
|
+
debug "SSL Error in Basic Auth request: #{e.message}", 1, :red
|
319
368
|
debug "OpenSSL version: #{OpenSSL::OPENSSL_VERSION}", 1
|
320
369
|
debug e.backtrace.join("\n"), 3 if e.backtrace && @verbosity >= 3
|
321
370
|
raise e
|
322
371
|
rescue => e
|
323
|
-
debug "Error during #{method} request with Basic Auth: #{e.class.name}: #{e.message}",
|
372
|
+
debug "Error during #{method} request with Basic Auth: #{e.class.name}: #{e.message}", 1, :red
|
324
373
|
debug e.backtrace.join("\n"), 2 if e.backtrace && @verbosity >= 2
|
325
374
|
raise e
|
326
375
|
end
|
@@ -338,7 +387,7 @@ module IDRAC
|
|
338
387
|
|
339
388
|
def create_session_with_content_type(url, payload)
|
340
389
|
begin
|
341
|
-
debug "Creating session with Content-Type: application/json",
|
390
|
+
debug "Creating session with Content-Type: application/json", 1
|
342
391
|
|
343
392
|
response = connection.post(url) do |req|
|
344
393
|
req.headers['Content-Type'] = 'application/json'
|
@@ -353,18 +402,18 @@ module IDRAC
|
|
353
402
|
debug "Response body: #{response.body}", 2
|
354
403
|
|
355
404
|
if response.status == 405
|
356
|
-
debug "405 Method Not Allowed: Check if the endpoint supports POST requests and verify the request format.",
|
405
|
+
debug "405 Method Not Allowed: Check if the endpoint supports POST requests and verify the request format.", 1, :red
|
357
406
|
return false
|
358
407
|
end
|
359
408
|
|
360
409
|
if process_session_response(response)
|
361
|
-
debug "Redfish session created successfully",
|
410
|
+
debug "Redfish session created successfully", 1, :green
|
362
411
|
return true
|
363
412
|
end
|
364
413
|
|
365
414
|
# If the response status is 415 (Unsupported Media Type), try with different Content-Type
|
366
415
|
if response.status == 415 || (response.body.to_s.include?("unsupported media type"))
|
367
|
-
debug "415 Unsupported Media Type, trying alternate content type",
|
416
|
+
debug "415 Unsupported Media Type, trying alternate content type", 1, :yellow
|
368
417
|
|
369
418
|
# Try with no content-type header, just the payload
|
370
419
|
alt_response = connection.post(url) do |req|
|
@@ -374,18 +423,18 @@ module IDRAC
|
|
374
423
|
end
|
375
424
|
|
376
425
|
if process_session_response(alt_response)
|
377
|
-
debug "Redfish session created successfully with alternate content type",
|
426
|
+
debug "Redfish session created successfully with alternate content type", 1, :green
|
378
427
|
return true
|
379
428
|
end
|
380
429
|
end
|
381
430
|
rescue Faraday::SSLError => e
|
382
|
-
debug "SSL Error: #{e.message}",
|
431
|
+
debug "SSL Error: #{e.message}", 1, :red
|
383
432
|
debug "OpenSSL version: #{OpenSSL::OPENSSL_VERSION}", 1
|
384
433
|
debug "Connection URL: #{base_url}#{url}", 1
|
385
434
|
debug e.backtrace.join("\n"), 3 if e.backtrace && @verbosity >= 3
|
386
435
|
return false
|
387
436
|
rescue => e
|
388
|
-
debug "First session creation attempt failed: #{e.class.name}: #{e.message}",
|
437
|
+
debug "First session creation attempt failed: #{e.class.name}: #{e.message}", 1, :light_red
|
389
438
|
debug e.backtrace.join("\n"), 2 if e.backtrace && @verbosity >= 2
|
390
439
|
end
|
391
440
|
false
|
@@ -393,7 +442,7 @@ module IDRAC
|
|
393
442
|
|
394
443
|
def create_session_with_basic_auth(url, payload)
|
395
444
|
begin
|
396
|
-
debug "Creating session with Basic Auth",
|
445
|
+
debug "Creating session with Basic Auth", 1
|
397
446
|
|
398
447
|
# Try first with JSON format
|
399
448
|
response = request_with_basic_auth(:post, url, payload.to_json, 'application/json')
|
@@ -406,26 +455,26 @@ module IDRAC
|
|
406
455
|
end
|
407
456
|
|
408
457
|
if process_session_response(response)
|
409
|
-
debug "Redfish session created successfully with Basic Auth (JSON)",
|
458
|
+
debug "Redfish session created successfully with Basic Auth (JSON)", 1, :green
|
410
459
|
return true
|
411
460
|
end
|
412
461
|
|
413
462
|
# If that fails, try with form-urlencoded
|
414
463
|
if response.status == 415 || (response.body.to_s.include?("unsupported media type"))
|
415
|
-
debug "415 Unsupported Media Type with JSON, trying form-urlencoded",
|
464
|
+
debug "415 Unsupported Media Type with JSON, trying form-urlencoded", 1, :yellow
|
416
465
|
|
417
466
|
form_data = "UserName=#{URI.encode_www_form_component(username)}&Password=#{URI.encode_www_form_component(password)}"
|
418
467
|
form_response = request_with_basic_auth(:post, url, form_data, 'application/x-www-form-urlencoded')
|
419
468
|
|
420
469
|
if process_session_response(form_response)
|
421
|
-
debug "Redfish session created successfully with Basic Auth (form-urlencoded)",
|
470
|
+
debug "Redfish session created successfully with Basic Auth (form-urlencoded)", 1, :green
|
422
471
|
return true
|
423
472
|
elsif form_response.status == 400
|
424
473
|
# Check for maximum sessions error
|
425
474
|
if (form_response.body.include?("maximum number of user sessions") ||
|
426
475
|
form_response.body.include?("RAC0218") ||
|
427
476
|
form_response.body.include?("Internal Server Error"))
|
428
|
-
debug "Maximum sessions reached detected during session creation",
|
477
|
+
debug "Maximum sessions reached detected during session creation", 1, :light_red
|
429
478
|
@sessions_maxed = true
|
430
479
|
return false
|
431
480
|
end
|
@@ -435,14 +484,14 @@ module IDRAC
|
|
435
484
|
if (response.body.include?("maximum number of user sessions") ||
|
436
485
|
response.body.include?("RAC0218") ||
|
437
486
|
response.body.include?("Internal Server Error"))
|
438
|
-
debug "Maximum sessions reached detected during session creation",
|
487
|
+
debug "Maximum sessions reached detected during session creation", 1, :light_red
|
439
488
|
@sessions_maxed = true
|
440
489
|
return false
|
441
490
|
end
|
442
491
|
end
|
443
492
|
|
444
493
|
# Try one more approach with no Content-Type header
|
445
|
-
debug "Trying Basic Auth with no Content-Type header",
|
494
|
+
debug "Trying Basic Auth with no Content-Type header", 1, :yellow
|
446
495
|
no_content_type_response = connection.post(url) do |req|
|
447
496
|
req.headers['Authorization'] = "Basic #{Base64.strict_encode64("#{username}:#{password}")}"
|
448
497
|
req.headers['Accept'] = '*/*'
|
@@ -450,19 +499,19 @@ module IDRAC
|
|
450
499
|
end
|
451
500
|
|
452
501
|
if process_session_response(no_content_type_response)
|
453
|
-
debug "Redfish session created successfully with Basic Auth (no content type)",
|
502
|
+
debug "Redfish session created successfully with Basic Auth (no content type)", 1, :green
|
454
503
|
return true
|
455
504
|
end
|
456
505
|
|
457
|
-
debug "Failed to create Redfish session: #{response.status} - #{response.body}",
|
506
|
+
debug "Failed to create Redfish session: #{response.status} - #{response.body}", 1, :red
|
458
507
|
return false
|
459
508
|
rescue Faraday::SSLError => e
|
460
|
-
debug "SSL Error in Basic Auth request: #{e.message}",
|
509
|
+
debug "SSL Error in Basic Auth request: #{e.message}", 1, :red
|
461
510
|
debug "OpenSSL version: #{OpenSSL::OPENSSL_VERSION}", 1
|
462
511
|
debug e.backtrace.join("\n"), 3 if e.backtrace && @verbosity >= 3
|
463
512
|
return false
|
464
513
|
rescue => e
|
465
|
-
debug "Error during Redfish session creation with Basic Auth: #{e.class.name}: #{e.message}",
|
514
|
+
debug "Error during Redfish session creation with Basic Auth: #{e.class.name}: #{e.message}", 1, :red
|
466
515
|
debug e.backtrace.join("\n"), 2 if e.backtrace && @verbosity >= 2
|
467
516
|
return false
|
468
517
|
end
|
@@ -471,10 +520,10 @@ module IDRAC
|
|
471
520
|
def handle_max_sessions_and_retry(url, payload)
|
472
521
|
return false unless @sessions_maxed
|
473
522
|
|
474
|
-
debug "Maximum sessions reached, attempting to clear sessions",
|
523
|
+
debug "Maximum sessions reached, attempting to clear sessions", 1
|
475
524
|
if @auto_delete_sessions
|
476
525
|
if force_clear_sessions
|
477
|
-
debug "Successfully cleared sessions, trying to create a new session",
|
526
|
+
debug "Successfully cleared sessions, trying to create a new session", 1, :green
|
478
527
|
|
479
528
|
# Give the iDRAC a moment to process the session deletions
|
480
529
|
sleep(3)
|
@@ -488,28 +537,28 @@ module IDRAC
|
|
488
537
|
end
|
489
538
|
|
490
539
|
if process_session_response(response)
|
491
|
-
debug "Redfish session created successfully after clearing sessions",
|
540
|
+
debug "Redfish session created successfully after clearing sessions", 1, :green
|
492
541
|
return true
|
493
542
|
else
|
494
|
-
debug "Failed to create Redfish session after clearing sessions: #{response.status} - #{response.body}",
|
543
|
+
debug "Failed to create Redfish session after clearing sessions: #{response.status} - #{response.body}", 1, :red
|
495
544
|
# If still failing, try direct mode
|
496
|
-
debug "Falling back to direct mode",
|
545
|
+
debug "Falling back to direct mode", 1, :light_yellow
|
497
546
|
@direct_mode = true
|
498
547
|
return false
|
499
548
|
end
|
500
549
|
rescue => e
|
501
|
-
debug "Error during session creation after clearing: #{e.class.name}: #{e.message}",
|
502
|
-
debug "Falling back to direct mode",
|
550
|
+
debug "Error during session creation after clearing: #{e.class.name}: #{e.message}", 1, :red
|
551
|
+
debug "Falling back to direct mode", 1, :light_yellow
|
503
552
|
@direct_mode = true
|
504
553
|
return false
|
505
554
|
end
|
506
555
|
else
|
507
|
-
debug "Failed to clear sessions, switching to direct mode",
|
556
|
+
debug "Failed to clear sessions, switching to direct mode", 1, :light_yellow
|
508
557
|
@direct_mode = true
|
509
558
|
return false
|
510
559
|
end
|
511
560
|
else
|
512
|
-
debug "Auto delete sessions is disabled, switching to direct mode",
|
561
|
+
debug "Auto delete sessions is disabled, switching to direct mode", 1, :light_yellow
|
513
562
|
@direct_mode = true
|
514
563
|
return false
|
515
564
|
end
|
@@ -518,7 +567,7 @@ module IDRAC
|
|
518
567
|
def create_session_with_form_urlencoded(url, payload)
|
519
568
|
# Only try with form-urlencoded if we had a 415 error previously
|
520
569
|
begin
|
521
|
-
debug "Trying with form-urlencoded content type",
|
570
|
+
debug "Trying with form-urlencoded content type", 1
|
522
571
|
debug "URL: #{base_url}#{url}", 1
|
523
572
|
|
524
573
|
# Try first without any authorization header
|
@@ -534,21 +583,21 @@ module IDRAC
|
|
534
583
|
debug "Response body: #{response.body}", 3
|
535
584
|
|
536
585
|
if process_session_response(response)
|
537
|
-
debug "Redfish session created successfully with form-urlencoded",
|
586
|
+
debug "Redfish session created successfully with form-urlencoded", 1, :green
|
538
587
|
return true
|
539
588
|
end
|
540
589
|
|
541
590
|
# If that fails, try with Basic Auth + form-urlencoded
|
542
|
-
debug "Trying form-urlencoded with Basic Auth",
|
591
|
+
debug "Trying form-urlencoded with Basic Auth", 1
|
543
592
|
auth_response = request_with_basic_auth(:post, url, "UserName=#{URI.encode_www_form_component(username)}&Password=#{URI.encode_www_form_component(password)}", 'application/x-www-form-urlencoded')
|
544
593
|
|
545
594
|
if process_session_response(auth_response)
|
546
|
-
debug "Redfish session created successfully with form-urlencoded + Basic Auth",
|
595
|
+
debug "Redfish session created successfully with form-urlencoded + Basic Auth", 1, :green
|
547
596
|
return true
|
548
597
|
end
|
549
598
|
|
550
599
|
# Last resort: try with both headers (some iDRAC versions need this)
|
551
|
-
debug "Trying with both Content-Type headers",
|
600
|
+
debug "Trying with both Content-Type headers", 1
|
552
601
|
both_response = connection.post(url) do |req|
|
553
602
|
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
554
603
|
req.headers['Accept'] = 'application/json'
|
@@ -558,20 +607,20 @@ module IDRAC
|
|
558
607
|
end
|
559
608
|
|
560
609
|
if process_session_response(both_response)
|
561
|
-
debug "Redfish session created successfully with multiple content types",
|
610
|
+
debug "Redfish session created successfully with multiple content types", 1, :green
|
562
611
|
return true
|
563
612
|
else
|
564
|
-
debug "Failed with form-urlencoded too: #{response.status} - #{response.body}",
|
613
|
+
debug "Failed with form-urlencoded too: #{response.status} - #{response.body}", 1, :red
|
565
614
|
return false
|
566
615
|
end
|
567
616
|
rescue Faraday::SSLError => e
|
568
|
-
debug "SSL Error in form-urlencoded request: #{e.message}",
|
617
|
+
debug "SSL Error in form-urlencoded request: #{e.message}", 1, :red
|
569
618
|
debug "OpenSSL version: #{OpenSSL::OPENSSL_VERSION}", 1
|
570
619
|
debug "Connection URL: #{base_url}#{url}", 1
|
571
620
|
debug e.backtrace.join("\n"), 3 if e.backtrace && @verbosity >= 3
|
572
621
|
return false
|
573
622
|
rescue => e
|
574
|
-
debug "Error during form-urlencoded session creation: #{e.class.name}: #{e.message}",
|
623
|
+
debug "Error during form-urlencoded session creation: #{e.class.name}: #{e.message}", 1, :red
|
575
624
|
debug e.backtrace.join("\n"), 2 if e.backtrace && @verbosity >= 2
|
576
625
|
return false
|
577
626
|
end
|
@@ -607,21 +656,21 @@ module IDRAC
|
|
607
656
|
end
|
608
657
|
end
|
609
658
|
rescue JSON::ParserError => e
|
610
|
-
debug "Error parsing Redfish version: #{e.message}",
|
659
|
+
debug "Error parsing Redfish version: #{e.message}", 1, :red
|
611
660
|
debug e.backtrace.join("\n"), 3 if e.backtrace && @verbosity >= 3
|
612
661
|
rescue => e
|
613
|
-
debug "Error determining Redfish version: #{e.message}",
|
662
|
+
debug "Error determining Redfish version: #{e.message}", 1, :red
|
614
663
|
debug e.backtrace.join("\n"), 3 if e.backtrace && @verbosity >= 3
|
615
664
|
end
|
616
665
|
end
|
617
666
|
rescue => e
|
618
|
-
debug "Error checking Redfish version: #{e.message}",
|
667
|
+
debug "Error checking Redfish version: #{e.message}", 1, :red
|
619
668
|
debug e.backtrace.join("\n"), 3 if e.backtrace && @verbosity >= 3
|
620
669
|
end
|
621
670
|
|
622
671
|
# Default to /redfish/v1/Sessions if we can't determine version
|
623
672
|
default_endpoint = '/redfish/v1/Sessions'
|
624
|
-
debug "Defaulting to endpoint #{default_endpoint}",
|
673
|
+
debug "Defaulting to endpoint #{default_endpoint}", 1, :light_yellow
|
625
674
|
default_endpoint
|
626
675
|
end
|
627
676
|
end
|
@@ -629,34 +678,34 @@ module IDRAC
|
|
629
678
|
# Module containing extracted session methods to be included in Client
|
630
679
|
module SessionMethods
|
631
680
|
def force_clear_sessions
|
632
|
-
debug = ->(msg, level=
|
681
|
+
debug = ->(msg, level=1, color=:light_cyan) {
|
633
682
|
verbosity = respond_to?(:verbosity) ? verbosity : 0
|
634
683
|
return unless verbosity >= level
|
635
684
|
msg = msg.send(color) if color && msg.respond_to?(color)
|
636
685
|
puts msg
|
637
686
|
}
|
638
687
|
|
639
|
-
debug.call "Attempting to force clear all sessions...",
|
688
|
+
debug.call "Attempting to force clear all sessions...", 1
|
640
689
|
|
641
690
|
if delete_all_sessions_with_basic_auth
|
642
|
-
debug.call "Successfully cleared sessions using Basic Auth",
|
691
|
+
debug.call "Successfully cleared sessions using Basic Auth", 1, :green
|
643
692
|
true
|
644
693
|
else
|
645
|
-
debug.call "Failed to clear sessions using Basic Auth",
|
694
|
+
debug.call "Failed to clear sessions using Basic Auth", 1, :red
|
646
695
|
false
|
647
696
|
end
|
648
697
|
end
|
649
698
|
|
650
699
|
# Delete all sessions using Basic Authentication
|
651
700
|
def delete_all_sessions_with_basic_auth
|
652
|
-
debug = ->(msg, level=
|
701
|
+
debug = ->(msg, level=1, color=:light_cyan) {
|
653
702
|
verbosity = respond_to?(:verbosity) ? verbosity : 0
|
654
703
|
return unless verbosity >= level
|
655
704
|
msg = msg.send(color) if color && msg.respond_to?(color)
|
656
705
|
puts msg
|
657
706
|
}
|
658
707
|
|
659
|
-
debug.call "Attempting to delete all sessions using Basic Authentication...",
|
708
|
+
debug.call "Attempting to delete all sessions using Basic Authentication...", 1
|
660
709
|
|
661
710
|
# First, get the list of sessions
|
662
711
|
sessions_url = session&.determine_session_endpoint || '/redfish/v1/Sessions'
|
@@ -666,7 +715,7 @@ module IDRAC
|
|
666
715
|
response = authenticated_request(:get, sessions_url)
|
667
716
|
|
668
717
|
if response.status != 200
|
669
|
-
debug.call "Failed to get sessions list: #{response.status} - #{response.body}",
|
718
|
+
debug.call "Failed to get sessions list: #{response.status} - #{response.body}", 1, :red
|
670
719
|
return false
|
671
720
|
end
|
672
721
|
|
@@ -675,7 +724,7 @@ module IDRAC
|
|
675
724
|
sessions_data = JSON.parse(response.body)
|
676
725
|
|
677
726
|
if sessions_data['Members'] && sessions_data['Members'].any?
|
678
|
-
debug.call "Found #{sessions_data['Members'].count} active sessions",
|
727
|
+
debug.call "Found #{sessions_data['Members'].count} active sessions", 1, :light_yellow
|
679
728
|
|
680
729
|
# Delete each session
|
681
730
|
success = true
|
@@ -691,7 +740,7 @@ module IDRAC
|
|
691
740
|
if delete_response.status == 200 || delete_response.status == 204
|
692
741
|
debug.call "Successfully deleted session: #{session_url}", 1, :green
|
693
742
|
else
|
694
|
-
debug.call "Failed to delete session #{session_url}: #{delete_response.status}",
|
743
|
+
debug.call "Failed to delete session #{session_url}: #{delete_response.status}", 1, :red
|
695
744
|
success = false
|
696
745
|
end
|
697
746
|
|
@@ -701,15 +750,15 @@ module IDRAC
|
|
701
750
|
|
702
751
|
return success
|
703
752
|
else
|
704
|
-
debug.call "No active sessions found",
|
753
|
+
debug.call "No active sessions found", 1, :light_yellow
|
705
754
|
return true
|
706
755
|
end
|
707
756
|
rescue JSON::ParserError => e
|
708
|
-
debug.call "Error parsing sessions response: #{e.message}",
|
757
|
+
debug.call "Error parsing sessions response: #{e.message}", 1, :red
|
709
758
|
return false
|
710
759
|
end
|
711
760
|
rescue => e
|
712
|
-
debug.call "Error during session deletion with Basic Auth: #{e.message}",
|
761
|
+
debug.call "Error during session deletion with Basic Auth: #{e.message}", 1, :red
|
713
762
|
return false
|
714
763
|
end
|
715
764
|
end
|