idrac 0.1.29 → 0.1.31

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.
@@ -2,10 +2,13 @@ require 'net/http'
2
2
  require 'uri'
3
3
  require 'fileutils'
4
4
  require 'nokogiri'
5
+ require 'open-uri'
6
+ require 'colorize'
5
7
 
6
8
  module IDRAC
7
9
  class FirmwareCatalog
8
- CATALOG_URL = "https://downloads.dell.com/catalog/Catalog.xml.gz"
10
+ DELL_CATALOG_BASE = 'https://downloads.dell.com'
11
+ DELL_CATALOG_URL = "#{DELL_CATALOG_BASE}/catalog/Catalog.xml.gz"
9
12
 
10
13
  attr_reader :catalog_path
11
14
 
@@ -14,40 +17,38 @@ module IDRAC
14
17
  end
15
18
 
16
19
  def download(output_dir = nil)
17
- # Use ~/.idrac as the default directory
18
- output_dir ||= File.expand_path("~/.idrac")
20
+ # Default to ~/.idrac directory
21
+ output_dir ||= File.expand_path('~/.idrac')
19
22
  FileUtils.mkdir_p(output_dir) unless Dir.exist?(output_dir)
20
23
 
21
- catalog_gz_path = File.join(output_dir, "Catalog.xml.gz")
22
- catalog_path = File.join(output_dir, "Catalog.xml")
23
-
24
- puts "Downloading Dell catalog from #{CATALOG_URL}..."
25
-
26
- uri = URI.parse(CATALOG_URL)
27
- Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
28
- request = Net::HTTP::Get.new(uri)
29
- http.request(request) do |response|
30
- if response.code == "200"
31
- File.open(catalog_gz_path, 'wb') do |file|
32
- response.read_body do |chunk|
33
- file.write(chunk)
34
- end
35
- end
36
- else
37
- raise Error, "Failed to download catalog: #{response.code} #{response.message}"
38
- end
39
- end
40
- end
24
+ catalog_gz = File.join(output_dir, 'Catalog.xml.gz')
25
+ catalog_xml = File.join(output_dir, 'Catalog.xml')
41
26
 
42
- puts "Extracting catalog..."
43
- system("gunzip -f #{catalog_gz_path}")
27
+ puts "Downloading Dell catalog from #{DELL_CATALOG_URL}...".light_cyan
44
28
 
45
- if File.exist?(catalog_path)
46
- puts "Catalog downloaded and extracted to #{catalog_path}"
47
- @catalog_path = catalog_path
48
- return catalog_path
49
- else
50
- raise Error, "Failed to extract catalog"
29
+ begin
30
+ # Download the catalog
31
+ URI.open(DELL_CATALOG_URL) do |remote_file|
32
+ File.open(catalog_gz, 'wb') do |local_file|
33
+ local_file.write(remote_file.read)
34
+ end
35
+ end
36
+
37
+ puts "Extracting catalog...".light_cyan
38
+
39
+ # Extract the catalog
40
+ system("gunzip -f #{catalog_gz}")
41
+
42
+ if File.exist?(catalog_xml)
43
+ puts "Catalog downloaded and extracted to #{catalog_xml}".green
44
+ @catalog_path = catalog_xml
45
+ return catalog_xml
46
+ else
47
+ raise Error, "Failed to extract catalog"
48
+ end
49
+ rescue => e
50
+ puts "Error downloading catalog: #{e.message}".red.bold
51
+ raise Error, "Failed to download Dell catalog: #{e.message}"
51
52
  end
52
53
  end
53
54
 
data/lib/idrac/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IDRAC
4
- VERSION = "0.1.29"
4
+ VERSION = "0.1.31"
5
5
  end
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require_relative 'lib/idrac'
3
+ require 'lib/idrac'
4
+ require 'colorize'
4
5
 
5
6
  # Create a client
6
7
  client = IDRAC::Client.new(
@@ -12,59 +13,56 @@ client = IDRAC::Client.new(
12
13
 
13
14
  begin
14
15
  # Login to iDRAC
16
+ puts "Logging in to iDRAC...".light_cyan
15
17
  client.login
16
- puts "Logged in successfully"
18
+ puts "Logged in successfully".green
17
19
 
18
20
  # Create a firmware instance
19
21
  firmware = IDRAC::Firmware.new(client)
20
22
 
21
23
  # Get system inventory
22
- puts "Getting system inventory..."
24
+ puts "Getting system inventory...".light_cyan
23
25
  inventory = firmware.get_system_inventory
24
26
 
25
- puts "System Information:"
26
- puts " Model: #{inventory[:system][:model]}"
27
- puts " Manufacturer: #{inventory[:system][:manufacturer]}"
28
- puts " Service Tag: #{inventory[:system][:service_tag]}"
29
- puts " BIOS Version: #{inventory[:system][:bios_version]}"
27
+ puts "System Information:".green.bold
28
+ puts " Model: #{inventory[:system][:model]}".light_cyan
29
+ puts " Manufacturer: #{inventory[:system][:manufacturer]}".light_cyan
30
+ puts " Service Tag: #{inventory[:system][:service_tag]}".light_cyan
31
+ puts " BIOS Version: #{inventory[:system][:bios_version]}".light_cyan
30
32
 
31
- puts "\nInstalled Firmware:"
33
+ puts "\nInstalled Firmware:".green.bold
32
34
  inventory[:firmware].each do |fw|
33
- puts " #{fw[:name]}: #{fw[:version]} (#{fw[:updateable] ? 'Updateable' : 'Not Updateable'})"
35
+ puts " #{fw[:name]}: #{fw[:version]} (#{fw[:updateable] ? 'Updateable'.light_green : 'Not Updateable'.light_red})".light_cyan
34
36
  end
35
37
 
36
38
  # Check for updates
37
39
  catalog_path = File.expand_path("~/.idrac/Catalog.xml")
38
40
  if File.exist?(catalog_path)
39
- puts "\nChecking for updates using catalog: #{catalog_path}"
41
+ puts "\nChecking for updates using catalog: #{catalog_path}".light_cyan
40
42
  updates = firmware.check_updates(catalog_path)
41
43
 
42
- if updates.empty?
43
- puts "No updates available."
44
- else
45
- puts "\nAvailable Updates:"
44
+ if updates.any?
45
+ puts "\nAvailable Updates:".green.bold
46
46
  updates.each_with_index do |update, index|
47
- puts "#{index + 1}. #{update[:name]}: #{update[:current_version]} -> #{update[:available_version]}"
47
+ puts "#{index + 1}. #{update[:name]}: #{update[:current_version]} -> #{update[:available_version]}".light_cyan
48
48
  end
49
49
 
50
- # For testing, select the first update
51
- if updates.any?
52
- selected_update = updates.first
53
- puts "\nSelected update: #{selected_update[:name]}: #{selected_update[:current_version]} -> #{selected_update[:available_version]}"
54
-
55
- # Download and install the update
56
- puts "Starting interactive update for selected component..."
57
- firmware.interactive_update(catalog_path, [selected_update])
58
- end
50
+ # Interactive update for the first update
51
+ puts "\nSelected update: #{updates.first[:name]}".light_yellow
52
+ puts "Starting interactive update for selected component...".light_cyan.bold
53
+
54
+ firmware.interactive_update(catalog_path, [updates.first])
55
+ else
56
+ puts "No updates available for your system.".yellow
59
57
  end
60
58
  else
61
- puts "\nCatalog file not found at #{catalog_path}. Please download the catalog first."
59
+ puts "\nCatalog not found at #{catalog_path}. Run 'idrac firmware:catalog' to download it.".yellow
62
60
  end
63
61
 
64
62
  rescue IDRAC::Error => e
65
- puts "Error: #{e.message}"
63
+ puts "Error: #{e.message}".red.bold
66
64
  ensure
67
65
  # Logout
68
- client.logout if client.instance_variable_get(:@session_id)
69
- puts "Logged out"
66
+ client.logout if client
67
+ puts "Logged out".light_cyan
70
68
  end