Module: Supermicro::SystemConfig

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

Instance Method Summary collapse

Instance Method Details

#manager_infoObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/supermicro/system_config.rb', line 64

def manager_info
  response = authenticated_request(:get, "/redfish/v1/Managers/1")
  
  if response.status == 200
    begin
      data = JSON.parse(response.body)
      
      {
        "name" => data["Name"],
        "model" => data["Model"],
        "firmware_version" => data["FirmwareVersion"],
        "uuid" => data["UUID"],
        "status" => data.dig("Status", "Health"),
        "datetime" => data["DateTime"],
        "datetime_local_offset" => data["DateTimeLocalOffset"]
      }
    rescue JSON::ParserError
      raise Error, "Failed to parse manager info response: #{response.body}"
    end
  else
    raise Error, "Failed to get manager info. Status code: #{response.status}"
  end
end

#manager_network_protocolObject

BIOS methods have been moved to the Bios module for better organization Use client.bios_attributes, client.set_bios_attribute, etc. instead



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

def manager_network_protocol
  response = authenticated_request(:get, "/redfish/v1/Managers/1/NetworkProtocol")
  
  if response.status == 200
    begin
      data = JSON.parse(response.body)
      
      protocols = {}
      ["HTTP", "HTTPS", "IPMI", "SSH", "SNMP", "VirtualMedia", "KVMIP", "NTP", "Telnet"].each do |proto|
        if data[proto]
          protocols[proto.downcase] = {
            "enabled" => data[proto]["ProtocolEnabled"],
            "port" => data[proto]["Port"]
          }
        end
      end
      
      protocols
    rescue JSON::ParserError
      raise Error, "Failed to parse network protocol response: #{response.body}"
    end
  else
    raise Error, "Failed to get network protocols. Status code: #{response.status}"
  end
end

#reset_managerObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/supermicro/system_config.rb', line 110

def reset_manager
  puts "Resetting BMC...".yellow
  
  response = authenticated_request(
    :post,
    "/redfish/v1/Managers/1/Actions/Manager.Reset",
    body: { "ResetType": "GracefulRestart" }.to_json,
    headers: { 'Content-Type': 'application/json' }
  )
  
  if response.status.between?(200, 299)
    puts "BMC reset initiated successfully.".green
    return true
  else
    raise Error, "Failed to reset BMC: #{response.status} - #{response.body}"
  end
end

#set_manager_datetime(datetime_str) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/supermicro/system_config.rb', line 88

def set_manager_datetime(datetime_str)
  puts "Setting BMC datetime to #{datetime_str}...".yellow
  
  body = {
    "DateTime" => datetime_str
  }
  
  response = authenticated_request(
    :patch,
    "/redfish/v1/Managers/1",
    body: body.to_json,
    headers: { 'Content-Type': 'application/json' }
  )
  
  if response.status.between?(200, 299)
    puts "DateTime set successfully.".green
    return true
  else
    raise Error, "Failed to set datetime: #{response.status} - #{response.body}"
  end
end

#set_network_protocol(protocol, enabled:, port: nil) ⇒ Object



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

def set_network_protocol(protocol, enabled:, port: nil)
  puts "Configuring #{protocol} protocol...".yellow
  
  proto_key = protocol.upcase
  body = {
    proto_key => {
      "ProtocolEnabled" => enabled
    }
  }
  
  body[proto_key]["Port"] = port if port
  
  response = authenticated_request(
    :patch,
    "/redfish/v1/Managers/1/NetworkProtocol",
    body: body.to_json,
    headers: { 'Content-Type': 'application/json' }
  )
  
  if response.status.between?(200, 299)
    puts "Network protocol configured successfully.".green
    return true
  else
    raise Error, "Failed to configure network protocol: #{response.status} - #{response.body}"
  end
end