-
Notifications
You must be signed in to change notification settings - Fork 16
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
19 changed files
with
356 additions
and
3 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
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,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" |
39 changes: 39 additions & 0 deletions
39
lib/oneview-sdk/resource/api800/c7000/hypervisor_cluster_profile.rb
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,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 |
22 changes: 22 additions & 0 deletions
22
lib/oneview-sdk/resource/api800/synergy/hypervisor_cluster_profile.rb
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 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 |
8 changes: 8 additions & 0 deletions
8
spec/integration/resource/api800/c7000/hypervisor_cluster_profile/create_spec.rb
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,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 |
8 changes: 8 additions & 0 deletions
8
spec/integration/resource/api800/c7000/hypervisor_cluster_profile/delete_spec.rb
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,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 |
7 changes: 7 additions & 0 deletions
7
spec/integration/resource/api800/c7000/hypervisor_cluster_profile/update_spec.rb
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,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 |
8 changes: 8 additions & 0 deletions
8
spec/integration/resource/api800/synergy/hypervisor_cluster_profile/create_spec.rb
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,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 |
8 changes: 8 additions & 0 deletions
8
spec/integration/resource/api800/synergy/hypervisor_cluster_profile/delete_spec.rb
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,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 |
7 changes: 7 additions & 0 deletions
7
spec/integration/resource/api800/synergy/hypervisor_cluster_profile/update_spec.rb
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,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 |
55 changes: 55 additions & 0 deletions
55
spec/integration/shared_examples/hypervisor_cluster_profile/create.rb
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,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 |
26 changes: 26 additions & 0 deletions
26
spec/integration/shared_examples/hypervisor_cluster_profile/delete.rb
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,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 |
27 changes: 27 additions & 0 deletions
27
spec/integration/shared_examples/hypervisor_cluster_profile/update.rb
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 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 |
17 changes: 17 additions & 0 deletions
17
spec/support/fixtures/integration/hypervisor_cluster_profile.json
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,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" | ||
} | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
spec/unit/resource/api800/c7000/hypervisor_cluster_profile_spec.rb
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 @@ | ||
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 |
9 changes: 9 additions & 0 deletions
9
spec/unit/resource/api800/synergy/hypervisor_cluster_profile_spec.rb
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::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 |