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
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.
-
#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!, #deep_merge!, #each, #eql?, #exists?, find_by, find_with_pagination, 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
87 88 89 90 91 92 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 87 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
122 123 124 125 126 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 122 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
169 170 171 172 173 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 169 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
114 115 116 117 118 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 114 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
177 178 179 180 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 177 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
130 131 132 133 134 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 130 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
98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 98 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 |
# 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'] 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
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/oneview-sdk/resource/api200/enclosure.rb', line 141 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 |