Class: OneviewSDK::PowerDevice
- 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
-
.discover(client, options) ⇒ OneviewSDK::PowerDevice
Adds an iPDU and bring all components under management by discovery of its management modules.
-
.get_ipdu_devices(client, hostname) ⇒ Array
Retrieves the list of power devices given an iPDU hostname.
Instance Method Summary collapse
-
#add ⇒ OneviewSDK::PowerDevice
Add the resource on OneView using the current data.
-
#add_connection(resource, connection) ⇒ Object
Adds a power connection.
-
#create ⇒ Object
Method is not available.
-
#delete ⇒ Object
Method is not available.
-
#get_power_state ⇒ String
Gets the power state of a power device.
-
#get_uid_state ⇒ String
Retrieves the unit identification state of the specified power outlet.
-
#initialize(client, params = {}, api_ver = nil) ⇒ PowerDevice
constructor
Create a resource object, associate it with a client, and set its properties.
-
#remove ⇒ true
Remove resource from OneView.
-
#remove_connection(resource, connection) ⇒ Object
Removes the power connection.
-
#set_power_state(state) ⇒ Object
Sets the power state of the power delivery device.
-
#set_refresh_state(options) ⇒ Object
Refreshes a power delivery device.
-
#set_uid_state(state) ⇒ Object
Sets the unit identification light state of the power delivery device.
-
#utilization(queryParameters = {}) ⇒ Hash
Retrieves historical utilization.
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.
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
56 57 58 59 60 61 |
# File 'lib/oneview-sdk/resource/power_device.rb', line 56 def self.discover(client, ) ['force'] ||= [:force] || false response = client.rest_post(BASE_URI + '/discover', 'body' => ) 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
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
#add ⇒ OneviewSDK::PowerDevice
Calls the refresh method to set additional data
Add the resource on OneView using the current data
22 |
# File 'lib/oneview-sdk/resource/power_device.rb', line 22 alias add create |
#add_connection(resource, connection) ⇒ Object
Adds a power connection
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 |
#create ⇒ Object
Method is not available
42 43 44 |
# File 'lib/oneview-sdk/resource/power_device.rb', line 42 def create unavailable_method end |
#delete ⇒ Object
Method is not available
48 49 50 |
# File 'lib/oneview-sdk/resource/power_device.rb', line 48 def delete unavailable_method end |
#get_power_state ⇒ String
Gets the power state of a power device
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_state ⇒ String
Retrieves the unit identification state of the specified power outlet
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 |
#remove ⇒ true
Remove resource from OneView
26 |
# File 'lib/oneview-sdk/resource/power_device.rb', line 26 alias remove delete |
#remove_connection(resource, connection) ⇒ Object
Removes the power connection
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
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
110 111 112 113 |
# File 'lib/oneview-sdk/resource/power_device.rb', line 110 def set_refresh_state() response = @client.rest_put(@data['uri'] + '/refreshState', 'body' => ) @client.response_handler(response) end |
#set_uid_state(state) ⇒ Object
Sets the unit identification light state of the power delivery device
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
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 |