oneview-sdk 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +81 -2
- data/README.md +118 -113
- data/Rakefile +11 -0
- data/lib/oneview-sdk/cli.rb +21 -15
- data/lib/oneview-sdk/client.rb +34 -21
- data/lib/oneview-sdk/config_loader.rb +12 -1
- data/lib/oneview-sdk/exceptions.rb +55 -0
- data/lib/oneview-sdk/resource/connection_template.rb +48 -0
- data/lib/oneview-sdk/resource/datacenter.rb +77 -0
- data/lib/oneview-sdk/resource/enclosure.rb +46 -24
- data/lib/oneview-sdk/resource/enclosure_group.rb +20 -36
- data/lib/oneview-sdk/resource/ethernet_network.rb +19 -23
- data/lib/oneview-sdk/resource/fabric.rb +41 -0
- data/lib/oneview-sdk/resource/fc_network.rb +15 -16
- data/lib/oneview-sdk/resource/fcoe_network.rb +15 -12
- data/lib/oneview-sdk/resource/firmware_bundle.rb +23 -24
- data/lib/oneview-sdk/resource/firmware_driver.rb +21 -9
- data/lib/oneview-sdk/resource/interconnect.rb +29 -9
- data/lib/oneview-sdk/resource/lig_uplink_set.rb +22 -28
- data/lib/oneview-sdk/resource/logical_downlink.rb +53 -0
- data/lib/oneview-sdk/resource/logical_enclosure.rb +35 -33
- data/lib/oneview-sdk/resource/logical_interconnect.rb +29 -65
- data/lib/oneview-sdk/resource/logical_interconnect_group.rb +26 -6
- data/lib/oneview-sdk/resource/logical_switch.rb +184 -0
- data/lib/oneview-sdk/resource/logical_switch_group.rb +66 -0
- data/lib/oneview-sdk/resource/managed_san.rb +79 -0
- data/lib/oneview-sdk/resource/network_set.rb +64 -0
- data/lib/oneview-sdk/resource/power_device.rb +174 -0
- data/lib/oneview-sdk/resource/rack.rb +83 -0
- data/lib/oneview-sdk/resource/san_manager.rb +88 -0
- data/lib/oneview-sdk/resource/server_hardware.rb +139 -18
- data/lib/oneview-sdk/resource/server_hardware_type.rb +32 -1
- data/lib/oneview-sdk/resource/server_profile.rb +352 -9
- data/lib/oneview-sdk/resource/server_profile_template.rb +193 -4
- data/lib/oneview-sdk/resource/storage_pool.rb +42 -20
- data/lib/oneview-sdk/resource/storage_system.rb +64 -14
- data/lib/oneview-sdk/resource/switch.rb +86 -0
- data/lib/oneview-sdk/resource/unmanaged_device.rb +55 -0
- data/lib/oneview-sdk/resource/uplink_set.rb +24 -64
- data/lib/oneview-sdk/resource/volume.rb +29 -29
- data/lib/oneview-sdk/resource/volume_attachment.rb +79 -0
- data/lib/oneview-sdk/resource/volume_snapshot.rb +20 -1
- data/lib/oneview-sdk/resource/volume_template.rb +22 -33
- data/lib/oneview-sdk/resource.rb +66 -28
- data/lib/oneview-sdk/rest.rb +69 -24
- data/lib/oneview-sdk/ssl_helper.rb +20 -9
- data/lib/oneview-sdk/version.rb +12 -1
- data/lib/oneview-sdk.rb +12 -0
- data/oneview-sdk.gemspec +11 -0
- metadata +17 -2
@@ -1,3 +1,14 @@
|
|
1
|
+
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# You may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
6
|
+
#
|
7
|
+
# Unless required by applicable law or agreed to in writing, software distributed
|
8
|
+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
9
|
+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
|
10
|
+
# language governing permissions and limitations under the License.
|
11
|
+
|
1
12
|
module OneviewSDK
|
2
13
|
# Server profile resource implementation
|
3
14
|
class ServerProfile < Resource
|
@@ -9,13 +20,107 @@ module OneviewSDK
|
|
9
20
|
@data['type'] ||= 'ServerProfileV5'
|
10
21
|
end
|
11
22
|
|
12
|
-
#
|
23
|
+
# Sets the Server Hardware for the resource
|
24
|
+
# @param [OneviewSDK::ServerHardware] server_hardware Server Hardware resource
|
25
|
+
def set_server_hardware(server_hardware)
|
26
|
+
self['serverHardwareUri'] = server_hardware['uri'] if server_hardware['uri'] || server_hardware.retrieve!
|
27
|
+
fail "Resource #{server_hardware['name']} could not be found!" unless server_hardware['uri']
|
28
|
+
end
|
29
|
+
|
30
|
+
# Sets the Server Hardware Type for the resource
|
31
|
+
# @param [OneviewSDK::ServerHardwareType] server_hardware_type Type of the desired Server Hardware
|
32
|
+
def set_server_hardware_type(server_hardware_type)
|
33
|
+
self['serverHardwareTypeUri'] = server_hardware_type['uri'] if server_hardware_type['uri'] || server_hardware_type.retrieve!
|
34
|
+
fail "Resource #{server_hardware_type['name']} could not be found!" unless server_hardware_type['uri']
|
35
|
+
end
|
36
|
+
|
37
|
+
# Sets the Enclosure Group for the resource
|
38
|
+
# @param [OneviewSDK::EnclosureGroup] enclosure_group Enclosure Group that the Server is a member
|
39
|
+
def set_enclosure_group(enclosure_group)
|
40
|
+
self['enclosureGroupUri'] = enclosure_group['uri'] if enclosure_group['uri'] || enclosure_group.retrieve!
|
41
|
+
fail "Resource #{enclosure_group['name']} could not be found!" unless enclosure_group['uri']
|
42
|
+
end
|
43
|
+
|
44
|
+
# Sets the Enclosure Group for the resource
|
45
|
+
# @param [OneviewSDK::Enclosure] enclosure Enclosure that the Server is a member
|
46
|
+
def set_enclosure(enclosure)
|
47
|
+
self['enclosureUri'] = enclosure['uri'] if enclosure['uri'] || enclosure.retrieve!
|
48
|
+
fail "Resource #{enclosure['name']} could not be found!" unless enclosure['uri']
|
49
|
+
end
|
50
|
+
|
51
|
+
# Gets the preview of manual and automatic updates required to make the server profile consistent with its template.
|
52
|
+
# @return [Hash] Hash containing the required information
|
53
|
+
def get_compliance_preview
|
54
|
+
ensure_client & ensure_uri
|
55
|
+
response = @client.rest_get("#{self['uri']}/compliance-preview")
|
56
|
+
@client.response_handler(response)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Retrieves the error or status messages associated with the specified profile.
|
60
|
+
# @return [Hash] Hash containing the required information
|
61
|
+
def get_messages
|
62
|
+
ensure_client & ensure_uri
|
63
|
+
response = @client.rest_get("#{self['uri']}/messages")
|
64
|
+
@client.response_handler(response)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Transforms an existing profile by supplying a new server hardware type and/or enclosure group.
|
68
|
+
# A profile will be returned with a new configuration based on the capabilities of the supplied
|
69
|
+
# server hardware type and/or enclosure group. All deployed connections will have their port assignment
|
70
|
+
# set to 'Auto'. Re-selection of the server hardware may also be required. The new profile can subsequently
|
71
|
+
# be used for the PUT https://{appl}/rest/server- profiles/{id} API but is not guaranteed to pass
|
72
|
+
# validation. Any incompatibilities will be flagged when the transformed server profile is submitted.
|
73
|
+
# @param [Hash<String,Object>] query Query parameters
|
74
|
+
# @option query [OneviewSDK::EnclosureGroup] 'enclosure_group' Enclosure Group associated with the resource
|
75
|
+
# @option query [OneviewSDK::ServerHardware] 'server_hardware' The server hardware associated with the resource
|
76
|
+
# @option query [OneviewSDK::ServerHardwareType] 'server_hardware_type' The server hardware type associated with the resource
|
77
|
+
# @return [Hash] Hash containing the required information
|
78
|
+
def get_transformation(query = nil)
|
79
|
+
ensure_client & ensure_uri
|
80
|
+
query_uri = OneviewSDK::Resource.build_query(query) if query
|
81
|
+
response = @client.rest_get("#{self['uri']}/transformation#{query_uri}")
|
82
|
+
@client.response_handler(response)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Updates the server profile from the server profile template.
|
86
|
+
def update_from_template
|
87
|
+
ensure_client & ensure_uri
|
88
|
+
patch_operation = { 'op' => 'replace', 'path' => '/templateCompliance', 'value' => 'Compliant' }
|
89
|
+
patch_options = {
|
90
|
+
'If-Match' => self['eTag'],
|
91
|
+
'body' => [patch_operation]
|
92
|
+
}
|
93
|
+
response = @client.rest_patch(self['uri'], patch_options)
|
94
|
+
@client.response_handler(response)
|
95
|
+
end
|
96
|
+
|
97
|
+
# @!group Helpers
|
98
|
+
|
99
|
+
# Gets attached ServerHardware for the profile
|
100
|
+
# @return [OneviewSDK::ServerHardware] if hardware is attached
|
101
|
+
# @return [nil] if no hardware is attached
|
102
|
+
def get_server_hardware
|
103
|
+
return nil unless self['serverHardwareUri']
|
104
|
+
sh = OneviewSDK::ServerHardware.new(@client, uri: self['serverHardwareUri'])
|
105
|
+
sh.retrieve!
|
106
|
+
sh
|
107
|
+
end
|
108
|
+
|
109
|
+
# Gets all the available Ethernet and FC Networks, and Network Sets
|
110
|
+
# @return [Hash]
|
111
|
+
# A hash containing the lists of Ethernet Networks and FC Networks
|
112
|
+
def get_available_networks
|
113
|
+
query = { enclosure_group_uri: @data['enclosureGroupUri'], server_hardware_type_uri: @data['serverHardwareTypeUri'] }
|
114
|
+
self.class.get_available_networks(@client, query)
|
115
|
+
end
|
116
|
+
|
117
|
+
# Gets available server hardware
|
13
118
|
# @return [Array<OneviewSDK::ServerHardware>] Array of ServerHardware resources that matches this
|
14
119
|
# profile's server hardware type and enclosure group and who's state is 'NoProfileApplied'
|
15
|
-
def
|
120
|
+
def get_available_hardware
|
16
121
|
ensure_client
|
17
|
-
fail 'Must set @data[\'serverHardwareTypeUri\']' unless @data['serverHardwareTypeUri']
|
18
|
-
fail 'Must set @data[\'enclosureGroupUri\']' unless @data['enclosureGroupUri']
|
122
|
+
fail IncompleteResource, 'Must set @data[\'serverHardwareTypeUri\']' unless @data['serverHardwareTypeUri']
|
123
|
+
fail IncompleteResource, 'Must set @data[\'enclosureGroupUri\']' unless @data['enclosureGroupUri']
|
19
124
|
params = {
|
20
125
|
state: 'NoProfileApplied',
|
21
126
|
serverHardwareTypeUri: @data['serverHardwareTypeUri'],
|
@@ -23,15 +128,253 @@ module OneviewSDK
|
|
23
128
|
}
|
24
129
|
OneviewSDK::ServerHardware.find_by(@client, params)
|
25
130
|
rescue StandardError => e
|
26
|
-
raise "Failed to get available hardware. Message: #{e.message}"
|
131
|
+
raise IncompleteResource, "Failed to get available hardware. Message: #{e.message}"
|
132
|
+
end
|
133
|
+
|
134
|
+
# Adds a connection entry to Server profile template
|
135
|
+
# @param [OneviewSDK::EthernetNetwork,OneviewSDK::FCNetwork] network Network associated with the connection
|
136
|
+
# @param [Hash<String,String>] connection_options Hash containing the configuration of the connection
|
137
|
+
# @option connection_options [Integer] 'allocatedMbps' The transmit throughput (mbps) currently allocated to
|
138
|
+
# this connection. When Fibre Channel connections are set to Auto for requested bandwidth, the value can be set to -2000
|
139
|
+
# to indicate that the actual value is unknown until OneView is able to negotiate the actual speed.
|
140
|
+
# @option connection_options [Integer] 'allocatedVFs' The number of virtual functions allocated to this connection. This value will be null.
|
141
|
+
# @option connection_options [Hash] 'boot' indicates that the server will attempt to boot from this connection.
|
142
|
+
# This object can only be specified if "boot.manageBoot" is set to 'true'
|
143
|
+
# @option connection_options [String] 'deploymentStatus' The deployment status of the connection.
|
144
|
+
# The value can be 'Undefined', 'Reserved', or 'Deployed'.
|
145
|
+
# @option connection_options [String] 'functionType' Type of function required for the connection.
|
146
|
+
# functionType cannot be modified after the connection is created.
|
147
|
+
# @option connection_options [String] 'mac' The MAC address that is currently programmed on the FlexNic.
|
148
|
+
# @option connection_options [String] 'macType' Specifies the type of MAC address to be programmed into the IO Devices.
|
149
|
+
# The value can be 'Virtual', 'Physical' or 'UserDefined'.
|
150
|
+
# @option connection_options [String] 'maximumMbps' Maximum transmit throughput (mbps) allowed on this connection.
|
151
|
+
# The value is limited by the maximum throughput of the network link and maximumBandwidth of the selected network (networkUri).
|
152
|
+
# For Fibre Channel connections, the value is limited to the same value as the allocatedMbps.
|
153
|
+
# @option connection_options [String] 'name' A string used to identify the respective connection.
|
154
|
+
# The connection name is case insensitive, limited to 63 characters and must be unique within the profile.
|
155
|
+
# @option connection_options [String] 'portId' Identifies the port (FlexNIC) used for this connection.
|
156
|
+
# @option connection_options [String] 'requestedMbps' The transmit throughput (mbps) that should be allocated to this connection.
|
157
|
+
# @option connection_options [String] 'requestedVFs' This value can be "Auto" or 0.
|
158
|
+
# @option connection_options [String] 'wwnn' The node WWN address that is currently programmed on the FlexNic.
|
159
|
+
# @option connection_options [String] 'wwpn' The port WWN address that is currently programmed on the FlexNic.
|
160
|
+
# @option connection_options [String] 'wwpnType' Specifies the type of WWN address to be porgrammed on the FlexNIC.
|
161
|
+
# The value can be 'Virtual', 'Physical' or 'UserDefined'.
|
162
|
+
def add_connection(network, connection_options = {})
|
163
|
+
self['connections'] = [] unless self['connections']
|
164
|
+
connection_options['id'] = 0 # Letting OneView treat the ID registering
|
165
|
+
connection_options['networkUri'] = network['uri'] if network['uri'] || network.retrieve!
|
166
|
+
self['connections'] << connection_options
|
167
|
+
end
|
168
|
+
|
169
|
+
# Removes a connection entry in Server profile template
|
170
|
+
# @param [String] connection_name Name of the connection
|
171
|
+
# @return Returns the connection hash if found, otherwise returns nil
|
172
|
+
def remove_connection(connection_name)
|
173
|
+
desired_connection = nil
|
174
|
+
return desired_connection unless self['connections']
|
175
|
+
self['connections'].each do |con|
|
176
|
+
desired_connection = self['connections'].delete(con) if con['name'] == connection_name
|
177
|
+
end
|
178
|
+
desired_connection
|
179
|
+
end
|
180
|
+
|
181
|
+
# Adds volume attachment entry with associated Volume in Server profile
|
182
|
+
# @param [OneviewSDK::Volume] volume Volume Resource to add an attachment
|
183
|
+
# @param [Hash] attachment_options Options of the new attachment
|
184
|
+
# @option attachment_options [Fixnum] 'id' The ID of the attached storage volume. Do not use it if you want it to be created automatically.
|
185
|
+
# @option attachment_options [String] 'lun' The logical unit number.
|
186
|
+
# @option attachment_options [String] 'lunType' The logical unit number type: Auto or Manual.
|
187
|
+
# @option attachment_options [Boolean] 'permanent' Required. If true, indicates that the volume will persist when the profile is deleted.
|
188
|
+
# If false, then the volume will be deleted when the profile is deleted.
|
189
|
+
# @option attachment_options [Array] 'storagePaths' A list of host-to-target path associations.
|
190
|
+
# @return Returns the connection hash if found, otherwise returns nil
|
191
|
+
def add_volume_attachment(volume, attachment_options = {})
|
192
|
+
self['sanStorage'] ||= {}
|
193
|
+
self['sanStorage']['volumeAttachments'] ||= []
|
194
|
+
attachment_options['id'] ||= 0
|
195
|
+
|
196
|
+
volume.retrieve! unless volume['uri'] || volume['storagePoolUri'] || volume['storageSystemUri']
|
197
|
+
attachment_options['volumeUri'] = volume['uri']
|
198
|
+
attachment_options['volumeStoragePoolUri'] = volume['storagePoolUri']
|
199
|
+
attachment_options['volumeStorageSystemUri'] = volume['storageSystemUri']
|
200
|
+
|
201
|
+
self['sanStorage']['volumeAttachments'] << attachment_options
|
202
|
+
end
|
203
|
+
|
204
|
+
# Adds volume attachment entry and creates a new Volume associated in the Server profile
|
205
|
+
# @param [OneviewSDK::Volume] volume Volume Resource to add an attachment
|
206
|
+
# @param [Hash] volume_options Options to create a new Volume.
|
207
|
+
# Please refer to OneviewSDK::Volume documentation for the data necessary to create a new Volume.
|
208
|
+
# @param [Hash] attachment_options Options of the new attachment
|
209
|
+
# @option attachment_options [Fixnum] 'id' The ID of the attached storage volume. Do not use it if you want it to be created automatically.
|
210
|
+
# @option attachment_options [String] 'lun' The logical unit number.
|
211
|
+
# @option attachment_options [String] 'lunType' The logical unit number type: Auto or Manual.
|
212
|
+
# @option attachment_options [Boolean] 'permanent' Required. If true, indicates that the volume will persist when the profile is deleted.
|
213
|
+
# If false, then the volume will be deleted when the profile is deleted.
|
214
|
+
# @option attachment_options [Array] 'storagePaths' A list of host-to-target path associations.
|
215
|
+
# @return Returns the connection hash if found, otherwise returns nil
|
216
|
+
def create_volume_with_attachment(storage_pool, volume_options, attachment_options = {})
|
217
|
+
self['sanStorage'] ||= {}
|
218
|
+
self['sanStorage']['volumeAttachments'] ||= []
|
219
|
+
attachment_options['id'] ||= 0
|
220
|
+
# Removing provisioningParameters and adding them to the top level hash
|
221
|
+
provision_param = volume_options.delete('provisioningParameters') || volume_options.delete(:provisioningParameters)
|
222
|
+
provision_param.each do |k, v|
|
223
|
+
volume_options[k] = v
|
224
|
+
end
|
225
|
+
# Each provisioningParameter has the prefix 'volume' attached to its name in the original options
|
226
|
+
# Also, it needs to respect the lower camel case
|
227
|
+
volume_options.each do |k, v|
|
228
|
+
attachment_options["volume#{k.to_s[0].capitalize}#{k.to_s[1, k.to_s.length - 1]}"] = v
|
229
|
+
end
|
230
|
+
|
231
|
+
attachment_options['volumeStoragePoolUri'] = storage_pool['uri'] if storage_pool['uri'] || storage_pool.retrieve!
|
232
|
+
|
233
|
+
# Since the volume is being created in this method, it needs to be nil
|
234
|
+
attachment_options['volumeUri'] = nil
|
235
|
+
attachment_options['volumeStorageSystemUri'] = nil
|
236
|
+
|
237
|
+
# volumeProvisionedCapacityBytes is not following the same pattern in Volume
|
238
|
+
attachment_options['volumeProvisionedCapacityBytes'] ||= attachment_options.delete('volumeRequestedCapacity')
|
239
|
+
|
240
|
+
# Defaults
|
241
|
+
attachment_options['permanent'] ||= true
|
242
|
+
attachment_options['lunType'] ||= 'Auto'
|
243
|
+
attachment_options['lun'] ||= nil
|
244
|
+
attachment_options['storagePaths'] ||= []
|
245
|
+
|
246
|
+
self['sanStorage']['volumeAttachments'] << attachment_options
|
247
|
+
end
|
248
|
+
|
249
|
+
# Removes a volume attachment entry in the Server profile
|
250
|
+
# @param [Fixnum] id ID number of the attachment entry
|
251
|
+
# @return Returns the volume hash if found, otherwise returns nil
|
252
|
+
def remove_volume_attachment(id)
|
253
|
+
self['sanStorage'] ||= {}
|
254
|
+
self['sanStorage']['volumeAttachments'] ||= []
|
255
|
+
return if self['sanStorage'].empty? || self['sanStorage']['volumeAttachments'].empty?
|
256
|
+
|
257
|
+
volume_attachment = nil
|
258
|
+
self['sanStorage']['volumeAttachments'].each do |entry|
|
259
|
+
volume_attachment = self['sanStorage']['volumeAttachments'].delete(entry) if entry['id'] == id
|
260
|
+
end
|
261
|
+
volume_attachment
|
262
|
+
end
|
263
|
+
|
264
|
+
# Sets the Firmware Driver for the server profile
|
265
|
+
# @param [OneviewSDK::FirmwareDriver] firmware Firmware Driver to be associated with the resource
|
266
|
+
# @param [Hash<String,Object>] firmware_options Firmware Driver options
|
267
|
+
# @option firmware_options [Boolean] 'manageFirmware' Indicates that the server firmware is configured using the server profile.
|
268
|
+
# Value can be 'true' or 'false'.
|
269
|
+
# @option firmware_options [Boolean] 'forceInstallFirmware' Force installation of firmware even if same or newer version is installed.
|
270
|
+
# Downgrading the firmware can result in the installation of unsupported firmware and cause server hardware to cease operation.
|
271
|
+
# Value can be 'true' or 'false'.
|
272
|
+
# @option firmware_options [String] 'firmwareInstallType' Specifies the way a Service Pack for ProLiant (SPP) is installed.
|
273
|
+
# This field is used if the 'manageFirmware' field is true.
|
274
|
+
# Values are 'FirmwareAndOSDrivers', 'FirmwareOnly', and 'FirmwareOnlyOfflineMode'.
|
275
|
+
def set_firmware_driver(firmware, firmware_options = {})
|
276
|
+
firmware_options['firmwareBaselineUri'] = firmware['uri'] if firmware['uri'] || firmware.retrieve!
|
277
|
+
self['firmware'] = firmware_options
|
278
|
+
end
|
279
|
+
|
280
|
+
# @!endgroup
|
281
|
+
|
282
|
+
# Gets all the available ethernet and fc networks, and network sets
|
283
|
+
# @param [OneviewSDK::Client] client The client object for the OneView appliance
|
284
|
+
# @param [Hash<String,Object>] query Query parameters
|
285
|
+
# @option query [OneviewSDK::EnclosureGroup] 'enclosure_group' Enclosure Group associated with the resource
|
286
|
+
# @option query [String] 'function_type' The FunctionType (Ethernet or FibreChannel) to filter the list of networks returned
|
287
|
+
# @option query [OneviewSDK::ServerHardware] 'server_hardware' The server hardware associated with the resource
|
288
|
+
# @option query [OneviewSDK::ServerHardwareType] 'server_hardware_type' The server hardware type associated with the resource
|
289
|
+
# @option query [String] 'view' Name of a predefined view to return a specific subset of the attributes of the resource or collection
|
290
|
+
# @return [Hash]
|
291
|
+
# A hash containing the lists of Ethernet and FC Networks, and Network Sets
|
292
|
+
# Options:
|
293
|
+
# * [String] 'ethernetNetworks' The list of Ethernet Networks
|
294
|
+
# * [String] 'fcNetworks' The list of FC Networks
|
295
|
+
# * [String] 'networkSets' The list of Networks Sets
|
296
|
+
def self.get_available_networks(client, query)
|
297
|
+
query_uri = build_query(query) if query
|
298
|
+
response = client.rest_get("#{BASE_URI}/available-networks#{query_uri}")
|
299
|
+
body = client.response_handler(response)
|
300
|
+
body.select { |k, _v| %w(ethernetNetworks networkSets fcNetworks).include?(k) }
|
301
|
+
end
|
302
|
+
|
303
|
+
# Gets the available servers based on the query parameters
|
304
|
+
# @param [OneviewSDK::Client] client The client object for the OneView appliance
|
305
|
+
# @param [Hash<String,Object>] query Query parameters
|
306
|
+
# @option query [OneviewSDK::EnclosureGroup] 'enclosure_group' Enclosure Group associated with the resource
|
307
|
+
# @option query [OneviewSDK::ServerProfile] 'server_profile' The server profile associated with the resource
|
308
|
+
# @option query [OneviewSDK::ServerHardwareType] 'server_hardware_type' The server hardware type associated with the resource
|
309
|
+
# @return [Hash] Hash containing all the available server information
|
310
|
+
def self.get_available_servers(client, query = nil)
|
311
|
+
if query
|
312
|
+
query_uri = build_query(query)
|
313
|
+
# profileUri attribute is not following the standards in OneView
|
314
|
+
query_uri.sub!('serverProfileUri', 'profileUri')
|
315
|
+
end
|
316
|
+
response = client.rest_get("#{BASE_URI}/available-servers#{query_uri}")
|
317
|
+
client.response_handler(response)
|
318
|
+
end
|
319
|
+
|
320
|
+
# Gets the available storage systems based on the query parameters
|
321
|
+
# @param [OneviewSDK::Client] client The client object for the OneView appliance
|
322
|
+
# @param [Hash<String,Object>] query Query parameters
|
323
|
+
# @option query [OneviewSDK::EnclosureGroup] 'enclosure_group' Enclosure Group associated with the resource
|
324
|
+
# @option query [OneviewSDK::ServerHardwareType] 'server_hardware_type' The server hardware type associated with the resource
|
325
|
+
# @option query [OneviewSDK::StorageSystem] 'storage_system' The Storage System the resources are associated with
|
326
|
+
def self.get_available_storage_system(client, query = nil)
|
327
|
+
# For storage_system the query requires the ID instead the URI
|
328
|
+
if query && query['storage_system']
|
329
|
+
query['storage_system'].retrieve! unless query['storage_system']['uri']
|
330
|
+
query['storage_system_id'] = query['storage_system']['uri'].split('/').last
|
331
|
+
query.delete('storage_system')
|
332
|
+
end
|
333
|
+
query_uri = build_query(query) if query
|
334
|
+
response = client.rest_get("#{BASE_URI}/available-storage-system#{query_uri}")
|
335
|
+
client.response_handler(response)
|
336
|
+
end
|
337
|
+
|
338
|
+
# Gets the available storage systems based on the query parameters
|
339
|
+
# @param [OneviewSDK::Client] client The client object for the OneView appliance
|
340
|
+
# @param [Hash<String,Object>] query Query parameters
|
341
|
+
# @option query [OneviewSDK::EnclosureGroup] 'enclosure_group' The enclosure group associated with the resource
|
342
|
+
# @option query [OneviewSDK::ServerHardwareType] 'server_hardware_type' The server hardware type associated with the resource
|
343
|
+
# @option query [Array<String>] 'filter' A general filter/query string to narrow the list of items returned.
|
344
|
+
# The default is no filter - all resources are returned.
|
345
|
+
# @option query [Integer] 'start' The first item to return, using 0-based indexing.
|
346
|
+
# If not specified, the default is 0 - start with the first available item.
|
347
|
+
# @option query [Integer] 'count' The sort order of the returned data set.
|
348
|
+
# By default, the sort order is based on create time, with the oldest entry first.
|
349
|
+
# @option query [String] 'sort' The number of resources to return. A count of -1 requests all the items.
|
350
|
+
def self.get_available_storage_systems(client, query = nil)
|
351
|
+
query_uri = build_query(query) if query
|
352
|
+
response = client.rest_get("#{BASE_URI}/available-storage-systems#{query_uri}")
|
353
|
+
client.response_handler(response)
|
27
354
|
end
|
28
355
|
|
29
|
-
|
30
|
-
|
356
|
+
# Get the available targets based on the query parameters
|
357
|
+
# @param [OneviewSDK::Client] client The client object for the OneView appliance
|
358
|
+
# @param [Hash<String,Object>] query Query parameters
|
359
|
+
# @option query [OneviewSDK::EnclosureGroup] 'enclosure_group' Enclosure Group associated with the resource
|
360
|
+
# @option query [OneviewSDK::ServerProfile] 'server_profile' The server profile associated with the resource
|
361
|
+
# @option query [OneviewSDK::ServerHardwareType] 'server_hardware_type' The server hardware type associated with the resource
|
362
|
+
def self.get_available_targets(client, query = nil)
|
363
|
+
query_uri = build_query(query) if query
|
364
|
+
response = client.rest_get("#{BASE_URI}/available-targets#{query_uri}")
|
365
|
+
client.response_handler(response)
|
31
366
|
end
|
32
367
|
|
33
|
-
|
34
|
-
|
368
|
+
# Gets all the available ethernet and fc networks
|
369
|
+
# @param [OneviewSDK::Client] client The client object for the OneView appliance
|
370
|
+
# @param [Hash<String,Object>] query Query parameters
|
371
|
+
# @option query [OneviewSDK::EnclosureGroup] 'enclosure_group' Enclosure Group associated with the resource
|
372
|
+
# @option query [OneviewSDK::ServerHardware] 'server_hardware' The server hardware associated with the resource
|
373
|
+
# @option query [OneviewSDK::ServerHardwareType] 'server_hardware_type' The server hardware type associated with the resource
|
374
|
+
def self.get_profile_ports(client, query = nil)
|
375
|
+
query_uri = build_query(query) if query
|
376
|
+
response = client.rest_get("#{BASE_URI}/profile-ports#{query_uri}")
|
377
|
+
client.response_handler(response)
|
35
378
|
end
|
36
379
|
end
|
37
380
|
end
|
@@ -1,3 +1,14 @@
|
|
1
|
+
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# You may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
6
|
+
#
|
7
|
+
# Unless required by applicable law or agreed to in writing, software distributed
|
8
|
+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
9
|
+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
|
10
|
+
# language governing permissions and limitations under the License.
|
11
|
+
|
1
12
|
module OneviewSDK
|
2
13
|
# Server profile template resource implementation
|
3
14
|
class ServerProfileTemplate < Resource
|
@@ -9,15 +20,193 @@ module OneviewSDK
|
|
9
20
|
@data['type'] ||= 'ServerProfileTemplateV1'
|
10
21
|
end
|
11
22
|
|
12
|
-
#
|
23
|
+
# Sets the Server Hardware Type for the Server Profile Template
|
24
|
+
# @param [OneviewSDK::ServerHardwareType] server_hardware_type Type of the desired Server Hardware
|
25
|
+
def set_server_hardware_type(server_hardware_type)
|
26
|
+
self['serverHardwareTypeUri'] = server_hardware_type['uri'] if server_hardware_type['uri'] || server_hardware_type.retrieve!
|
27
|
+
fail "Resource #{server_hardware_type['name']} could not be found!" unless server_hardware_type['uri']
|
28
|
+
end
|
29
|
+
|
30
|
+
# Sets the enclosure group for the server profile template
|
31
|
+
# @param [OneviewSDK::EnclosureGroup] enclosure_group Enclosure Group that the Server is a member
|
32
|
+
def set_enclosure_group(enclosure_group)
|
33
|
+
self['enclosureGroupUri'] = enclosure_group['uri'] if enclosure_group['uri'] || enclosure_group.retrieve!
|
34
|
+
fail "Resource #{enclosure_group['name']} could not be found!" unless enclosure_group['uri']
|
35
|
+
end
|
36
|
+
|
37
|
+
# Sets the firmware driver for the current server profile template
|
38
|
+
# @param [OneviewSDK::FirmwareDriver] firmware Firmware Driver to be associated with the resource
|
39
|
+
# @param [Hash<String,Object>] firmware_options Firmware Driver options
|
40
|
+
# @option firmware_options [Boolean] 'manageFirmware' Indicates that the server firmware is configured using the server profile.
|
41
|
+
# Value can be 'true' or 'false'.
|
42
|
+
# @option firmware_options [Boolean] 'forceInstallFirmware' Force installation of firmware even if same or newer version is installed.
|
43
|
+
# Downgrading the firmware can result in the installation of unsupported firmware and cause server hardware to cease operation.
|
44
|
+
# Value can be 'true' or 'false'.
|
45
|
+
# @option firmware_options [String] 'firmwareInstallType' Specifies the way a Service Pack for ProLiant (SPP) is installed.
|
46
|
+
# This field is used if the 'manageFirmware' field is true.
|
47
|
+
# Values are 'FirmwareAndOSDrivers', 'FirmwareOnly', and 'FirmwareOnlyOfflineMode'.
|
48
|
+
def set_firmware_driver(firmware, firmware_options = {})
|
49
|
+
firmware_options['firmwareBaselineUri'] = firmware['uri'] if firmware['uri'] || firmware.retrieve!
|
50
|
+
self['firmware'] = firmware_options
|
51
|
+
end
|
52
|
+
|
53
|
+
# Adds a connection entry to server profile template
|
54
|
+
# @param [OneviewSDK::EthernetNetwork,OneviewSDK::FCNetwork] network Network associated with the connection
|
55
|
+
# @param [Hash<String,String>] connection_options Hash containing the configuration of the connection
|
56
|
+
# @option connection_options [Integer] 'allocatedMbps' The transmit throughput (mbps) currently allocated to
|
57
|
+
# this connection. When Fibre Channel connections are set to Auto for requested bandwidth, the value can be set to -2000
|
58
|
+
# to indicate that the actual value is unknown until OneView is able to negotiate the actual speed.
|
59
|
+
# @option connection_options [Integer] 'allocatedVFs' The number of virtual functions allocated to this connection. This value will be null.
|
60
|
+
# @option connection_options [Hash] 'boot' indicates that the server will attempt to boot from this connection.
|
61
|
+
# This object can only be specified if "boot.manageBoot" is set to 'true'
|
62
|
+
# @option connection_options [String] 'deploymentStatus' The deployment status of the connection.
|
63
|
+
# The value can be 'Undefined', 'Reserved', or 'Deployed'.
|
64
|
+
# @option connection_options [String] 'functionType' Type of function required for the connection.
|
65
|
+
# functionType cannot be modified after the connection is created.
|
66
|
+
# @option connection_options [String] 'mac' The MAC address that is currently programmed on the FlexNic.
|
67
|
+
# @option connection_options [String] 'macType' Specifies the type of MAC address to be programmed into the IO Devices.
|
68
|
+
# The value can be 'Virtual', 'Physical' or 'UserDefined'.
|
69
|
+
# @option connection_options [String] 'maximumMbps' Maximum transmit throughput (mbps) allowed on this connection.
|
70
|
+
# The value is limited by the maximum throughput of the network link and maximumBandwidth of the selected network (networkUri).
|
71
|
+
# For Fibre Channel connections, the value is limited to the same value as the allocatedMbps.
|
72
|
+
# @option connection_options [String] 'name' A string used to identify the respective connection.
|
73
|
+
# The connection name is case insensitive, limited to 63 characters and must be unique within the profile.
|
74
|
+
# @option connection_options [String] 'portId' Identifies the port (FlexNIC) used for this connection.
|
75
|
+
# @option connection_options [String] 'requestedMbps' The transmit throughput (mbps) that should be allocated to this connection.
|
76
|
+
# @option connection_options [String] 'requestedVFs' This value can be "Auto" or 0.
|
77
|
+
# @option connection_options [String] 'wwnn' The node WWN address that is currently programmed on the FlexNic.
|
78
|
+
# @option connection_options [String] 'wwpn' The port WWN address that is currently programmed on the FlexNic.
|
79
|
+
# @option connection_options [String] 'wwpnType' Specifies the type of WWN address to be porgrammed on the FlexNIC.
|
80
|
+
# The value can be 'Virtual', 'Physical' or 'UserDefined'.
|
81
|
+
def add_connection(network, connection_options = {})
|
82
|
+
self['connections'] = [] unless self['connections']
|
83
|
+
connection_options['id'] = 0 # Letting OneView treat the ID registering
|
84
|
+
connection_options['networkUri'] = network['uri'] if network['uri'] || network.retrieve!
|
85
|
+
self['connections'] << connection_options
|
86
|
+
end
|
87
|
+
|
88
|
+
# Removes a connection entry in server profile template
|
89
|
+
# @param [String] connection_name Name of the connection
|
90
|
+
# @return Returns the connection hash if found, otherwise returns nil
|
91
|
+
def remove_connection(connection_name)
|
92
|
+
desired_connection = nil
|
93
|
+
return desired_connection unless self['connections']
|
94
|
+
self['connections'].each do |con|
|
95
|
+
desired_connection = self['connections'].delete(con) if con['name'] == connection_name
|
96
|
+
end
|
97
|
+
desired_connection
|
98
|
+
end
|
99
|
+
|
100
|
+
# Adds a volume attachment entry with associated volume in server profile template
|
101
|
+
# @param [OneviewSDK::Volume] volume Volume Resource to add an attachment
|
102
|
+
# @param [Hash] attachment_options Options of the new attachment
|
103
|
+
# @option attachment_options [Fixnum] 'id' The ID of the attached storage volume. Do not use it if you want it to be created automatically.
|
104
|
+
# @option attachment_options [String] 'lun' The logical unit number.
|
105
|
+
# @option attachment_options [String] 'lunType' The logical unit number type: Auto or Manual.
|
106
|
+
# @option attachment_options [Boolean] 'permanent' Required. If true, indicates that the volume will persist when the profile is deleted.
|
107
|
+
# If false, then the volume will be deleted when the profile is deleted.
|
108
|
+
# @option attachment_options [Array] 'storagePaths' A list of host-to-target path associations.
|
109
|
+
# @return Returns the connection hash if found, otherwise returns nil
|
110
|
+
def add_volume_attachment(volume, attachment_options = {})
|
111
|
+
self['sanStorage'] ||= {}
|
112
|
+
self['sanStorage']['volumeAttachments'] ||= []
|
113
|
+
attachment_options['id'] ||= 0
|
114
|
+
|
115
|
+
volume.retrieve! unless volume['uri'] || volume['storagePoolUri'] || volume['storageSystemUri']
|
116
|
+
attachment_options['volumeUri'] = volume['uri']
|
117
|
+
attachment_options['volumeStoragePoolUri'] = volume['storagePoolUri']
|
118
|
+
attachment_options['volumeStorageSystemUri'] = volume['storageSystemUri']
|
119
|
+
|
120
|
+
self['sanStorage']['volumeAttachments'] << attachment_options
|
121
|
+
end
|
122
|
+
|
123
|
+
# Adds a volume attachment entry with new volume in Server profile template
|
124
|
+
# @param [OneviewSDK::Volume] volume Volume Resource to add an attachment
|
125
|
+
# @param [Hash] volume_options Options to create a new Volume.
|
126
|
+
# Please refer to OneviewSDK::Volume documentation for the data necessary to create a new Volume.
|
127
|
+
# @param [Hash] attachment_options Options of the new attachment
|
128
|
+
# @option attachment_options [Fixnum] 'id' The ID of the attached storage volume. Do not use it if you want it to be created automatically.
|
129
|
+
# @option attachment_options [String] 'lun' The logical unit number.
|
130
|
+
# @option attachment_options [String] 'lunType' The logical unit number type: Auto or Manual.
|
131
|
+
# @option attachment_options [Boolean] 'permanent' Required. If true, indicates that the volume will persist when the profile is deleted.
|
132
|
+
# If false, then the volume will be deleted when the profile is deleted.
|
133
|
+
# @option attachment_options [Array] 'storagePaths' A list of host-to-target path associations.
|
134
|
+
# @return Returns the connection hash if found, otherwise returns nil
|
135
|
+
def create_volume_with_attachment(storage_pool, volume_options, attachment_options = {})
|
136
|
+
self['sanStorage'] ||= {}
|
137
|
+
self['sanStorage']['volumeAttachments'] ||= []
|
138
|
+
attachment_options['id'] ||= 0
|
139
|
+
# Removing provisioningParameters and adding them to the top level hash
|
140
|
+
provision_param = volume_options.delete('provisioningParameters') || volume_options.delete(:provisioningParameters)
|
141
|
+
provision_param.each do |k, v|
|
142
|
+
volume_options[k] = v
|
143
|
+
end
|
144
|
+
# Each provisioningParameter has the prefix 'volume' attached to its name in the original options
|
145
|
+
# Also, it needs to respect the lower camel case
|
146
|
+
volume_options.each do |k, v|
|
147
|
+
attachment_options["volume#{k.to_s[0].capitalize}#{k.to_s[1, k.to_s.length - 1]}"] = v
|
148
|
+
end
|
149
|
+
|
150
|
+
attachment_options['volumeStoragePoolUri'] = storage_pool['uri'] if storage_pool['uri'] || storage_pool.retrieve!
|
151
|
+
|
152
|
+
# Since the volume is being created in this method, it needs to be nil
|
153
|
+
attachment_options['volumeUri'] = nil
|
154
|
+
attachment_options['volumeStorageSystemUri'] = nil
|
155
|
+
|
156
|
+
# volumeProvisionedCapacityBytes is not following the same pattern in Volume
|
157
|
+
attachment_options['volumeProvisionedCapacityBytes'] ||= attachment_options.delete('volumeRequestedCapacity')
|
158
|
+
|
159
|
+
# Defaults
|
160
|
+
attachment_options['permanent'] ||= true
|
161
|
+
attachment_options['lunType'] ||= 'Auto'
|
162
|
+
attachment_options['lun'] ||= nil
|
163
|
+
attachment_options['storagePaths'] ||= []
|
164
|
+
|
165
|
+
self['sanStorage']['volumeAttachments'] << attachment_options
|
166
|
+
end
|
167
|
+
|
168
|
+
# Removes a volume attachment entry in Server profile template
|
169
|
+
# @param [Fixnum] id ID number of the attachment entry
|
170
|
+
# @return Returns the volume hash if found, otherwise returns nil
|
171
|
+
def remove_volume_attachment(id)
|
172
|
+
self['sanStorage'] ||= {}
|
173
|
+
self['sanStorage']['volumeAttachments'] ||= []
|
174
|
+
return if self['sanStorage'].empty? || self['sanStorage']['volumeAttachments'].empty?
|
175
|
+
|
176
|
+
volume_attachment = nil
|
177
|
+
self['sanStorage']['volumeAttachments'].each do |entry|
|
178
|
+
volume_attachment = self['sanStorage']['volumeAttachments'].delete(entry) if entry['id'] == id
|
179
|
+
end
|
180
|
+
volume_attachment
|
181
|
+
end
|
182
|
+
|
183
|
+
# Gets the available server hardwares
|
184
|
+
# @return [Array<OneviewSDK::ServerHardware>] Array of ServerHardware resources that matches this
|
185
|
+
# profile template's server hardware type and enclosure group and who's state is 'NoProfileApplied'
|
186
|
+
def get_available_hardware
|
187
|
+
ensure_client
|
188
|
+
fail IncompleteResource, 'Must set @data[\'serverHardwareTypeUri\']' unless @data['serverHardwareTypeUri']
|
189
|
+
fail IncompleteResource, 'Must set @data[\'enclosureGroupUri\']' unless @data['enclosureGroupUri']
|
190
|
+
params = {
|
191
|
+
state: 'NoProfileApplied',
|
192
|
+
serverHardwareTypeUri: @data['serverHardwareTypeUri'],
|
193
|
+
serverGroupUri: @data['enclosureGroupUri']
|
194
|
+
}
|
195
|
+
OneviewSDK::ServerHardware.find_by(@client, params)
|
196
|
+
rescue StandardError => e
|
197
|
+
raise IncompleteResource, "Failed to get available hardware. Message: #{e.message}"
|
198
|
+
end
|
199
|
+
|
200
|
+
# Creates a ServerProfile using this template
|
13
201
|
# @param [String] name Name of new server profile
|
14
|
-
# @return [ServerProfile] New server profile from template.
|
202
|
+
# @return [OneviewSDK::ServerProfile] New server profile from template.
|
15
203
|
# Temporary object only; call .create to actually create resource on OneView.
|
16
204
|
def new_profile(name = nil)
|
17
205
|
ensure_client && ensure_uri
|
18
|
-
|
206
|
+
response = @client.rest_get("#{@data['uri']}/new-profile")
|
207
|
+
options = @client.response_handler(response)
|
19
208
|
profile = OneviewSDK::ServerProfile.new(@client, options)
|
20
|
-
profile[
|
209
|
+
profile['name'] = name ? name : "Server_Profile_created_from_#{@data['name']}"
|
21
210
|
profile
|
22
211
|
end
|
23
212
|
end
|