class OneviewSDK::API200::Enclosure
Enclosure
resource implementation
Constants
- BASE_URI
- UNIQUE_IDENTIFIERS
Public Class Methods
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/enclosure.rb, line 34 def initialize(client, params = {}, api_ver = nil) super # Default values: @data['type'] ||= 'EnclosureV200' end
Public Instance Methods
Claim/configure the enclosure and its components to the appliance @note Calls the refresh method to set additional data @return [OneviewSDK::Enclosure] self
# File lib/oneview-sdk/resource/api200/enclosure.rb, line 55 def add ensure_client required_attributes = %w[enclosureGroupUri hostname username password licensingIntent] required_attributes.each { |k| raise IncompleteResource, "Missing required attribute: '#{k}'" unless @data.key?(k) } optional_attrs = %w[enclosureUri firmwareBaselineUri force forceInstallFirmware state unmanagedEnclosure updateFirmwareOn] temp_data = @data.select { |k, _v| required_attributes.include?(k) || optional_attrs.include?(k) } response = @client.rest_post(self.class::BASE_URI, { 'body' => temp_data }, @api_version) new_data = @client.response_handler(response) old_name = @data.select { |k, _v| %w[name rackName].include?(k) } # Save name (if given) %w[username password hostname].each { |k| @data.delete(k) } # These are no longer needed set_all(new_data) set_all(old_name) update self end
Method is not available @raise [OneviewSDK::MethodUnavailable] method is not available
# File lib/oneview-sdk/resource/api200/enclosure.rb, line 42 def create(*) unavailable_method end
Method is not available @raise [OneviewSDK::MethodUnavailable] method is not available
# File lib/oneview-sdk/resource/api200/enclosure.rb, line 48 def delete(*) unavailable_method end
Gets the enclosure settings that describe the environmental configuration @return [Hash] The enclosure envirnomental configuration
# File lib/oneview-sdk/resource/api200/enclosure.rb, line 115 def environmental_configuration ensure_client && ensure_uri response = @client.rest_get(@data['uri'] + '/environmentalConfiguration', {}, @api_version) @client.response_handler(response) end
Updates specific attributes of a given enclosure resource @param [String] operation operation to be performed @param [String] path path @param [String] value value
# File lib/oneview-sdk/resource/api200/enclosure.rb, line 162 def patch(operation, path, value) ensure_client && ensure_uri response = @client.rest_patch(@data['uri'], { 'body' => [{ op: operation, path: path, value: value }] }, @api_version) @client.response_handler(response) end
Remove resource from OneView @return [true] if resource was removed successfully
Gets the enclosure script content @return [String] Script content
# File lib/oneview-sdk/resource/api200/enclosure.rb, line 107 def script ensure_client && ensure_uri response = @client.rest_get(@data['uri'] + '/script', {}, @api_version) @client.response_handler(response) end
Associates an enclosure group to the enclosure @param [OneviewSDK<Resource>] eg Enclosure
Group associated
# File lib/oneview-sdk/resource/api200/enclosure.rb, line 170 def set_enclosure_group(eg) eg.retrieve! unless eg['uri'] @data['enclosureGroupUri'] = eg['uri'] end
Sets the calibrated max power of an unmanaged or unsupported enclosure @param [String] power The calibrated maximum power of the resource
# File lib/oneview-sdk/resource/api200/enclosure.rb, line 123 def set_environmental_configuration(power) ensure_client && ensure_uri response = @client.rest_put(@data['uri'] + '/environmentalConfiguration', 'body' => { calibratedMaxPower: power }) @client.response_handler(response) end
Refreshes the enclosure along with all of its components @param [String] state NotRefreshing, RefreshFailed, RefreshPending, Refreshing @param [Hash] options Optional force fields for refreshing the enclosure
# File lib/oneview-sdk/resource/api200/enclosure.rb, line 91 def set_refresh_state(state, options = {}) ensure_client && ensure_uri s = state.to_s rescue state requestBody = { 'body' => { refreshState: s, refreshForceOptions: options } } response = @client.rest_put(@data['uri'] + '/refreshState', requestBody, @api_version) new_data = @client.response_handler(response) set_all(new_data) end
Overrides the update operation because only the name and rackName can be updated (and it uses PATCH). @param [Hash] attributes attributes to be updated @return [OneviewSDK::Enclosure] self
# File lib/oneview-sdk/resource/api200/enclosure.rb, line 75 def update(attributes = {}) set_all(attributes) ensure_client && ensure_uri cur_state = self.class.find_by(@client, uri: @data['uri']).first unless cur_state[:name] == @data['name'] patch('replace', '/name', @data['name']) end unless cur_state[:rackName] == @data['rackName'] patch('replace', '/rackName', @data['rackName']) end self 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
# File lib/oneview-sdk/resource/api200/enclosure.rb, line 134 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 @raise [InvalidResource] if time is not formatted correctly
# File lib/oneview-sdk/resource/api200/enclosure.rb, line 179 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 InvalidResource, "Invalid time format '#{t.class}'. Valid options are Time, Date, or String" end rescue StandardError => e raise InvalidResource, "Failed to parse time value '#{t}'. #{e.message}" end