Class: OneviewSDK::PowerDevice

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

Overview

Power device resource implementation

Constant Summary collapse

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

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!, #each, #eql?, #exists?, find_by, from_file, get_all, #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.



32
33
34
35
36
37
38
# File 'lib/oneview-sdk/resource/power_device.rb', line 32

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:



56
57
58
59
60
61
# File 'lib/oneview-sdk/resource/power_device.rb', line 56

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



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

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:

Raises:



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

alias add create

#add_connection(resource, connection) ⇒ Object

Adds a power connection

Parameters:



81
82
83
84
85
86
87
# File 'lib/oneview-sdk/resource/power_device.rb', line 81

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

#createObject

Method is not available

Raises:



42
43
44
# File 'lib/oneview-sdk/resource/power_device.rb', line 42

def create
  unavailable_method
end

#deleteObject

Method is not available

Raises:



48
49
50
# File 'lib/oneview-sdk/resource/power_device.rb', line 48

def delete
  unavailable_method
end

#get_power_stateString

Gets the power state of a power device

Returns:

  • (String)

    Power state



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

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



117
118
119
120
# File 'lib/oneview-sdk/resource/power_device.rb', line 117

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



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

alias remove delete

#remove_connection(resource, connection) ⇒ Object

Removes the power connection

Parameters:



92
93
94
95
96
# File 'lib/oneview-sdk/resource/power_device.rb', line 92

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



100
101
102
103
# File 'lib/oneview-sdk/resource/power_device.rb', line 100

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)


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

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



124
125
126
127
# File 'lib/oneview-sdk/resource/power_device.rb', line 124

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



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

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