Class: OneviewSDK::ServerHardware

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

Overview

Server hardware resource implementation

Constant Summary collapse

BASE_URI =
'/rest/server-hardware'.freeze

Instance Attribute Summary

Attributes inherited from Resource

#api_version, #client, #data, #logger

Instance Method Summary collapse

Methods inherited from Resource

#==, #[], #[]=, build_query, #create!, #each, #eql?, #exists?, find_by, from_file, get_all, #like?, #refresh, #retrieve!, #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.

Parameters:

  • client (OneviewSDK::Client)

    The client object for the OneView appliance

  • params (Hash) (defaults to: {})

    The options for this resource (key-value pairs)

  • api_ver (Integer) (defaults to: nil)

    The api version to use when interracting with this resource.



25
26
27
28
29
# File 'lib/oneview-sdk/resource/server_hardware.rb', line 25

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

Returns:

Raises:



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/oneview-sdk/resource/server_hardware.rb', line 46

def add
  ensure_client
  required_attributes = %w(hostname username password licensingIntent)
  required_attributes.each { |k| fail 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:



33
34
35
# File 'lib/oneview-sdk/resource/server_hardware.rb', line 33

def create
  unavailable_method
end

#deleteObject

Method is not available

Raises:



39
40
41
# File 'lib/oneview-sdk/resource/server_hardware.rb', line 39

def delete
  unavailable_method
end

#environmental_configurationObject

Gets the settings that describe the environmental configuration



132
133
134
135
136
# File 'lib/oneview-sdk/resource/server_hardware.rb', line 132

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

#get_biosHash

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

Returns:

  • (Hash)

    List with BIOS/UEFI settings



82
83
84
85
# File 'lib/oneview-sdk/resource/server_hardware.rb', line 82

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

Returns:

  • (Hash)

    url



89
90
91
92
# File 'lib/oneview-sdk/resource/server_hardware.rb', line 89

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

Returns:

  • (Hash)

    url



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

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

Returns:

  • (Hash)

    url



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

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

Parameters:

  • force (Boolean) (defaults to: false)

    Use ‘PressAndHold’ action?

Returns:

  • (Boolean)

    Returns whether or not the server was powered off



76
77
78
# File 'lib/oneview-sdk/resource/server_hardware.rb', line 76

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

#power_on(force = false) ⇒ Boolean

Power on the server hardware

Parameters:

  • force (Boolean) (defaults to: false)

    Use ‘PressAndHold’ action?

Returns:

  • (Boolean)

    Returns whether or not the server was powered on



69
70
71
# File 'lib/oneview-sdk/resource/server_hardware.rb', line 69

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

#removetrue

Remove resource from OneView

Returns:

  • (true)

    if resource was removed successfully



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

alias remove delete

#set_refresh_state(state, options = {}) ⇒ Object

Refreshes the enclosure along with all of its components

Parameters:

  • state (String)

    NotRefreshing, RefreshFailed, RefreshPending, Refreshing

  • options (Hash) (defaults to: {})

    Optional force fields for refreshing the enclosure



111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/oneview-sdk/resource/server_hardware.rb', line 111

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:



62
63
64
# File 'lib/oneview-sdk/resource/server_hardware.rb', line 62

def update(*)
  unavailable_method
end

#update_ilo_firmwareObject

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



126
127
128
129
# File 'lib/oneview-sdk/resource/server_hardware.rb', line 126

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

#utilization(queryParameters = {}) ⇒ Object

Retrieves historical utilization

Parameters:

  • queryParameters (Hash) (defaults to: {})

    query parameters (ie :startDate, :endDate, :fields, :view, etc.)

Options Hash (queryParameters):

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


143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/oneview-sdk/resource/server_hardware.rb', line 143

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