Class: OneviewSDK::API200::ServerProfileTemplate
- Defined in:
- lib/oneview-sdk/resource/api200/server_profile_template.rb
Overview
Server profile template resource implementation
Direct Known Subclasses
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
-
#add_connection(network, connection_options = {}) ⇒ Object
Adds a connection entry to server profile template.
-
#add_volume_attachment(volume, attachment_options = {}) ⇒ Object
Adds a volume attachment entry with associated volume in server profile template.
-
#create_volume_with_attachment(storage_pool, volume_options, attachment_options = {}) ⇒ Object
Adds a volume attachment entry with new volume in Server profile template.
-
#get_available_hardware ⇒ Array<OneviewSDK::ServerHardware>
Gets the available server hardwares.
-
#initialize(client, params = {}, api_ver = nil) ⇒ ServerProfileTemplate
constructor
Create a resource object, associate it with a client, and set its properties.
-
#new_profile(name = nil) ⇒ OneviewSDK::ServerProfile
Creates a ServerProfile using this template.
-
#remove_connection(connection_name) ⇒ Object
Removes a connection entry in server profile template.
-
#remove_volume_attachment(id) ⇒ Object
Removes a volume attachment entry in Server profile template.
-
#set_enclosure_group(enclosure_group) ⇒ Object
Sets the enclosure group for the server profile template.
-
#set_firmware_driver(firmware, firmware_options = {}) ⇒ Object
Sets the firmware driver for the current server profile template.
-
#set_server_hardware_type(server_hardware_type) ⇒ Object
Sets the Server Hardware Type for the Server Profile Template.
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.
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
88 89 90 91 92 93 94 |
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 88 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 a volume attachment entry with associated volume in server profile template
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 (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'] if volume['storageSystemUri'] self['sanStorage']['volumeAttachments'] << end |
#create_volume_with_attachment(storage_pool, volume_options, attachment_options = {}) ⇒ Object
Adds a volume attachment entry with new volume in Server profile template
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 (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'] # volumeProvisionedCapacityBytes is not following the same pattern in Volume ['volumeProvisionedCapacityBytes'] ||= .delete('volumeRequestedCapacity') # Defaults ['volumeUri'] = nil ['volumeStorageSystemUri'] = nil ['permanent'] ||= true ['volumeShareable'] = false self['sanStorage']['manageSanStorage'] ||= true self['sanStorage']['volumeAttachments'] << end |
#get_available_hardware ⇒ Array<OneviewSDK::ServerHardware>
Gets the available server hardwares
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.}" end |
#new_profile(name = nil) ⇒ OneviewSDK::ServerProfile
Creates a ServerProfile using this template
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") = @client.response_handler(response) profile = OneviewSDK::ServerProfile.new(@client, ) 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
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
183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 183 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_group(enclosure_group) ⇒ Object
Sets the enclosure group for the server profile template
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
55 56 57 58 |
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 55 def set_firmware_driver(firmware, = {}) ['firmwareBaselineUri'] = firmware['uri'] if firmware['uri'] || firmware.retrieve! self['firmware'] = end |
#set_server_hardware_type(server_hardware_type) ⇒ Object
Sets the Server Hardware Type for the Server Profile Template
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 |