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::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!, #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) ⇒ ServerProfileTemplate

Returns a new instance of ServerProfileTemplate.



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

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



84
85
86
87
88
89
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 84

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



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 113

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 a volume attachment entry with new volume in Server profile template

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



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 138

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



189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 189

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.



207
208
209
210
211
212
213
214
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 207

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



94
95
96
97
98
99
100
101
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 94

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



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

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



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

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



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

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



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

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