From 5d8b21a14f01a27040e726f1fdfe25e05c4edf40 Mon Sep 17 00:00:00 2001 From: Alex Monteiro Date: Fri, 8 Dec 2017 14:07:36 +0000 Subject: [PATCH] Adjusting the headers on the methods --- .../resource/api200/logical_interconnect_group.rb | 4 ++-- lib/oneview-sdk/resource/api200/logical_switch.rb | 4 ++-- lib/oneview-sdk/resource/api200/user.rb | 4 ++-- lib/oneview-sdk/resource/api200/volume.rb | 11 ++++++----- lib/oneview-sdk/resource/api200/volume_template.rb | 4 ++-- lib/oneview-sdk/resource/api300/c7000/scope.rb | 4 ++-- lib/oneview-sdk/resource/api500/c7000/volume.rb | 14 ++++++++------ .../resource/api500/c7000/volume_template.rb | 4 ++-- 8 files changed, 26 insertions(+), 23 deletions(-) diff --git a/lib/oneview-sdk/resource/api200/logical_interconnect_group.rb b/lib/oneview-sdk/resource/api200/logical_interconnect_group.rb index b0664d3fa..44646f16c 100644 --- a/lib/oneview-sdk/resource/api200/logical_interconnect_group.rb +++ b/lib/oneview-sdk/resource/api200/logical_interconnect_group.rb @@ -88,9 +88,9 @@ def get_settings # @raise [OneviewSDK::IncompleteResource] if the client is not set # @raise [StandardError] if the resource creation fails # @return [Resource] self - def create(header = DEFAULT_REQUEST_HEADER) + def create(header = {}) verify_interconnects_before_save! - super(header) + super(DEFAULT_REQUEST_HEADER.merge(header)) end # Set data and save to OneView diff --git a/lib/oneview-sdk/resource/api200/logical_switch.rb b/lib/oneview-sdk/resource/api200/logical_switch.rb index aed3d6256..3913c8019 100644 --- a/lib/oneview-sdk/resource/api200/logical_switch.rb +++ b/lib/oneview-sdk/resource/api200/logical_switch.rb @@ -35,13 +35,13 @@ def initialize(client, params = {}, api_ver = nil) # @raise [OneviewSDK::IncompleteResource] if the client is not set # @raise [StandardError] if the resource creation fails # @return [OneviewSDK::LogicalSwitch] self - def create(header = DEFAULT_REQUEST_HEADER) + def create(header = {}) ensure_client request_body = {} request_body['logicalSwitchCredentials'] = generate_logical_switch_credentials request_body['logicalSwitch'] = @data.clone request_body['logicalSwitch']['switchCredentialConfiguration'] = generate_logical_switch_credential_configuration - options = {}.merge(header).merge('body' => request_body) + options = DEFAULT_REQUEST_HEADER.merge(header).merge('body' => request_body) response = @client.rest_post(self.class::BASE_URI, options, @api_version) body = @client.response_handler(response) set_all(body) diff --git a/lib/oneview-sdk/resource/api200/user.rb b/lib/oneview-sdk/resource/api200/user.rb index 1d6ce0549..f7e7a5cb2 100644 --- a/lib/oneview-sdk/resource/api200/user.rb +++ b/lib/oneview-sdk/resource/api200/user.rb @@ -37,9 +37,9 @@ def initialize(client, params = {}, api_ver = nil) # @raise [OneviewSDK::IncompleteResource] if the client is not set # @raise [StandardError] if the resource creation fails # @return [Resource] self - def create(header = DEFAULT_REQUEST_HEADER) + def create(header = {}) ensure_client - response = @client.rest_post(BASE_URI, header.merge('body' => @data), @api_version) + response = @client.rest_post(BASE_URI, DEFAULT_REQUEST_HEADER.merge(header).merge('body' => @data), @api_version) body = @client.response_handler(response) @data.delete('password') set_all(body) diff --git a/lib/oneview-sdk/resource/api200/volume.rb b/lib/oneview-sdk/resource/api200/volume.rb index fba79514e..65702dde3 100644 --- a/lib/oneview-sdk/resource/api200/volume.rb +++ b/lib/oneview-sdk/resource/api200/volume.rb @@ -31,8 +31,8 @@ class Volume < Resource # @raise [OneviewSDK::IncompleteResource] if the client is not set # @raise [StandardError] if the resource creation fails # @return [Resource] self - def create(header = DEFAULT_REQUEST_HEADER) - super(header) + def create(header = {}) + super(DEFAULT_REQUEST_HEADER.merge(header)) @data.delete('provisioningParameters') self end @@ -43,8 +43,9 @@ def create(header = DEFAULT_REQUEST_HEADER) # @raise [OneviewSDK::IncompleteResource] if the client is not set # @raise [StandardError] if the resource creation fails # @return [Resource] self - def create!(header = DEFAULT_REQUEST_HEADER) + def create!(header = {}) temp = self.class.new(@client, @data) + header = DEFAULT_REQUEST_HEADER.merge(header) temp.delete(:all, header) if temp.retrieve!(header) create(header) end @@ -61,10 +62,10 @@ def update(attributes = {}) # @param [Symbol] flag Delete storage system from Oneview only or in storage system as well # @param [Hash] header The header options for the request (key-value pairs) # @return [true] if resource was deleted successfully - def delete(flag = :all, header = DEFAULT_REQUEST_HEADER) + def delete(flag = :all, header = {}) ensure_client && ensure_uri raise InvalidResource, 'Invalid flag value, use :oneview or :all' unless %i[oneview all].include?(flag) - header = header.merge('exportOnly' => true) if flag == :oneview + header = DEFAULT_REQUEST_HEADER.merge(header).merge('exportOnly' => true) if flag == :oneview super(header) end diff --git a/lib/oneview-sdk/resource/api200/volume_template.rb b/lib/oneview-sdk/resource/api200/volume_template.rb index c53900dc1..01c2ef83f 100644 --- a/lib/oneview-sdk/resource/api200/volume_template.rb +++ b/lib/oneview-sdk/resource/api200/volume_template.rb @@ -39,14 +39,14 @@ def initialize(client, params = {}, api_ver = nil) # @raise [StandardError] if the resource creation fails # @return [Resource] self def create(header = {}) - super(header.merge(DEFAULT_REQUEST_HEADER)) + super(DEFAULT_REQUEST_HEADER.merge(header)) end # Deletes the volume template from OneView # @param [Hash] header The header options for the request (key-value pairs) # @return [TrueClass] if the volume template was deleted successfully def delete(header = {}) - super(header.merge(DEFAULT_REQUEST_HEADER)) + super(DEFAULT_REQUEST_HEADER.merge(header)) end # Updates the volume template from OneView diff --git a/lib/oneview-sdk/resource/api300/c7000/scope.rb b/lib/oneview-sdk/resource/api300/c7000/scope.rb index 2d5871032..13408c938 100644 --- a/lib/oneview-sdk/resource/api300/c7000/scope.rb +++ b/lib/oneview-sdk/resource/api300/c7000/scope.rb @@ -50,8 +50,8 @@ def update(attributes = {}) # @param [Hash] header The header options for the request (key-value pairs) # @raise [OneviewSDK::IncompleteResource] if the client or uri is not set # @return [true] if resource was deleted successfully - def delete(header = DEFAULT_REQUEST_HEADER) - super(header.merge('If-Match' => @data['eTag'])) + def delete(header = {}) + super(DEFAULT_REQUEST_HEADER.merge(header).merge('If-Match' => @data['eTag'])) end # Adds resource assignments diff --git a/lib/oneview-sdk/resource/api500/c7000/volume.rb b/lib/oneview-sdk/resource/api500/c7000/volume.rb index cdb54a605..55f19a28e 100644 --- a/lib/oneview-sdk/resource/api500/c7000/volume.rb +++ b/lib/oneview-sdk/resource/api500/c7000/volume.rb @@ -29,7 +29,7 @@ def set_storage_system(*) # @raise [OneviewSDK::IncompleteResource] if the client is not set. # @raise [StandardError] if the resource creation fails. # @return [Resource] self - def create(header = DEFAULT_REQUEST_HEADER) + def create(header = {}) properties = Hash[@data['properties'].map { |k, v| [k.to_sym, v] }] family = properties[:dataProtectionLevel].nil? ? 'StoreServ' : 'StoreVirtual' template_data = { @@ -38,7 +38,7 @@ def create(header = DEFAULT_REQUEST_HEADER) } @data['templateUri'] = get_volume_template_uri(template_data) unless @data['templateUri'] - OneviewSDK::Resource.instance_method(:create).bind(self).call(header) + OneviewSDK::Resource.instance_method(:create).bind(self).call(DEFAULT_REQUEST_HEADER.merge(header)) @data.delete('properties') @data.delete('templateUri') self @@ -58,12 +58,12 @@ def update(attributes = {}) # @param [Hash] header The header options for the request (key-value pairs) # @raise [InvalidResource] if an invalid flag is passed. # @return [true] if resource was deleted successfully. - def delete(flag = :all, header = DEFAULT_REQUEST_HEADER) + def delete(flag = :all, header = {}) ensure_client && ensure_uri raise InvalidResource, 'Invalid flag value, use :oneview or :all' unless %i[oneview all].include?(flag) uri = @data['uri'] uri << '?suppressDeviceUpdates=true' if flag == :oneview - response = @client.rest_delete(uri, header.merge('If-Match' => @data['eTag'])) + response = @client.rest_delete(uri, DEFAULT_REQUEST_HEADER.merge(header).merge('If-Match' => @data['eTag'])) @client.response_handler(response) true end @@ -162,7 +162,8 @@ def add # @note one of the UNIQUE_IDENTIFIERS, e.g. name or uri or properties['name'], must be specified in the resource # @param [Hash] header The header options for the request (key-value pairs) # @return [Boolean] Whether or not retrieve was successful - def retrieve!(header = DEFAULT_REQUEST_HEADER) + def retrieve!(header = {}) + header = DEFAULT_REQUEST_HEADER.merge(header) return super(header) unless @data['properties'] results = find_by_name_in_properties(header) return false unless results.size == 1 @@ -174,7 +175,8 @@ def retrieve!(header = DEFAULT_REQUEST_HEADER) # @note one of the UNIQUE_IDENTIFIERS, e.g. name or uri or properties['name'], must be specified in the resource # @param [Hash] header The header options for the request (key-value pairs) # @return [Boolean] Whether or not resource exists - def exists?(header = DEFAULT_REQUEST_HEADER) + def exists?(header = {}) + header = DEFAULT_REQUEST_HEADER.merge(header) return super(header) unless @data['properties'] find_by_name_in_properties(header).size == 1 end diff --git a/lib/oneview-sdk/resource/api500/c7000/volume_template.rb b/lib/oneview-sdk/resource/api500/c7000/volume_template.rb index 9e231842b..c91542457 100644 --- a/lib/oneview-sdk/resource/api500/c7000/volume_template.rb +++ b/lib/oneview-sdk/resource/api500/c7000/volume_template.rb @@ -21,8 +21,8 @@ class VolumeTemplate < Resource # Delete resource from OneView # @param [Hash] header The header options for the request (key-value pairs) # @return [true] if resource was deleted successfully - def delete(header = DEFAULT_REQUEST_HEADER) - super(header.merge('If-Match' => @data['eTag'])) + def delete(header = {}) + super(DEFAULT_REQUEST_HEADER.merge(header).merge('If-Match' => @data['eTag'])) end # Sets the root template