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,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 Secure Boot actions
12
+ module SecureBootHelper
13
+ # Get the UEFI secure boot
14
+ # @raise [RuntimeError] if the request failed
15
+ # @return [TrueClass, FalseClass] uefi_secure_boot
16
+ def get_uefi_secure_boot
17
+ response = rest_get('/redfish/v1/Systems/1/SecureBoot/')
18
+ response_handler(response)['SecureBootEnable']
19
+ end
20
+
21
+ # Set the UEFI secure boot true or false
22
+ # @param [Boolean] secure_boot_enable
23
+ # @raise [RuntimeError] if the request failed
24
+ # @return true
25
+ def set_uefi_secure_boot(secure_boot_enable)
26
+ new_action = { 'SecureBootEnable' => secure_boot_enable }
27
+ response = rest_patch('/redfish/v1/Systems/1/SecureBoot/', body: new_action)
28
+ response_handler(response)
29
+ true
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,48 @@
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 Service Root Actions
12
+ module ServiceRootHelper
13
+ # Get the schema information with given prefix
14
+ # @param [String, Symbol] schema_prefix
15
+ # @raise [RuntimeError] if the request failed
16
+ # @return [String] schema
17
+ def get_schema(schema_prefix)
18
+ response = rest_get('/redfish/v1/Schemas/')
19
+ schemas = response_handler(response)['Items']
20
+ schema = schemas.select { |s| s['Schema'].start_with?(schema_prefix) }
21
+ raise "NO schema found with this schema prefix : #{schema_prefix}" if schema.empty?
22
+ info = []
23
+ schema.each do |sc|
24
+ response = rest_get(sc['Location'][0]['Uri']['extref'])
25
+ schema_store = response_handler(response)
26
+ info.push(schema_store)
27
+ end
28
+ info
29
+ end
30
+
31
+ # Get the Registry with given registry_prefix
32
+ # @param [String, Symbol] registry_prefix
33
+ # @raise [RuntimeError] if the request failed
34
+ # @return [String] registry
35
+ def get_registry(registry_prefix)
36
+ response = rest_get('/redfish/v1/Registries/')
37
+ registries = response_handler(response)['Items']
38
+ registry = registries.select { |reg| reg['Schema'].start_with?(registry_prefix) }
39
+ info = []
40
+ registry.each do |reg|
41
+ response = rest_get(reg['Location'][0]['Uri']['extref'])
42
+ registry_store = response_handler(response)
43
+ info.push(registry_store)
44
+ end
45
+ info
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,41 @@
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 SNMP Service actions
12
+ module SNMPServiceHelper
13
+ # Get the SNMP Mode
14
+ # @raise [RuntimeError] if the request failed
15
+ # @return [String] snmp_mode
16
+ def get_snmp_mode
17
+ response = rest_get('/redfish/v1/Managers/1/SnmpService/')
18
+ response_handler(response)['Mode']
19
+ end
20
+
21
+ # Get the SNMP Alerts Enabled value
22
+ # @raise [RuntimeError] if the request failed
23
+ # @return [String] snmp_alerts_enabled
24
+ def get_snmp_alerts_enabled
25
+ response = rest_get('/redfish/v1/Managers/1/SnmpService/')
26
+ response_handler(response)['AlertsEnabled']
27
+ end
28
+
29
+ # Set the SNMP Mode and Alerts Enabled value
30
+ # @param [String, Symbol] snmp_mode
31
+ # @param [Boolean] snmp_alerts
32
+ # @raise [RuntimeError] if the request failed
33
+ # @return true
34
+ def set_snmp(snmp_mode, snmp_alerts)
35
+ new_action = { 'Mode' => snmp_mode, 'AlertsEnabled' => snmp_alerts }
36
+ response = rest_patch('/redfish/v1/Managers/1/SnmpService/', body: new_action)
37
+ response_handler(response)
38
+ true
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,66 @@
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 Virtual Media actions
12
+ module VirtualMediaHelper
13
+ # Get the Virtual Media Information
14
+ # @raise [RuntimeError] if the request failed
15
+ # @return [String] virtual_media
16
+ def get_virtual_media
17
+ response = rest_get('/redfish/v1/Managers/1/VirtualMedia/')
18
+ media = {}
19
+ response_handler(response)['links']['Member'].each do |vm|
20
+ response = rest_get(vm['href'])
21
+ virtual_media = response_handler(response)
22
+ media[virtual_media['Id']] = {
23
+ 'Image' => virtual_media['Image'],
24
+ 'MediaTypes' => virtual_media['MediaTypes']
25
+ }
26
+ end
27
+ media
28
+ end
29
+
30
+ # Return whether Virtual Media is inserted
31
+ # @raise [RuntimeError] if the request failed
32
+ # @return [TrueClass, FalseClass] virtual_media_inserted
33
+ def virtual_media_inserted?(id)
34
+ response = rest_get("/redfish/v1/Managers/1/VirtualMedia/#{id}/")
35
+ response_handler(response)['Inserted']
36
+ end
37
+
38
+ # Insert Virtual Media
39
+ # @param [String, Symbol] id
40
+ # @param [String, Symbol] image
41
+ # @return true
42
+ def insert_virtual_media(id, image)
43
+ new_action = {
44
+ 'Action' => 'InsertVirtualMedia',
45
+ 'Target' => '/Oem/Hp',
46
+ 'Image' => image
47
+ }
48
+ response = rest_post("/redfish/v1/Managers/1/VirtualMedia/#{id}/", body: new_action)
49
+ response_handler(response)
50
+ true
51
+ end
52
+
53
+ # Eject Virtual Media
54
+ # @param [String, Symbol] id
55
+ # @return true
56
+ def eject_virtual_media(id)
57
+ new_action = {
58
+ 'Action' => 'EjectVirtualMedia',
59
+ 'Target' => '/Oem/Hp'
60
+ }
61
+ response = rest_post("/redfish/v1/Managers/1/VirtualMedia/#{id}/", body: new_action)
62
+ response_handler(response)
63
+ true
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,165 @@
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 'uri'
11
+ require 'net/http'
12
+ require 'openssl'
13
+ require 'json'
14
+
15
+ module ILO_SDK
16
+ # Contains all the methods for making API REST calls
17
+ module Rest
18
+ # Make a restful API request to the iLO
19
+ # @param [Symbol] type the rest method/type Options are :get, :post, :put, :patch, and :delete
20
+ # @param [String] path the path for the request. Usually starts with "/rest/"
21
+ # @param [Hash] options the options for the request
22
+ # @option options [String] :body Hash to be converted into json and set as the request body
23
+ # @option options [String] :Content-Type ('application/json') Set to nil or :none to have this option removed
24
+ # @return [NetHTTPResponse] The response object
25
+ def rest_api(type, path, options = {})
26
+ raise 'Must specify path' unless path
27
+ raise 'Must specify type' unless type
28
+ @logger.debug "Making :#{type} rest call to #{@host}#{path}"
29
+
30
+ uri = URI.parse(URI.escape("#{@host}#{path}"))
31
+ http = Net::HTTP.new(uri.host, uri.port)
32
+ http.use_ssl = true if uri.scheme == 'https'
33
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @ssl_enabled
34
+
35
+ request = build_request(type, uri, options)
36
+ response = http.request(request)
37
+ @logger.debug " Response: Code=#{response.code}. Headers=#{response.to_hash}\n Body=#{response.body}"
38
+ response
39
+ rescue OpenSSL::SSL::SSLError => e
40
+ msg = 'SSL verification failed for request. Please either:'
41
+ msg += "\n 1. Install the certificate into your cert store"
42
+ msg += ". Using cert store: #{ENV['SSL_CERT_FILE']}" if ENV['SSL_CERT_FILE']
43
+ msg += "\n 2. Set the :ssl_enabled option to false for your ilo client"
44
+ @logger.error msg
45
+ raise e
46
+ end
47
+
48
+ # Make a restful GET request
49
+ # Parameters & return value align with those of the {ILO_SDK::Rest::rest_api} method above
50
+ def rest_get(path)
51
+ rest_api(:get, path, {})
52
+ end
53
+
54
+ # Make a restful POST request
55
+ # Parameters & return value align with those of the {ILO_SDK::Rest::rest_api} method above
56
+ def rest_post(path, options = {})
57
+ rest_api(:post, path, options)
58
+ end
59
+
60
+ # Make a restful PUT request
61
+ # Parameters & return value align with those of the {ILO_SDK::Rest::rest_api} method above
62
+ def rest_put(path, options = {})
63
+ rest_api(:put, path, options)
64
+ end
65
+
66
+ # Make a restful PATCH request
67
+ # Parameters & return value align with those of the {ILO_SDK::Rest::rest_api} method above
68
+ def rest_patch(path, options = {})
69
+ rest_api(:patch, path, options)
70
+ end
71
+
72
+ # Make a restful DELETE request
73
+ # Parameters & return value align with those of the {ILO_SDK::Rest::rest_api} method above
74
+ def rest_delete(path, options = {})
75
+ rest_api(:delete, path, options)
76
+ end
77
+
78
+ RESPONSE_CODE_OK = 200
79
+ RESPONSE_CODE_CREATED = 201
80
+ RESPONSE_CODE_ACCEPTED = 202
81
+ RESPONSE_CODE_NO_CONTENT = 204
82
+ RESPONSE_CODE_BAD_REQUEST = 400
83
+ RESPONSE_CODE_UNAUTHORIZED = 401
84
+ RESPONSE_CODE_NOT_FOUND = 404
85
+
86
+ # Handle the response for rest call.
87
+ # If an asynchronous task was started, this waits for it to complete.
88
+ # @param [HTTPResponse] HTTP response
89
+ # @raise [RuntimeError] if the request failed
90
+ # @raise [RuntimeError] if a task was returned that did not complete successfully
91
+ # @return [Hash] The parsed JSON body
92
+ def response_handler(response)
93
+ case response.code.to_i
94
+ when RESPONSE_CODE_OK # Synchronous read/query
95
+ begin
96
+ return JSON.parse(response.body)
97
+ rescue JSON::ParserError => e
98
+ @logger.warn "Failed to parse JSON response. #{e}"
99
+ return response.body
100
+ end
101
+ when RESPONSE_CODE_CREATED # Synchronous add
102
+ return JSON.parse(response.body)
103
+ when RESPONSE_CODE_ACCEPTED # Asynchronous add, update or delete
104
+ return JSON.parse(response.body) # TODO: Remove when tested
105
+ # TODO: Make this actually wait for the task
106
+ # @logger.debug "Waiting for task: #{response.header['location']}"
107
+ # task = wait_for(response.header['location'])
108
+ # return true unless task['associatedResource'] && task['associatedResource']['resourceUri']
109
+ # resource_data = rest_get(task['associatedResource']['resourceUri'])
110
+ # return JSON.parse(resource_data.body)
111
+ when RESPONSE_CODE_NO_CONTENT # Synchronous delete
112
+ return {}
113
+ when RESPONSE_CODE_BAD_REQUEST
114
+ raise "400 BAD REQUEST #{response.body}"
115
+ when RESPONSE_CODE_UNAUTHORIZED
116
+ raise "401 UNAUTHORIZED #{response.body}"
117
+ when RESPONSE_CODE_NOT_FOUND
118
+ raise "404 NOT FOUND #{response.body}"
119
+ else
120
+ raise "#{response.code} #{response.body}"
121
+ end
122
+ end
123
+
124
+
125
+ private
126
+
127
+ def build_request(type, uri, options)
128
+ case type.downcase
129
+ when 'get', :get
130
+ request = Net::HTTP::Get.new(uri.request_uri)
131
+ when 'post', :post
132
+ request = Net::HTTP::Post.new(uri.request_uri)
133
+ when 'put', :put
134
+ request = Net::HTTP::Put.new(uri.request_uri)
135
+ when 'patch', :patch
136
+ request = Net::HTTP::Patch.new(uri.request_uri)
137
+ when 'delete', :delete
138
+ request = Net::HTTP::Delete.new(uri.request_uri)
139
+ else
140
+ raise "Invalid rest call: #{type}"
141
+ end
142
+ options['Content-Type'] ||= 'application/json'
143
+ options.delete('Content-Type') if [:none, 'none', nil].include?(options['Content-Type'])
144
+ auth = true
145
+ if [:none, 'none'].include?(options['auth'])
146
+ options.delete('auth')
147
+ auth = false
148
+ end
149
+ options.each do |key, val|
150
+ if key.to_s.downcase == 'body'
151
+ request.body = val.to_json rescue val
152
+ else
153
+ request[key] = val
154
+ end
155
+ end
156
+
157
+ filtered_options = options.to_s
158
+ filtered_options.gsub!(@password, 'filtered') if @password
159
+ @logger.debug " Options: #{filtered_options}"
160
+
161
+ request.basic_auth(@user, @password) if auth
162
+ request
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,13 @@
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
+ # Gem version defined here
11
+ module ILO_SDK
12
+ VERSION = '1.0.0'.freeze
13
+ end
metadata ADDED
@@ -0,0 +1,162 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ilo-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Anirudh Gupta
8
+ - Bik Bajwa
9
+ - Jared Smartt
10
+ - Vivek Bhatia
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2016-06-08 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: pry
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ - !ruby/object:Gem::Dependency
45
+ name: rspec
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ - !ruby/object:Gem::Dependency
59
+ name: rake
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ - !ruby/object:Gem::Dependency
73
+ name: simplecov
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ - !ruby/object:Gem::Dependency
87
+ name: rubocop
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '='
91
+ - !ruby/object:Gem::Version
92
+ version: 0.39.0
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '='
98
+ - !ruby/object:Gem::Version
99
+ version: 0.39.0
100
+ description: Gem to interact with iLO API
101
+ email:
102
+ - anirudhg@hpe.com
103
+ - bik.bajwa@hpe.com
104
+ - jared.smartt@hpe.com
105
+ - vivek.bhatia@hpe.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - ".gitignore"
111
+ - ".rubocop.yml"
112
+ - ".travis.yml"
113
+ - CHANGELOG.md
114
+ - Gemfile
115
+ - LICENSE
116
+ - README.md
117
+ - Rakefile
118
+ - ilo-sdk.gemspec
119
+ - lib/ilo-sdk.rb
120
+ - lib/ilo-sdk/client.rb
121
+ - lib/ilo-sdk/helpers/account_service_helper.rb
122
+ - lib/ilo-sdk/helpers/bios_helper.rb
123
+ - lib/ilo-sdk/helpers/boot_settings_helper.rb
124
+ - lib/ilo-sdk/helpers/chassis_helper.rb
125
+ - lib/ilo-sdk/helpers/computer_details_helper.rb
126
+ - lib/ilo-sdk/helpers/computer_system_helper.rb
127
+ - lib/ilo-sdk/helpers/date_time_helper.rb
128
+ - lib/ilo-sdk/helpers/firmware_update.rb
129
+ - lib/ilo-sdk/helpers/log_entry_helper.rb
130
+ - lib/ilo-sdk/helpers/manager_network_protocol_helper.rb
131
+ - lib/ilo-sdk/helpers/power_helper.rb
132
+ - lib/ilo-sdk/helpers/secure_boot_helper.rb
133
+ - lib/ilo-sdk/helpers/service_root_helper.rb
134
+ - lib/ilo-sdk/helpers/snmp_service_helper.rb
135
+ - lib/ilo-sdk/helpers/virtual_media_helper.rb
136
+ - lib/ilo-sdk/rest.rb
137
+ - lib/ilo-sdk/version.rb
138
+ homepage: https://github.com/HewlettPackard/ilo-sdk-ruby
139
+ licenses:
140
+ - Apache-2.0
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.5.2
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Gem to interact with iLO API
162
+ test_files: []