-
Notifications
You must be signed in to change notification settings - Fork 16
/
hypervisor_manager.rb
65 lines (53 loc) · 2.63 KB
/
hypervisor_manager.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# (C) Copyright 2020 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:
# - 800, 1000, 1200, 1600 and 1800
# Supported Variants:
# - C7000 and Synergy for all API versions
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]}'."