Class: OneviewSDK::API200::ServerHardware
- Defined in:
- lib/oneview-sdk/resource/api200/server_hardware.rb
Overview
Server hardware resource implementation
Direct Known Subclasses
Constant Summary collapse
- BASE_URI =
'/rest/server-hardware'.freeze
- UNIQUE_IDENTIFIERS =
%w[name uri serialNumber virtualSerialNumber serverProfileUri].freeze
Constants inherited from Resource
Resource::DEFAULT_REQUEST_HEADER
Instance Attribute Summary
Attributes inherited from Resource
#api_version, #client, #data, #logger
Instance Method Summary collapse
-
#add ⇒ OneviewSDK::ServerHardware
Adds the resource on OneView using the current data.
-
#create ⇒ Object
Method is not available.
-
#create! ⇒ Object
Method is not available.
-
#delete ⇒ Object
Method is not available.
-
#environmental_configuration ⇒ Object
Gets the settings that describe the environmental configuration.
-
#exists? ⇒ Boolean
Check if a resource exists.
-
#get_bios ⇒ Hash
Gets a list of BIOS/UEFI values on the physical server.
-
#get_ilo_sso_url ⇒ Hash
Gets a url to the iLO web interface.
-
#get_java_remote_sso_url ⇒ Hash
Gets a Single Sign-On session for the Java Applet console.
-
#get_remote_console_url ⇒ Hash
Gets a url to the iLO web interface.
-
#initialize(client, params = {}, api_ver = nil) ⇒ ServerHardware
constructor
Create a resource object, associate it with a client, and set its properties.
-
#power_off(force = false) ⇒ Boolean
Power off the server hardware.
-
#power_on(force = false) ⇒ Boolean
Power on the server hardware.
-
#remove ⇒ true
Remove resource from OneView.
-
#retrieve! ⇒ Boolean
Retrieve resource details based on this resource’s name or URI.
-
#set_power_state(state, force) ⇒ Object
Set power state.
-
#set_refresh_state(state, options = {}) ⇒ Object
Refreshes the enclosure along with all of its components.
-
#update ⇒ Object
Method is not available.
-
#update_ilo_firmware ⇒ Object
Updates the iLO firmware on a physical server to a minimum iLO firmware required by OneView.
-
#utilization(queryParameters = {}) ⇒ Object
Retrieves historical utilization.
Methods inherited from Resource
#==, #[], #[]=, build_query, #deep_merge!, #each, #eql?, find_by, find_with_pagination, from_file, get_all, get_all_with_query, #like?, #refresh, schema, #schema, #set, #set_all, #to_file
Constructor Details
#initialize(client, params = {}, api_ver = nil) ⇒ ServerHardware
Create a resource object, associate it with a client, and set its properties.
29 30 31 32 33 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 29 def initialize(client, params = {}, api_ver = nil) super # Default values @data['type'] ||= 'server-hardware-4' end |
Instance Method Details
#add ⇒ OneviewSDK::ServerHardware
Adds the resource on OneView using the current data
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 86 def add ensure_client required_attributes = %w[hostname username password licensingIntent] required_attributes.each { |k| raise IncompleteResource, "Missing required attribute: '#{k}'" unless @data.key?(k) } optional_attrs = %w[configurationState force restore] temp_data = @data.select { |k, _v| required_attributes.include?(k) || optional_attrs.include?(k) } response = @client.rest_post(self.class::BASE_URI, { 'body' => temp_data }, @api_version) body = @client.response_handler(response) set_all(body) %w[username password hostname].each { |k| @data.delete(k) } # These are no longer needed self end |
#create ⇒ Object
Method is not available
73 74 75 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 73 def create(*) unavailable_method end |
#create! ⇒ Object
Method is not available
37 38 39 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 37 def create!(*) unavailable_method end |
#delete ⇒ Object
Method is not available
79 80 81 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 79 def delete(*) unavailable_method end |
#environmental_configuration ⇒ Object
Gets the settings that describe the environmental configuration
172 173 174 175 176 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 172 def environmental_configuration ensure_client && ensure_uri response = @client.rest_get(@data['uri'] + '/environmentalConfiguration', {}, @api_version) @client.response_handler(response) end |
#exists? ⇒ Boolean
one of the UNIQUE_IDENTIFIERS must be specified in the resource
Check if a resource exists
62 63 64 65 66 67 68 69 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 62 def exists? hostname = @data['hostname'] || @data['mpHostInfo']['mpHostName'] rescue nil return true if hostname && self.class.find_by(@client, 'mpHostInfo' => { 'mpHostName' => hostname }).size == 1 super rescue IncompleteResource => e raise e unless hostname false end |
#get_bios ⇒ Hash
Gets a list of BIOS/UEFI values on the physical server
122 123 124 125 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 122 def get_bios response = @client.rest_get(@data['uri'] + '/bios') @client.response_handler(response) end |
#get_ilo_sso_url ⇒ Hash
Gets a url to the iLO web interface
129 130 131 132 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 129 def get_ilo_sso_url response = @client.rest_get(@data['uri'] + '/iloSsoUrl') @client.response_handler(response) end |
#get_java_remote_sso_url ⇒ Hash
Gets a Single Sign-On session for the Java Applet console
136 137 138 139 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 136 def get_java_remote_sso_url response = @client.rest_get(@data['uri'] + '/javaRemoteConsoleUrl') @client.response_handler(response) end |
#get_remote_console_url ⇒ Hash
Gets a url to the iLO web interface
143 144 145 146 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 143 def get_remote_console_url response = @client.rest_get(@data['uri'] + '/remoteConsoleUrl') @client.response_handler(response) end |
#power_off(force = false) ⇒ Boolean
Power off the server hardware
116 117 118 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 116 def power_off(force = false) set_power_state('off', force) end |
#power_on(force = false) ⇒ Boolean
Power on the server hardware
109 110 111 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 109 def power_on(force = false) set_power_state('on', force) end |
#remove ⇒ true
Remove resource from OneView
23 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 23 alias remove delete |
#retrieve! ⇒ Boolean
one of the UNIQUE_IDENTIFIERS must be specified in the resource
Retrieve resource details based on this resource’s name or URI.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 44 def retrieve! hostname = @data['hostname'] || @data['mpHostInfo']['mpHostName'] rescue nil if hostname results = self.class.find_by(@client, 'mpHostInfo' => { 'mpHostName' => hostname }) if results.size == 1 set_all(results[0].data) return true end end super rescue IncompleteResource => e raise e unless hostname false end |
#set_power_state(state, force) ⇒ Object
Set power state. Takes into consideration the current state and does the right thing
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 208 def set_power_state(state, force) refresh return true if @data['powerState'].downcase == state @logger.debug "Powering #{state} server hardware '#{@data['name']}'. Current state: '#{@data['powerState']}'" action = 'PressAndHold' if force action ||= case @data['powerState'].downcase when 'poweringon', 'poweringoff' # Wait sleep 5 return set_power_state(state, force) when 'resetting' if state == 'on' # Wait sleep 5 return set_power_state(state, force) end 'PressAndHold' when 'unknown' then state == 'on' ? 'ColdBoot' : 'PressAndHold' else 'MomentaryPress' end = { 'body' => { powerState: state.capitalize, powerControl: action } } response = @client.rest_put("#{@data['uri']}/powerState", ) body = @client.response_handler(response) set_all(body) true end |
#set_refresh_state(state, options = {}) ⇒ Object
Refreshes the enclosure along with all of its components
151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 151 def set_refresh_state(state, = {}) ensure_client && ensure_uri s = state.to_s rescue state requestBody = { 'body' => { refreshState: s } } requestBody['body'].merge() response = @client.rest_put(@data['uri'] + '/refreshState', requestBody, @api_version) new_data = @client.response_handler(response) set_all(new_data) end |
#update ⇒ Object
Method is not available
102 103 104 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 102 def update(*) unavailable_method end |
#update_ilo_firmware ⇒ Object
Updates the iLO firmware on a physical server to a minimum iLO firmware required by OneView
166 167 168 169 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 166 def update_ilo_firmware response = @client.rest_put(@data['uri'] + '/mpFirmwareVersion') @client.response_handler(response) end |
#utilization(queryParameters = {}) ⇒ Object
Retrieves historical utilization
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 183 def utilization(queryParameters = {}) ensure_client && ensure_uri uri = "#{@data['uri']}/utilization?" queryParameters[:endDate] = convert_time(queryParameters[:endDate]) queryParameters[:startDate] = convert_time(queryParameters[:startDate]) queryParameters.each do |key, value| next if value.nil? uri += case key.to_sym when :fields "fields=#{value.join(',')}" when :startDate, :endDate "filter=#{key}=#{value}" else "#{key}=#{value}" end uri += '&' end uri.chop! # Get rid of trailing '&' or '?' response = @client.rest_get(uri, {}, @api_version) @client.response_handler(response) end |