Class: OneviewSDK::API200::Enclosure
- Includes:
- ResourceHelper::ConfigurationOperation
- Defined in:
- lib/oneview-sdk/resource/api200/enclosure.rb
Overview
Enclosure resource implementation
Direct Known Subclasses
Constant Summary collapse
- BASE_URI =
'/rest/enclosures'.freeze
- UNIQUE_IDENTIFIERS =
%w[name uri serialNumber activeOaPreferredIP standbyOaPreferredIP].freeze
Constants inherited from Resource
Resource::DEFAULT_REQUEST_HEADER
Instance Attribute Summary
Attributes inherited from Resource
#api_version, #client, #data, #logger
Instance Method Summary collapse
-
#add ⇒ OneviewSDK::Enclosure
Claim/configure the enclosure and its components to the appliance.
-
#create ⇒ Object
Method is not available.
-
#delete ⇒ Object
Method is not available.
-
#environmental_configuration ⇒ Hash
Gets the enclosure settings that describe the environmental configuration.
-
#initialize(client, params = {}, api_ver = nil) ⇒ Enclosure
constructor
Create a resource object, associate it with a client, and set its properties.
-
#patch(operation, path, value) ⇒ Object
Updates specific attributes of a given enclosure resource.
-
#remove ⇒ true
Remove resource from OneView.
-
#script ⇒ String
Gets the enclosure script content.
-
#set_enclosure_group(eg) ⇒ Object
Associates an enclosure group to the enclosure.
-
#set_environmental_configuration(power) ⇒ Object
Sets the calibrated max power of an unmanaged or unsupported enclosure.
-
#set_refresh_state(state, options = {}) ⇒ Object
Refreshes the enclosure along with all of its components.
-
#update(attributes = {}) ⇒ OneviewSDK::Enclosure
Overrides the update operation because only the name and rackName can be updated (and it uses PATCH).
-
#utilization(queryParameters = {}) ⇒ Object
Retrieves historical utilization.
Methods included from ResourceHelper::ConfigurationOperation
Methods inherited from Resource
#==, #[], #[]=, build_query, #create!, #deep_merge!, #each, #eql?, #exists?, find_by, find_with_pagination, from_file, get_all, get_all_with_query, #like?, #refresh, #retrieve!, #schema, schema, #set, #set_all, #to_file
Constructor Details
#initialize(client, params = {}, api_ver = nil) ⇒ Enclosure
Create a resource object, associate it with a client, and set its properties.
34 35 36 37 38 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 34 def initialize(client, params = {}, api_ver = nil) super # Default values: @data['type'] ||= 'EnclosureV200' end |
Instance Method Details
#add ⇒ OneviewSDK::Enclosure
Calls the refresh method to set additional data
Claim/configure the enclosure and its components to the appliance
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# 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 |
#create ⇒ Object
Method is not available
42 43 44 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 42 def create(*) unavailable_method end |
#delete ⇒ Object
Method is not available
48 49 50 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 48 def delete(*) unavailable_method end |
#environmental_configuration ⇒ Hash
Gets the enclosure settings that describe the environmental configuration
115 116 117 118 119 |
# 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 |
#patch(operation, path, value) ⇒ Object
Updates specific attributes of a given enclosure resource
162 163 164 165 166 |
# 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 ⇒ true
Remove resource from OneView
28 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 28 alias remove delete |
#script ⇒ String
Gets the enclosure script content
107 108 109 110 111 |
# 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 |
#set_enclosure_group(eg) ⇒ Object
Associates an enclosure group to the enclosure
170 171 172 173 |
# 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 |
#set_environmental_configuration(power) ⇒ Object
Sets the calibrated max power of an unmanaged or unsupported enclosure
123 124 125 126 127 |
# 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 |
#set_refresh_state(state, options = {}) ⇒ Object
Refreshes the enclosure along with all of its components
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 91 def set_refresh_state(state, = {}) ensure_client && ensure_uri s = state.to_s rescue state requestBody = { 'body' => { refreshState: s, refreshForceOptions: } } response = @client.rest_put(@data['uri'] + '/refreshState', requestBody, @api_version) new_data = @client.response_handler(response) set_all(new_data) end |
#update(attributes = {}) ⇒ OneviewSDK::Enclosure
Overrides the update operation because only the name and rackName can be updated (and it uses PATCH).
75 76 77 78 79 80 81 82 83 84 85 86 |
# 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 |
#utilization(queryParameters = {}) ⇒ Object
Retrieves historical utilization
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# 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 |