Module: Supermicro::License

Included in:
Client
Defined in:
lib/supermicro/license.rb

Instance Method Summary collapse

Instance Method Details

#activate_license(license_key) ⇒ Object

Activate a license



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/supermicro/license.rb', line 97

def activate_license(license_key)
  response = authenticated_request(
    :post,
    "/redfish/v1/Managers/1/LicenseManager/Actions/LicenseManager.ActivateLicense",
    body: { "LicenseKey" => license_key }.to_json,
    headers: { 'Content-Type': 'application/json' }
  )
  
  if response.status.between?(200, 299)
    debug "License activated successfully", 1, :green
    true
  else
    debug "Failed to activate license: #{response.status}", 1, :red
    false
  end
end

#check_virtual_media_licenseObject

Check if the BMC has the required licenses for virtual media



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
# File 'lib/supermicro/license.rb', line 8

def check_virtual_media_license
  response = authenticated_request(:get, "/redfish/v1/Managers/1/LicenseManager/QueryLicense")
  
  if response.status != 200
    debug "Unable to query license status: #{response.status}", 1, :yellow
    return { 
      available: :unknown, 
      message: "Unable to query license status",
      licenses: []
    }
  end
  
  begin
    data = JSON.parse(response.body)
    licenses = data["Licenses"] || []
    
    found_licenses = []
    has_oob = false
    has_dcms = false
    
    licenses.each do |license_json|
      # Parse the nested JSON structure
      license_data = JSON.parse(license_json) rescue nil
      next unless license_data
      
      license_name = license_data.dig("ProductKey", "Node", "LicenseName")
      next unless license_name
      
      found_licenses << license_name
      
      # Check for required licenses
      has_oob = true if license_name == "SFT-OOB-LIC"
      has_dcms = true if license_name == "SFT-DCMS-SINGLE"
    end
    
    # Virtual media requires either SFT-OOB-LIC or SFT-DCMS-SINGLE
    has_required_license = has_oob || has_dcms
    
    {
      available: has_required_license,
      licenses: found_licenses,
      message: if has_required_license
                 "Virtual media license present: #{found_licenses.join(', ')}"
               elsif found_licenses.empty?
                 "No licenses found. Virtual media requires SFT-OOB-LIC or SFT-DCMS-SINGLE"
               else
                 "Virtual media requires SFT-OOB-LIC or SFT-DCMS-SINGLE. Found: #{found_licenses.join(', ')}"
               end
    }
  rescue JSON::ParserError => e
    debug "Failed to parse license response: #{e.message}", 1, :red
    { 
      available: :unknown, 
      message: "Failed to parse license response",
      licenses: []
    }
  end
end

#clear_license(license_id) ⇒ Object

Clear/remove a license



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/supermicro/license.rb', line 115

def clear_license(license_id)
  response = authenticated_request(
    :post,
    "/redfish/v1/Managers/1/LicenseManager/Actions/LicenseManager.ClearLicense",
    body: { "LicenseID" => license_id }.to_json,
    headers: { 'Content-Type': 'application/json' }
  )
  
  if response.status.between?(200, 299)
    debug "License cleared successfully", 1, :green
    true
  else
    debug "Failed to clear license: #{response.status}", 1, :red
    false
  end
end

#licensesObject

Get all licenses



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
# File 'lib/supermicro/license.rb', line 68

def licenses
  response = authenticated_request(:get, "/redfish/v1/Managers/1/LicenseManager/QueryLicense")
  
  return [] if response.status != 200
  
  begin
    data = JSON.parse(response.body)
    licenses = data["Licenses"] || []
    
    parsed_licenses = []
    licenses.each do |license_json|
      license_data = JSON.parse(license_json) rescue nil
      next unless license_data
      
      node = license_data.dig("ProductKey", "Node") || {}
      parsed_licenses << {
        id: node["LicenseID"],
        name: node["LicenseName"],
        created: node["CreateDate"]
      }
    end
    
    parsed_licenses
  rescue JSON::ParserError
    []
  end
end