Class: OneviewSDK::ServerProfileTemplate
- Defined in:
- lib/oneview-sdk/resource/server_profile_template.rb
Overview
Server profile template resource implementation
Constant Summary collapse
- BASE_URI =
'/rest/server-profile-templates'.freeze
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.
17 18 19 20 21 |
# File 'lib/oneview-sdk/resource/server_profile_template.rb', line 17 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
81 82 83 84 85 86 |
# File 'lib/oneview-sdk/resource/server_profile_template.rb', line 81 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
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/oneview-sdk/resource/server_profile_template.rb', line 110 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
135 136 137 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 |
# File 'lib/oneview-sdk/resource/server_profile_template.rb', line 135 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
186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/oneview-sdk/resource/server_profile_template.rb', line 186 def get_available_hardware ensure_client fail IncompleteResource, 'Must set @data[\'serverHardwareTypeUri\']' unless @data['serverHardwareTypeUri'] fail 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
204 205 206 207 208 209 210 211 |
# File 'lib/oneview-sdk/resource/server_profile_template.rb', line 204 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
91 92 93 94 95 96 97 98 |
# File 'lib/oneview-sdk/resource/server_profile_template.rb', line 91 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
171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/oneview-sdk/resource/server_profile_template.rb', line 171 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
32 33 34 35 |
# File 'lib/oneview-sdk/resource/server_profile_template.rb', line 32 def set_enclosure_group(enclosure_group) self['enclosureGroupUri'] = enclosure_group['uri'] if enclosure_group['uri'] || enclosure_group.retrieve! fail "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
48 49 50 51 |
# File 'lib/oneview-sdk/resource/server_profile_template.rb', line 48 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
25 26 27 28 |
# File 'lib/oneview-sdk/resource/server_profile_template.rb', line 25 def set_server_hardware_type(server_hardware_type) self['serverHardwareTypeUri'] = server_hardware_type['uri'] if server_hardware_type['uri'] || server_hardware_type.retrieve! fail "Resource #{server_hardware_type['name']} could not be found!" unless server_hardware_type['uri'] end |