-
Notifications
You must be signed in to change notification settings - Fork 16
/
enclosure_group.rb
94 lines (77 loc) · 3.41 KB
/
enclosure_group.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# (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 '../_client' # Gives access to @client
# Example: Create an enclosure group for an API300 C7000 Appliance
# NOTE: This will create an enclosure group named 'OneViewSDK Test Enclosure Group', then delete it.
#
# Supported APIs:
# - 200, 300, 500, 600, 800, 1200, 1600 and 1800.
# Supported Variants:
# C7000 and Synergy for all API versions
# Resource Class used in this sample
encl_group_class = OneviewSDK.resource_named('EnclosureGroup', @client.api_version)
# LogicalInterconnectGroup class used in this sample.
lig_class = OneviewSDK.resource_named('LogicalInterconnectGroup', @client.api_version)
type = 'enclosure group'
encl_group_name = 'OneViewSDK Test Enclosure Group'
interconnect_bay_mapping = [
{ interconnectBay: 3, logicalInterconnectGroupUri: '/rest/logical-interconnect-groups/6aabd433-7ed0-4c59-963c-c3f36bbd4f85' },
{ interconnectBay: 6, logicalInterconnectGroupUri: '/rest/logical-interconnect-groups/6aabd433-7ed0-4c59-963c-c3f36bbd4f85' }
]
options = {
name: encl_group_name,
ipAddressingMode: 'External',
enclosureCount: 1,
interconnectBayMappings: interconnect_bay_mapping
}
item = encl_group_class.new(@client, options)
lig = lig_class.get_all(@client).first
item.add_logical_interconnect_group(lig)
if @client.api_version >= 600
# Gets enclosure group by scopeUris
scope_class = OneviewSDK.resource_named('Scope', @client.api_version)
scope_item = scope_class.get_all(@client).first
query = {
scopeUris: scope_item['uri']
}
puts "\nGets enclosure group with scope '#{query[:scopeUris]}'"
items = encl_group_class.get_all_with_query(@client, query)
puts "Found enclosure group '#{items}'."
end
puts "\nCreating an #{type} with name = '#{item[:name]}' and logical interconnect group uri = '#{lig[:uri]}''"
item.create!
puts "\nCreated #{type} '#{item[:name]}' sucessfully.\n uri = '#{item[:uri]}'"
item2 = encl_group_class.new(@client, name: encl_group_name)
item2.retrieve!
puts "\nFound #{type} by name: '#{item[:name]}'.\n uri = '#{item2[:uri]}'"
item.refresh
puts "\nUpdating an #{type} with name = '#{item[:name]}' and uri = '#{item[:uri]}''"
item.update(name: 'OneViewSDK Test Enclosure_Group Updated')
puts "\nUpdated #{type} with new name = '#{item[:name]}' sucessfully."
begin
command = '#TEST COMMAND'
puts "\nSetting a script with command = '#{command}'"
item.set_script(command)
puts "\nScript attributed sucessfully."
rescue OneviewSDK::MethodUnavailable => e
puts "\n#{e}. Available only for C7000."
end
begin
puts "\nGetting a script"
script = item.get_script
puts "\nScript retrieved sucessfully."
puts script
rescue OneviewSDK::MethodUnavailable => e
puts "\n#{e}. Available only for C7000."
end
puts "\nDeleting the #{type} with name = '#{item[:name]}' and uri = '#{item[:uri]}''"
item.delete
puts "\nSucessfully deleted #{type} '#{item[:name]}'."