diff --git a/.rubocop.yml b/.rubocop.yml index f41b60249..d3b2682d0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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_600, $client_600_synergy, $client_800, $client_800_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] Style/FrozenStringLiteralComment: Enabled: false diff --git a/endpoints-support.md b/endpoints-support.md index 6b5f9a2af..666b2f517 100644 --- a/endpoints-support.md +++ b/endpoints-support.md @@ -145,6 +145,13 @@ OneviewSDK::Datacenter.find_by(@client, width: 11000).map(&:remove) |/rest/hypervisor-managers/{id} | GET | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | |/rest/hypervisor-managers/{id} | PUT | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | |/rest/hypervisor-managers/{id} | DELETE | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | +| **Hypervisor Cluster Profiles** | +|/rest/hypervisor-cluster-profiles | GET | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | +|/rest/hypervisor-cluster-profiles | POST | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | +|/rest/hypervisor-cluster-profiles/{id} | GET | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | +|/rest/hypervisor-cluster-profiles/{id} | PUT | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | +|/rest/hypervisor-cluster-profiles/{id}/compliance-preview | GET | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | +|/rest/hypervisor-cluster-profiles/{id} | DELETE | :heavy_minus_sign: | :heavy_minus_sign: | :heavy_minus_sign: | :white_check_mark: | | **ID Pools** | |/rest/id-pools/{poolType} | GET | :white_check_mark: | :white_check_mark: | :white_check_mark: | |/rest/id-pools/{poolType} | PUT | :white_check_mark: | :white_check_mark: | :white_check_mark: | diff --git a/examples/_client.rb.example b/examples/_client.rb.example index 9c2181ea8..16aeb7c9d 100644 --- a/examples/_client.rb.example +++ b/examples/_client.rb.example @@ -57,3 +57,12 @@ puts "Connected to OneView appliance at #{@client.url}\n\n" # @hypervisor_manager_ip = '172.18.13.11' # @hypervisor_manager_username ='dcs' # @hypervisor_manager_password ='dcs' +# @hypervisor_cluster_profile_name = "Cluster5" +# @hypervisor_path = "DC2" +# @hypervisor_server_password = "dcs" +# @hypervisor_host_prefix = "Test-Cluster-host" +# @hypervisor_hypervisorType = "Vmware" +# @hypervisor_type = "HypervisorClusterProfileV3" +# @hypervisor_manager_uri = "/rest/hypervisor-managers/befc6bd9-0366-4fd9-a3fc-c92ab0df3603" +# @hypervisor_serverProfileTemplateUri = "/rest/server-profile-templates/c865a62c-8fd8-414c-8c16-3f7ca75ab2ba" +# @hypervisor_deploymentPlanUri = "/rest/os-deployment-plans/c54e1dab-cc14-48fa-92bf-d301671fb0cf" diff --git a/examples/shared_samples/hypervisor_cluster_profile.rb b/examples/shared_samples/hypervisor_cluster_profile.rb new file mode 100644 index 000000000..04786a323 --- /dev/null +++ b/examples/shared_samples/hypervisor_cluster_profile.rb @@ -0,0 +1,71 @@ +# (C) Copyright 2018 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 '../_client' # Gives access to @client + +# Example: Create/Update/Delete hypervisor cluster profile +# NOTE: This will create a hypervisor cluster profile named 'cluster5', update it and then delete it. +# +# Supported APIs: +# - API800 for C7000 +# - API800 for Synergy + +# Resources that can be created according to parameters: +# api_version = 800 & variant = C7000 to OneviewSDK::API800::C7000::HypervisorClusterProfile +# api_version = 800 & variant = Synergy to OneviewSDK::API800::Synergy::HypervisorClusterProfile + +# Resource Class used in this sample +hypervisor_cluster_profile_class = OneviewSDK.resource_named('HypervisorClusterProfile', @client.api_version) + +options = { + type: @hypervisor_type, + name: @hypervisor_cluster_profile_name, + hypervisorManagerUri: @hypervisor_manager_uri, + path: @hypervisor_path, + hypervisorType: @hypervisor_hypervisorType, + hypervisorHostProfileTemplate: { + serverProfileTemplateUri: @hypervisor_serverProfileTemplateUri, + deploymentPlan: { + deploymentPlanUri: @hypervisor_deploymentPlanUri, + serverPassword: @hypervisor_server_password + }, + hostprefix: @hypervisor_host_prefix + } +} + +hcp = hypervisor_cluster_profile_class.new(@client, options) +hcp.create! +puts "\nCreated hypervisor-cluster_profile '#{hcp[:name]}' sucessfully.\n uri = '#{hcp[:uri]}'" + +# Lists all the hypervisor cluster profiles present +puts "\nListing all the available cluster profiles\n" +hypervisor_cluster_profile_class.find_by(@client, {}).each do |profile| + puts "#{profile['name']} was found." +end + +# Find cluster profile by name +hcp_by_name = hypervisor_cluster_profile_class.find_by(@client, name: hypervisor_cluster_profile_class.find_by(@client, {}).first[:name]).first +puts "\nFound hypervisor cluster profile by name: '#{hcp_by_name[:name]}'.\n uri : '#{hcp_by_name[:uri]}'" + +# Update a hypervisor cluster profile +hcp2 = hypervisor_cluster_profile_class.find_by(@client, {}).first +data = { description: 'New Description' } +puts "\nCluster profile description before update : '#{hcp2[:description]}'" +hcp2.update(data) +puts "Cluster profile description after update : '#{hcp2[:description]}'\n" + +# Listing compliance details of the previously updated cluster profile +cp = hcp2.compliance_preview +puts "\nCompliance preview details are :\n#{cp}\n" + +# Deletes the created hypervisor cluster profile +hcp.delete +puts "\nSuccesfully deleted the cluster profile" diff --git a/lib/oneview-sdk/resource/api800/c7000/hypervisor_cluster_profile.rb b/lib/oneview-sdk/resource/api800/c7000/hypervisor_cluster_profile.rb new file mode 100644 index 000000000..39e469ac4 --- /dev/null +++ b/lib/oneview-sdk/resource/api800/c7000/hypervisor_cluster_profile.rb @@ -0,0 +1,39 @@ +# (C) Copyright 2016 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 '../../../resource' + +module OneviewSDK + module API800 + module C7000 + # Hypervisor Cluster profile resource implementation + class HypervisorClusterProfile < OneviewSDK::Resource + BASE_URI = '/rest/hypervisor-cluster-profiles'.freeze + + # 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) + super + # Default values + @data['type'] ||= 'HypervisorClusterProfileListV3' + end + + # Gets the preview of manual and automatic updates required to make the cluster profile consistent with its template. + def compliance_preview + ensure_client && ensure_uri + @client.response_handler(@client.rest_get(@data['uri'] + '/compliance-preview', {}, @api_version)) + end + end + end + end +end diff --git a/lib/oneview-sdk/resource/api800/synergy/hypervisor_cluster_profile.rb b/lib/oneview-sdk/resource/api800/synergy/hypervisor_cluster_profile.rb new file mode 100644 index 000000000..854336ddd --- /dev/null +++ b/lib/oneview-sdk/resource/api800/synergy/hypervisor_cluster_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 '../c7000/hypervisor_cluster_profile' + +module OneviewSDK + module API800 + module Synergy + # Hypervisor cluster profile resource implementation for API800 Synergy + class HypervisorClusterProfile < OneviewSDK::API800::C7000::HypervisorClusterProfile + end + end + end +end diff --git a/spec/integration/resource/api800/c7000/hypervisor_cluster_profile/create_spec.rb b/spec/integration/resource/api800/c7000/hypervisor_cluster_profile/create_spec.rb new file mode 100644 index 000000000..d5ed99baf --- /dev/null +++ b/spec/integration/resource/api800/c7000/hypervisor_cluster_profile/create_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +klass = OneviewSDK::API800::C7000::HypervisorClusterProfile +RSpec.describe klass, integration: true, type: CREATE, sequence: seq(klass) do + include_examples 'HypervisorClusterProfileCreateExample', 'integration api800 context' do + let(:current_client) { $client_800 } + end +end diff --git a/spec/integration/resource/api800/c7000/hypervisor_cluster_profile/delete_spec.rb b/spec/integration/resource/api800/c7000/hypervisor_cluster_profile/delete_spec.rb new file mode 100644 index 000000000..824e3c829 --- /dev/null +++ b/spec/integration/resource/api800/c7000/hypervisor_cluster_profile/delete_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +klass = OneviewSDK::API800::C7000::HypervisorClusterProfile +RSpec.describe klass, integration: true, type: DELETE, sequence: rseq(klass) do + include_examples 'HypervisorClusterProfileDeleteExample', 'integration api800 context' do + let(:current_client) { $client_800 } + end +end diff --git a/spec/integration/resource/api800/c7000/hypervisor_cluster_profile/update_spec.rb b/spec/integration/resource/api800/c7000/hypervisor_cluster_profile/update_spec.rb new file mode 100644 index 000000000..5c74176f6 --- /dev/null +++ b/spec/integration/resource/api800/c7000/hypervisor_cluster_profile/update_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +RSpec.describe OneviewSDK::API800::C7000::HypervisorClusterProfile, integration: true, type: UPDATE do + include_examples 'HypervisorClusterProfileUpdateExample', 'integration api800 context' do + let(:current_client) { $client_800 } + end +end diff --git a/spec/integration/resource/api800/synergy/hypervisor_cluster_profile/create_spec.rb b/spec/integration/resource/api800/synergy/hypervisor_cluster_profile/create_spec.rb new file mode 100644 index 000000000..508855f96 --- /dev/null +++ b/spec/integration/resource/api800/synergy/hypervisor_cluster_profile/create_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +klass = OneviewSDK::API800::Synergy::HypervisorClusterProfile +RSpec.describe klass, integration: true, type: CREATE, sequence: seq(klass) do + include_examples 'HypervisorClusterProfileCreateExample', 'integration api800 context' do + let(:current_client) { $client_800 } + end +end diff --git a/spec/integration/resource/api800/synergy/hypervisor_cluster_profile/delete_spec.rb b/spec/integration/resource/api800/synergy/hypervisor_cluster_profile/delete_spec.rb new file mode 100644 index 000000000..f87847afb --- /dev/null +++ b/spec/integration/resource/api800/synergy/hypervisor_cluster_profile/delete_spec.rb @@ -0,0 +1,8 @@ +require 'spec_helper' + +klass = OneviewSDK::API800::Synergy::HypervisorClusterProfile +RSpec.describe klass, integration: true, type: DELETE, sequence: rseq(klass) do + include_examples 'HypervisorClusterProfileDeleteExample', 'integration api800 context' do + let(:current_client) { $client_800 } + end +end diff --git a/spec/integration/resource/api800/synergy/hypervisor_cluster_profile/update_spec.rb b/spec/integration/resource/api800/synergy/hypervisor_cluster_profile/update_spec.rb new file mode 100644 index 000000000..0850f1e4a --- /dev/null +++ b/spec/integration/resource/api800/synergy/hypervisor_cluster_profile/update_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +RSpec.describe OneviewSDK::API800::Synergy::HypervisorClusterProfile, integration: true, type: UPDATE do + include_examples 'HypervisorClusterProfileUpdateExample', 'integration api800 context' do + let(:current_client) { $client_800 } + end +end diff --git a/spec/integration/shared_examples/hypervisor_cluster_profile/create.rb b/spec/integration/shared_examples/hypervisor_cluster_profile/create.rb new file mode 100644 index 000000000..4ff035dc7 --- /dev/null +++ b/spec/integration/shared_examples/hypervisor_cluster_profile/create.rb @@ -0,0 +1,55 @@ +# (C) Copyright 2017 Hewlett Packard Enterprise Development LP +# (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. + +RSpec.shared_examples 'HypervisorClusterProfileCreateExample' do |context_name| + include_context context_name + + let(:file_path) { 'spec/support/fixtures/integration/hypervisor_cluster_profile.json' } + + describe '#create' do + it 'can create resources' do + item = described_class.from_file(current_client, file_path) + + item.create + expect(item[:name]).to eq(HYP_CLUSTER_PROF) + expect(item[:hypervisorType]).to eq(Vmware) + expect(item[:deploymentPlanUri]).not_to eq(nil) + expect(item[:type]).to eq('HypervisorClusterProfileV3') + end + end + + describe '#retrieve!' do + it 'retrieves the resource' do + item = described_class.new(current_client, name: HYP_CLUSTER_PROF) + item.retrieve! + expect(item[:name]).to eq(HYP_CLUSTER_PROF) + expect(item[:hypervisorType]).to eq(Vmware) + expect(item[:deploymentPlanUri]).not_to eq(nil) + expect(item[:type]).to eq('HypervisorClusterProfileV3') + end + end + + describe '#find_by' do + it 'returns all resources when the hash is empty' do + names = described_class.find_by(current_client, {}).map { |item| item[:name] } + expect(names).to include(HYP_CLUSTER_PROF) + end + end + + describe '#compliance_preview' do + it 'Gets the compliance preview' do + item = described_class.get_all(current_client).first + item.compliance_preview + expect { item.compliance_preview }.not_to raise_error + end + end +end diff --git a/spec/integration/shared_examples/hypervisor_cluster_profile/delete.rb b/spec/integration/shared_examples/hypervisor_cluster_profile/delete.rb new file mode 100644 index 000000000..4a863450d --- /dev/null +++ b/spec/integration/shared_examples/hypervisor_cluster_profile/delete.rb @@ -0,0 +1,26 @@ +# (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. + +RSpec.shared_examples 'HypervisorClusterProfileDeleteExample' do |context_name| + include_context context_name + + describe '#delete' do + it 'deletes the resource' do + item = described_class.new(current_client, name: HYP_CLUSTER_PROF) + + expect(item.retrieve!).to eq(true) + + expect { item.delete }.not_to raise_error + + expect(item.retrieve!).to eq(false) + end + end +end diff --git a/spec/integration/shared_examples/hypervisor_cluster_profile/update.rb b/spec/integration/shared_examples/hypervisor_cluster_profile/update.rb new file mode 100644 index 000000000..1f7a3b63b --- /dev/null +++ b/spec/integration/shared_examples/hypervisor_cluster_profile/update.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. + +RSpec.shared_examples 'HypervisorClusterProfileUpdateExample' do |context_name| + include_context context_name + + describe '#update' do + it 'updates the network name' do + item = described_class.new(current_client, name: HYP_CLUSTER_PROF) + item.retrieve! + item.update(name: HYP_CLUSTER_PROF_UPDATED) + item.refresh + expect(item[:name]).to eq(HYP_CLUSTER_PROF_UPDATED) + item.update(name: HYP_CLUSTER_PROF) # Put it back to normal + item.refresh + expect(item[:name]).to eq(HYP_CLUSTER_PROF) + end + end +end diff --git a/spec/support/fixtures/integration/hypervisor_cluster_profile.json b/spec/support/fixtures/integration/hypervisor_cluster_profile.json new file mode 100644 index 000000000..4064cbf5c --- /dev/null +++ b/spec/support/fixtures/integration/hypervisor_cluster_profile.json @@ -0,0 +1,17 @@ +{ + "data": { + "type":"HypervisorClusterProfileV3", + "name":"Cluster5", + "hypervisorManagerUri":"/rest/hypervisor-managers/befc6bd9-0366-4fd9-a3fc-c92ab0df3603", + "path":"DC2", + "hypervisorType":"Vmware", + "hypervisorHostProfileTemplate":{ + "serverProfileTemplateUri":"/rest/server-profile-templates/c865a62c-8fd8-414c-8c16-3f7ca75ab2ba", + "deploymentPlan":{ + "deploymentPlanUri":"/rest/os-deployment-plans/c54e1dab-cc14-48fa-92bf-d301671fb0cf", + "serverPassword":"dcs" + }, + "hostprefix":"Test-Cluster-host" + } + } +} diff --git a/spec/system/README.md b/spec/system/README.md index d19a08a44..a4723f92f 100644 --- a/spec/system/README.md +++ b/spec/system/README.md @@ -54,8 +54,6 @@ These config files get loaded and create the following global variables: - `$client_500_synergy`: Client object using API v500 Synergy - `$client_800`: Client object using API v800 C7000 - `$client_800_synergy`: Client object using API v800 Synergy - - `$client_600`: Client object using API v600 C7000 - - `$client_600_synergy`: Client object using API v600 Synergy ## Running the tests The following command must run in your Ruby SDK root directory: diff --git a/spec/unit/resource/api800/c7000/hypervisor_cluster_profile_spec.rb b/spec/unit/resource/api800/c7000/hypervisor_cluster_profile_spec.rb new file mode 100644 index 000000000..8102c5aa8 --- /dev/null +++ b/spec/unit/resource/api800/c7000/hypervisor_cluster_profile_spec.rb @@ -0,0 +1,27 @@ +require_relative '../../../../spec_helper' + +RSpec.describe OneviewSDK::API800::C7000::HypervisorClusterProfile do + include_context 'shared context' + + it 'inherits from Resource' do + expect(described_class).to be < OneviewSDK::Resource + end + + before(:each) do + @item = OneviewSDK::API800::C7000::HypervisorClusterProfile.new(@client_800, uri: '/rest/fake') + end + + describe '#initialize' do + it 'sets the type correctly' do + expect(@item[:type]).to eq('HypervisorClusterProfileListV3') + end + end + + describe '#compliance_preview' do + it 'Makes a GET call' do + expect(@client_800).to receive(:rest_get).with(@item['uri'] + '/compliance-preview', {}, @item.api_version) + .and_return(FakeResponse.new({})) + @item.compliance_preview + end + end +end diff --git a/spec/unit/resource/api800/synergy/hypervisor_cluster_profile_spec.rb b/spec/unit/resource/api800/synergy/hypervisor_cluster_profile_spec.rb new file mode 100644 index 000000000..6d782d89d --- /dev/null +++ b/spec/unit/resource/api800/synergy/hypervisor_cluster_profile_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +RSpec.describe OneviewSDK::API800::Synergy::HypervisorClusterProfile do + include_context 'shared context' + + it 'inherits from OneviewSDK::API800::C7000::HypervisorClusterProfile' do + expect(described_class).to be < OneviewSDK::API800::C7000::HypervisorClusterProfile + end +end