-
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
21 changed files
with
319 additions
and
1 deletion.
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,67 @@ | ||
# (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 manager | ||
# NOTE: This will create a hypervisor manager named 'vcenter.corp.com', 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::HypervisorManager | ||
# api_version = 800 & variant = Synergy to OneviewSDK::API800::Synergy::HypervisorManager | ||
|
||
raise 'ERROR: Must set @hypervisor_manager_ip in _client.rb' unless @hypervisor_manager_ip | ||
raise 'ERROR: Must set @hypervisor_manager_username in _client.rb' unless @hypervisor_manager_username | ||
raise 'ERROR: Must set @hypervisor_manager_password in _client.rb' unless @hypervisor_manager_password | ||
|
||
# Resource Class used in this sample | ||
hypervisor_manager_class = OneviewSDK.resource_named('HypervisorManager', @client.api_version) | ||
|
||
options = { | ||
name: @hypervisor_manager_ip, | ||
username: @hypervisor_manager_username, | ||
password: @hypervisor_manager_password | ||
} | ||
|
||
hm = hypervisor_manager_class.new(@client, options) | ||
hm.create! | ||
puts "\nCreated hypervisor-manager '#{hm[:name]}' sucessfully.\n uri = '#{hm[:uri]}'" | ||
|
||
# Find recently created hypervisor manager by name | ||
matches = hypervisor_manager_class.find_by(@client, name: hm[:name]) | ||
hm2 = matches.first | ||
puts "\nFound hypervisor-manager by name: '#{hm2[:name]}'.\n uri = '#{hm2[:uri]}'" | ||
|
||
# Retrieve recently created hypervisor manager | ||
hm3 = hypervisor_manager_class.new(@client, name: hm[:name]) | ||
hm3.retrieve! | ||
puts "\nRetrieved hypervisor-manager data by name: '#{hm3[:name]}'.\n uri = '#{hm3[:uri]}'" | ||
|
||
# Update hypervisor manager registration | ||
attribute = { name: @hypervisor_manager_ip } | ||
hm2.update(attribute) | ||
puts "\nUpdated hypervisor-manager: '#{hm2[:name]}'.\n uri = '#{hm2[:uri]}'" | ||
puts "with attribute: #{attribute}" | ||
|
||
# Example: List all hypervisor managers certain attributes | ||
attributes = { name: @hypervisor_manager_ip } | ||
puts "\nHypervisor manager with #{attributes}" | ||
hypervisor_manager_class.find_by(@client, attributes).each do |hypervisor_manager| | ||
puts " #{hypervisor_manager[:name]}" | ||
end | ||
|
||
# Delete this hypervisor manager | ||
hm.delete | ||
puts "\nSucessfully deleted hypervisor-manager '#{hm[:name]}'." |
33 changes: 33 additions & 0 deletions
33
lib/oneview-sdk/resource/api800/c7000/hypervisor_manager.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,33 @@ | ||
# (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 '../../../resource' | ||
|
||
module OneviewSDK | ||
module API800 | ||
module C7000 | ||
# Hypervisor Manager resource implementation | ||
class HypervisorManager < OneviewSDK::Resource | ||
BASE_URI = '/rest/hypervisor-managers'.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['hypervisorType'] ||= 'Vmware' | ||
@data['type'] ||= 'HypervisorManagerV2' | ||
end | ||
end | ||
end | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
lib/oneview-sdk/resource/api800/synergy/hypervisor_manager.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 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 '../c7000/hypervisor_manager' | ||
|
||
module OneviewSDK | ||
module API800 | ||
module Synergy | ||
# Hypervisor Manager resource implementation | ||
class HypervisorManager < OneviewSDK::API800::C7000::HypervisorManager | ||
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
8 changes: 8 additions & 0 deletions
8
spec/integration/resource/api800/c7000/hypervisor_manager/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::HypervisorManager | ||
RSpec.describe klass, integration: true, type: CREATE, sequence: seq(klass) do | ||
include_examples 'HypervisorManagerCreateExample', 'integration api800 context' do | ||
let(:current_client) { $client_800 } | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
spec/integration/resource/api800/c7000/hypervisor_manager/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::HypervisorManager | ||
RSpec.describe klass, integration: true, type: DELETE, sequence: rseq(klass) do | ||
include_examples 'HypervisorManagerDeleteExample', 'integration api800 context' do | ||
let(:current_client) { $client_800 } | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
spec/integration/resource/api800/c7000/hypervisor_manager/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::HypervisorManager, integration: true, type: UPDATE do | ||
include_examples 'HypervisorManagerUpdateExample', 'integration api800 context' do | ||
let(:current_client) { $client_800 } | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
spec/integration/resource/api800/synergy/hypervisor_manager/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::HypervisorManager | ||
RSpec.describe klass, integration: true, type: CREATE, sequence: seq(klass) do | ||
include_examples 'HypervisorManagerCreateExample', 'integration api800 context' do | ||
let(:current_client) { $client_800 } | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
spec/integration/resource/api800/synergy/hypervisor_manager/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::HypervisorManager | ||
RSpec.describe klass, integration: true, type: DELETE, sequence: rseq(klass) do | ||
include_examples 'HypervisorManagerDeleteExample', 'integration api800 context' do | ||
let(:current_client) { $client_800 } | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
spec/integration/resource/api800/synergy/hypervisor_manager/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::HypervisorManager, integration: true, type: UPDATE do | ||
include_examples 'HypervisorManagerUpdateExample', 'integration api800 context' do | ||
let(:current_client) { $client_800 } | ||
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
48 changes: 48 additions & 0 deletions
48
spec/integration/shared_examples/hypervisor_manager/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,48 @@ | ||
# (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. | ||
|
||
RSpec.shared_examples 'HypervisorManagerCreateExample' do |context_name| | ||
include_context context_name | ||
|
||
let(:file_path) { 'spec/support/fixtures/integration/hypervisor_manager.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(HYPERVISOR_MGR_NAME) | ||
expect(item[:hypervisorType]).to eq('Vmware') | ||
end | ||
end | ||
|
||
describe '#retrieve!' do | ||
it 'retrieves the resource' do | ||
item = described_class.new(current_client, name: HYPERVISOR_MGR_NAME) | ||
item.retrieve! | ||
expect(item[:name]).to eq(HYPERVISOR_MGR_NAME) | ||
expect(item[:hypervisorType]).to eq('Vmware') | ||
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(HYPERVISOR_MGR_NAME) | ||
end | ||
|
||
it 'finds hypervisor manager by multiple attributes' do | ||
attrs = { name: HYPERVISOR_MGR_NAME, hypervisorType: 'Vmware' } | ||
names = described_class.find_by(current_client, attrs).map { |item| item[:name] } | ||
expect(names).to include(HYPERVISOR_MGR_NAME) | ||
end | ||
end | ||
end |
27 changes: 27 additions & 0 deletions
27
spec/integration/shared_examples/hypervisor_manager/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,27 @@ | ||
# (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. | ||
|
||
RSpec.shared_examples 'HypervisorManagerDeleteExample' do |context_name| | ||
include_context context_name | ||
|
||
describe '#delete' do | ||
it 'deletes the resource' do | ||
item = described_class.new(current_client, name: HYPERVISOR_MGR_NAME) | ||
|
||
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_manager/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 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. | ||
|
||
RSpec.shared_examples 'HypervisorManagerUpdateExample' do |context_name| | ||
include_context context_name | ||
|
||
describe '#update' do | ||
it 'updates the hypervisor manager name' do | ||
item = described_class.new(current_client, name: HYPERVISOR_MGR_NAME) | ||
item.retrieve! | ||
item.update(name: HYPERVISOR_MGR_NAME) | ||
item.refresh | ||
expect(item[:name]).to eq(HYPERVISOR_MGR_NAME) | ||
item.update(name: HYPERVISOR_MGR_NAME) # Put it back to normal | ||
item.refresh | ||
expect(item[:name]).to eq(HYPERVISOR_MGR_NAME) | ||
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 @@ | ||
{ | ||
"data": { | ||
"name": "172.18.13.11", | ||
"username": "dcs", | ||
"password": "dcs", | ||
"hypervisorType": "Vmware", | ||
"type": "HypervisorManagerV2" | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
spec/unit/resource/api800/c7000/hypervisor_manager_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,13 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe OneviewSDK::API800::C7000::HypervisorManager do | ||
include_context 'shared context' | ||
|
||
describe '#initialize' do | ||
it 'sets the defaults correctly' do | ||
item = OneviewSDK::API800::C7000::HypervisorManager.new(@client_800) | ||
expect(item[:type]).to eq('HypervisorManagerV2') | ||
expect(item[:hypervisorType]).to eq('Vmware') | ||
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::API800::Synergy::HypervisorManager do | ||
include_context 'shared context' | ||
|
||
it 'inherits from OneviewSDK::API800::C7000::HypervisorManager' do | ||
expect(described_class).to be < OneviewSDK::API800::C7000::HypervisorManager | ||
end | ||
end |