idrac 0.1.91 → 0.1.92
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 +3 -3
- data/lib/idrac/client.rb +14 -14
- data/lib/idrac/jobs.rb +4 -0
- data/lib/idrac/lifecycle.rb +86 -189
- data/lib/idrac/session.rb +75 -75
- data/lib/idrac/version.rb +1 -1
- data/lib/idrac.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aeade8ac07bcfebc5686e67d9ae98ce853db0167b237119226e0335e0a9808b4
|
4
|
+
data.tar.gz: c53b5df8739b622864c07cec553fc9cc97651f3acf58d20edef3fa5892d2e43f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d73c18d555af727735ce70d35d0d347d8a3665fd2c8ba73d854065af24d77b1886d6aade4ffec7e6bdb45f37a771d58ed683f567897274a86e49deb453527112
|
7
|
+
data.tar.gz: 90e2ec395028e29244ce17f72906883b0d3f327d372faa29826ea8791ee33489ab3484e3fa568e1548fb0ffacd7563d4b36c8796354a090066aab9f906a24ba8
|
data/bin/idrac
CHANGED
@@ -119,7 +119,7 @@ module IDRAC
|
|
119
119
|
map "lifecycle:status" => :lifecycle_status
|
120
120
|
def lifecycle_status
|
121
121
|
with_idrac_client do |client|
|
122
|
-
client.
|
122
|
+
client.get_lifecycle_status
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
@@ -127,7 +127,7 @@ module IDRAC
|
|
127
127
|
map "lifecycle:enable" => :lifecycle_enable
|
128
128
|
def lifecycle_enable
|
129
129
|
with_idrac_client do |client|
|
130
|
-
client.
|
130
|
+
client.set_lifecycle_status(true)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
@@ -135,7 +135,7 @@ module IDRAC
|
|
135
135
|
map "lifecycle:disable" => :lifecycle_disable
|
136
136
|
def lifecycle_disable
|
137
137
|
with_idrac_client do |client|
|
138
|
-
client.
|
138
|
+
client.set_lifecycle_status(false)
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
data/lib/idrac/client.rb
CHANGED
@@ -53,16 +53,16 @@ module IDRAC
|
|
53
53
|
def login
|
54
54
|
# If we're in direct mode, skip login attempts
|
55
55
|
if @direct_mode
|
56
|
-
|
56
|
+
debug "Using direct mode (Basic Auth) for all requests", 1, :light_yellow
|
57
57
|
return true
|
58
58
|
end
|
59
59
|
|
60
60
|
# Try to create a Redfish session
|
61
61
|
if session.create
|
62
|
-
|
62
|
+
debug "Successfully logged in to iDRAC using Redfish session", 1, :green
|
63
63
|
return true
|
64
64
|
else
|
65
|
-
|
65
|
+
debug "Failed to create Redfish session, falling back to direct mode", 1, :light_yellow
|
66
66
|
@direct_mode = true
|
67
67
|
return true
|
68
68
|
end
|
@@ -72,7 +72,7 @@ module IDRAC
|
|
72
72
|
def logout
|
73
73
|
session.delete if session.x_auth_token
|
74
74
|
web.logout if web.session_id
|
75
|
-
|
75
|
+
debug "Logged out from iDRAC", 1, :green
|
76
76
|
return true
|
77
77
|
end
|
78
78
|
|
@@ -80,7 +80,7 @@ module IDRAC
|
|
80
80
|
def authenticated_request(method, path, options = {}, retry_count = 0)
|
81
81
|
# Limit retries to prevent infinite loops
|
82
82
|
if retry_count >= 3
|
83
|
-
|
83
|
+
debug "Maximum retry count reached for authenticated request", 1, :red
|
84
84
|
raise Error, "Maximum retry count reached for authenticated request"
|
85
85
|
end
|
86
86
|
|
@@ -110,7 +110,7 @@ module IDRAC
|
|
110
110
|
|
111
111
|
return response
|
112
112
|
rescue => e
|
113
|
-
|
113
|
+
debug "Error during authenticated request (direct mode): #{e.message}", 1, :red
|
114
114
|
raise Error, "Error during authenticated request: #{e.message}"
|
115
115
|
end
|
116
116
|
else
|
@@ -135,14 +135,14 @@ module IDRAC
|
|
135
135
|
|
136
136
|
# Check if the session is still valid
|
137
137
|
if response.status == 401 || response.status == 403
|
138
|
-
|
138
|
+
debug "Session expired or invalid, attempting to create a new session...", 1, :light_yellow
|
139
139
|
|
140
140
|
# Try to create a new session
|
141
141
|
if session.create
|
142
|
-
|
142
|
+
debug "Successfully created a new session, retrying request...", 1, :green
|
143
143
|
return authenticated_request(method, path, options, retry_count + 1)
|
144
144
|
else
|
145
|
-
|
145
|
+
debug "Failed to create a new session, falling back to direct mode...", 1, :light_yellow
|
146
146
|
@direct_mode = true
|
147
147
|
return authenticated_request(method, path, options, retry_count + 1)
|
148
148
|
end
|
@@ -150,14 +150,14 @@ module IDRAC
|
|
150
150
|
|
151
151
|
return response
|
152
152
|
rescue => e
|
153
|
-
|
153
|
+
debug "Error during authenticated request (token mode): #{e.message}", 1, :red
|
154
154
|
|
155
155
|
# Try to create a new session
|
156
156
|
if session.create
|
157
|
-
|
157
|
+
debug "Successfully created a new session after error, retrying request...", 1, :green
|
158
158
|
return authenticated_request(method, path, options, retry_count + 1)
|
159
159
|
else
|
160
|
-
|
160
|
+
debug "Failed to create a new session after error, falling back to direct mode...", 1, :light_yellow
|
161
161
|
@direct_mode = true
|
162
162
|
return authenticated_request(method, path, options, retry_count + 1)
|
163
163
|
end
|
@@ -165,10 +165,10 @@ module IDRAC
|
|
165
165
|
else
|
166
166
|
# If we don't have a token, try to create a session
|
167
167
|
if session.create
|
168
|
-
|
168
|
+
debug "Successfully created a new session, making request...", 1, :green
|
169
169
|
return authenticated_request(method, path, options, retry_count + 1)
|
170
170
|
else
|
171
|
-
|
171
|
+
debug "Failed to create a session, falling back to direct mode...", 1, :light_yellow
|
172
172
|
@direct_mode = true
|
173
173
|
return authenticated_request(method, path, options, retry_count + 1)
|
174
174
|
end
|
data/lib/idrac/jobs.rb
CHANGED
@@ -46,6 +46,8 @@ module IDRAC
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# Clear all jobs from the job queue
|
49
|
+
# Apparently too many jobs will slow down the iDRAC. Let's clear them out.
|
50
|
+
# https://github.com/dell/iDRAC-Redfish-Scripting/issues/116
|
49
51
|
def clear_jobs!
|
50
52
|
# Get list of jobs
|
51
53
|
jobs_response = authenticated_request(:get, '/redfish/v1/Managers/iDRAC.Embedded.1/Jobs?$expand=*($levels=1)')
|
@@ -78,6 +80,8 @@ module IDRAC
|
|
78
80
|
# Force clear the job queue
|
79
81
|
def force_clear_jobs!
|
80
82
|
# Clear the job queue using force option which will also clear any pending data and restart processes
|
83
|
+
# Once you executed the command to force clear the job queue, wait a few minutes and then execute command
|
84
|
+
# below to check LC status. Continue to execute this command until you see LC status reported as Ready which shouldn't take longer than a couple of minutes.
|
81
85
|
path = '/redfish/v1/Dell/Managers/iDRAC.Embedded.1/DellJobService/Actions/DellJobService.DeleteJobQueue'
|
82
86
|
payload = { "JobID" => "JID_CLEARALL_FORCE" }
|
83
87
|
|
data/lib/idrac/lifecycle.rb
CHANGED
@@ -3,221 +3,113 @@ require 'colorize'
|
|
3
3
|
|
4
4
|
module IDRAC
|
5
5
|
module LifecycleMethods
|
6
|
-
#
|
6
|
+
# Check if the Lifecycle Controller is enabled
|
7
7
|
def get_lifecycle_status
|
8
|
-
# Try
|
9
|
-
|
8
|
+
# Try the standard Attributes endpoint first
|
9
|
+
path = "/redfish/v1/Managers/iDRAC.Embedded.1/Attributes"
|
10
|
+
response = authenticated_request(:get, path)
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
if response.status.between?(200, 299)
|
20
|
-
begin
|
21
|
-
lc_data = JSON.parse(response.body)
|
22
|
-
puts "LC Status: #{lc_data['LCStatus']}".light_cyan
|
23
|
-
return lc_data
|
24
|
-
rescue JSON::ParserError
|
25
|
-
# Fall through to alternative method
|
12
|
+
if response.status == 200
|
13
|
+
begin
|
14
|
+
attributes_data = JSON.parse(response.body)
|
15
|
+
if attributes_data["Attributes"] && attributes_data["Attributes"]["LCAttributes.1.LifecycleControllerState"]
|
16
|
+
lifecycle_state = attributes_data["Attributes"]["LCAttributes.1.LifecycleControllerState"]
|
17
|
+
debug "Lifecycle Controller state (from Attributes): #{lifecycle_state}".light_cyan, 1
|
18
|
+
return lifecycle_state == "Enabled"
|
26
19
|
end
|
20
|
+
rescue JSON::ParserError
|
21
|
+
debug "Failed to parse Attributes response".yellow, 1
|
22
|
+
# Fall through to registry method if parsing fails or attribute not found
|
27
23
|
end
|
28
|
-
|
29
|
-
|
24
|
+
else
|
25
|
+
debug "Failed to get Attributes endpoint (Status: #{response.status}), trying registry method...".yellow, 1
|
30
26
|
end
|
31
27
|
|
32
|
-
# Try
|
33
|
-
|
28
|
+
# Try getting the DellAttributes for LifecycleController directly
|
29
|
+
# The key insight is that we need to use just the base path without the fragment
|
30
|
+
attributes_path = "/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/LifecycleController.Embedded.1"
|
31
|
+
attributes_response = authenticated_request(:get, attributes_path)
|
34
32
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
if attributes_data["Attributes"] && attributes_data["Attributes"]["LCAttributes.1.LifecycleControllerState"]
|
43
|
-
lifecycle_state = attributes_data["Attributes"]["LCAttributes.1.LifecycleControllerState"]
|
44
|
-
puts "Lifecycle Controller state: #{lifecycle_state}".light_cyan
|
45
|
-
return { "LCStatus" => lifecycle_state }
|
46
|
-
end
|
47
|
-
rescue JSON::ParserError
|
48
|
-
# Fall through to final error
|
49
|
-
end
|
50
|
-
end
|
51
|
-
rescue => e
|
52
|
-
# Fall through to final error
|
53
|
-
end
|
54
|
-
|
55
|
-
# If we get here, try one last approach - try to get iDRAC status
|
56
|
-
begin
|
57
|
-
response = authenticated_request(:get, '/redfish/v1/Managers/iDRAC.Embedded.1')
|
58
|
-
|
59
|
-
if response.status.between?(200, 299)
|
60
|
-
begin
|
61
|
-
data = JSON.parse(response.body)
|
62
|
-
status = data["Status"] && data["Status"]["State"]
|
63
|
-
if status
|
64
|
-
puts "iDRAC State: #{status}".light_cyan
|
65
|
-
puts "Note: Could not retrieve direct LC status, showing iDRAC status instead".yellow
|
66
|
-
return { "iDRACStatus" => status }
|
67
|
-
end
|
68
|
-
rescue JSON::ParserError
|
69
|
-
# Fall through to final error
|
33
|
+
if attributes_response.status == 200
|
34
|
+
begin
|
35
|
+
dell_attr_data = JSON.parse(attributes_response.body)
|
36
|
+
if dell_attr_data["Attributes"] && dell_attr_data["Attributes"]["LCAttributes.1.LifecycleControllerState"]
|
37
|
+
lifecycle_state = dell_attr_data["Attributes"]["LCAttributes.1.LifecycleControllerState"]
|
38
|
+
debug "Lifecycle Controller state (from Dell Attributes): #{lifecycle_state}".light_cyan, 1
|
39
|
+
return lifecycle_state == "Enabled"
|
70
40
|
end
|
41
|
+
rescue JSON::ParserError
|
42
|
+
debug "Failed to parse Dell Attributes response".yellow, 1
|
43
|
+
# Fall through to registry method if parsing fails or attribute not found
|
71
44
|
end
|
72
|
-
|
73
|
-
#
|
45
|
+
else
|
46
|
+
debug "Failed to get Dell Attributes (Status: #{attributes_response.status}), trying registry method...".yellow, 1
|
74
47
|
end
|
75
|
-
|
76
|
-
# If we reached here, all methods failed
|
77
|
-
puts "Unable to retrieve Lifecycle Controller status through any available method".red
|
78
|
-
raise Error, "Failed to get Lifecycle Controller status through any available method"
|
79
|
-
end
|
80
|
-
|
81
|
-
# Check if the Lifecycle Controller is enabled
|
82
|
-
def get_idrac_lifecycle_status
|
83
|
-
# Use the DellLCService GetRemoteServicesAPIStatus
|
84
|
-
path = '/redfish/v1/Dell/Managers/iDRAC.Embedded.1/DellLCService/Actions/DellLCService.GetRemoteServicesAPIStatus'
|
85
48
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
headers: { 'Content-Type' => 'application/json' }
|
49
|
+
# Fallback to the registry method if both Attributes endpoints fail
|
50
|
+
registry_response = authenticated_request(
|
51
|
+
:get,
|
52
|
+
"/redfish/v1/Registries/ManagerAttributeRegistry/ManagerAttributeRegistry.v1_0_0.json"
|
91
53
|
)
|
92
54
|
|
93
|
-
if
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
begin
|
106
|
-
attributes_data = JSON.parse(attributes_response.body)
|
107
|
-
lc_replication = attributes_data["Attributes"]["ServiceModule.1.LCLReplication"]
|
108
|
-
|
109
|
-
debug "ServiceModule.1.LCLReplication: #{lc_replication}", 1
|
110
|
-
|
111
|
-
is_enabled = lc_replication == "Enabled"
|
112
|
-
|
113
|
-
puts "Lifecycle Controller replication is #{is_enabled ? 'enabled' : 'disabled'}".light_cyan
|
114
|
-
puts "Lifecycle Controller status: #{status}".light_cyan
|
115
|
-
return is_enabled
|
116
|
-
rescue => e
|
117
|
-
debug "Error parsing attributes: #{e.message}", 1
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
# If we can't determine from attributes, just return if LC is Ready
|
122
|
-
is_ready = status == "Ready"
|
123
|
-
puts "Lifecycle Controller is #{is_ready ? 'Ready' : status}".light_cyan
|
124
|
-
return is_ready
|
125
|
-
rescue JSON::ParserError
|
126
|
-
raise Error, "Failed to parse Lifecycle Controller status response: #{response.body}"
|
55
|
+
if registry_response.status != 200
|
56
|
+
debug "Failed to get Lifecycle Controller Attributes Registry", 0, :red
|
57
|
+
return false
|
58
|
+
end
|
59
|
+
|
60
|
+
begin
|
61
|
+
registry_data = JSON.parse(registry_response.body)
|
62
|
+
# This is the attribute we want:
|
63
|
+
target = registry_data['RegistryEntries']['Attributes'].find {|q| q['AttributeName'] =~ /LCAttributes.1.LifecycleControllerState/ }
|
64
|
+
if !target
|
65
|
+
debug "Could not find LCAttributes.1.LifecycleControllerState in registry", 0, :red
|
66
|
+
return false
|
127
67
|
end
|
128
|
-
|
129
|
-
|
68
|
+
|
69
|
+
debug "Found attribute in registry but couldn't access it via other endpoints".yellow, 1
|
70
|
+
return false
|
71
|
+
rescue JSON::ParserError, NoMethodError, StandardError => e
|
72
|
+
debug "Error during registry access: #{e.message}", 0, :red
|
73
|
+
return false
|
130
74
|
end
|
131
75
|
end
|
132
76
|
|
133
77
|
# Set the Lifecycle Controller status (enable/disable)
|
134
|
-
def
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
# Create the payload with the attribute we want to modify
|
143
|
-
payload = {
|
144
|
-
"Attributes": {
|
145
|
-
"ServiceModule.1.LCLReplication": enabled ? "Enabled" : "Disabled"
|
146
|
-
}
|
147
|
-
}
|
148
|
-
|
149
|
-
debug "Using attributes endpoint: #{path}", 1
|
150
|
-
debug "Payload: #{payload.inspect}", 1
|
78
|
+
def set_lifecycle_status(status)
|
79
|
+
payload = { "Attributes": { "LCAttributes.1.LifecycleControllerState": status ? 'Enabled' : 'Disabled' } }
|
80
|
+
response = authenticated_request(
|
81
|
+
:patch,
|
82
|
+
"/redfish/v1/Managers/iDRAC.Embedded.1/Oem/Dell/DellAttributes/LifecycleController.Embedded.1",
|
83
|
+
body: payload.to_json,
|
84
|
+
headers: { 'Content-Type': 'application/json' }
|
85
|
+
)
|
151
86
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
debug "Response body: #{response.body}", 2 if response.body
|
162
|
-
|
163
|
-
if response.status.between?(200, 299)
|
164
|
-
puts "Successfully #{enabled ? 'enabled' : 'disabled'} Lifecycle Controller".green
|
165
|
-
return true
|
166
|
-
else
|
167
|
-
error_message = "Failed to set Lifecycle Controller status. Status code: #{response.status}"
|
168
|
-
|
169
|
-
# Print the full response body for debugging
|
170
|
-
puts "Full error response body:".red
|
171
|
-
puts response.body.inspect.red
|
172
|
-
|
173
|
-
begin
|
174
|
-
error_data = JSON.parse(response.body)
|
175
|
-
puts "Extended error information:".red if error_data['@Message.ExtendedInfo']
|
176
|
-
|
177
|
-
if error_data['error'] && error_data['error']['message']
|
178
|
-
error_message += ", Message: #{error_data['error']['message']}"
|
179
|
-
end
|
180
|
-
|
181
|
-
if error_data['@Message.ExtendedInfo']
|
182
|
-
error_data['@Message.ExtendedInfo'].each do |info|
|
183
|
-
puts " Message: #{info['Message']}".red
|
184
|
-
puts " Resolution: #{info['Resolution']}".yellow if info['Resolution']
|
185
|
-
puts " Severity: #{info['Severity']}".yellow if info['Severity']
|
186
|
-
puts " MessageId: #{info['MessageId']}".yellow if info['MessageId']
|
187
|
-
end
|
188
|
-
|
189
|
-
if error_data['@Message.ExtendedInfo'].first
|
190
|
-
error_message += ", Message: #{error_data['@Message.ExtendedInfo'].first['Message']}"
|
191
|
-
error_message += ", Resolution: #{error_data['@Message.ExtendedInfo'].first['Resolution']}" if error_data['@Message.ExtendedInfo'].first['Resolution']
|
192
|
-
end
|
193
|
-
end
|
194
|
-
rescue => e
|
195
|
-
debug "Error parsing response: #{e.message}", 1
|
196
|
-
# Ignore JSON parsing errors
|
197
|
-
end
|
198
|
-
|
199
|
-
raise Error, error_message
|
200
|
-
end
|
201
|
-
rescue => e
|
202
|
-
debug "Error in request: #{e.message}", 1
|
203
|
-
raise Error, "Failed to set Lifecycle Controller status: #{e.message}"
|
87
|
+
code = response.status
|
88
|
+
case code
|
89
|
+
when 200..299
|
90
|
+
debug "Lifecycle Controller is now #{status ? 'Enabled' : 'Disabled'}".green, 1
|
91
|
+
when 400..499
|
92
|
+
debug "[#{code}] This iDRAC does not support Lifecycle Controller", 0, :red
|
93
|
+
when 500..599
|
94
|
+
debug "[#{code}] iDRAC does not support Lifecycle Controller", 0, :red
|
95
|
+
else
|
204
96
|
end
|
205
97
|
end
|
206
98
|
|
207
99
|
# Ensure the Lifecycle Controller is enabled
|
208
100
|
def ensure_lifecycle_controller!
|
209
|
-
if !
|
210
|
-
|
211
|
-
|
101
|
+
if !get_lifecycle_status
|
102
|
+
debug "Lifecycle Controller is disabled, enabling...".yellow, 1
|
103
|
+
set_lifecycle_status(true)
|
212
104
|
|
213
105
|
# Verify it was enabled
|
214
|
-
if !
|
106
|
+
if !get_lifecycle_status
|
215
107
|
raise Error, "Failed to enable Lifecycle Controller"
|
216
108
|
end
|
217
109
|
|
218
|
-
|
110
|
+
debug "Lifecycle Controller successfully enabled".green, 1
|
219
111
|
else
|
220
|
-
|
112
|
+
debug "Lifecycle Controller is already enabled".green, 1
|
221
113
|
end
|
222
114
|
|
223
115
|
return true
|
@@ -236,10 +128,10 @@ module IDRAC
|
|
236
128
|
)
|
237
129
|
|
238
130
|
if response.status.between?(200, 299)
|
239
|
-
|
131
|
+
debug "Lifecycle log cleared", 0, :green
|
240
132
|
return true
|
241
133
|
else
|
242
|
-
|
134
|
+
debug "Failed to clear Lifecycle log", 0, :red
|
243
135
|
|
244
136
|
error_message = "Failed to clear Lifecycle log. Status code: #{response.status}"
|
245
137
|
|
@@ -279,10 +171,10 @@ module IDRAC
|
|
279
171
|
response = authenticated_request(:post, path, body: {}.to_json, headers: { 'Content-Type' => 'application/json' })
|
280
172
|
|
281
173
|
if response.status.between?(200, 299)
|
282
|
-
|
174
|
+
debug "System Event Logs cleared", 0, :green
|
283
175
|
return true
|
284
176
|
else
|
285
|
-
|
177
|
+
debug "Failed to clear System Event Logs", 0, :red
|
286
178
|
|
287
179
|
error_message = "Failed to clear System Event Logs. Status code: #{response.status}"
|
288
180
|
|
@@ -296,5 +188,10 @@ module IDRAC
|
|
296
188
|
raise Error, error_message
|
297
189
|
end
|
298
190
|
end
|
191
|
+
|
192
|
+
# Updates the status message for the lifecycle controller
|
193
|
+
def update_status_message(status)
|
194
|
+
debug "Lifecycle Controller is now #{status ? 'Enabled' : 'Disabled'}".green, 1
|
195
|
+
end
|
299
196
|
end
|
300
197
|
end
|
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
|
|
@@ -206,7 +206,7 @@ module IDRAC
|
|
206
206
|
return 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
211
|
# Use the X-Auth-Token for authentication
|
212
212
|
headers = { 'X-Auth-Token' => @x_auth_token }
|
@@ -216,16 +216,16 @@ module IDRAC
|
|
216
216
|
end
|
217
217
|
|
218
218
|
if response.status == 200 || response.status == 204
|
219
|
-
debug "Redfish session deleted successfully",
|
219
|
+
debug "Redfish session deleted successfully", 1, :green
|
220
220
|
@x_auth_token = nil
|
221
221
|
@session_location = nil
|
222
222
|
return true
|
223
223
|
else
|
224
|
-
debug "Failed to delete Redfish session: #{response.status} - #{response.body}",
|
224
|
+
debug "Failed to delete Redfish session: #{response.status} - #{response.body}", 1, :red
|
225
225
|
return false
|
226
226
|
end
|
227
227
|
rescue => e
|
228
|
-
debug "Error during Redfish session deletion: #{e.message}",
|
228
|
+
debug "Error during Redfish session deletion: #{e.message}", 1, :red
|
229
229
|
return false
|
230
230
|
end
|
231
231
|
end
|
@@ -315,12 +315,12 @@ module IDRAC
|
|
315
315
|
debug "Request headers: #{req.headers.reject { |k,v| k =~ /auth/i }.to_json}", 2
|
316
316
|
end
|
317
317
|
rescue Faraday::SSLError => e
|
318
|
-
debug "SSL Error in Basic Auth request: #{e.message}",
|
318
|
+
debug "SSL Error in Basic Auth request: #{e.message}", 1, :red
|
319
319
|
debug "OpenSSL version: #{OpenSSL::OPENSSL_VERSION}", 1
|
320
320
|
debug e.backtrace.join("\n"), 3 if e.backtrace && @verbosity >= 3
|
321
321
|
raise e
|
322
322
|
rescue => e
|
323
|
-
debug "Error during #{method} request with Basic Auth: #{e.class.name}: #{e.message}",
|
323
|
+
debug "Error during #{method} request with Basic Auth: #{e.class.name}: #{e.message}", 1, :red
|
324
324
|
debug e.backtrace.join("\n"), 2 if e.backtrace && @verbosity >= 2
|
325
325
|
raise e
|
326
326
|
end
|
@@ -338,7 +338,7 @@ module IDRAC
|
|
338
338
|
|
339
339
|
def create_session_with_content_type(url, payload)
|
340
340
|
begin
|
341
|
-
debug "Creating session with Content-Type: application/json",
|
341
|
+
debug "Creating session with Content-Type: application/json", 1
|
342
342
|
|
343
343
|
response = connection.post(url) do |req|
|
344
344
|
req.headers['Content-Type'] = 'application/json'
|
@@ -353,18 +353,18 @@ module IDRAC
|
|
353
353
|
debug "Response body: #{response.body}", 2
|
354
354
|
|
355
355
|
if response.status == 405
|
356
|
-
debug "405 Method Not Allowed: Check if the endpoint supports POST requests and verify the request format.",
|
356
|
+
debug "405 Method Not Allowed: Check if the endpoint supports POST requests and verify the request format.", 1, :red
|
357
357
|
return false
|
358
358
|
end
|
359
359
|
|
360
360
|
if process_session_response(response)
|
361
|
-
debug "Redfish session created successfully",
|
361
|
+
debug "Redfish session created successfully", 1, :green
|
362
362
|
return true
|
363
363
|
end
|
364
364
|
|
365
365
|
# If the response status is 415 (Unsupported Media Type), try with different Content-Type
|
366
366
|
if response.status == 415 || (response.body.to_s.include?("unsupported media type"))
|
367
|
-
debug "415 Unsupported Media Type, trying alternate content type",
|
367
|
+
debug "415 Unsupported Media Type, trying alternate content type", 1, :yellow
|
368
368
|
|
369
369
|
# Try with no content-type header, just the payload
|
370
370
|
alt_response = connection.post(url) do |req|
|
@@ -374,18 +374,18 @@ module IDRAC
|
|
374
374
|
end
|
375
375
|
|
376
376
|
if process_session_response(alt_response)
|
377
|
-
debug "Redfish session created successfully with alternate content type",
|
377
|
+
debug "Redfish session created successfully with alternate content type", 1, :green
|
378
378
|
return true
|
379
379
|
end
|
380
380
|
end
|
381
381
|
rescue Faraday::SSLError => e
|
382
|
-
debug "SSL Error: #{e.message}",
|
382
|
+
debug "SSL Error: #{e.message}", 1, :red
|
383
383
|
debug "OpenSSL version: #{OpenSSL::OPENSSL_VERSION}", 1
|
384
384
|
debug "Connection URL: #{base_url}#{url}", 1
|
385
385
|
debug e.backtrace.join("\n"), 3 if e.backtrace && @verbosity >= 3
|
386
386
|
return false
|
387
387
|
rescue => e
|
388
|
-
debug "First session creation attempt failed: #{e.class.name}: #{e.message}",
|
388
|
+
debug "First session creation attempt failed: #{e.class.name}: #{e.message}", 1, :light_red
|
389
389
|
debug e.backtrace.join("\n"), 2 if e.backtrace && @verbosity >= 2
|
390
390
|
end
|
391
391
|
false
|
@@ -393,7 +393,7 @@ module IDRAC
|
|
393
393
|
|
394
394
|
def create_session_with_basic_auth(url, payload)
|
395
395
|
begin
|
396
|
-
debug "Creating session with Basic Auth",
|
396
|
+
debug "Creating session with Basic Auth", 1
|
397
397
|
|
398
398
|
# Try first with JSON format
|
399
399
|
response = request_with_basic_auth(:post, url, payload.to_json, 'application/json')
|
@@ -406,26 +406,26 @@ module IDRAC
|
|
406
406
|
end
|
407
407
|
|
408
408
|
if process_session_response(response)
|
409
|
-
debug "Redfish session created successfully with Basic Auth (JSON)",
|
409
|
+
debug "Redfish session created successfully with Basic Auth (JSON)", 1, :green
|
410
410
|
return true
|
411
411
|
end
|
412
412
|
|
413
413
|
# If that fails, try with form-urlencoded
|
414
414
|
if response.status == 415 || (response.body.to_s.include?("unsupported media type"))
|
415
|
-
debug "415 Unsupported Media Type with JSON, trying form-urlencoded",
|
415
|
+
debug "415 Unsupported Media Type with JSON, trying form-urlencoded", 1, :yellow
|
416
416
|
|
417
417
|
form_data = "UserName=#{URI.encode_www_form_component(username)}&Password=#{URI.encode_www_form_component(password)}"
|
418
418
|
form_response = request_with_basic_auth(:post, url, form_data, 'application/x-www-form-urlencoded')
|
419
419
|
|
420
420
|
if process_session_response(form_response)
|
421
|
-
debug "Redfish session created successfully with Basic Auth (form-urlencoded)",
|
421
|
+
debug "Redfish session created successfully with Basic Auth (form-urlencoded)", 1, :green
|
422
422
|
return true
|
423
423
|
elsif form_response.status == 400
|
424
424
|
# Check for maximum sessions error
|
425
425
|
if (form_response.body.include?("maximum number of user sessions") ||
|
426
426
|
form_response.body.include?("RAC0218") ||
|
427
427
|
form_response.body.include?("Internal Server Error"))
|
428
|
-
debug "Maximum sessions reached detected during session creation",
|
428
|
+
debug "Maximum sessions reached detected during session creation", 1, :light_red
|
429
429
|
@sessions_maxed = true
|
430
430
|
return false
|
431
431
|
end
|
@@ -435,14 +435,14 @@ module IDRAC
|
|
435
435
|
if (response.body.include?("maximum number of user sessions") ||
|
436
436
|
response.body.include?("RAC0218") ||
|
437
437
|
response.body.include?("Internal Server Error"))
|
438
|
-
debug "Maximum sessions reached detected during session creation",
|
438
|
+
debug "Maximum sessions reached detected during session creation", 1, :light_red
|
439
439
|
@sessions_maxed = true
|
440
440
|
return false
|
441
441
|
end
|
442
442
|
end
|
443
443
|
|
444
444
|
# Try one more approach with no Content-Type header
|
445
|
-
debug "Trying Basic Auth with no Content-Type header",
|
445
|
+
debug "Trying Basic Auth with no Content-Type header", 1, :yellow
|
446
446
|
no_content_type_response = connection.post(url) do |req|
|
447
447
|
req.headers['Authorization'] = "Basic #{Base64.strict_encode64("#{username}:#{password}")}"
|
448
448
|
req.headers['Accept'] = '*/*'
|
@@ -450,19 +450,19 @@ module IDRAC
|
|
450
450
|
end
|
451
451
|
|
452
452
|
if process_session_response(no_content_type_response)
|
453
|
-
debug "Redfish session created successfully with Basic Auth (no content type)",
|
453
|
+
debug "Redfish session created successfully with Basic Auth (no content type)", 1, :green
|
454
454
|
return true
|
455
455
|
end
|
456
456
|
|
457
|
-
debug "Failed to create Redfish session: #{response.status} - #{response.body}",
|
457
|
+
debug "Failed to create Redfish session: #{response.status} - #{response.body}", 1, :red
|
458
458
|
return false
|
459
459
|
rescue Faraday::SSLError => e
|
460
|
-
debug "SSL Error in Basic Auth request: #{e.message}",
|
460
|
+
debug "SSL Error in Basic Auth request: #{e.message}", 1, :red
|
461
461
|
debug "OpenSSL version: #{OpenSSL::OPENSSL_VERSION}", 1
|
462
462
|
debug e.backtrace.join("\n"), 3 if e.backtrace && @verbosity >= 3
|
463
463
|
return false
|
464
464
|
rescue => e
|
465
|
-
debug "Error during Redfish session creation with Basic Auth: #{e.class.name}: #{e.message}",
|
465
|
+
debug "Error during Redfish session creation with Basic Auth: #{e.class.name}: #{e.message}", 1, :red
|
466
466
|
debug e.backtrace.join("\n"), 2 if e.backtrace && @verbosity >= 2
|
467
467
|
return false
|
468
468
|
end
|
@@ -471,10 +471,10 @@ module IDRAC
|
|
471
471
|
def handle_max_sessions_and_retry(url, payload)
|
472
472
|
return false unless @sessions_maxed
|
473
473
|
|
474
|
-
debug "Maximum sessions reached, attempting to clear sessions",
|
474
|
+
debug "Maximum sessions reached, attempting to clear sessions", 1
|
475
475
|
if @auto_delete_sessions
|
476
476
|
if force_clear_sessions
|
477
|
-
debug "Successfully cleared sessions, trying to create a new session",
|
477
|
+
debug "Successfully cleared sessions, trying to create a new session", 1, :green
|
478
478
|
|
479
479
|
# Give the iDRAC a moment to process the session deletions
|
480
480
|
sleep(3)
|
@@ -488,28 +488,28 @@ module IDRAC
|
|
488
488
|
end
|
489
489
|
|
490
490
|
if process_session_response(response)
|
491
|
-
debug "Redfish session created successfully after clearing sessions",
|
491
|
+
debug "Redfish session created successfully after clearing sessions", 1, :green
|
492
492
|
return true
|
493
493
|
else
|
494
|
-
debug "Failed to create Redfish session after clearing sessions: #{response.status} - #{response.body}",
|
494
|
+
debug "Failed to create Redfish session after clearing sessions: #{response.status} - #{response.body}", 1, :red
|
495
495
|
# If still failing, try direct mode
|
496
|
-
debug "Falling back to direct mode",
|
496
|
+
debug "Falling back to direct mode", 1, :light_yellow
|
497
497
|
@direct_mode = true
|
498
498
|
return false
|
499
499
|
end
|
500
500
|
rescue => e
|
501
|
-
debug "Error during session creation after clearing: #{e.class.name}: #{e.message}",
|
502
|
-
debug "Falling back to direct mode",
|
501
|
+
debug "Error during session creation after clearing: #{e.class.name}: #{e.message}", 1, :red
|
502
|
+
debug "Falling back to direct mode", 1, :light_yellow
|
503
503
|
@direct_mode = true
|
504
504
|
return false
|
505
505
|
end
|
506
506
|
else
|
507
|
-
debug "Failed to clear sessions, switching to direct mode",
|
507
|
+
debug "Failed to clear sessions, switching to direct mode", 1, :light_yellow
|
508
508
|
@direct_mode = true
|
509
509
|
return false
|
510
510
|
end
|
511
511
|
else
|
512
|
-
debug "Auto delete sessions is disabled, switching to direct mode",
|
512
|
+
debug "Auto delete sessions is disabled, switching to direct mode", 1, :light_yellow
|
513
513
|
@direct_mode = true
|
514
514
|
return false
|
515
515
|
end
|
@@ -518,7 +518,7 @@ module IDRAC
|
|
518
518
|
def create_session_with_form_urlencoded(url, payload)
|
519
519
|
# Only try with form-urlencoded if we had a 415 error previously
|
520
520
|
begin
|
521
|
-
debug "Trying with form-urlencoded content type",
|
521
|
+
debug "Trying with form-urlencoded content type", 1
|
522
522
|
debug "URL: #{base_url}#{url}", 1
|
523
523
|
|
524
524
|
# Try first without any authorization header
|
@@ -534,21 +534,21 @@ module IDRAC
|
|
534
534
|
debug "Response body: #{response.body}", 3
|
535
535
|
|
536
536
|
if process_session_response(response)
|
537
|
-
debug "Redfish session created successfully with form-urlencoded",
|
537
|
+
debug "Redfish session created successfully with form-urlencoded", 1, :green
|
538
538
|
return true
|
539
539
|
end
|
540
540
|
|
541
541
|
# If that fails, try with Basic Auth + form-urlencoded
|
542
|
-
debug "Trying form-urlencoded with Basic Auth",
|
542
|
+
debug "Trying form-urlencoded with Basic Auth", 1
|
543
543
|
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
544
|
|
545
545
|
if process_session_response(auth_response)
|
546
|
-
debug "Redfish session created successfully with form-urlencoded + Basic Auth",
|
546
|
+
debug "Redfish session created successfully with form-urlencoded + Basic Auth", 1, :green
|
547
547
|
return true
|
548
548
|
end
|
549
549
|
|
550
550
|
# Last resort: try with both headers (some iDRAC versions need this)
|
551
|
-
debug "Trying with both Content-Type headers",
|
551
|
+
debug "Trying with both Content-Type headers", 1
|
552
552
|
both_response = connection.post(url) do |req|
|
553
553
|
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
554
554
|
req.headers['Accept'] = 'application/json'
|
@@ -558,20 +558,20 @@ module IDRAC
|
|
558
558
|
end
|
559
559
|
|
560
560
|
if process_session_response(both_response)
|
561
|
-
debug "Redfish session created successfully with multiple content types",
|
561
|
+
debug "Redfish session created successfully with multiple content types", 1, :green
|
562
562
|
return true
|
563
563
|
else
|
564
|
-
debug "Failed with form-urlencoded too: #{response.status} - #{response.body}",
|
564
|
+
debug "Failed with form-urlencoded too: #{response.status} - #{response.body}", 1, :red
|
565
565
|
return false
|
566
566
|
end
|
567
567
|
rescue Faraday::SSLError => e
|
568
|
-
debug "SSL Error in form-urlencoded request: #{e.message}",
|
568
|
+
debug "SSL Error in form-urlencoded request: #{e.message}", 1, :red
|
569
569
|
debug "OpenSSL version: #{OpenSSL::OPENSSL_VERSION}", 1
|
570
570
|
debug "Connection URL: #{base_url}#{url}", 1
|
571
571
|
debug e.backtrace.join("\n"), 3 if e.backtrace && @verbosity >= 3
|
572
572
|
return false
|
573
573
|
rescue => e
|
574
|
-
debug "Error during form-urlencoded session creation: #{e.class.name}: #{e.message}",
|
574
|
+
debug "Error during form-urlencoded session creation: #{e.class.name}: #{e.message}", 1, :red
|
575
575
|
debug e.backtrace.join("\n"), 2 if e.backtrace && @verbosity >= 2
|
576
576
|
return false
|
577
577
|
end
|
@@ -607,21 +607,21 @@ module IDRAC
|
|
607
607
|
end
|
608
608
|
end
|
609
609
|
rescue JSON::ParserError => e
|
610
|
-
debug "Error parsing Redfish version: #{e.message}",
|
610
|
+
debug "Error parsing Redfish version: #{e.message}", 1, :red
|
611
611
|
debug e.backtrace.join("\n"), 3 if e.backtrace && @verbosity >= 3
|
612
612
|
rescue => e
|
613
|
-
debug "Error determining Redfish version: #{e.message}",
|
613
|
+
debug "Error determining Redfish version: #{e.message}", 1, :red
|
614
614
|
debug e.backtrace.join("\n"), 3 if e.backtrace && @verbosity >= 3
|
615
615
|
end
|
616
616
|
end
|
617
617
|
rescue => e
|
618
|
-
debug "Error checking Redfish version: #{e.message}",
|
618
|
+
debug "Error checking Redfish version: #{e.message}", 1, :red
|
619
619
|
debug e.backtrace.join("\n"), 3 if e.backtrace && @verbosity >= 3
|
620
620
|
end
|
621
621
|
|
622
622
|
# Default to /redfish/v1/Sessions if we can't determine version
|
623
623
|
default_endpoint = '/redfish/v1/Sessions'
|
624
|
-
debug "Defaulting to endpoint #{default_endpoint}",
|
624
|
+
debug "Defaulting to endpoint #{default_endpoint}", 1, :light_yellow
|
625
625
|
default_endpoint
|
626
626
|
end
|
627
627
|
end
|
@@ -629,34 +629,34 @@ module IDRAC
|
|
629
629
|
# Module containing extracted session methods to be included in Client
|
630
630
|
module SessionMethods
|
631
631
|
def force_clear_sessions
|
632
|
-
debug = ->(msg, level=
|
632
|
+
debug = ->(msg, level=1, color=:light_cyan) {
|
633
633
|
verbosity = respond_to?(:verbosity) ? verbosity : 0
|
634
634
|
return unless verbosity >= level
|
635
635
|
msg = msg.send(color) if color && msg.respond_to?(color)
|
636
636
|
puts msg
|
637
637
|
}
|
638
638
|
|
639
|
-
debug.call "Attempting to force clear all sessions...",
|
639
|
+
debug.call "Attempting to force clear all sessions...", 1
|
640
640
|
|
641
641
|
if delete_all_sessions_with_basic_auth
|
642
|
-
debug.call "Successfully cleared sessions using Basic Auth",
|
642
|
+
debug.call "Successfully cleared sessions using Basic Auth", 1, :green
|
643
643
|
true
|
644
644
|
else
|
645
|
-
debug.call "Failed to clear sessions using Basic Auth",
|
645
|
+
debug.call "Failed to clear sessions using Basic Auth", 1, :red
|
646
646
|
false
|
647
647
|
end
|
648
648
|
end
|
649
649
|
|
650
650
|
# Delete all sessions using Basic Authentication
|
651
651
|
def delete_all_sessions_with_basic_auth
|
652
|
-
debug = ->(msg, level=
|
652
|
+
debug = ->(msg, level=1, color=:light_cyan) {
|
653
653
|
verbosity = respond_to?(:verbosity) ? verbosity : 0
|
654
654
|
return unless verbosity >= level
|
655
655
|
msg = msg.send(color) if color && msg.respond_to?(color)
|
656
656
|
puts msg
|
657
657
|
}
|
658
658
|
|
659
|
-
debug.call "Attempting to delete all sessions using Basic Authentication...",
|
659
|
+
debug.call "Attempting to delete all sessions using Basic Authentication...", 1
|
660
660
|
|
661
661
|
# First, get the list of sessions
|
662
662
|
sessions_url = session&.determine_session_endpoint || '/redfish/v1/Sessions'
|
@@ -666,7 +666,7 @@ module IDRAC
|
|
666
666
|
response = authenticated_request(:get, sessions_url)
|
667
667
|
|
668
668
|
if response.status != 200
|
669
|
-
debug.call "Failed to get sessions list: #{response.status} - #{response.body}",
|
669
|
+
debug.call "Failed to get sessions list: #{response.status} - #{response.body}", 1, :red
|
670
670
|
return false
|
671
671
|
end
|
672
672
|
|
@@ -675,7 +675,7 @@ module IDRAC
|
|
675
675
|
sessions_data = JSON.parse(response.body)
|
676
676
|
|
677
677
|
if sessions_data['Members'] && sessions_data['Members'].any?
|
678
|
-
debug.call "Found #{sessions_data['Members'].count} active sessions",
|
678
|
+
debug.call "Found #{sessions_data['Members'].count} active sessions", 1, :light_yellow
|
679
679
|
|
680
680
|
# Delete each session
|
681
681
|
success = true
|
@@ -691,7 +691,7 @@ module IDRAC
|
|
691
691
|
if delete_response.status == 200 || delete_response.status == 204
|
692
692
|
debug.call "Successfully deleted session: #{session_url}", 1, :green
|
693
693
|
else
|
694
|
-
debug.call "Failed to delete session #{session_url}: #{delete_response.status}",
|
694
|
+
debug.call "Failed to delete session #{session_url}: #{delete_response.status}", 1, :red
|
695
695
|
success = false
|
696
696
|
end
|
697
697
|
|
@@ -701,15 +701,15 @@ module IDRAC
|
|
701
701
|
|
702
702
|
return success
|
703
703
|
else
|
704
|
-
debug.call "No active sessions found",
|
704
|
+
debug.call "No active sessions found", 1, :light_yellow
|
705
705
|
return true
|
706
706
|
end
|
707
707
|
rescue JSON::ParserError => e
|
708
|
-
debug.call "Error parsing sessions response: #{e.message}",
|
708
|
+
debug.call "Error parsing sessions response: #{e.message}", 1, :red
|
709
709
|
return false
|
710
710
|
end
|
711
711
|
rescue => e
|
712
|
-
debug.call "Error during session deletion with Basic Auth: #{e.message}",
|
712
|
+
debug.call "Error during session deletion with Basic Auth: #{e.message}", 1, :red
|
713
713
|
return false
|
714
714
|
end
|
715
715
|
end
|
data/lib/idrac/version.rb
CHANGED
data/lib/idrac.rb
CHANGED
@@ -14,7 +14,7 @@ module IDRAC
|
|
14
14
|
# Provides debugging functionality to IDRAC classes
|
15
15
|
module Debuggable
|
16
16
|
# Debug output helper - only outputs if verbosity level is high enough
|
17
|
-
def debug(message, level =
|
17
|
+
def debug(message, level = 1, color = :light_cyan)
|
18
18
|
return unless respond_to?(:verbosity) && verbosity >= level
|
19
19
|
color_method = color.is_a?(Symbol) && String.method_defined?(color) ? color : :to_s
|
20
20
|
puts message.send(color_method)
|