Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
318 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.