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
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
A new instance of ServerProfileTemplate.
-
#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!, #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
84 85 86 87 88 89 |
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 84 def add_connection(network, = {}) self['connections'] = [] unless self['connections'] ['id'] = 0 # Letting OneView treat the ID registering ['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
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 (volume, = {}) self['sanStorage'] ||= {} self['sanStorage']['volumeAttachments'] ||= [] ['id'] ||= 0 volume.retrieve! unless volume['uri'] || volume['storagePoolUri'] || volume['storageSystemUri'] ['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 a volume attachment entry with new volume in Server profile template
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 (storage_pool, , = {}) 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'] if storage_pool['uri'] || storage_pool.retrieve! # 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'] ||= [] self['sanStorage']['volumeAttachments'] << end |
#get_available_hardware ⇒ Array<OneviewSDK::ServerHardware>
Gets the available server hardwares
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.}" end |
#new_profile(name = nil) ⇒ OneviewSDK::ServerProfile
Creates a ServerProfile using this template
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") = @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
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
174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 174 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
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
51 52 53 54 |
# File 'lib/oneview-sdk/resource/api200/server_profile_template.rb', line 51 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
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 |