Class: OneviewSDK::API200::ServerHardware

Inherits:
Resource show all
Defined in:
lib/oneview-sdk/resource/api200/server_hardware.rb

Overview

Server hardware resource implementation

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

Methods inherited from Resource

#==, #[], #[]=, build_query, #create!, #deep_merge!, #each, #eql?, find_by, find_with_pagination, from_file, get_all, #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

#addOneviewSDK::ServerHardware

Adds the resource on OneView using the current data

Raises:



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 80

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

#createObject

Method is not available

Raises:



67
68
69
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 67

def create(*)
  unavailable_method
end

#deleteObject

Method is not available

Raises:



73
74
75
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 73

def delete(*)
  unavailable_method
end

#environmental_configurationObject

Gets the settings that describe the environmental configuration



166
167
168
169
170
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 166

def environmental_configuration
  ensure_client && ensure_uri
  response = @client.rest_get(@data['uri'] + '/environmentalConfiguration', {}, @api_version)
  @client.response_handler(response)
end

#exists?Boolean

Note:

one of the UNIQUE_IDENTIFIERS must be specified in the resource

Check if a resource exists



56
57
58
59
60
61
62
63
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 56

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_biosHash

Gets a list of BIOS/UEFI values on the physical server



116
117
118
119
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 116

def get_bios
  response = @client.rest_get(@data['uri'] + '/bios')
  @client.response_handler(response)
end

#get_ilo_sso_urlHash

Gets a url to the iLO web interface



123
124
125
126
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 123

def get_ilo_sso_url
  response = @client.rest_get(@data['uri'] + '/iloSsoUrl')
  @client.response_handler(response)
end

#get_java_remote_sso_urlHash

Gets a Single Sign-On session for the Java Applet console



130
131
132
133
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 130

def get_java_remote_sso_url
  response = @client.rest_get(@data['uri'] + '/javaRemoteConsoleUrl')
  @client.response_handler(response)
end

#get_remote_console_urlHash

Gets a url to the iLO web interface



137
138
139
140
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 137

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



110
111
112
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 110

def power_off(force = false)
  set_power_state('off', force)
end

#power_on(force = false) ⇒ Boolean

Power on the server hardware



103
104
105
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 103

def power_on(force = false)
  set_power_state('on', force)
end

#removetrue

Remove resource from OneView



23
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 23

alias remove delete

#retrieve!Boolean

Note:

one of the UNIQUE_IDENTIFIERS must be specified in the resource

Retrieve resource details based on this resource’s name or URI.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 38

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_refresh_state(state, options = {}) ⇒ Object

Refreshes the enclosure along with all of its components



145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 145

def set_refresh_state(state, options = {})
  ensure_client && ensure_uri
  s = state.to_s rescue state
  requestBody = {
    'body' => {
      refreshState: s
    }
  }
  requestBody['body'].merge(options)
  response = @client.rest_put(@data['uri'] + '/refreshState', requestBody, @api_version)
  new_data = @client.response_handler(response)
  set_all(new_data)
end

#updateObject

Method is not available

Raises:



96
97
98
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 96

def update(*)
  unavailable_method
end

#update_ilo_firmwareObject

Updates the iLO firmware on a physical server to a minimum iLO firmware required by OneView



160
161
162
163
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 160

def update_ilo_firmware
  response = @client.rest_put(@data['uri'] + '/mpFirmwareVersion')
  @client.response_handler(response)
end

#utilization(queryParameters = {}) ⇒ Object

Retrieves historical utilization

Options Hash (queryParameters):

  • :fields (Array)
  • :startDate (Time, Date, String)
  • :endDate (Time, Date, String)


177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/oneview-sdk/resource/api200/server_hardware.rb', line 177

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