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.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'bundler'
2
+ require 'bundler/gem_tasks'
3
+ require 'bundler/setup'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ task default: :spec
8
+ spec_pattern = 'spec/**/*_spec.rb'
9
+ def_spec_options = '--color '
10
+
11
+ desc 'Run unit tests only'
12
+ RSpec::Core::RakeTask.new(:spec) do |spec|
13
+ spec.pattern = spec_pattern
14
+ spec.rspec_opts = def_spec_options
15
+ end
16
+
17
+ RuboCop::RakeTask.new
18
+
19
+ desc 'Runs rubocop and unit tests'
20
+ task :test do
21
+ Rake::Task[:rubocop].invoke
22
+ Rake::Task[:spec].invoke
23
+ end
data/ilo-sdk.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ # http://guides.rubygems.org/specification-reference
3
+
4
+ require_relative './lib/ilo-sdk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ilo-sdk'
8
+ spec.version = ILO_SDK::VERSION
9
+ spec.authors = ['Anirudh Gupta', 'Bik Bajwa', 'Jared Smartt', 'Vivek Bhatia']
10
+ spec.email = ['anirudhg@hpe.com', 'bik.bajwa@hpe.com', 'jared.smartt@hpe.com', 'vivek.bhatia@hpe.com']
11
+ spec.summary = 'Gem to interact with iLO API'
12
+ spec.description = 'Gem to interact with iLO API'
13
+ spec.license = 'Apache-2.0'
14
+ spec.homepage = 'https://github.com/HewlettPackard/ilo-sdk-ruby'
15
+
16
+ all_files = `git ls-files -z`.split("\x0")
17
+ spec.files = all_files.reject { |f| f.match(%r{^(examples\/)|(spec\/)}) }
18
+ spec.executables = all_files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'pry'
22
+
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'simplecov'
27
+ spec.add_development_dependency 'rubocop', '= 0.39.0'
28
+
29
+ end
data/lib/ilo-sdk.rb ADDED
@@ -0,0 +1,15 @@
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
+ require_relative 'ilo-sdk/version'
11
+ require_relative 'ilo-sdk/client'
12
+
13
+ # Module for interracting with the HPE iLO API
14
+ module ILO_SDK
15
+ end
@@ -0,0 +1,65 @@
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
+ require 'logger'
11
+ require_relative 'rest'
12
+ # Load all helpers:
13
+ Dir[File.join(File.dirname(__FILE__), '/helpers/*.rb')].each { |file| require file }
14
+
15
+ module ILO_SDK
16
+ # The client defines the connection to the iLO and handles communication with it
17
+ class Client
18
+ attr_accessor :host, :user, :password, :ssl_enabled, :logger, :log_level
19
+
20
+ # Create a client object
21
+ # @param [Hash] options the options to configure the client
22
+ # @option options [String] :host URL, hostname, or IP address of the iLO
23
+ # @option options [String] :user ('Administrator') Username to use for authentication with the iLO
24
+ # @option options [String] :password Password to use for authentication with the iLO
25
+ # @option options [Logger] :logger (Logger.new(STDOUT)) Logger object to use.
26
+ # Must implement debug(String), info(String), warn(String), error(String), & level=
27
+ # @option options [Symbol] :log_level (:info) Log level. Logger must define a constant with this name. ie Logger::INFO
28
+ # @option options [Boolean] :ssl_enabled (true) Use ssl for requests?
29
+ def initialize(options = {})
30
+ options = Hash[options.map { |k, v| [k.to_sym, v] }] # Convert string hash keys to symbols
31
+ @logger = options[:logger] || Logger.new(STDOUT)
32
+ [:debug, :info, :warn, :error, :level=].each { |m| raise "Logger must respond to #{m} method " unless @logger.respond_to?(m) }
33
+ @log_level = options[:log_level] || :info
34
+ @logger.level = @logger.class.const_get(@log_level.upcase) rescue @log_level
35
+ @host = options[:host]
36
+ raise 'Must set the host option' unless @host
37
+ @host = 'https://' + @host unless @host.start_with?('http://', 'https://')
38
+ @ssl_enabled = options[:ssl_enabled].nil? ? true : options[:ssl_enabled]
39
+ raise 'ssl_enabled option must be either true or false' unless [true, false].include?(@ssl_enabled)
40
+ @logger.warn 'User option not set. Using default (Administrator)' unless options[:user]
41
+ @user = options[:user] || 'Administrator'
42
+ @password = options[:password]
43
+ raise 'Must set the password option' unless @password
44
+ end
45
+
46
+ include Rest
47
+
48
+ # Include helper modules:
49
+ include ManagerNetworkProtocolHelper
50
+ include DateTimeHelper
51
+ include ComputerDetailsHelper
52
+ include SNMPServiceHelper
53
+ include PowerHelper
54
+ include AccountServiceHelper
55
+ include LogEntryHelper
56
+ include SecureBootHelper
57
+ include BiosHelper
58
+ include BootSettingsHelper
59
+ include FirmwareUpdateHelper
60
+ include VirtualMediaHelper
61
+ include ComputerSystemHelper
62
+ include ChassisHelper
63
+ include ServiceRootHelper
64
+ end
65
+ end
@@ -0,0 +1,70 @@
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 Account Service actions
12
+ module AccountServiceHelper
13
+ # Get the HREF for a user with a specific username
14
+ # @param [String, Symbol] uri
15
+ # @param [String, Symbol] username
16
+ # @raise [RuntimeError] if the request failed
17
+ # @return [String] userhref
18
+ def userhref(uri, username)
19
+ response = rest_get(uri)
20
+ items = response_handler(response)['Items']
21
+ items.each do |it|
22
+ return it['links']['self']['href'] if it['UserName'] == username
23
+ end
24
+ end
25
+
26
+ # Get the users
27
+ # @raise [RuntimeError] if the request failed
28
+ # @return [String[]] users
29
+ def get_users
30
+ response = rest_get('/redfish/v1/AccountService/Accounts/')
31
+ response_handler(response)['Items'].collect { |user| user['UserName'] }
32
+ end
33
+
34
+ # Create a user
35
+ # @param [String, Symbol] username
36
+ # @param [String, Symbol] password
37
+ # @raise [RuntimeError] if the request failed
38
+ # @return true
39
+ def create_user(username, password)
40
+ new_action = { 'UserName' => username, 'Password' => password, 'Oem' => { 'Hp' => { 'LoginName' => username } } }
41
+ response = rest_post('/redfish/v1/AccountService/Accounts/', body: new_action)
42
+ response_handler(response)
43
+ true
44
+ end
45
+
46
+ # Change the password for a user
47
+ # @param [String, Symbol] username
48
+ # @param [String, Symbol] password
49
+ # @raise [RuntimeError] if the request failed
50
+ # @return true
51
+ def change_password(username, password)
52
+ new_action = { 'Password' => password }
53
+ userhref = userhref('/redfish/v1/AccountService/Accounts/', username)
54
+ response = rest_patch(userhref, body: new_action)
55
+ response_handler(response)
56
+ true
57
+ end
58
+
59
+ # Delete a specific user
60
+ # @param [String, Symbol] username
61
+ # @raise [RuntimeError] if the request failed
62
+ # @return true
63
+ def delete_user(username)
64
+ userhref = userhref('/redfish/v1/AccountService/Accounts/', username)
65
+ response = rest_delete(userhref)
66
+ response_handler(response)
67
+ true
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,146 @@
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 Bios actions
12
+ module BiosHelper
13
+ # Get the bios base config
14
+ # @raise [RuntimeError] if the request failed
15
+ # @return [Fixnum] bios_baseconfig
16
+ def get_bios_baseconfig
17
+ response = rest_get('/redfish/v1/Systems/1/bios/Settings/')
18
+ response_handler(response)['BaseConfig']
19
+ end
20
+
21
+ # Revert the BIOS
22
+ # @raise [RuntimeError] if the request failed
23
+ # @return true
24
+ def revert_bios
25
+ new_action = { 'BaseConfig' => 'default' }
26
+ response = rest_patch('/redfish/v1/systems/1/bios/Settings/', body: new_action)
27
+ response_handler(response)
28
+ true
29
+ end
30
+
31
+ # Get the UEFI shell start up
32
+ # @raise [RuntimeError] if the request failed
33
+ # @return [String] uefi_shell_startup
34
+ def get_uefi_shell_startup
35
+ response = rest_get('/redfish/v1/Systems/1/bios/Settings/')
36
+ bios = response_handler(response)
37
+ {
38
+ 'UefiShellStartup' => bios['UefiShellStartup'],
39
+ 'UefiShellStartupLocation' => bios['UefiShellStartupLocation'],
40
+ 'UefiShellStartupUrl' => bios['UefiShellStartupUrl']
41
+ }
42
+ end
43
+
44
+ # Set the UEFI shell start up
45
+ # @param [String, Symbol] uefi_shell_startup
46
+ # @param [String, Symbol] uefi_shell_startup_location
47
+ # @param [String, Symbol] uefi_shell_startup_url
48
+ # @raise [RuntimeError] if the request failed
49
+ # @return true
50
+ def set_uefi_shell_startup(uefi_shell_startup, uefi_shell_startup_location, uefi_shell_startup_url)
51
+ new_action = {
52
+ 'UefiShellStartup' => uefi_shell_startup,
53
+ 'UefiShellStartupLocation' => uefi_shell_startup_location,
54
+ 'UefiShellStartupUrl' => uefi_shell_startup_url
55
+ }
56
+ response = rest_patch('/redfish/v1/Systems/1/bios/Settings/', body: new_action)
57
+ response_handler(response)
58
+ true
59
+ end
60
+
61
+ # Get the BIOS DHCP
62
+ # @raise [RuntimeError] if the request failed
63
+ # @return [String] bios_dhcp
64
+ def get_bios_dhcp
65
+ response = rest_get('/redfish/v1/Systems/1/bios/Settings/')
66
+ bios = response_handler(response)
67
+ {
68
+ 'Dhcpv4' => bios['Dhcpv4'],
69
+ 'Ipv4Address' => bios['Ipv4Address'],
70
+ 'Ipv4Gateway' => bios['Ipv4Gateway'],
71
+ 'Ipv4PrimaryDNS' => bios['Ipv4PrimaryDNS'],
72
+ 'Ipv4SecondaryDNS' => bios['Ipv4SecondaryDNS'],
73
+ 'Ipv4SubnetMask' => bios['Ipv4SubnetMask']
74
+ }
75
+ end
76
+
77
+ # Set the BIOS DHCP
78
+ # @param [String, Symbol] dhcpv4
79
+ # @param [String, Symbol] ipv4_address
80
+ # @param [String, Symbol] ipv4_gateway
81
+ # @param [String, Symbol] ipv4_primary_dns
82
+ # @param [String, Symbol] ipv4_secondary_dns
83
+ # @param [String, Symbol] ipv4_subnet_mask
84
+ # @raise [RuntimeError] if the request failed
85
+ # @return true
86
+ def set_bios_dhcp(dhcpv4, ipv4_address = '', ipv4_gateway = '', ipv4_primary_dns = '', ipv4_secondary_dns = '', ipv4_subnet_mask = '')
87
+ new_action = {
88
+ 'Dhcpv4' => dhcpv4,
89
+ 'Ipv4Address' => ipv4_address,
90
+ 'Ipv4Gateway' => ipv4_gateway,
91
+ 'Ipv4PrimaryDNS' => ipv4_primary_dns,
92
+ 'Ipv4SecondaryDNS' => ipv4_secondary_dns,
93
+ 'Ipv4SubnetMask' => ipv4_subnet_mask
94
+ }
95
+ response = rest_patch('/redfish/v1/Systems/1/bios/Settings/', body: new_action)
96
+ response_handler(response)
97
+ true
98
+ end
99
+
100
+ # Get the URL boot file
101
+ # @raise [RuntimeError] if the request failed
102
+ # @return [String] url_boot_file
103
+ def get_url_boot_file
104
+ response = rest_get('/redfish/v1/Systems/1/bios/Settings/')
105
+ response_handler(response)['UrlBootFile']
106
+ end
107
+
108
+ # Set the URL boot file
109
+ # @param [String, Symbol] url_boot_file
110
+ # @raise [RuntimeError] if the request failed
111
+ # @return true
112
+ def set_url_boot_file(url_boot_file)
113
+ new_action = { 'UrlBootFile' => url_boot_file }
114
+ response = rest_patch('/redfish/v1/Systems/1/bios/Settings/', body: new_action)
115
+ response_handler(response)
116
+ true
117
+ end
118
+
119
+ # Get the BIOS service
120
+ # @raise [RuntimeError] if the request failed
121
+ # @return [String] bios_service
122
+ def get_bios_service
123
+ response = rest_get('/redfish/v1/Systems/1/bios/Settings/')
124
+ bios = response_handler(response)
125
+ {
126
+ 'ServiceName' => bios['ServiceName'],
127
+ 'ServiceEmail' => bios['ServiceEmail']
128
+ }
129
+ end
130
+
131
+ # Set the BIOS service
132
+ # @param [String, Symbol] name
133
+ # @param [String, Symbol] email
134
+ # @raise [RuntimeError] if the request failed
135
+ # @return true
136
+ def set_bios_service(name, email)
137
+ new_action = {
138
+ 'ServiceName' => name,
139
+ 'ServiceEmail' => email
140
+ }
141
+ response = rest_patch('/redfish/v1/Systems/1/bios/Settings/', body: new_action)
142
+ response_handler(response)
143
+ true
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,74 @@
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 Boot Settings actions
12
+ module BootSettingsHelper
13
+ # Get the boot base config
14
+ # @raise [RuntimeError] if the request failed
15
+ # @return [Fixnum] boot_baseconfig
16
+ def get_boot_baseconfig
17
+ response = rest_get('/redfish/v1/Systems/1/bios/Boot/Settings/')
18
+ response_handler(response)['BaseConfig']
19
+ end
20
+
21
+ # Revert the boot
22
+ # @raise [RuntimeError] if the request failed
23
+ # @return true
24
+ def revert_boot
25
+ new_action = { 'BaseConfig' => 'default' }
26
+ response = rest_patch('/redfish/v1/systems/1/bios/Boot/Settings/', body: new_action)
27
+ response_handler(response)
28
+ true
29
+ end
30
+
31
+ # Get the boot order
32
+ # @raise [RuntimeError] if the request failed
33
+ # @return [Fixnum] boot_order
34
+ def get_boot_order
35
+ response = rest_get('/redfish/v1/systems/1/bios/Boot/Settings/')
36
+ response_handler(response)['PersistentBootConfigOrder']
37
+ end
38
+
39
+ # Set the boot order
40
+ # @param [Fixnum] boot_order
41
+ # @raise [RuntimeError] if the request failed
42
+ # @return true
43
+ def set_boot_order(boot_order)
44
+ new_action = { 'PersistentBootConfigOrder' => boot_order }
45
+ response = rest_patch('/redfish/v1/systems/1/bios/Boot/Settings/', body: new_action)
46
+ response_handler(response)
47
+ true
48
+ end
49
+
50
+ # Get the temporary boot order
51
+ # @raise [RuntimeError] if the request failed
52
+ # @return [Fixnum] temporary_boot_order
53
+ def get_temporary_boot_order
54
+ response = rest_get('/redfish/v1/Systems/1/')
55
+ response_handler(response)['Boot']['BootSourceOverrideTarget']
56
+ end
57
+
58
+ # Set the temporary boot order
59
+ # @param [Fixnum] boot_target
60
+ # @raise [RuntimeError] if the request failed
61
+ # @return true
62
+ def set_temporary_boot_order(boot_target)
63
+ response = rest_get('/redfish/v1/Systems/1/')
64
+ boottargets = response_handler(response)['Boot']['BootSourceOverrideSupported']
65
+ unless boottargets.include? boot_target
66
+ raise "BootSourceOverrideTarget value - #{boot_target} is not supported. Valid values are: #{boottargets}"
67
+ end
68
+ new_action = { 'Boot' => { 'BootSourceOverrideTarget' => boot_target } }
69
+ response = rest_patch('/redfish/v1/Systems/1/', body: new_action)
70
+ response_handler(response)
71
+ true
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,67 @@
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 Chassis actions
12
+ module ChassisHelper
13
+ # Get the power metrics
14
+ # @raise [RuntimeError] if the request failed
15
+ # @return [Hash] power_metrics
16
+ def get_power_metrics
17
+ chassis = rest_get('/redfish/v1/Chassis/')
18
+ chassis_uri = response_handler(chassis)['links']['Member'][0]['href']
19
+ power_metrics_uri = response_handler(rest_get(chassis_uri))['links']['PowerMetrics']['href']
20
+ response = rest_get(power_metrics_uri)
21
+ metrics = response_handler(response)
22
+ power_supplies = []
23
+ metrics['PowerSupplies'].each do |ps|
24
+ power_supply = {
25
+ 'LineInputVoltage' => ps['LineInputVoltage'],
26
+ 'LineInputVoltageType' => ps['LineInputVoltageType'],
27
+ 'PowerCapacityWatts' => ps['PowerCapacityWatts'],
28
+ 'PowerSupplyType' => ps['PowerSupplyType'],
29
+ 'Health' => ps['Status']['Health'],
30
+ 'State' => ps['Status']['State']
31
+ }
32
+ power_supplies.push(power_supply)
33
+ end
34
+ {
35
+ @host => {
36
+ 'PowerCapacityWatts' => metrics['PowerCapacityWatts'],
37
+ 'PowerConsumedWatts' => metrics['PowerConsumedWatts'],
38
+ 'PowerSupplies' => power_supplies
39
+ }
40
+ }
41
+ end
42
+
43
+ # Get the thermal metrics
44
+ # @raise [RuntimeError] if the request failed
45
+ # @return [Hash] thermal_metrics
46
+ def get_thermal_metrics
47
+ chassis = rest_get('/redfish/v1/Chassis/')
48
+ chassis_uri = response_handler(chassis)['links']['Member'][0]['href']
49
+ thermal_metrics_uri = response_handler(rest_get(chassis_uri))['links']['ThermalMetrics']['href']
50
+ response = rest_get(thermal_metrics_uri)
51
+ temperatures = response_handler(response)['Temperatures']
52
+ temp_details = []
53
+ temperatures.each do |temp|
54
+ temp_detail = {
55
+ 'PhysicalContext' => temp['PhysicalContext'],
56
+ 'Name' => temp['Name'],
57
+ 'CurrentReading' => temp['ReadingCelsius'],
58
+ 'CriticalThreshold' => temp['LowerThresholdCritical'],
59
+ 'Health' => temp['Status']['Health'],
60
+ 'State' => temp['Status']['State']
61
+ }
62
+ temp_details.push(temp_detail)
63
+ end
64
+ { @host => temp_details }
65
+ end
66
+ end
67
+ end