Class: OneviewSDK::API200::PowerDevice

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

Overview

Power device resource implementation

Constant Summary collapse

BASE_URI =
'/rest/power-devices'.freeze

Constants inherited from Resource

Resource::DEFAULT_REQUEST_HEADER, Resource::UNIQUE_IDENTIFIERS

Instance Attribute Summary

Attributes inherited from Resource

#api_version, #client, #data, #logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, #[], #[]=, build_query, #create!, #deep_merge!, #each, #eql?, #exists?, find_by, find_with_pagination, from_file, get_all, get_all_with_query, #like?, #refresh, #retrieve!, schema, #schema, #set, #set_all, #to_file, #update

Constructor Details

#initialize(client, params = {}, api_ver = nil) ⇒ PowerDevice

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.



35
36
37
38
39
40
41
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 35

def initialize(client, params = {}, api_ver = nil)
  super
  # Default values
  @data['deviceType'] ||= 'BranchCircuit'
  @data['phaseType'] ||= 'Unknown'
  @data['powerConnections'] ||= []
end

Class Method Details

.discover(client, options) ⇒ OneviewSDK::PowerDevice

Adds an iPDU and bring all components under management by discovery of its management modules

Parameters:

  • client (OneviewSDK::Client)

    The client object for the OneView appliance

  • options (Hash)

    options for the iPDU

Returns:

  • (OneviewSDK::PowerDevice)

    The iPDU power device created in OneView



59
60
61
62
63
64
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 59

def self.discover(client, options)
  options['force'] ||= options[:force] || false
  response = client.rest_post(BASE_URI + '/discover', 'body' => options)
  power_device_info = client.response_handler(response)
  new(client, power_device_info)
end

.get_ipdu_devices(client, hostname) ⇒ Array

Retrieves the list of power devices given an iPDU hostname

Parameters:

  • client (OneviewSDK::Client)

    The client object for the OneView appliance

  • hostname (String)

    The iPDU hostname

Returns:

  • (Array)

    array of OneviewSDK::PowerDevice



70
71
72
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 70

def self.get_ipdu_devices(client, hostname)
  find_by(client, managedBy: { hostName: hostname })
end

Instance Method Details

#addOneviewSDK::PowerDevice

Note:

Calls the refresh method to set additional data

Add the resource on OneView using the current data

Returns:

  • (OneviewSDK::PowerDevice)

    self

Raises:



25
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 25

alias add create

#add_connection(resource, connection) ⇒ Object

Adds a power connection

Parameters:



84
85
86
87
88
89
90
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 84

def add_connection(resource, connection)
  @data['powerConnections'] << {
    'connectionUri' => resource['uri'],
    'deviceConnection' => connection,
    'sourceConnection' => connection
  }
end

#createObject

Method is not available

Raises:



45
46
47
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 45

def create(*)
  unavailable_method
end

#deleteObject

Method is not available

Raises:



51
52
53
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 51

def delete(*)
  unavailable_method
end

#get_power_stateString

Gets the power state of a power device

Returns:

  • (String)

    Power state



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

def get_power_state
  response = @client.rest_get(@data['uri'] + '/powerState')
  response.body
end

#get_uid_stateString

Retrieves the unit identification state of the specified power outlet

Returns:

  • (String)

    Uid state



120
121
122
123
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 120

def get_uid_state
  response = @client.rest_get(@data['uri'] + '/uidState')
  response.body
end

#removetrue

Remove resource from OneView

Returns:

  • (true)

    if resource was removed successfully



29
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 29

alias remove delete

#remove_connection(resource, connection) ⇒ Object

Removes the power connection

Parameters:



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

def remove_connection(resource, connection)
  @data['powerConnections'].reject! do |conn|
    conn['connectionUri'] == resource['uri'] && conn['deviceConnection'] == connection
  end
end

#set_power_state(state) ⇒ Object

Sets the power state of the power delivery device

Parameters:

  • state (String)

    On|Off



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

def set_power_state(state)
  response = @client.rest_put(@data['uri'] + '/powerState', 'body' => { powerState: state })
  @client.response_handler(response)
end

#set_refresh_state(options) ⇒ Object

Refreshes a power delivery device

Parameters:

  • options (Hash)

Options Hash (options):

  • :refreshState (String)
  • :username (String)
  • :password (String)


113
114
115
116
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 113

def set_refresh_state(options)
  response = @client.rest_put(@data['uri'] + '/refreshState', 'body' => options)
  @client.response_handler(response)
end

#set_uid_state(state) ⇒ Object

Sets the unit identification light state of the power delivery device

Parameters:

  • state (String)

    On|Off



127
128
129
130
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 127

def set_uid_state(state)
  response = @client.rest_put(@data['uri'] + '/uidState', 'body' => { uidState: state })
  @client.response_handler(response)
end

#utilization(queryParameters = {}) ⇒ Hash

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)

Returns:

  • (Hash)

    Utilization data



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 138

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