Class: OneviewSDK::API200::PowerDevice
- Defined in:
- lib/oneview-sdk/resource/api200/power_device.rb
Overview
Power device resource implementation
Direct Known Subclasses
OneviewSDK::API300::C7000::PowerDevice, OneviewSDK::API300::Synergy::PowerDevice
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
-
.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!, #deep_merge!, #each, #eql?, #exists?, find_by, find_with_pagination, 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.
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
59 60 61 62 63 64 |
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 59 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
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
#add ⇒ OneviewSDK::PowerDevice
Calls the refresh method to set additional data
Add the resource on OneView using the current data
25 |
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 25 alias add create |
#add_connection(resource, connection) ⇒ Object
Adds a power connection
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 |
#create ⇒ Object
Method is not available
45 46 47 |
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 45 def create(*) unavailable_method end |
#delete ⇒ Object
Method is not available
51 52 53 |
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 51 def delete(*) unavailable_method end |
#get_power_state ⇒ String
Gets the power state of a power device
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_state ⇒ String
Retrieves the unit identification state of the specified power outlet
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 |
#remove ⇒ true
Remove resource from OneView
29 |
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 29 alias remove delete |
#remove_connection(resource, connection) ⇒ Object
Removes the power connection
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
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
113 114 115 116 |
# File 'lib/oneview-sdk/resource/api200/power_device.rb', line 113 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
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
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 |