Class: OneviewSDK::API200::ServerProfile
- Includes:
- ResourceHelper::PatchOperation
- Defined in:
- lib/oneview-sdk/resource/api200/server_profile.rb
Overview
Server profile resource implementation
Direct Known Subclasses
Constant Summary collapse
- BASE_URI =
'/rest/server-profiles'.freeze
- UNIQUE_IDENTIFIERS =
%w[name uri associatedServer serialNumber serverHardwareUri].freeze
Constants inherited from Resource
Resource::DEFAULT_REQUEST_HEADER
Instance Attribute Summary
Attributes inherited from Resource
#api_version, #client, #data, #logger
Helpers collapse
-
#add_connection(network, connection_options = {}) ⇒ Object
Adds a connection entry to Server profile template.
-
#add_volume_attachment(volume, attachment_options = {}) ⇒ Object
Adds volume attachment entry with associated Volume in Server profile.
-
#create_volume_with_attachment(storage_pool, volume_options, attachment_options = {}) ⇒ Object
Adds volume attachment entry and creates a new Volume associated in the Server profile.
-
#get_available_hardware ⇒ Array<OneviewSDK::ServerHardware>
Gets available server hardware.
-
#get_available_networks ⇒ Hash
Gets all the available Ethernet and FC Networks, and Network Sets.
-
#get_server_hardware ⇒ OneviewSDK::ServerHardware?
Gets attached ServerHardware for the profile.
-
#remove_connection(connection_name) ⇒ Object
Removes a connection entry in Server profile template.
-
#remove_volume_attachment(id) ⇒ Object
Removes a volume attachment entry in the Server profile.
-
#set_firmware_driver(firmware, firmware_options = {}) ⇒ Object
Sets the Firmware Driver for the server profile.
Class Method Summary collapse
-
.get_available_networks(client, query) ⇒ Hash
Gets all the available ethernet and fc networks, and network sets.
-
.get_available_servers(client, query = nil) ⇒ Hash
Gets the available servers based on the query parameters.
-
.get_available_storage_system(client, query = nil) ⇒ Object
Gets the available storage systems based on the query parameters.
-
.get_available_storage_systems(client, query = nil) ⇒ Object
Gets the available storage systems based on the query parameters.
-
.get_available_targets(client, query = nil) ⇒ Object
Get the available targets based on the query parameters.
-
.get_profile_ports(client, query = nil) ⇒ Object
Gets all the available ethernet and fc networks.
Instance Method Summary collapse
-
#get_compliance_preview ⇒ Hash
Gets the preview of manual and automatic updates required to make the server profile consistent with its template.
-
#get_messages ⇒ Hash
Retrieves the error or status messages associated with the specified profile.
-
#get_transformation(query = nil) ⇒ Hash
Transforms an existing profile by supplying a new server hardware type and/or enclosure group.
-
#initialize(client, params = {}, api_ver = nil) ⇒ ServerProfile
constructor
A new instance of ServerProfile.
-
#set_enclosure(enclosure) ⇒ Object
Sets the Enclosure for the resource.
-
#set_enclosure_group(enclosure_group) ⇒ Object
Sets the Enclosure Group for the resource.
-
#set_server_hardware(server_hardware) ⇒ Object
Sets the Server Hardware for the resource.
-
#set_server_hardware_type(server_hardware_type) ⇒ Object
Sets the Server Hardware Type for the resource.
-
#update_from_template ⇒ Object
Updates the server profile from the server profile template.
Methods included from ResourceHelper::PatchOperation
Methods inherited from Resource
#==, #[], #[]=, build_query, #create, #create!, #deep_merge!, #delete, #each, #eql?, #exists?, find_by, find_with_pagination, from_file, get_all, get_all_with_query, #like?, #refresh, #retrieve!, #schema, schema, #set, #set_all, #to_file, #update
Constructor Details
#initialize(client, params = {}, api_ver = nil) ⇒ ServerProfile
Returns a new instance of ServerProfile.
23 24 25 26 27 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 23 def initialize(client, params = {}, api_ver = nil) super # Default values @data['type'] ||= 'ServerProfileV5' end |
Class Method Details
.get_available_networks(client, query) ⇒ Hash
Gets all the available ethernet and fc networks, and network sets
312 313 314 315 316 317 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 312 def self.get_available_networks(client, query) query_uri = build_query(query) if query response = client.rest_get("#{BASE_URI}/available-networks#{query_uri}") body = client.response_handler(response) body.select { |k, _v| %w[ethernetNetworks networkSets fcNetworks].include?(k) } end |
.get_available_servers(client, query = nil) ⇒ Hash
Gets the available servers based on the query parameters
326 327 328 329 330 331 332 333 334 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 326 def self.get_available_servers(client, query = nil) if query query_uri = build_query(query) # profileUri attribute is not following the standards in OneView query_uri.sub!('serverProfileUri', 'profileUri') end response = client.rest_get("#{BASE_URI}/available-servers#{query_uri}") client.response_handler(response) end |
.get_available_storage_system(client, query = nil) ⇒ Object
Gets the available storage systems based on the query parameters
342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 342 def self.get_available_storage_system(client, query = nil) # For storage_system the query requires the ID instead the URI if query && query['storage_system'] query['storage_system'].retrieve! unless query['storage_system']['uri'] query['storage_system_id'] = query['storage_system']['uri'].split('/').last query.delete('storage_system') end query_uri = build_query(query) if query response = client.rest_get("#{BASE_URI}/available-storage-system#{query_uri}") client.response_handler(response) end |
.get_available_storage_systems(client, query = nil) ⇒ Object
Gets the available storage systems based on the query parameters
366 367 368 369 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 366 def self.get_available_storage_systems(client, query = nil) query_uri = build_query(query) if query find_with_pagination(client, "#{BASE_URI}/available-storage-systems#{query_uri}") end |
.get_available_targets(client, query = nil) ⇒ Object
Get the available targets based on the query parameters
377 378 379 380 381 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 377 def self.get_available_targets(client, query = nil) query_uri = build_query(query) if query response = client.rest_get("#{BASE_URI}/available-targets#{query_uri}") client.response_handler(response) end |
.get_profile_ports(client, query = nil) ⇒ Object
Gets all the available ethernet and fc networks
389 390 391 392 393 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 389 def self.get_profile_ports(client, query = nil) query_uri = build_query(query) if query response = client.rest_get("#{BASE_URI}/profile-ports#{query_uri}") client.response_handler(response) end |
Instance Method Details
#add_connection(network, connection_options = {}) ⇒ Object
Adds a connection entry to Server profile template
167 168 169 170 171 172 173 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 167 def add_connection(network, = {}) = Hash[.map { |k, v| [k.to_s, v] }] self['connections'] = [] unless self['connections'] ['id'] ||= 0 ['networkUri'] = network['uri'] if network['uri'] || network.retrieve! self['connections'] << end |
#add_volume_attachment(volume, attachment_options = {}) ⇒ Object
Adds volume attachment entry with associated Volume in Server profile
198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 198 def (volume, = {}) raise IncompleteResource, 'Volume not found!' unless volume.retrieve! # Convert symbols keys to string = Hash[.map { |k, v| [k.to_s, v] }] self['sanStorage'] ||= {} self['sanStorage']['volumeAttachments'] ||= [] self['sanStorage']['manageSanStorage'] ||= true ['id'] ||= 0 ['volumeUri'] = volume['uri'] ['volumeStoragePoolUri'] = volume['storagePoolUri'] ['volumeStorageSystemUri'] = volume['storageSystemUri'] self['sanStorage']['volumeAttachments'] << end |
#create_volume_with_attachment(storage_pool, volume_options, attachment_options = {}) ⇒ Object
Adds volume attachment entry and creates a new Volume associated in the Server profile
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 226 def (storage_pool, , = {}) raise IncompleteResource, 'Storage Pool not found!' unless storage_pool.retrieve! # Convert symbols keys to string in volume_options and attachment_options = Hash[.map { |k, v| [k.to_s, v] }] = Hash[.map { |k, v| [k.to_s, v] }] self['sanStorage'] ||= {} self['sanStorage']['volumeAttachments'] ||= [] ['id'] ||= 0 # Removing provisioningParameters and adding them to the top level hash provision_param = .delete('provisioningParameters') || .delete(:provisioningParameters) provision_param.each do |k, v| [k] = v end # Each provisioningParameter has the prefix 'volume' attached to its name in the original options # Also, it needs to respect the lower camel case .each do |k, v| ["volume#{k.to_s[0].capitalize}#{k.to_s[1, k.to_s.length - 1]}"] = v end ['volumeStoragePoolUri'] = storage_pool['uri'] # Since the volume is being created in this method, it needs to be nil ['volumeUri'] = nil ['volumeStorageSystemUri'] = nil # volumeProvisionedCapacityBytes is not following the same pattern in Volume ['volumeProvisionedCapacityBytes'] ||= .delete('volumeRequestedCapacity') # Defaults ['permanent'] ||= true ['lunType'] ||= 'Auto' ['lun'] ||= nil ['storagePaths'] ||= [] ['volumeShareable'] = false self['sanStorage']['manageSanStorage'] ||= true self['sanStorage']['volumeAttachments'] << end |
#get_available_hardware ⇒ Array<OneviewSDK::ServerHardware>
Gets available server hardware
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 123 def get_available_hardware ensure_client raise IncompleteResource, 'Must set @data[\'serverHardwareTypeUri\']' unless @data['serverHardwareTypeUri'] raise IncompleteResource, 'Must set @data[\'enclosureGroupUri\']' unless @data['enclosureGroupUri'] params = { state: 'NoProfileApplied', serverHardwareTypeUri: @data['serverHardwareTypeUri'], serverGroupUri: @data['enclosureGroupUri'] } variant = self.class.name.split('::').at(-2) OneviewSDK.resource_named('ServerHardware', @client.api_version, variant).find_by(@client, params) rescue StandardError => e raise IncompleteResource, "Failed to get available hardware. Message: #{e.}" end |
#get_available_networks ⇒ Hash
Gets all the available Ethernet and FC Networks, and Network Sets
115 116 117 118 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 115 def get_available_networks query = { enclosure_group_uri: @data['enclosureGroupUri'], server_hardware_type_uri: @data['serverHardwareTypeUri'] } self.class.get_available_networks(@client, query) end |
#get_compliance_preview ⇒ Hash
Gets the preview of manual and automatic updates required to make the server profile consistent with its template.
63 64 65 66 67 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 63 def get_compliance_preview ensure_client & ensure_uri response = @client.rest_get("#{self['uri']}/compliance-preview") @client.response_handler(response) end |
#get_messages ⇒ Hash
Retrieves the error or status messages associated with the specified profile.
71 72 73 74 75 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 71 def ensure_client & ensure_uri response = @client.rest_get("#{self['uri']}/messages") @client.response_handler(response) end |
#get_server_hardware ⇒ OneviewSDK::ServerHardware?
Gets attached ServerHardware for the profile
105 106 107 108 109 110 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 105 def get_server_hardware return nil unless self['serverHardwareUri'] sh = OneviewSDK::ServerHardware.new(@client, uri: self['serverHardwareUri']) sh.retrieve! sh end |
#get_transformation(query = nil) ⇒ Hash
Transforms an existing profile by supplying a new server hardware type and/or enclosure group.
A profile will be returned with a new configuration based on the capabilities of the supplied
server hardware type and/or enclosure group. All deployed connections will have their port assignment
set to 'Auto'. Re-selection of the server hardware may also be required. The new profile can subsequently
be used for the PUT https://{appl}/rest/server- profiles/{id} API but is not guaranteed to pass
validation. Any incompatibilities will be flagged when the transformed server profile is submitted.
88 89 90 91 92 93 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 88 def get_transformation(query = nil) ensure_client & ensure_uri query_uri = OneviewSDK::Resource.build_query(query) if query response = @client.rest_get("#{self['uri']}/transformation#{query_uri}") @client.response_handler(response) end |
#remove_connection(connection_name) ⇒ Object
Removes a connection entry in Server profile template
178 179 180 181 182 183 184 185 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 178 def remove_connection(connection_name) desired_connection = nil return desired_connection unless self['connections'] self['connections'].each do |con| desired_connection = self['connections'].delete(con) if con['name'] == connection_name end desired_connection end |
#remove_volume_attachment(id) ⇒ Object
Removes a volume attachment entry in the Server profile
268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 268 def (id) self['sanStorage'] ||= {} self['sanStorage']['volumeAttachments'] ||= [] return if self['sanStorage'].empty? || self['sanStorage']['volumeAttachments'].empty? = nil self['sanStorage']['volumeAttachments'].each do |entry| = self['sanStorage']['volumeAttachments'].delete(entry) if entry['id'] == id end end |
#set_enclosure(enclosure) ⇒ Object
Sets the Enclosure for the resource
56 57 58 59 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 56 def set_enclosure(enclosure) raise 'Enclosure could not be found!' unless enclosure.retrieve! self['enclosureUri'] = enclosure['uri'] end |
#set_enclosure_group(enclosure_group) ⇒ Object
Sets the Enclosure Group for the resource
48 49 50 51 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 48 def set_enclosure_group(enclosure_group) raise 'Enclosure Group could not be found!' unless enclosure_group.retrieve! self['enclosureGroupUri'] = enclosure_group['uri'] end |
#set_firmware_driver(firmware, firmware_options = {}) ⇒ Object
Sets the Firmware Driver for the server profile
291 292 293 294 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 291 def set_firmware_driver(firmware, = {}) ['firmwareBaselineUri'] = firmware['uri'] if firmware['uri'] || firmware.retrieve! self['firmware'] = end |
#set_server_hardware(server_hardware) ⇒ Object
Sets the Server Hardware for the resource
32 33 34 35 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 32 def set_server_hardware(server_hardware) raise 'Server Hardware could not be found!' unless server_hardware.retrieve! self['serverHardwareUri'] = server_hardware['uri'] end |
#set_server_hardware_type(server_hardware_type) ⇒ Object
Sets the Server Hardware Type for the resource
40 41 42 43 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 40 def set_server_hardware_type(server_hardware_type) raise 'Server Hardware Type could not be found!' unless server_hardware_type.retrieve! self['serverHardwareTypeUri'] = server_hardware_type['uri'] end |
#update_from_template ⇒ Object
Updates the server profile from the server profile template.
96 97 98 |
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 96 def update_from_template patch('replace', '/templateCompliance', 'Compliant', 'If-Match' => self['eTag']) end |