ilo-sdk 1.0.0

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.
@@ -0,0 +1,158 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing,
6
+ # software distributed under the License is distributed on an "AS IS" BASIS,
7
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and limitations under the License.
9
+
10
+ module ILO_SDK
11
+ # Contains helper methods for computer details actions
12
+ module ComputerDetailsHelper
13
+ # Get all of the computer details
14
+ # @raise [RuntimeError] if the request failed
15
+ # @return [Hash] computer_details
16
+ def get_computer_details
17
+ general_computer_details = get_general_computer_details
18
+ computer_network_details = get_computer_network_details
19
+ array_controller_details = get_array_controller_details
20
+ general_computer_details.merge(computer_network_details).merge(array_controller_details)
21
+ end
22
+
23
+ # Get the general computer details
24
+ # @raise [RuntimeError] if the request failed
25
+ # @return [Fixnum] general_computer_details
26
+ def get_general_computer_details
27
+ response = rest_get('/redfish/v1/Systems/1/')
28
+ details = response_handler(response)
29
+ {
30
+ 'GeneralDetails' => {
31
+ 'manufacturer' => details['Manufacturer'],
32
+ 'model' => details['Model'],
33
+ 'AssetTag' => details['AssetTag'],
34
+ 'bios_version' => details['Bios']['Current']['VersionString'],
35
+ 'memory' => details['Memory']['TotalSystemMemoryGB'].to_s + ' GB',
36
+ 'processors' => details['Processors']['Count'].to_s + ' x ' + details['Processors']['ProcessorFamily'].to_s
37
+ }
38
+ }
39
+ end
40
+
41
+ # Get the computer network details
42
+ # @raise [RuntimeError] if the request failed
43
+ # @return [Hash] computer_network_details
44
+ def get_computer_network_details
45
+ network_adapters = []
46
+ response = rest_get('/redfish/v1/Systems/1/NetworkAdapters/')
47
+ networks = response_handler(response)['links']['Member']
48
+ networks.each do |network|
49
+ response = rest_get(network['href'])
50
+ detail = response_handler(response)
51
+ physical_ports = []
52
+ detail['PhysicalPorts'].each do |port|
53
+ n = {
54
+ 'Name' => port['Name'],
55
+ 'StructuredName' => port['Oem']['Hp']['StructuredName'],
56
+ 'MacAddress' => port['MacAddress'],
57
+ 'State' => port['Status']['State']
58
+ }
59
+ physical_ports.push(n)
60
+ end
61
+ nets = {
62
+ 'Name' => detail['Name'],
63
+ 'StructuredName' => detail['StructuredName'],
64
+ 'PartNumber' => detail['PartNumber'],
65
+ 'State' => detail['Status']['State'],
66
+ 'Health' => detail['Status']['Health'],
67
+ 'PhysicalPorts' => physical_ports
68
+ }
69
+ network_adapters.push(nets)
70
+ end
71
+ {
72
+ 'NetworkAdapters' => network_adapters
73
+ }
74
+ end
75
+
76
+ # Get the array controller details
77
+ # @raise [RuntimeError] if the request failed
78
+ # @return [Hash] array_controller_details
79
+ def get_array_controller_details
80
+ response = rest_get('/redfish/v1/Systems/1/SmartStorage/')
81
+ storages = response_handler(response)
82
+ array_controllers = []
83
+ response = rest_get(storages['links']['ArrayControllers']['href'])
84
+ array_ctrls = response_handler(response)
85
+ if array_ctrls['links'].key? 'Member'
86
+ array_ctrls['links']['Member'].each do |array_controller|
87
+ response = rest_get(array_controller['href'])
88
+ controller = response_handler(response)
89
+ storage_enclosures = []
90
+ response = rest_get(controller['links']['StorageEnclosures']['href'])
91
+ response_handler(response)['links']['Member'].each do |enclosure|
92
+ response = rest_get(enclosure['href'])
93
+ enclsr = response_handler(response)
94
+ enc = {
95
+ 'Model' => enclsr['Model'],
96
+ 'SerialNumber' => enclsr['SerialNumber'],
97
+ 'DriveBayCount' => enclsr['DriveBayCount'],
98
+ 'State' => enclsr['Status']['State'],
99
+ 'Health' => enclsr['Status']['Health'],
100
+ 'Location' => enclsr['Location'].to_s + ' (' + enclsr['LocationFormat'].to_s + ')',
101
+ 'FirmwareVersion' => enclsr['FirmwareVersion']['Current']['VersionString']
102
+ }
103
+ storage_enclosures.push(enc)
104
+ end
105
+
106
+ logical_drives = []
107
+ response = rest_get(controller['links']['LogicalDrives']['href'])
108
+ response_handler(response)['links']['Member'].each do |logicaldrive|
109
+ response = rest_get(logicaldrive['href'])
110
+ lds = response_handler(response)
111
+ data_drives = []
112
+ response = rest_get(lds['links']['DataDrives']['href'])
113
+ response_handler(response)['links']['Member'].each do |datadrives|
114
+ response = rest_get(datadrives['href'])
115
+ disk_drive = response_handler(response)
116
+ dd = {
117
+ 'Model' => disk_drive['Model'],
118
+ 'Name' => disk_drive['Name'],
119
+ 'RotationalSpeedRpm' => disk_drive['RotationalSpeedRpm'],
120
+ 'SerialNumber' => disk_drive['SerialNumber'],
121
+ 'State' => disk_drive['Status']['State'],
122
+ 'Health' => disk_drive['Status']['Health'],
123
+ 'CapacityMiB' => disk_drive['CapacityMiB'],
124
+ 'CurrentTemperatureCelsius' => disk_drive['CurrentTemperatureCelsius']
125
+ }
126
+ data_drives.push(dd)
127
+ end
128
+ ld = {
129
+ 'Size' => lds['CapacityMiB'],
130
+ 'Raid' => lds['Raid'],
131
+ 'Status' => lds['Status']['State'],
132
+ 'Health' => lds['Status']['Health'],
133
+ 'DataDrives' => data_drives
134
+ }
135
+ logical_drives.push(ld)
136
+ end
137
+ ac = {
138
+ 'Model' => controller['Model'],
139
+ 'SerialNumber' => controller['SerialNumber'],
140
+ 'State' => controller['Status']['State'],
141
+ 'Health' => controller['Status']['Health'],
142
+ 'Location' => controller['Location'],
143
+ 'FirmWareVersion' => controller['FirmwareVersion']['Current']['VersionString'],
144
+ 'LogicalDrives' => logical_drives,
145
+ 'Enclosures' => storage_enclosures
146
+ }
147
+ array_controllers.push(ac)
148
+ end
149
+ end
150
+ {
151
+ 'HPSmartStorage' => {
152
+ 'Health' => storages['Status']['Health'],
153
+ 'ArrayControllers' => array_controllers
154
+ }
155
+ }
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,51 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing,
6
+ # software distributed under the License is distributed on an "AS IS" BASIS,
7
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and limitations under the License.
9
+
10
+ module ILO_SDK
11
+ # Contains helper methods for Computer System actions
12
+ module ComputerSystemHelper
13
+ # Get the Asset Tag
14
+ # @raise [RuntimeError] if the request failed
15
+ # @return [String] asset_tag
16
+ def get_asset_tag
17
+ response = rest_get('/redfish/v1/Systems/1/')
18
+ response_handler(response)['AssetTag']
19
+ end
20
+
21
+ # Set the Asset Tag
22
+ # @param [String, Symbol] asset_tag
23
+ # @raise [RuntimeError] if the request failed
24
+ # @return true
25
+ def set_asset_tag(asset_tag)
26
+ new_action = { 'AssetTag' => asset_tag }
27
+ response = rest_patch('/redfish/v1/Systems/1/', body: new_action)
28
+ response_handler(response)
29
+ true
30
+ end
31
+
32
+ # Get the UID indicator LED state
33
+ # @raise [RuntimeError] if the request failed
34
+ # @return [String] indicator_led
35
+ def get_indicator_led
36
+ response = rest_get('/redfish/v1/Systems/1/')
37
+ response_handler(response)['IndicatorLED']
38
+ end
39
+
40
+ # Set the UID indicator LED
41
+ # @param [String, Symbol] state
42
+ # @raise [RuntimeError] if the request failed
43
+ # @return true
44
+ def set_indicator_led(state)
45
+ new_action = { 'IndicatorLED' => state }
46
+ response = rest_patch('/redfish/v1/Systems/1/', body: new_action)
47
+ response_handler(response)
48
+ true
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,72 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing,
6
+ # software distributed under the License is distributed on an "AS IS" BASIS,
7
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and limitations under the License.
9
+
10
+ module ILO_SDK
11
+ # Contains helper methods for Date and Time actions
12
+ module DateTimeHelper
13
+ # Get the Time Zone
14
+ # @raise [RuntimeError] if the request failed
15
+ # @return [String] time_zone
16
+ def get_time_zone
17
+ response = rest_get('/redfish/v1/Managers/1/DateTime/')
18
+ response_handler(response)['TimeZone']['Name']
19
+ end
20
+
21
+ # Set the Time Zone
22
+ # @param [Fixnum] time_zone
23
+ # @raise [RuntimeError] if the request failed
24
+ # @return true
25
+ def set_time_zone(time_zone)
26
+ time_response = rest_get('/redfish/v1/Managers/1/DateTime/')
27
+ new_time_zone = response_handler(time_response)['TimeZoneList'].select { |timezone| timezone['Name'] == time_zone }
28
+ new_action = { 'TimeZone' => { 'Index' => new_time_zone[0]['Index'] } }
29
+ response = rest_patch('/redfish/v1/Managers/1/DateTime/', body: new_action)
30
+ response_handler(response)
31
+ true
32
+ end
33
+
34
+ # Get whether or not ntp servers are being used
35
+ # @raise [RuntimeError] if the request failed
36
+ # @return [TrueClass, FalseClass] use_ntp
37
+ def get_ntp
38
+ response = rest_get('/redfish/v1/Managers/1/EthernetInterfaces/1/')
39
+ response_handler(response)['Oem']['Hp']['DHCPv4']['UseNTPServers']
40
+ end
41
+
42
+ # Set whether or not ntp servers are being used
43
+ # @param [TrueClass, FalseClass] use_ntp
44
+ # @raise [RuntimeError] if the request failed
45
+ # @return true
46
+ def set_ntp(use_ntp)
47
+ new_action = { 'Oem' => { 'Hp' => { 'DHCPv4' => { 'UseNTPServers' => use_ntp } } } }
48
+ response = rest_patch('/redfish/v1/Managers/1/EthernetInterfaces/1/', body: new_action)
49
+ response_handler(response)
50
+ true
51
+ end
52
+
53
+ # Get the NTP Servers
54
+ # @raise [RuntimeError] if the request failed
55
+ # @return [Array] ntp_servers
56
+ def get_ntp_servers
57
+ response = rest_get('/redfish/v1/Managers/1/DateTime/')
58
+ response_handler(response)['StaticNTPServers']
59
+ end
60
+
61
+ # Set the NTP Servers
62
+ # @param [Fixnum] ntp_servers
63
+ # @raise [RuntimeError] if the request failed
64
+ # @return true
65
+ def set_ntp_servers(ntp_servers)
66
+ new_action = { 'StaticNTPServers' => ntp_servers }
67
+ response = rest_patch('/redfish/v1/Managers/1/DateTime/', body: new_action)
68
+ response_handler(response)
69
+ true
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,32 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing,
6
+ # software distributed under the License is distributed on an "AS IS" BASIS,
7
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and limitations under the License.
9
+
10
+ module ILO_SDK
11
+ # Contains helper methods for Firmware Update actions
12
+ module FirmwareUpdateHelper
13
+ # Get the Firmware Version
14
+ # @raise [RuntimeError] if the request failed
15
+ # @return [String] fw_version
16
+ def get_fw_version
17
+ response = rest_get('/redfish/v1/Systems/1/FirmWareInventory/')
18
+ response_handler(response)['Current']['SystemBMC'][0]['VersionString']
19
+ end
20
+
21
+ # Set the Firmware Upgrade
22
+ # @param [String, Symbol] uri
23
+ # @raise [RuntimeError] if the request failed
24
+ # @return true
25
+ def set_fw_upgrade(uri, tpm_override_flag = true)
26
+ new_action = { 'Action' => 'InstallFromURI', 'FirmwareURI' => uri, 'TPMOverrideFlag' => tpm_override_flag }
27
+ response = rest_post('/redfish/v1/Managers/1/UpdateService/', body: new_action)
28
+ response_handler(response)
29
+ true
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,53 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing,
6
+ # software distributed under the License is distributed on an "AS IS" BASIS,
7
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and limitations under the License.
9
+
10
+ module ILO_SDK
11
+ # Contains helper methods for Log Entry actions
12
+ module LogEntryHelper
13
+ # Clear the specified logs
14
+ # @param [String, Symbol] log_type
15
+ # @raise [RuntimeError] if the request failed
16
+ # @return true
17
+ def clear_logs(log_type)
18
+ new_action = { 'Action' => 'ClearLog' }
19
+ response = rest_post("/redfish/v1/Managers/1/LogServices/#{log_type}/", body: new_action)
20
+ response_handler(response)
21
+ true
22
+ end
23
+
24
+ # Check to see if the specified logs are empty
25
+ # @param [String, Symbol] log_type
26
+ # @raise [RuntimeError] if the request failed
27
+ # @return [TrueClass, FalseClass] logs_empty
28
+ def logs_empty?(log_type)
29
+ response = rest_get("/redfish/v1/Managers/1/LogServices/#{log_type}/Entries/")
30
+ response_handler(response)['Items'].empty?
31
+ end
32
+
33
+ # Get the specified logs
34
+ # @param [String, Symbol] severity_level
35
+ # @param [String, Symbol] duration
36
+ # @param [String, Symbol] log_type
37
+ # @raise [RuntimeError] if the request failed
38
+ # @return logs
39
+ def get_logs(severity_level, duration, log_type)
40
+ response = rest_get("/redfish/v1/Managers/1/LogServices/#{log_type}/Entries/")
41
+ entries = response_handler(response)['Items']
42
+ logs = []
43
+ entries.each do |e|
44
+ if severity_level.nil?
45
+ logs.push("#{e['Severity']} | #{e['Message']} | #{e['Created']}") if Time.parse(e['Created']) > (Time.now.utc - (duration * 3600))
46
+ elsif e['Severity'] == severity_level && Time.parse(e['Created']) > (Time.now.utc - (duration * 3600))
47
+ logs.push("#{e['Severity']} | #{e['Message']} | #{e['Created']}")
48
+ end
49
+ end
50
+ logs
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,32 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing,
6
+ # software distributed under the License is distributed on an "AS IS" BASIS,
7
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and limitations under the License.
9
+
10
+ module ILO_SDK
11
+ # Contains helper methods for Manager Network Protocol actions
12
+ module ManagerNetworkProtocolHelper
13
+ # Get the Session Timeout Minutes
14
+ # @raise [RuntimeError] if the request failed
15
+ # @return [Fixnum] timeout
16
+ def get_timeout
17
+ response = rest_get('/redfish/v1/Managers/1/NetworkService/')
18
+ response_handler(response)['SessionTimeoutMinutes']
19
+ end
20
+
21
+ # Set the Session Timeout Minutes
22
+ # @param [Fixnum] timeout
23
+ # @raise [RuntimeError] if the request failed
24
+ # @return true
25
+ def set_timeout(timeout)
26
+ new_action = { 'SessionTimeoutMinutes' => timeout }
27
+ response = rest_patch('/redfish/v1/Managers/1/NetworkService/', body: new_action)
28
+ response_handler(response)
29
+ true
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,42 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License");
2
+ # you may not use this file except in compliance with the License.
3
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4
+ #
5
+ # Unless required by applicable law or agreed to in writing,
6
+ # software distributed under the License is distributed on an "AS IS" BASIS,
7
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
8
+ # See the License for the specific language governing permissions and limitations under the License.
9
+
10
+ module ILO_SDK
11
+ # Contains helper methods for Power actions
12
+ module PowerHelper
13
+ # Get the Power State
14
+ # @raise [RuntimeError] if the request failed
15
+ # @return [String] power_state
16
+ def get_power_state
17
+ response = rest_get('/redfish/v1/Systems/1/')
18
+ response_handler(response)['PowerState']
19
+ end
20
+
21
+ # Set the Power State
22
+ # @param [String, Symbol] state
23
+ # @raise [RuntimeError] if the request failed
24
+ # @return true
25
+ def set_power_state(state)
26
+ new_action = { 'Action' => 'Reset', 'ResetType' => state }
27
+ response = rest_post('/redfish/v1/Systems/1/', body: new_action)
28
+ response_handler(response)
29
+ true
30
+ end
31
+
32
+ # Reset the iLO
33
+ # @raise [RuntimeError] if the request failed
34
+ # @return true
35
+ def reset_ilo
36
+ new_action = { 'Action' => 'Reset' }
37
+ response = rest_post('/redfish/v1/Managers/1/', body: new_action)
38
+ response_handler(response)
39
+ true
40
+ end
41
+ end
42
+ end