class OneviewSDK::API200::PowerDevice
Power device resource implementation
Constants
- BASE_URI
Public Class Methods
Adds an iPDU and bring all components under management by discovery of its management modules @param [OneviewSDK::Client] client The client object for the OneView appliance @param [Hash] options options for the iPDU @return [OneviewSDK::PowerDevice] The iPDU power device created in OneView
# 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
Retrieves the list of power devices given an iPDU hostname @param [OneviewSDK::Client] client The client object for the OneView appliance @param [String] hostname The iPDU hostname @return [Array] array of OneviewSDK::PowerDevice
# 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
Create a resource object, associate it with a client, and set its properties. @param [OneviewSDK::Client] client The client object for the OneView appliance @param [Hash] params The options for this resource (key-value pairs) @param [Integer] api_ver The api version to use when interracting with this resource.
OneviewSDK::Resource::new
# 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
Public Instance Methods
Add the resource on OneView using the current data @note Calls the refresh method to set additional data @raise [OneviewSDK::IncompleteResource] if the client is not set @raise [StandardError] if the resource creation fails @return [OneviewSDK::PowerDevice] self
Adds a power connection @param [OneviewSDK::Resource] resource @param [Integer] connection connection number
# 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
Method is not available @raise [OneviewSDK::MethodUnavailable] method is not available
# File lib/oneview-sdk/resource/api200/power_device.rb, line 45 def create(*) unavailable_method end
Method is not available @raise [OneviewSDK::MethodUnavailable] method is not available
# File lib/oneview-sdk/resource/api200/power_device.rb, line 51 def delete(*) unavailable_method end
Gets the power state of a power device @return [String] Power state
# 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
Retrieves the unit identification state of the specified power outlet @return [String] Uid state
# 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 resource from OneView @return [true] if resource was removed successfully
Removes the power connection @param [OneviewSDK::Resource] resource @param [Integer] connection connection number
# 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
Sets the power state of the power delivery device @param [String] state On|Off
# 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
Refreshes a power delivery device @param [Hash] options @option options [String] :refreshState @option options [String] :username @option options [String] :password
# 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
Sets the unit identification light state of the power delivery device @param [String] state On|Off
# 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
Retrieves historical utilization @param [Hash] queryParameters query parameters (ie :startDate, :endDate, :fields, :view, etc.) @option queryParameters [Array] :fields @option queryParameters [Time, Date, String] :startDate @option queryParameters [Time, Date, String] :endDate @return [Hash] Utilization data
# 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
Private Instance Methods
Converts Date, Time, or String objects to iso8601 string
# File lib/oneview-sdk/resource/api200/power_device.rb, line 165 def convert_time(t) case t when nil then nil when Date then t.to_time.utc.iso8601(3) when Time then t.utc.iso8601(3) when String then Time.parse(t).utc.iso8601(3) else raise "Invalid time format '#{t.class}'. Valid options are Time, Date, or String" end rescue StandardError => e raise "Failed to parse time value '#{t}'. #{e.message}" end