Class: OneviewSDK::API200::ServerProfileTemplate

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

Overview

Server profile template resource implementation

Constant Summary collapse

BASE_URI =
'/rest/server-profile-templates'.freeze

Constants inherited from Resource

Resource::DEFAULT_REQUEST_HEADER, Resource::UNIQUE_IDENTIFIERS

Instance Attribute Summary

Attributes inherited from Resource

#api_version, #client, #data, #logger

Instance Method Summary collapse

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) ⇒ ServerProfileTemplate

Create a resource object, associate it with a client, and set its properties.

Parameters:

  • client (OneviewSDK::Client)

    The client object for the OneView appliance

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

    The options for this resource (key-value pairs)

  • api_ver (Integer) (defaults to: nil)

    The api version to use when interracting with this resource.



24
25
26
27
28
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 24

def initialize(client, params = {}, api_ver = nil)
  super
  # Default values
  @data['type'] ||= 'ServerProfileTemplateV1'
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’.



88
89
90
91
92
93
94
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 88

def add_connection(network, connection_options = {})
  connection_options = Hash[connection_options.map { |k, v| [k.to_s, v] }]
  self['connections'] = [] unless self['connections']
  connection_options['id'] ||= 0
  connection_options['networkUri'] = network['uri'] if network['uri'] || network.retrieve!
  self['connections'] << connection_options
end

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

Adds a volume attachment entry with associated volume in server profile template

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

Raises:



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 119

def add_volume_attachment(volume, attachment_options = {})
  raise IncompleteResource, 'Volume not found!' unless volume.retrieve!
  # Convert symbols keys to string
  attachment_options = Hash[attachment_options.map { |k, v| [k.to_s, v] }]
  self['sanStorage'] ||= {}
  self['sanStorage']['volumeAttachments'] ||= []
  self['sanStorage']['manageSanStorage'] ||= true
  attachment_options['id'] ||= 0
  attachment_options['volumeUri'] = volume['uri']
  attachment_options['volumeStoragePoolUri'] = volume['storagePoolUri']
  attachment_options['volumeStorageSystemUri'] = volume['storageSystemUri'] if volume['storageSystemUri']

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

#create_volume_with_attachment(storage_pool, volume_options, attachment_options = {}) ⇒ Object

Adds a volume attachment entry with new volume in Server profile template

Parameters:

  • storage_pool (OneviewSDK::StoragePool)

    StoragePool 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

Raises:



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 147

def create_volume_with_attachment(storage_pool, volume_options, attachment_options = {})
  raise IncompleteResource, 'Storage Pool not found!' unless storage_pool.retrieve!
  # Convert symbols keys to string in volume_options and attachment_options
  volume_options = Hash[volume_options.map { |k, v| [k.to_s, v] }]
  attachment_options = Hash[attachment_options.map { |k, v| [k.to_s, v] }]
  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']
  # volumeProvisionedCapacityBytes is not following the same pattern in Volume
  attachment_options['volumeProvisionedCapacityBytes'] ||= attachment_options.delete('volumeRequestedCapacity')

  # Defaults
  attachment_options['volumeUri'] = nil
  attachment_options['volumeStorageSystemUri'] = nil
  attachment_options['permanent'] ||= true
  attachment_options['volumeShareable'] = false

  self['sanStorage']['manageSanStorage'] ||= true
  self['sanStorage']['volumeAttachments'] << attachment_options
end

#get_available_hardwareArray<OneviewSDK::ServerHardware>

Gets the available server hardwares

Returns:

  • (Array<OneviewSDK::ServerHardware>)

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

Raises:



199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 199

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

#new_profile(name = nil) ⇒ OneviewSDK::ServerProfile

Creates a ServerProfile using this template

Parameters:

  • name (String) (defaults to: nil)

    Name of new server profile

Returns:

  • (OneviewSDK::ServerProfile)

    New server profile from template. Temporary object only; call .create to actually create resource on OneView.



217
218
219
220
221
222
223
224
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 217

def new_profile(name = nil)
  ensure_client && ensure_uri
  response = @client.rest_get("#{@data['uri']}/new-profile")
  options = @client.response_handler(response)
  profile = OneviewSDK::ServerProfile.new(@client, options)
  profile['name'] = name ? name : "Server_Profile_created_from_#{@data['name']}"
  profile
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



99
100
101
102
103
104
105
106
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 99

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 Server profile template

Parameters:

  • id (Fixnum)

    ID number of the attachment entry

Returns:

  • Returns the volume hash if found, otherwise returns nil



183
184
185
186
187
188
189
190
191
192
193
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 183

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_group(enclosure_group) ⇒ Object

Sets the enclosure group for the server profile template

Parameters:

  • enclosure_group (OneviewSDK::EnclosureGroup)

    Enclosure Group that the Server is a member



39
40
41
42
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 39

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 current server profile template

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’.



55
56
57
58
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 55

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_type(server_hardware_type) ⇒ Object

Sets the Server Hardware Type for the Server Profile Template

Parameters:

  • server_hardware_type (OneviewSDK::ServerHardwareType)

    Type of the desired Server Hardware



32
33
34
35
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 32

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