diff --git a/lib/oneview-sdk/resource/api800.rb b/lib/oneview-sdk/resource/api800.rb new file mode 100644 index 000000000..4cbb11da8 --- /dev/null +++ b/lib/oneview-sdk/resource/api800.rb @@ -0,0 +1,66 @@ +# (c) Copyright 2017 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 v800 + module API800 + 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 "API800 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::API800.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 API800 variant + def self.variant + @variant + end + + # Has the API800 variant been set by the user? + # @return [TrueClass, FalseClass] + def self.variant_updated? + @variant_updated + end + + # Sets the API800 variant + def self.variant=(variant) + raise "API800 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 API800 variant + def self.const_missing(const) + api800_module = OneviewSDK::API800.const_get(@variant.to_s) + api800_module.const_get(const) + rescue NameError + raise NameError, "The #{const} method or resource does not exist for OneView API800 variant #{@variant}." + end + end +end + +# Load all API800-specific resources: +Dir[File.dirname(__FILE__) + '/api800/*.rb'].each { |file| require file } diff --git a/lib/oneview-sdk/resource/api800/c7000.rb b/lib/oneview-sdk/resource/api800/c7000.rb new file mode 100644 index 000000000..5acbb2f4e --- /dev/null +++ b/lib/oneview-sdk/resource/api800/c7000.rb @@ -0,0 +1,27 @@ +# (c) Copyright 2017 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 API800 + # Module for API800 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::API800.resource_named(type, 'C7000') + end + end + end +end + +# Load all API-specific resources: +Dir[File.dirname(__FILE__) + '/c7000/*.rb'].each { |file| require file } diff --git a/lib/oneview-sdk/resource/api800/c7000/server_profile.rb b/lib/oneview-sdk/resource/api800/c7000/server_profile.rb new file mode 100644 index 000000000..a56254a2c --- /dev/null +++ b/lib/oneview-sdk/resource/api800/c7000/server_profile.rb @@ -0,0 +1,22 @@ +# (c) Copyright 2017 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 '../../api300/c7000/server_profile' + +module OneviewSDK + module API800 + module C7000 + # Server Profile resource implementation on API800 C7000 + class ServerProfile < OneviewSDK::API600::C7000::ServerProfile + end + end + end +end diff --git a/lib/oneview-sdk/resource/api800/c7000/server_profile_template.rb b/lib/oneview-sdk/resource/api800/c7000/server_profile_template.rb new file mode 100644 index 000000000..92d6534b2 --- /dev/null +++ b/lib/oneview-sdk/resource/api800/c7000/server_profile_template.rb @@ -0,0 +1,33 @@ +# (C) Copyright 2017 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 '../../api600/c7000/server_profile_template' + +module OneviewSDK + module API800 + module C7000 + # Server Profile Template resource implementation on API800 C7000 + class ServerProfileTemplate < OneviewSDK::API600::C7000::ServerProfileTemplate + + # Create a resource object, associate it with a client, and set its properties. + # @param [OneviewSDK::Client] client The client object for the OneView appliance + # @param [Hash] params The options for this resource (key-value pairs) + # @param [Integer] api_ver The api version to use when interracting with this resource. + def initialize(client, params = {}, api_ver = nil) + @data ||= {} + # Default values + @data['type'] ||= 'ServerProfileTemplateV5' + super + end + end + end + end +end diff --git a/lib/oneview-sdk/resource/api800/synergy.rb b/lib/oneview-sdk/resource/api800/synergy.rb new file mode 100644 index 000000000..8620d9b82 --- /dev/null +++ b/lib/oneview-sdk/resource/api800/synergy.rb @@ -0,0 +1,27 @@ +# (c) Copyright 2017 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 API800 + # Module for API800 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::API800.resource_named(type, 'Synergy') + end + end + end +end + +# Load all API-specific resources: +Dir[File.dirname(__FILE__) + '/synergy/*.rb'].each { |file| require file } diff --git a/lib/oneview-sdk/resource/api800/synergy/server_profile.rb b/lib/oneview-sdk/resource/api800/synergy/server_profile.rb new file mode 100644 index 000000000..e9fc885f4 --- /dev/null +++ b/lib/oneview-sdk/resource/api800/synergy/server_profile.rb @@ -0,0 +1,25 @@ +# (c) Copyright 2017 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 '../../api300/synergy/server_profile' +require_relative '../c7000/server_profile' + +module OneviewSDK + module API800 + module Synergy + # Server profile resource implementation for API800 Synergy + class ServerProfile < OneviewSDK::API600::C7000::ServerProfile + extend OneviewSDK::API300::Synergy::SASLogicalJBODHelper + include OneviewSDK::API300::Synergy::ServerProfileHelper + end + end + end +end diff --git a/lib/oneview-sdk/resource/api800/synergy/server_profile_template.rb b/lib/oneview-sdk/resource/api800/synergy/server_profile_template.rb new file mode 100644 index 000000000..c67714361 --- /dev/null +++ b/lib/oneview-sdk/resource/api800/synergy/server_profile_template.rb @@ -0,0 +1,22 @@ +# (C) Copyright 2017 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 '../c7000/server_profile_template' + +module OneviewSDK + module API800 + module Synergy + # Server Profile Template resource implementation for API800 Synergy + class ServerProfileTemplate < OneviewSDK::API800::C7000::ServerProfileTemplate + end + end + end +end diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index 080c42da0..431267a29 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -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: 800 } + options = { url: 'https://oneview.example.com', token: 'token123', api_version: 1000 } 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(800) + expect(client.api_version).to eq(1000) end it 'sets @print_wait_dots to false by default' do diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index 015839a38..b48c88a9a 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -36,7 +36,7 @@ end it 'can\'t use an api version greater than the client\'s max' do - expect { OneviewSDK::Resource.new(@client_200, {}, 800) }.to raise_error(OneviewSDK::UnsupportedVersion, /is greater than the client's max/) + expect { OneviewSDK::Resource.new(@client_200, {}, 1000) }.to raise_error(OneviewSDK::UnsupportedVersion, /is greater than the client's max/) end it 'starts with an empty data hash' do