radfish-ami 0.1.10 → 0.1.12
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/lib/radfish/ami/version.rb +1 -1
- data/lib/radfish/ami_adapter.rb +86 -4
- 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: a5eece6126f4c0d048e1aedcaa23d466e77c33dd4b69595bc6b53016815c7cec
|
|
4
|
+
data.tar.gz: 9da097025394a758dc0fa4a2347ce90993113d4d0086f985534580104a2298b3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3ec9ee1430c502c6e0364a9d345d16c67d9d459ee3ce226d8d92bafb0c1151a9bf714cb5cd94d4490da9a950ff50550d773a9062a45782b4cf6d3af8a91b8a53
|
|
7
|
+
data.tar.gz: 2a347044b3101aff4f31e47aaabf4d3bf68e752aea0e48864920b38b2a8a9df1c140fd97fd91fd6938cf9e148d75af36503069bcb10ae6471b28d9438b867add
|
data/lib/radfish/ami/version.rb
CHANGED
data/lib/radfish/ami_adapter.rb
CHANGED
|
@@ -484,7 +484,10 @@ module Radfish
|
|
|
484
484
|
end
|
|
485
485
|
end
|
|
486
486
|
|
|
487
|
-
def insert_virtual_media(iso_url, device: nil)
|
|
487
|
+
def insert_virtual_media(iso_url, device: nil, username: nil, password: nil)
|
|
488
|
+
# Ensure remote media is enabled (AMI-specific)
|
|
489
|
+
ensure_remote_media_enabled!
|
|
490
|
+
|
|
488
491
|
devices = virtual_media
|
|
489
492
|
target_device = if device
|
|
490
493
|
devices.find { |d| d["Id"] == device || d["Name"]&.include?(device.to_s) }
|
|
@@ -498,9 +501,20 @@ module Radfish
|
|
|
498
501
|
device_path = target_device["@odata.id"]
|
|
499
502
|
actions = target_device.dig("Actions", "#VirtualMedia.InsertMedia")
|
|
500
503
|
|
|
504
|
+
# Detect transfer protocol from URL (AMI requires this)
|
|
505
|
+
transfer_protocol = detect_transfer_protocol(iso_url)
|
|
506
|
+
|
|
501
507
|
if actions && actions["target"]
|
|
502
508
|
# Use the InsertMedia action
|
|
503
|
-
|
|
509
|
+
# AMI requires UserName/Password even for anonymous access
|
|
510
|
+
payload = {
|
|
511
|
+
"Image" => iso_url,
|
|
512
|
+
"Inserted" => true,
|
|
513
|
+
"WriteProtected" => true,
|
|
514
|
+
"TransferProtocolType" => transfer_protocol,
|
|
515
|
+
"UserName" => username || "",
|
|
516
|
+
"Password" => password || ""
|
|
517
|
+
}
|
|
504
518
|
response = authenticated_request(:post, actions["target"], body: payload.to_json)
|
|
505
519
|
else
|
|
506
520
|
# Fallback to PATCH method
|
|
@@ -508,12 +522,20 @@ module Radfish
|
|
|
508
522
|
response = authenticated_request(:patch, device_path, body: payload.to_json)
|
|
509
523
|
end
|
|
510
524
|
|
|
525
|
+
# 200, 202, 204 are all success (202 = accepted, async operation)
|
|
511
526
|
if response.status.between?(200, 204)
|
|
512
|
-
debug "Virtual media
|
|
527
|
+
debug "Virtual media insert initiated successfully", 1, :green
|
|
513
528
|
true
|
|
514
529
|
else
|
|
515
530
|
error_msg = begin
|
|
516
|
-
JSON.parse(response.body)
|
|
531
|
+
data = JSON.parse(response.body)
|
|
532
|
+
# Try to get detailed error from ExtendedInfo
|
|
533
|
+
extended = data.dig("error", "@Message.ExtendedInfo")
|
|
534
|
+
if extended&.any?
|
|
535
|
+
extended.map { |e| e["Message"] }.join("; ")
|
|
536
|
+
else
|
|
537
|
+
data.dig("error", "message")
|
|
538
|
+
end
|
|
517
539
|
rescue
|
|
518
540
|
response.body
|
|
519
541
|
end
|
|
@@ -521,6 +543,34 @@ module Radfish
|
|
|
521
543
|
end
|
|
522
544
|
end
|
|
523
545
|
|
|
546
|
+
# Enable remote media support (AMI-specific, required before virtual media works)
|
|
547
|
+
def enable_remote_media
|
|
548
|
+
response = authenticated_request(
|
|
549
|
+
:post,
|
|
550
|
+
"/redfish/v1/Managers/#{MANAGER_ID}/Actions/Oem/AMIVirtualMedia.EnableRMedia",
|
|
551
|
+
body: { "RMediaState" => "Enable" }.to_json
|
|
552
|
+
)
|
|
553
|
+
response.status.between?(200, 204)
|
|
554
|
+
end
|
|
555
|
+
|
|
556
|
+
# Disable remote media support (AMI-specific)
|
|
557
|
+
def disable_remote_media
|
|
558
|
+
response = authenticated_request(
|
|
559
|
+
:post,
|
|
560
|
+
"/redfish/v1/Managers/#{MANAGER_ID}/Actions/Oem/AMIVirtualMedia.EnableRMedia",
|
|
561
|
+
body: { "RMediaState" => "Disable" }.to_json
|
|
562
|
+
)
|
|
563
|
+
response.status.between?(200, 204)
|
|
564
|
+
end
|
|
565
|
+
|
|
566
|
+
# Check if remote media is enabled
|
|
567
|
+
def remote_media_enabled?
|
|
568
|
+
response = authenticated_request(:get, "/redfish/v1/Managers/#{MANAGER_ID}")
|
|
569
|
+
return false unless response.status == 200
|
|
570
|
+
data = JSON.parse(response.body)
|
|
571
|
+
data.dig("Oem", "Ami", "VirtualMedia", "RMediaStatus") == "Enabled"
|
|
572
|
+
end
|
|
573
|
+
|
|
524
574
|
def eject_virtual_media(device: nil)
|
|
525
575
|
devices = virtual_media
|
|
526
576
|
target_device = if device
|
|
@@ -962,6 +1012,38 @@ module Radfish
|
|
|
962
1012
|
end
|
|
963
1013
|
end
|
|
964
1014
|
end
|
|
1015
|
+
|
|
1016
|
+
# Detect transfer protocol from URL for AMI virtual media
|
|
1017
|
+
def detect_transfer_protocol(url)
|
|
1018
|
+
uri = URI.parse(url)
|
|
1019
|
+
case uri.scheme&.downcase
|
|
1020
|
+
when 'https'
|
|
1021
|
+
'HTTPS'
|
|
1022
|
+
when 'nfs'
|
|
1023
|
+
'NFS'
|
|
1024
|
+
when 'cifs', 'smb'
|
|
1025
|
+
'CIFS'
|
|
1026
|
+
when 'http'
|
|
1027
|
+
# AMI doesn't support plain HTTP, try HTTPS
|
|
1028
|
+
'HTTPS'
|
|
1029
|
+
else
|
|
1030
|
+
'HTTPS' # Default to HTTPS
|
|
1031
|
+
end
|
|
1032
|
+
end
|
|
1033
|
+
|
|
1034
|
+
# Ensure remote media is enabled (AMI-specific requirement)
|
|
1035
|
+
def ensure_remote_media_enabled!
|
|
1036
|
+
return if remote_media_enabled?
|
|
1037
|
+
|
|
1038
|
+
response = authenticated_request(
|
|
1039
|
+
:post,
|
|
1040
|
+
"/redfish/v1/Managers/#{MANAGER_ID}/Actions/Oem/AMIVirtualMedia.EnableRMedia",
|
|
1041
|
+
body: { "RMediaState" => "Enable" }.to_json
|
|
1042
|
+
)
|
|
1043
|
+
|
|
1044
|
+
# Wait for the action to complete
|
|
1045
|
+
sleep 3 if response.status.between?(200, 204)
|
|
1046
|
+
end
|
|
965
1047
|
end
|
|
966
1048
|
|
|
967
1049
|
# Register the AMI adapter
|