Skip to content

Commit

Permalink
Merge 4c79ddd into b1832f4
Browse files Browse the repository at this point in the history
  • Loading branch information
AsisBagga committed May 13, 2020
2 parents b1832f4 + 4c79ddd commit 362fff7
Show file tree
Hide file tree
Showing 21 changed files with 318 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Expand Up @@ -38,7 +38,7 @@ Metrics/PerceivedComplexity:
Enabled: false

Style/GlobalVars:
AllowedVariables: [$config, $secrets, $client, $client_120, $client_300, $client_300_synergy, $config_synergy, $secrets_synergy, $config_i3s, $client_i3s_300, $client_500, $client_500_synergy, $client_i3s_500, $client_600, $client_600_synergy, $client_i3s_600, $client_800, $client_800_synergy, $client_1000, $client_1000_synergy, $client_1200, $client_1200_synergy]
AllowedVariables: [$config, $secrets, $client, $client_120, $client_300, $client_300_synergy, $config_synergy, $secrets_synergy, $config_i3s, $client_i3s_300, $client_500, $client_500_synergy, $client_i3s_500, $client_600, $client_600_synergy, $client_i3s_600, $client_800, $client_800_synergy, $client_1000, $client_1000_synergy, $client_1200, $client_1200_synergy, $client_1600, $client_1600_synergy]

Style/FrozenStringLiteralComment:
Enabled: false
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,11 @@
## v5.12.0 (unreleased)

#### Notes
This release extends support of the SDK to OneView REST API version 1600 (OneView v5.20).

#### Features supported
- Enclosure

## v5.11.0

#### Notes
Expand Down
48 changes: 24 additions & 24 deletions endpoints-support.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions examples/shared_samples/enclosure.rb
Expand Up @@ -26,6 +26,14 @@
# api_version = 500 & variant = Synergy to OneviewSDK::API500::Synergy::Enclosure
# api_version = 600 & variant = C7000 to OneviewSDK::API600::C7000::Enclosure
# api_version = 600 & variant = Synergy to OneviewSDK::API600::Synergy::Enclosure
# api_version = 800 & variant = C7000 to OneviewSDK::API800::C7000::Enclosure
# api_version = 800 & variant = Synergy to OneviewSDK::API800::Synergy::Enclosure
# api_version = 1000 & variant = C7000 to OneviewSDK::API1000::C7000::Enclosure
# api_version = 1000 & variant = Synergy to OneviewSDK::API1000::Synergy::Enclosure
# api_version = 1200 & variant = C7000 to OneviewSDK::API1200::C7000::Enclosure
# api_version = 1200 & variant = Synergy to OneviewSDK::API1200::Synergy::Enclosure
# api_version = 1600 & variant = C7000 to OneviewSDK::API1600::C7000::Enclosure
# api_version = 1600 & variant = Synergy to OneviewSDK::API1600::Synergy::Enclosure

# Resource Class used in this sample
enclosure_class = OneviewSDK.resource_named('Enclosure', @client.api_version)
Expand Down
4 changes: 2 additions & 2 deletions lib/oneview-sdk.rb
@@ -1,4 +1,4 @@
# (c) Copyright 2016 Hewlett Packard Enterprise Development LP
# (c) Copyright 2020 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -26,7 +26,7 @@ module OneviewSDK
env_i3s = %w[I3S_URL I3S_SSL_ENABLED]
ENV_VARS = env_sdk.concat(env_i3s).freeze

SUPPORTED_API_VERSIONS = [200, 300, 500, 600, 800, 1000, 1200].freeze
SUPPORTED_API_VERSIONS = [200, 300, 500, 600, 800, 1000, 1200, 1600].freeze
DEFAULT_API_VERSION = 200
@api_version = DEFAULT_API_VERSION
@api_version_updated = false # Whether or not the API version has been set by the user
Expand Down
66 changes: 66 additions & 0 deletions lib/oneview-sdk/resource/api1600.rb
@@ -0,0 +1,66 @@
# (c) Copyright 2020 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

module OneviewSDK
# Module for API v1600
module API1600
SUPPORTED_VARIANTS = %w[C7000 Synergy].freeze
DEFAULT_VARIANT = 'C7000'.freeze
@variant = DEFAULT_VARIANT
@variant_updated = false # Whether or not the API variant has been set by the user

# Get resource class that matches the type given
# @param [String] type Name of the desired class type
# @param [String] variant Variant (C7000 or Synergy)
# @return [Class] Resource class or nil if not found
def self.resource_named(type, variant = @variant)
raise "API1600 variant '#{variant}' is not supported! Try one of #{SUPPORTED_VARIANTS}" unless SUPPORTED_VARIANTS.include?(variant.to_s)
new_type = type.to_s.downcase.gsub(/[ -_]/, '')
api_module = OneviewSDK::API1600.const_get(variant)
api_module.constants.each do |c|
klass = api_module.const_get(c)
next unless klass.is_a?(Class)
name = klass.name.split('::').last.downcase.delete('_').delete('-')
return klass if new_type =~ /^#{name}[s]?$/
end
nil
end

# Get the current API1600 variant
def self.variant
@variant
end

# Has the API1600 variant been set by the user?
# @return [TrueClass, FalseClass]
def self.variant_updated?
@variant_updated
end

# Sets the API1600 variant
def self.variant=(variant)
raise "API1600 variant '#{variant}' is not supported! Try one of #{SUPPORTED_VARIANTS}" unless SUPPORTED_VARIANTS.include?(variant)
@variant_updated = true
@variant = variant
end

# Helps redirect resources to the correct API1600 variant
def self.const_missing(const)
api1600_module = OneviewSDK::API1600.const_get(@variant.to_s)
api1600_module.const_get(const)
rescue NameError
raise NameError, "The #{const} method or resource does not exist for OneView API1600 variant #{@variant}."
end
end
end

# Load all API1600-specific resources:
Dir[File.dirname(__FILE__) + '/api1600/*.rb'].each { |file| require file }
27 changes: 27 additions & 0 deletions lib/oneview-sdk/resource/api1600/c7000.rb
@@ -0,0 +1,27 @@
# (c) Copyright 2020 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

module OneviewSDK
module API1600
# Module for API1600 C7000
module C7000
# Get resource class that matches the type given
# @param [String] type Name of the desired class type
# @return [Class] Resource class or nil if not found
def self.resource_named(type)
OneviewSDK::API1600.resource_named(type, 'C7000')
end
end
end
end

# Load all API-specific resources:
Dir[File.dirname(__FILE__) + '/c7000/*.rb'].each { |file| require file }
22 changes: 22 additions & 0 deletions lib/oneview-sdk/resource/api1600/c7000/enclosure.rb
@@ -0,0 +1,22 @@
# (c) Copyright 2020 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

require_relative '../../api1200/c7000/enclosure'

module OneviewSDK
module API1600
module C7000
# Enclosure resource implementation for API1600 C7000
class Enclosure < OneviewSDK::API1200::C7000::Enclosure
end
end
end
end
27 changes: 27 additions & 0 deletions lib/oneview-sdk/resource/api1600/synergy.rb
@@ -0,0 +1,27 @@
# (c) Copyright 2020 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

module OneviewSDK
module API1600
# Module for API1600 Synergy
module Synergy
# Get resource class that matches the type given
# @param [String] type Name of the desired class type
# @return [Class] Resource class or nil if not found
def self.resource_named(type)
OneviewSDK::API1600.resource_named(type, 'Synergy')
end
end
end
end

# Load all API-specific resources:
Dir[File.dirname(__FILE__) + '/synergy/*.rb'].each { |file| require file }
22 changes: 22 additions & 0 deletions lib/oneview-sdk/resource/api1600/synergy/enclosure.rb
@@ -0,0 +1,22 @@
# (c) Copyright 2020 Hewlett Packard Enterprise Development LP
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

require_relative '../../api1200/synergy/enclosure'

module OneviewSDK
module API1600
module Synergy
# Enclosure resource implementation for API1600 Synergy
class Enclosure < OneviewSDK::API1200::Synergy::Enclosure
end
end
end
end
19 changes: 19 additions & 0 deletions spec/shared_context.rb
Expand Up @@ -92,6 +92,15 @@
end
end

# Context for API1600 integration testing:
RSpec.shared_context 'integration api1600 context', a: :b do
before :all do
integration_context
$client_1600 ||= OneviewSDK::Client.new($config.merge(api_version: 1600))
$client_1600_synergy ||= OneviewSDK::Client.new($config_synergy.merge(api_version: 1600))
end
end

# Context for Image Streamer API300 integration testing:
RSpec.shared_context 'integration i3s api300 context', a: :b do
before :all do
Expand Down Expand Up @@ -171,6 +180,13 @@
end
end

RSpec.shared_context 'system api1600 context', a: :b do
before(:each) do
load_system_properties
generate_clients(1600)
end
end

# Must set the following environment variables:
# ENV['ONEVIEWSDK_INTEGRATION_CONFIG'] = '/full/path/to/one_view/config.json'
# ENV['ONEVIEWSDK_INTEGRATION_SECRETS'] = '/full/path/to/one_view/secrets.json'
Expand Down Expand Up @@ -290,6 +306,9 @@ def generate_clients(api_version)
when 1200
$client_1200 ||= OneviewSDK::Client.new($config.merge(api_version: api_version))
$client_1200_synergy ||= OneviewSDK::Client.new($config_synergy.merge(api_version: api_version))
when 1600
$client_1600 ||= OneviewSDK::Client.new($config.merge(api_version: api_version))
$client_1600_synergy ||= OneviewSDK::Client.new($config_synergy.merge(api_version: api_version))
end

allow_any_instance_of(OneviewSDK::Client).to receive(:appliance_api_version).and_call_original
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -115,7 +115,7 @@
config.before(:each) do
unless config.filter_manager.inclusions.rules[:integration] || config.filter_manager.inclusions.rules[:system]
# Mock appliance version and login api requests, as well as loading trusted certs
allow_any_instance_of(OneviewSDK::Client).to receive(:appliance_api_version).and_return(1200)
allow_any_instance_of(OneviewSDK::Client).to receive(:appliance_api_version).and_return(1600)
allow_any_instance_of(OneviewSDK::Client).to receive(:login).and_return('secretToken')
allow_any_instance_of(OneviewSDK::ImageStreamer::Client).to receive(:appliance_i3s_api_version).and_return(1020)
allow(OneviewSDK::SSLHelper).to receive(:load_trusted_certs).and_return(nil)
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/cli/version_spec.rb
Expand Up @@ -11,7 +11,7 @@
end

it 'prints the appliance version' do
expect { command }.to output(/OneView appliance API version at .* = 1200/).to_stdout_from_any_process
expect { command }.to output(/OneView appliance API version at .* = 1600/).to_stdout_from_any_process
end

it 'requires the url to be set' do
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/client_spec.rb
Expand Up @@ -84,10 +84,10 @@
end

it 'warns if the api level is greater than the appliance api version' do
options = { url: 'https://oneview.example.com', token: 'token123', api_version: 1400 }
options = { url: 'https://oneview.example.com', token: 'token123', api_version: 1800 }
client = nil
expect { client = OneviewSDK::Client.new(options) }.to output(/is greater than the appliance API version/).to_stdout_from_any_process
expect(client.api_version).to eq(1400)
expect(client.api_version).to eq(1800)
end

it 'sets @print_wait_dots to false by default' do
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/oneview_sdk_spec.rb
Expand Up @@ -5,11 +5,11 @@
it 'has a list of supported api versions' do
versions = described_class::SUPPORTED_API_VERSIONS
expect(versions).to be_a Array
[200, 300, 500, 600, 800, 1000, 1200].each { |v| expect(versions).to include(v) }
[200, 300, 500, 600, 800, 1000, 1200, 1600].each { |v| expect(versions).to include(v) }
end

it 'returns a valid API version' do
%w[API200 API300 API500 API600 API800 API1000 API1200].each { |v| expect { OneviewSDK.const_get(v) }.not_to raise_error }
%w[API200 API300 API500 API600 API800 API1000 API1200 API1600].each { |v| expect { OneviewSDK.const_get(v) }.not_to raise_error }
end

it 'raises an error when an invalid API300 version is called' do
Expand Down
9 changes: 9 additions & 0 deletions spec/unit/resource/api1600/c7000/enclosure_spec.rb
@@ -0,0 +1,9 @@
require 'spec_helper'

RSpec.describe OneviewSDK::API1600::C7000::Enclosure do
include_context 'shared context'

it 'inherits from OneviewSDK::API1200::C7000::Enclosure' do
expect(described_class).to be < OneviewSDK::API1200::C7000::Enclosure
end
end
10 changes: 10 additions & 0 deletions spec/unit/resource/api1600/c7000_spec.rb
@@ -0,0 +1,10 @@
require 'spec_helper'

RSpec.describe OneviewSDK::API1600::C7000 do
describe '#resource_named' do
it 'calls the OneviewSDK::API1600.resource_named method' do
expect(OneviewSDK::API1600).to receive(:resource_named).with('ConnectionTemplate', 'C7000')
described_class.resource_named('ConnectionTemplate')
end
end
end
9 changes: 9 additions & 0 deletions spec/unit/resource/api1600/synergy/enclosure_spec.rb
@@ -0,0 +1,9 @@
require 'spec_helper'

RSpec.describe OneviewSDK::API1600::Synergy::Enclosure do
include_context 'shared context'

it 'inherits from OneviewSDK::API1200::Synergy::Enclosure' do
expect(described_class).to be < OneviewSDK::API1200::Synergy::Enclosure
end
end
10 changes: 10 additions & 0 deletions spec/unit/resource/api1600/synergy_spec.rb
@@ -0,0 +1,10 @@
require 'spec_helper'

RSpec.describe OneviewSDK::API1600::Synergy do
describe '#resource_named' do
it 'calls the OneviewSDK::API1600.resource_named method' do
expect(OneviewSDK::API1600).to receive(:resource_named).with('ConnectionTemplate', 'Synergy')
described_class.resource_named('ConnectionTemplate')
end
end
end
47 changes: 47 additions & 0 deletions spec/unit/resource/api1600_spec.rb
@@ -0,0 +1,47 @@
require 'spec_helper'

RSpec.describe OneviewSDK::API1600 do
it 'has a list of supported variants' do
variants = described_class::SUPPORTED_VARIANTS
expect(variants).to be_a Array
%w[C7000 Synergy].each { |v| expect(variants).to include(v) }
end

it 'returns a valid API1600 variant' do
%w[C7000 Synergy].each { |v| expect { OneviewSDK::API1600.const_get(v) }.not_to raise_error }
end

it 'raises an error when an invalid API1600 variant is called' do
expect { OneviewSDK::API1600::C6000 }
.to raise_error(NameError, 'The C6000 method or resource does not exist for OneView API1600 variant C7000.')
end

it 'has a default api variant' do
expect(described_class::DEFAULT_VARIANT).to eq('C7000')
end

describe '#resource_named' do
it 'gets the correct resource class' do
expect(described_class.resource_named('Enclosure')).to eq(described_class::Enclosure)
end

it 'allows you to override the variant' do
expect(described_class.resource_named('Enclosure', 'Synergy')).to eq(described_class::Synergy::Enclosure)
expect(described_class.resource_named('Enclosure', 'C7000')).to eq(described_class::C7000::Enclosure)
end
end

describe '#variant' do
it 'gets the current variant' do
expect(described_class::SUPPORTED_VARIANTS).to include(OneviewSDK::API1600.variant)
end
end

describe '#variant=' do
it 'sets the current variant' do
OneviewSDK::API1600.variant = 'Synergy'
expect(OneviewSDK::API1600.variant).to eq('Synergy')
expect(OneviewSDK::API1600.variant_updated?).to eq(true)
end
end
end

0 comments on commit 362fff7

Please sign in to comment.