Skip to content

Commit

Permalink
Merge pull request #288 from HewlettPackard/fix/adds_endpoint_missing…
Browse files Browse the repository at this point in the history
…_of_interconnect

adds method to apply endpoint PUT /configuration that was missing of the Interconnect
  • Loading branch information
ricardogpsf committed Oct 19, 2017
2 parents a988be0 + 3f65ff2 commit 257189a
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 48 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## v5.2.0 (Unreleased)

#### New features
- [#290](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/290) Adding update ports for Switch API 300
#### New Features:
- [#287](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/287) Missing method to apply/reapply configuration to Interconnect of API500
- [#290](https://github.com/HewlettPackard/oneview-sdk-ruby/issues/290) Missing update ports method for Switch on API 300

## v5.1.2
#### Notes
Expand Down
2 changes: 1 addition & 1 deletion endpoints-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ OneviewSDK::Datacenter.find_by(@client, width: 11000).map(&:remove)
|<sub>/rest/interconnects</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/interconnects/{id}</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/interconnects/{id}</sub> | PATCH | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/interconnects/{id}/configuration</sub> | PUT | :heavy_minus_sign: | :heavy_minus_sign: | |
|<sub>/rest/interconnects/{id}/configuration</sub> | PUT | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: |
|<sub>/rest/interconnects/{id}/pluggableModuleInformation</sub> | GET | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: |
|<sub>/rest/interconnects/{id}/ports</sub> | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|<sub>/rest/interconnects/{id}/ports</sub> | PUT | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Expand Down
10 changes: 10 additions & 0 deletions examples/shared_samples/interconnect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,13 @@
rescue NoMethodError
puts 'The method #get_pluggable_module_information is available only for api greater than or equal to 500.'
end

# Applies or reapplies the current interconnect configuration.
# This method 'configuration' was added in API version 500.
begin
puts "\nApplying the configuration to interconnect #{item['uri']}."
item.configuration
puts "\nThe action was executed successfully"
rescue NoMethodError
puts 'The method #configuration is available only for API version greater than or equal to 500.'
end
12 changes: 3 additions & 9 deletions lib/oneview-sdk/resource/api200/enclosure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
require 'time'
require 'date'
require_relative 'resource'
require_relative '../../resource_helper'

module OneviewSDK
module API200
# Enclosure resource implementation
class Enclosure < Resource
include OneviewSDK::ResourceHelper::ConfigurationOperation

BASE_URI = '/rest/enclosures'.freeze
UNIQUE_IDENTIFIERS = %w(name uri serialNumber activeOaPreferredIP standbyOaPreferredIP).freeze

Expand Down Expand Up @@ -83,15 +86,6 @@ def update(attributes = {})
self
end

# Reapplies the enclosure configuration
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


# Refreshes the enclosure along with all of its components
# @param [String] state NotRefreshing, RefreshFailed, RefreshPending, Refreshing
# @param [Hash] options Optional force fields for refreshing the enclosure
Expand Down
12 changes: 3 additions & 9 deletions lib/oneview-sdk/resource/api200/logical_interconnect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
# language governing permissions and limitations under the License.

require_relative 'resource'
require_relative '../../resource_helper'

module OneviewSDK
module API200
# Logical interconnect resource implementation
class LogicalInterconnect < Resource
include OneviewSDK::ResourceHelper::ConfigurationOperation

BASE_URI = '/rest/logical-interconnects'.freeze
LOCATION_URI = '/rest/logical-interconnects/locations/interconnects'.freeze

Expand Down Expand Up @@ -135,15 +138,6 @@ def compliance
set_all(body)
end

# Asynchronously applies or re-applies the logical interconnect configuration to all managed interconnects
# @return returns the updated object
def configuration
ensure_client && ensure_uri
response = @client.rest_put(@data['uri'] + '/configuration', {}, @api_version)
body = client.response_handler(response)
set_all(body)
end

# Gets a collection of uplink ports from the member interconnects
# which are eligible for assignment to an analyzer port.
# @return [Hash] Hash of uplink ports eligibles for assignment to an analyzer port
Expand Down
2 changes: 1 addition & 1 deletion lib/oneview-sdk/resource/api200/server_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module OneviewSDK
module API200
# Server profile resource implementation
class ServerProfile < Resource
include OneviewSDK::ResourceHelper
include OneviewSDK::ResourceHelper::PatchOperation
BASE_URI = '/rest/server-profiles'.freeze
UNIQUE_IDENTIFIERS = %w(name uri associatedServer serialNumber serverHardwareUri).freeze

Expand Down
2 changes: 1 addition & 1 deletion lib/oneview-sdk/resource/api300/c7000/logical_enclosure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module API300
module C7000
# Logical Enclosure resource implementation on API300 C7000
class LogicalEnclosure < OneviewSDK::API200::LogicalEnclosure
include OneviewSDK::ResourceHelper
include OneviewSDK::ResourceHelper::PatchOperation

def initialize(client, params = {}, api_ver = nil)
super
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ module API300
module Synergy
# SAS logical interconnect resource implementation
class SASLogicalInterconnect < Resource
include OneviewSDK::ResourceHelper::ConfigurationOperation

BASE_URI = '/rest/sas-logical-interconnects'.freeze

# Create a resource object, associate it with a client, and set its properties.
Expand Down Expand Up @@ -95,15 +97,6 @@ def replace_drive_enclosure(old_serial_number, new_serial_number)
response = @client.rest_post(@data['uri'] + '/replaceDriveEnclosure', update_json)
@client.response_handler(response)
end

# Asynchronously applies or re-applies the SAS logical interconnect configuration to all managed interconnects
# @return returns the updated object
def configuration
ensure_client && ensure_uri
response = @client.rest_put(@data['uri'] + '/configuration', {}, @api_version)
body = client.response_handler(response)
set_all(body)
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/oneview-sdk/resource/api500/c7000/interconnect.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module API500
module C7000
# Interconnect resource implementation on API500 C7000
class Interconnect < OneviewSDK::API300::C7000::Interconnect
include OneviewSDK::ResourceHelper::ConfigurationOperation

# Gets all the Small Form-factor Pluggable (SFP) instances from an interconnect.
# @return [Hash] hash The Small Form-factor Pluggable (SFP) instances of the interconnect
Expand Down
2 changes: 1 addition & 1 deletion lib/oneview-sdk/resource/api500/c7000/logical_enclosure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module API500
module C7000
# Contains helper methods to include operation with firmware of a given logical enclosure resource
module FirmwareHelper
include ResourceHelper
include ResourceHelper::PatchOperation

# Updates the firmware attributes of a given logical enclosure resource
# @param [Hash] attributes Hash with firmware attributes
Expand Down
40 changes: 27 additions & 13 deletions lib/oneview-sdk/resource_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,33 @@
module OneviewSDK
# Contains helper methods to include certain functionalities on resources
module ResourceHelper
# Performs a specific patch operation for the given resource.
# If the resource supports the particular operation, the operation is performed
# and a response is returned to the caller with the results.
# @param [String] operation The operation to be performed
# @param [String] path The path of operation
# @param [String] value The value
# @note This attribute is subject to incompatible changes in future release versions, including redefinition or removal.
def patch(operation, path, value = nil, header_options = {})
ensure_client && ensure_uri
options = { 'body' => [op: operation, path: path, value: value] }
options = options.merge(header_options)
response = @client.rest_patch(@data['uri'], options, @api_version)
@client.response_handler(response)
# Contains helper method to call patch endpoint of resource
module PatchOperation
# Performs a specific patch operation for the given resource.
# If the resource supports the particular operation, the operation is performed
# and a response is returned to the caller with the results.
# @param [String] operation The operation to be performed
# @param [String] path The path of operation
# @param [String] value The value
# @note This attribute is subject to incompatible changes in future release versions, including redefinition or removal.
def patch(operation, path, value = nil, header_options = {})
ensure_client && ensure_uri
options = { 'body' => [op: operation, path: path, value: value] }
options = options.merge(header_options)
response = @client.rest_patch(@data['uri'], options, @api_version)
@client.response_handler(response)
end
end

# Contains helper method to call configuration endpoint of resource
module ConfigurationOperation
# Reapplies the configuration
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
end
end
end
6 changes: 6 additions & 0 deletions spec/integration/shared_examples/interconnect/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
end
end

describe '#configuration' do
it 'applies or re-applies the current interconnect configuration.' do
expect { item.configuration }.not_to raise_error
end
end

describe '#patch' do
xit 'update a given interconnect across a patch (Skipping this test due to the lack of type of interconnection that supports this operation)' do
expect { item.patch('replace', '/uidState', 'Off') }.not_to raise_error
Expand Down
23 changes: 21 additions & 2 deletions spec/unit/resource_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
RSpec.describe OneviewSDK::ResourceHelper do
include_context 'shared context'
class SomeIncluder < OneviewSDK::Resource
include OneviewSDK::ResourceHelper
include OneviewSDK::ResourceHelper::PatchOperation
end

subject(:klass) { SomeIncluder.new(@client_200) }
class SomeIncluderConfigurationOperation < OneviewSDK::Resource
include OneviewSDK::ResourceHelper::ConfigurationOperation
end

subject(:klass) { SomeIncluder.new(@client_200) }

describe '#patch' do
it 'requires a uri' do
Expand All @@ -27,4 +30,20 @@ class SomeIncluder < OneviewSDK::Resource
item.patch('replace', '/path', 'val', 'If-Match' => item['eTag'])
end
end

describe '#configuration' do
it 'requires a uri' do
item = SomeIncluderConfigurationOperation.new(@client_200)
expect { item.configuration }.to raise_error(OneviewSDK::IncompleteResource, /Please set uri/)
end

it 'applying configuration' do
item = SomeIncluderConfigurationOperation.new(@client_200, uri: '/rest/fake/1')
allow_any_instance_of(SomeIncluderConfigurationOperation).to receive(:retrieve!).and_return(true)
allow(@client_200).to receive(:response_handler)
expect(@client_200).to receive(:rest_put).with('/rest/fake/1/configuration', {}, item.api_version).and_return(FakeResponse.new)
expect(item).to receive(:set_all)
item.configuration
end
end
end

0 comments on commit 257189a

Please sign in to comment.