Skip to content

Commit

Permalink
added server profile template resource file for api800
Browse files Browse the repository at this point in the history
  • Loading branch information
sijeesh committed Mar 20, 2018
1 parent b20aa81 commit ed679d0
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 3 deletions.
66 changes: 66 additions & 0 deletions 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 }
27 changes: 27 additions & 0 deletions 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 }
22 changes: 22 additions & 0 deletions 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
33 changes: 33 additions & 0 deletions 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
27 changes: 27 additions & 0 deletions 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 }
25 changes: 25 additions & 0 deletions 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
22 changes: 22 additions & 0 deletions 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
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: 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
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/resource_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit ed679d0

Please sign in to comment.