Class: OneviewSDK::Enclosure
- Defined in:
- lib/oneview-sdk/resource/enclosure.rb
Overview
Enclosure resource implementation
Constant Summary collapse
- BASE_URI =
'/rest/enclosures'.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_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.
28 29 30 31 32 |
# File 'lib/oneview-sdk/resource/enclosure.rb', line 28 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
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/oneview-sdk/resource/enclosure.rb', line 50 def add ensure_client required_attributes = %w(enclosureGroupUri hostname username password licensingIntent) required_attributes.each { |k| fail 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
88 89 90 91 92 93 |
# File 'lib/oneview-sdk/resource/enclosure.rb', line 88 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
37 38 39 |
# File 'lib/oneview-sdk/resource/enclosure.rb', line 37 def create unavailable_method end |
#delete ⇒ Object
Method is not available
43 44 45 |
# File 'lib/oneview-sdk/resource/enclosure.rb', line 43 def delete unavailable_method end |
#environmental_configuration ⇒ Hash
Gets the enclosure settings that describe the environmental configuration
123 124 125 126 127 |
# File 'lib/oneview-sdk/resource/enclosure.rb', line 123 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/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
22 |
# File 'lib/oneview-sdk/resource/enclosure.rb', line 22 alias remove delete |
#script ⇒ String
Gets the enclosure script content
115 116 117 118 119 |
# File 'lib/oneview-sdk/resource/enclosure.rb', line 115 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/enclosure.rb', line 170 def set_enclosure_group(eg) eg.retrieve! unless eg['uri'] @data['enclosureGroupUri'] = eg['uri'] end |
#set_refresh_state(state, options = {}) ⇒ Object
Refreshes the enclosure along with all of its components
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/oneview-sdk/resource/enclosure.rb', line 99 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).
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/oneview-sdk/resource/enclosure.rb', line 70 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
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/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 |