Class: OneviewSDK::API200::Enclosure
- 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
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.
-
#configuration ⇒ Object
Reapplies the enclosure configuration.
-
#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 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
Constructor Details
#initialize(client, params = {}, api_ver = nil) ⇒ Enclosure
Create a resource object, associate it with a client, and set its properties.
31 32 33 34 35 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 31 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
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 53 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 |
#configuration ⇒ Object
Reapplies the enclosure configuration
91 92 93 94 95 96 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 91 def configuration ensure_client && ensure_uri response = @client.rest_put(@data['uri'] + '/configuration', {}, @api_version) new_data = @client.response_handler(response) set_all(new_data) end |
#create ⇒ Object
Method is not available
40 41 42 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 40 def create(*) unavailable_method end |
#delete ⇒ Object
Method is not available
46 47 48 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 46 def delete(*) unavailable_method end |
#environmental_configuration ⇒ Hash
Gets the enclosure settings that describe the environmental configuration
126 127 128 129 130 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 126 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
173 174 175 176 177 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 173 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
25 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 25 alias remove delete |
#script ⇒ String
Gets the enclosure script content
118 119 120 121 122 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 118 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
181 182 183 184 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 181 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
134 135 136 137 138 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 134 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
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 102 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).
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 73 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'] temp_data = [{ op: 'replace', path: '/name', value: @data['name'] }] response = @client.rest_patch(@data['uri'], { 'body' => temp_data }, @api_version) @client.response_handler(response) end unless cur_state[:rackName] == @data['rackName'] temp_data = [{ op: 'replace', path: '/rackName', value: @data['rackName'] }] response = @client.rest_patch(@data['uri'], { 'body' => temp_data }, @api_version) @client.response_handler(response) end self end |
#utilization(queryParameters = {}) ⇒ Object
Retrieves historical utilization
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 145 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 |