Class: OneviewSDK::API200::ServerProfile

Inherits:
Resource show all
Defined in:
lib/oneview-sdk/resource/api200/server_profile.rb

Overview

Server profile resource implementation

Constant Summary collapse

BASE_URI =
'/rest/server-profiles'.freeze
UNIQUE_IDENTIFIERS =
%w(name uri associatedServer serialNumber serverHardwareUri).freeze

Instance Attribute Summary

Attributes inherited from Resource

#api_version, #client, #data, #logger

Helpers collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, #[], #[]=, build_query, #create, #create!, #delete, #each, #eql?, #exists?, find_by, from_file, get_all, #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.



21
22
23
24
25
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 21

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

Parameters:

  • client (OneviewSDK::Client)

    The client object for the OneView appliance

  • query (Hash<String,Object>)

    Query parameters

Options Hash (query):

  • 'enclosure_group' (OneviewSDK::EnclosureGroup)

    Enclosure Group associated with the resource

  • 'function_type' (String)

    The FunctionType (Ethernet or FibreChannel) to filter the list of networks returned

  • 'server_hardware' (OneviewSDK::ServerHardware)

    The server hardware associated with the resource

  • 'server_hardware_type' (OneviewSDK::ServerHardwareType)

    The server hardware type associated with the resource

  • 'view' (String)

    Name of a predefined view to return a specific subset of the attributes of the resource or collection

Returns:

  • (Hash)

    A hash containing the lists of Ethernet and FC Networks, and Network Sets Options:

    * [String] 'ethernetNetworks' The list of Ethernet Networks
    * [String] 'fcNetworks' The list of FC Networks
    * [String] 'networkSets' The list of Networks Sets
    


300
301
302
303
304
305
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 300

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

Parameters:

  • client (OneviewSDK::Client)

    The client object for the OneView appliance

  • query (Hash<String,Object>) (defaults to: nil)

    Query parameters

Options Hash (query):

  • 'enclosure_group' (OneviewSDK::EnclosureGroup)

    Enclosure Group associated with the resource

  • 'server_profile' (OneviewSDK::ServerProfile)

    The server profile associated with the resource

  • 'server_hardware_type' (OneviewSDK::ServerHardwareType)

    The server hardware type associated with the resource

Returns:

  • (Hash)

    Hash containing all the available server information



314
315
316
317
318
319
320
321
322
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 314

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

Parameters:

  • client (OneviewSDK::Client)

    The client object for the OneView appliance

  • query (Hash<String,Object>) (defaults to: nil)

    Query parameters

Options Hash (query):

  • 'enclosure_group' (OneviewSDK::EnclosureGroup)

    Enclosure Group associated with the resource

  • 'server_hardware_type' (OneviewSDK::ServerHardwareType)

    The server hardware type associated with the resource

  • 'storage_system' (OneviewSDK::StorageSystem)

    The Storage System the resources are associated with



330
331
332
333
334
335
336
337
338
339
340
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 330

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

Parameters:

  • client (OneviewSDK::Client)

    The client object for the OneView appliance

  • query (Hash<String,Object>) (defaults to: nil)

    Query parameters

Options Hash (query):

  • 'enclosure_group' (OneviewSDK::EnclosureGroup)

    The enclosure group associated with the resource

  • 'server_hardware_type' (OneviewSDK::ServerHardwareType)

    The server hardware type associated with the resource

  • 'filter' (Array<String>)

    A general filter/query string to narrow the list of items returned. The default is no filter - all resources are returned.

  • 'start' (Integer)

    The first item to return, using 0-based indexing. If not specified, the default is 0 - start with the first available item.

  • 'count' (Integer)

    The sort order of the returned data set. By default, the sort order is based on create time, with the oldest entry first.

  • 'sort' (String)

    The number of resources to return. A count of -1 requests all the items.



354
355
356
357
358
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 354

def self.get_available_storage_systems(client, query = nil)
  query_uri = build_query(query) if query
  response = client.rest_get("#{BASE_URI}/available-storage-systems#{query_uri}")
  client.response_handler(response)
end

.get_available_targets(client, query = nil) ⇒ Object

Get the available targets based on the query parameters

Parameters:

  • client (OneviewSDK::Client)

    The client object for the OneView appliance

  • query (Hash<String,Object>) (defaults to: nil)

    Query parameters

Options Hash (query):

  • 'enclosure_group' (OneviewSDK::EnclosureGroup)

    Enclosure Group associated with the resource

  • 'server_profile' (OneviewSDK::ServerProfile)

    The server profile associated with the resource

  • 'server_hardware_type' (OneviewSDK::ServerHardwareType)

    The server hardware type associated with the resource



366
367
368
369
370
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 366

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

Parameters:

  • client (OneviewSDK::Client)

    The client object for the OneView appliance

  • query (Hash<String,Object>) (defaults to: nil)

    Query parameters

Options Hash (query):

  • 'enclosure_group' (OneviewSDK::EnclosureGroup)

    Enclosure Group associated with the resource

  • 'server_hardware' (OneviewSDK::ServerHardware)

    The server hardware associated with the resource

  • 'server_hardware_type' (OneviewSDK::ServerHardwareType)

    The server hardware type associated with the resource



378
379
380
381
382
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 378

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

Parameters:

  • network (OneviewSDK::EthernetNetwork, OneviewSDK::FCNetwork)

    Network associated with the connection

  • connection_options (Hash<String,String>) (defaults to: {})

    Hash containing the configuration of the connection

Options Hash (connection_options):

  • 'allocatedMbps' (Integer)

    The transmit throughput (mbps) currently allocated to this connection. When Fibre Channel connections are set to Auto for requested bandwidth, the value can be set to -2000 to indicate that the actual value is unknown until OneView is able to negotiate the actual speed.

  • 'allocatedVFs' (Integer)

    The number of virtual functions allocated to this connection. This value will be null.

  • 'boot' (Hash)

    indicates that the server will attempt to boot from this connection. This object can only be specified if “boot.manageBoot” is set to ‘true’

  • 'deploymentStatus' (String)

    The deployment status of the connection. The value can be ‘Undefined’, ‘Reserved’, or ‘Deployed’.

  • 'functionType' (String)

    Type of function required for the connection. functionType cannot be modified after the connection is created.

  • 'mac' (String)

    The MAC address that is currently programmed on the FlexNic.

  • 'macType' (String)

    Specifies the type of MAC address to be programmed into the IO Devices. The value can be ‘Virtual’, ‘Physical’ or ‘UserDefined’.

  • 'maximumMbps' (String)

    Maximum transmit throughput (mbps) allowed on this connection. The value is limited by the maximum throughput of the network link and maximumBandwidth of the selected network (networkUri). For Fibre Channel connections, the value is limited to the same value as the allocatedMbps.

  • 'name' (String)

    A string used to identify the respective connection. The connection name is case insensitive, limited to 63 characters and must be unique within the profile.

  • 'portId' (String)

    Identifies the port (FlexNIC) used for this connection.

  • 'requestedMbps' (String)

    The transmit throughput (mbps) that should be allocated to this connection.

  • 'requestedVFs' (String)

    This value can be “Auto” or 0.

  • 'wwnn' (String)

    The node WWN address that is currently programmed on the FlexNic.

  • 'wwpn' (String)

    The port WWN address that is currently programmed on the FlexNic.

  • 'wwpnType' (String)

    Specifies the type of WWN address to be porgrammed on the FlexNIC. The value can be ‘Virtual’, ‘Physical’ or ‘UserDefined’.



166
167
168
169
170
171
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 166

def add_connection(network, connection_options = {})
  self['connections'] = [] unless self['connections']
  connection_options['id'] = 0 # Letting OneView treat the ID registering
  connection_options['networkUri'] = network['uri'] if network['uri'] || network.retrieve!
  self['connections'] << connection_options
end

#add_volume_attachment(volume, attachment_options = {}) ⇒ Object

Adds volume attachment entry with associated Volume in Server profile

Parameters:

  • volume (OneviewSDK::Volume)

    Volume Resource to add an attachment

  • attachment_options (Hash) (defaults to: {})

    Options of the new attachment

Options Hash (attachment_options):

  • 'id' (Fixnum)

    The ID of the attached storage volume. Do not use it if you want it to be created automatically.

  • 'lun' (String)

    The logical unit number.

  • 'lunType' (String)

    The logical unit number type: Auto or Manual.

  • 'permanent' (Boolean)

    Required. If true, indicates that the volume will persist when the profile is deleted. If false, then the volume will be deleted when the profile is deleted.

  • 'storagePaths' (Array)

    A list of host-to-target path associations.

Returns:

  • Returns the connection hash if found, otherwise returns nil



195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 195

def add_volume_attachment(volume, attachment_options = {})
  self['sanStorage'] ||= {}
  self['sanStorage']['volumeAttachments'] ||= []
  attachment_options['id'] ||= 0

  volume.retrieve! unless volume['uri'] || volume['storagePoolUri'] || volume['storageSystemUri']
  attachment_options['volumeUri'] = volume['uri']
  attachment_options['volumeStoragePoolUri'] = volume['storagePoolUri']
  attachment_options['volumeStorageSystemUri'] = volume['storageSystemUri']

  self['sanStorage']['volumeAttachments'] << attachment_options
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

Parameters:

  • volume (OneviewSDK::Volume)

    Volume Resource to add an attachment

  • volume_options (Hash)

    Options to create a new Volume. Please refer to OneviewSDK::Volume documentation for the data necessary to create a new Volume.

  • attachment_options (Hash) (defaults to: {})

    Options of the new attachment

Options Hash (attachment_options):

  • 'id' (Fixnum)

    The ID of the attached storage volume. Do not use it if you want it to be created automatically.

  • 'lun' (String)

    The logical unit number.

  • 'lunType' (String)

    The logical unit number type: Auto or Manual.

  • 'permanent' (Boolean)

    Required. If true, indicates that the volume will persist when the profile is deleted. If false, then the volume will be deleted when the profile is deleted.

  • 'storagePaths' (Array)

    A list of host-to-target path associations.

Returns:

  • Returns the connection hash if found, otherwise returns nil



220
221
222
223
224
225
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
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 220

def create_volume_with_attachment(storage_pool, volume_options, attachment_options = {})
  self['sanStorage'] ||= {}
  self['sanStorage']['volumeAttachments'] ||= []
  attachment_options['id'] ||= 0
  # Removing provisioningParameters and adding them to the top level hash
  provision_param = volume_options.delete('provisioningParameters') || volume_options.delete(:provisioningParameters)
  provision_param.each do |k, v|
    volume_options[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
  volume_options.each do |k, v|
    attachment_options["volume#{k.to_s[0].capitalize}#{k.to_s[1, k.to_s.length - 1]}"] = v
  end

  attachment_options['volumeStoragePoolUri'] = storage_pool['uri'] if storage_pool['uri'] || storage_pool.retrieve!

  # Since the volume is being created in this method, it needs to be nil
  attachment_options['volumeUri'] = nil
  attachment_options['volumeStorageSystemUri'] = nil

  # volumeProvisionedCapacityBytes is not following the same pattern in Volume
  attachment_options['volumeProvisionedCapacityBytes'] ||= attachment_options.delete('volumeRequestedCapacity')

  # Defaults
  attachment_options['permanent'] ||= true
  attachment_options['lunType'] ||= 'Auto'
  attachment_options['lun'] ||= nil
  attachment_options['storagePaths'] ||= []

  self['sanStorage']['volumeAttachments'] << attachment_options
end

#get_available_hardwareArray<OneviewSDK::ServerHardware>

Gets available server hardware

Returns:

  • (Array<OneviewSDK::ServerHardware>)

    Array of ServerHardware resources that matches this profile’s server hardware type and enclosure group and who’s state is ‘NoProfileApplied’



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 124

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']
  }
  OneviewSDK::ServerHardware.find_by(@client, params)
rescue StandardError => e
  raise IncompleteResource, "Failed to get available hardware. Message: #{e.message}"
end

#get_available_networksHash

Gets all the available Ethernet and FC Networks, and Network Sets

Returns:

  • (Hash)

    A hash containing the lists of Ethernet Networks and FC Networks



116
117
118
119
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 116

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_previewHash

Gets the preview of manual and automatic updates required to make the server profile consistent with its template.

Returns:

  • (Hash)

    Hash containing the required information



57
58
59
60
61
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 57

def get_compliance_preview
  ensure_client & ensure_uri
  response = @client.rest_get("#{self['uri']}/compliance-preview")
  @client.response_handler(response)
end

#get_messagesHash

Retrieves the error or status messages associated with the specified profile.

Returns:

  • (Hash)

    Hash containing the required information



65
66
67
68
69
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 65

def get_messages
  ensure_client & ensure_uri
  response = @client.rest_get("#{self['uri']}/messages")
  @client.response_handler(response)
end

#get_server_hardwareOneviewSDK::ServerHardware?

Gets attached ServerHardware for the profile

Returns:

  • (OneviewSDK::ServerHardware)

    if hardware is attached

  • (nil)

    if no hardware is attached



106
107
108
109
110
111
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 106

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.

Parameters:

  • query (Hash<String,Object>) (defaults to: nil)

    Query parameters

Options Hash (query):

  • 'enclosure_group' (OneviewSDK::EnclosureGroup)

    Enclosure Group associated with the resource

  • 'server_hardware' (OneviewSDK::ServerHardware)

    The server hardware associated with the resource

  • 'server_hardware_type' (OneviewSDK::ServerHardwareType)

    The server hardware type associated with the resource

Returns:

  • (Hash)

    Hash containing the required information



82
83
84
85
86
87
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 82

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

Parameters:

  • connection_name (String)

    Name of the connection

Returns:

  • Returns the connection hash if found, otherwise returns nil



176
177
178
179
180
181
182
183
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 176

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

Parameters:

  • id (Fixnum)

    ID number of the attachment entry

Returns:

  • Returns the volume hash if found, otherwise returns nil



256
257
258
259
260
261
262
263
264
265
266
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 256

def remove_volume_attachment(id)
  self['sanStorage'] ||= {}
  self['sanStorage']['volumeAttachments'] ||= []
  return if self['sanStorage'].empty? || self['sanStorage']['volumeAttachments'].empty?

  volume_attachment = nil
  self['sanStorage']['volumeAttachments'].each do |entry|
    volume_attachment = self['sanStorage']['volumeAttachments'].delete(entry) if entry['id'] == id
  end
  volume_attachment
end

#set_enclosure(enclosure) ⇒ Object

Sets the Enclosure Group for the resource

Parameters:

  • enclosure (OneviewSDK::Enclosure)

    Enclosure that the Server is a member



50
51
52
53
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 50

def set_enclosure(enclosure)
  self['enclosureUri'] = enclosure['uri'] if enclosure['uri'] || enclosure.retrieve!
  raise "Resource #{enclosure['name']} could not be found!" unless enclosure['uri']
end

#set_enclosure_group(enclosure_group) ⇒ Object

Sets the Enclosure Group for the resource

Parameters:

  • enclosure_group (OneviewSDK::EnclosureGroup)

    Enclosure Group that the Server is a member



43
44
45
46
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 43

def set_enclosure_group(enclosure_group)
  self['enclosureGroupUri'] = enclosure_group['uri'] if enclosure_group['uri'] || enclosure_group.retrieve!
  raise "Resource #{enclosure_group['name']} could not be found!" unless enclosure_group['uri']
end

#set_firmware_driver(firmware, firmware_options = {}) ⇒ Object

Sets the Firmware Driver for the server profile

Parameters:

  • firmware (OneviewSDK::FirmwareDriver)

    Firmware Driver to be associated with the resource

  • firmware_options (Hash<String,Object>) (defaults to: {})

    Firmware Driver options

Options Hash (firmware_options):

  • 'manageFirmware' (Boolean)

    Indicates that the server firmware is configured using the server profile. Value can be ‘true’ or ‘false’.

  • 'forceInstallFirmware' (Boolean)

    Force installation of firmware even if same or newer version is installed. Downgrading the firmware can result in the installation of unsupported firmware and cause server hardware to cease operation. Value can be ‘true’ or ‘false’.

  • 'firmwareInstallType' (String)

    Specifies the way a Service Pack for ProLiant (SPP) is installed. This field is used if the ‘manageFirmware’ field is true. Values are ‘FirmwareAndOSDrivers’, ‘FirmwareOnly’, and ‘FirmwareOnlyOfflineMode’.



279
280
281
282
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 279

def set_firmware_driver(firmware, firmware_options = {})
  firmware_options['firmwareBaselineUri'] = firmware['uri'] if firmware['uri'] || firmware.retrieve!
  self['firmware'] = firmware_options
end

#set_server_hardware(server_hardware) ⇒ Object

Sets the Server Hardware for the resource

Parameters:

  • server_hardware (OneviewSDK::ServerHardware)

    Server Hardware resource



29
30
31
32
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 29

def set_server_hardware(server_hardware)
  self['serverHardwareUri'] = server_hardware['uri'] if server_hardware['uri'] || server_hardware.retrieve!
  raise "Resource #{server_hardware['name']} could not be found!" unless server_hardware['uri']
end

#set_server_hardware_type(server_hardware_type) ⇒ Object

Sets the Server Hardware Type for the resource

Parameters:

  • server_hardware_type (OneviewSDK::ServerHardwareType)

    Type of the desired Server Hardware



36
37
38
39
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 36

def set_server_hardware_type(server_hardware_type)
  self['serverHardwareTypeUri'] = server_hardware_type['uri'] if server_hardware_type['uri'] || server_hardware_type.retrieve!
  raise "Resource #{server_hardware_type['name']} could not be found!" unless server_hardware_type['uri']
end

#update_from_templateObject

Updates the server profile from the server profile template.



90
91
92
93
94
95
96
97
98
99
# File 'lib/oneview-sdk/resource/api200/server_profile.rb', line 90

def update_from_template
  ensure_client & ensure_uri
  patch_operation = { 'op' => 'replace', 'path' => '/templateCompliance', 'value' => 'Compliant' }
  patch_options = {
    'If-Match' => self['eTag'],
    'body' => [patch_operation]
  }
  response = @client.rest_patch(self['uri'], patch_options)
  @client.response_handler(response)
end