class OneviewSDK::API200::Volume
Volume
resource implementation
Constants
- BASE_URI
Public Class Methods
Gets all the attachable volumes managed by the appliance @param [OneviewSDK::Client] client The client object for the OneView appliance @return [Array<OneviewSDK::Volume>] Array of volumes
# File lib/oneview-sdk/resource/api200/volume.rb, line 150 def self.get_attachable_volumes(client, query = nil) query_uri = build_query(query) if query uri = "#{BASE_URI}/attachable-volumes#{query_uri}" find_by(client, {}, uri) end
Gets the list of extra managed storage volume paths @param [OneviewSDK::Client] client The client object for the OneView appliance @return response
# File lib/oneview-sdk/resource/api200/volume.rb, line 159 def self.get_extra_managed_volume_paths(client) response = client.rest_get(BASE_URI + '/repair?alertFixType=ExtraManagedStorageVolumePaths') client.response_handler(response) end
Public Instance Methods
Creates the volume @note provisioning parameters are required for creation, but not afterwards; after creation, they will be removed. @param [Hash] header The header options for the request (key-value pairs) @raise [OneviewSDK::IncompleteResource] if the client is not set @raise [StandardError] if the resource creation fails @return [Resource] self
OneviewSDK::Resource#create
# File lib/oneview-sdk/resource/api200/volume.rb, line 34 def create(header = {}) super(DEFAULT_REQUEST_HEADER.merge(header)) @data.delete('provisioningParameters') self end
Delete the resource from OneView if it exists, then create it using the current data @note Calls refresh method to set additional data @param [Hash] header The header options for the request (key-value pairs) @raise [OneviewSDK::IncompleteResource] if the client is not set @raise [StandardError] if the resource creation fails @return [Resource] self
# File lib/oneview-sdk/resource/api200/volume.rb, line 46 def create!(header = {}) temp = self.class.new(@client, @data) header = DEFAULT_REQUEST_HEADER.merge(header) temp.delete(:all, header) if temp.retrieve!(header) create(header) end
Creates a snapshot of the volume @param [String, OneviewSDK::VolumeSnapshot] snapshot String or OneviewSDK::VolumeSnapshot object @param [String] description Provide a description @return [true] if snapshot was created successfully
# File lib/oneview-sdk/resource/api200/volume.rb, line 107 def create_snapshot(snapshot, description = nil) ensure_uri && ensure_client if snapshot.is_a?(OneviewSDK::Resource) || snapshot.is_a?(Hash) name = snapshot[:name] || snapshot['name'] description ||= snapshot[:description] || snapshot['description'] else name = snapshot end data = generate_snapshot_data(name, description) response = @client.rest_post("#{@data['uri']}/snapshots", { 'body' => data }, @api_version) @client.response_handler(response) true end
Deletes the resource from OneView or from Oneview and storage system @param [Symbol] flag Delete storage system from Oneview only or in storage system as well @param [Hash] header The header options for the request (key-value pairs) @return [true] if resource was deleted successfully
OneviewSDK::Resource#delete
# File lib/oneview-sdk/resource/api200/volume.rb, line 65 def delete(flag = :all, header = {}) ensure_client && ensure_uri raise InvalidResource, 'Invalid flag value, use :oneview or :all' unless %i[oneview all].include?(flag) header = DEFAULT_REQUEST_HEADER.merge(header).merge('exportOnly' => true) if flag == :oneview super(header) end
Deletes a snapshot of the volume @param [String] name snapshot name @return [true] if snapshot was created successfully
# File lib/oneview-sdk/resource/api200/volume.rb, line 124 def delete_snapshot(name) result = get_snapshot(name) response = @client.rest_delete(result['uri'], { 'If-Match' => result['eTag'] }, @api_version) @client.response_handler(response) true end
Retrieves a snapshot by name @param [String] name @return [Hash] snapshot data
# File lib/oneview-sdk/resource/api200/volume.rb, line 134 def get_snapshot(name) results = get_snapshots results.find { |snap| snap['name'] == name } end
Gets all the snapshots of this volume @return [Array] Array of snapshots
# File lib/oneview-sdk/resource/api200/volume.rb, line 141 def get_snapshots ensure_uri && ensure_client uri = "#{@data['uri']}/snapshots" self.class.find_with_pagination(@client, uri) end
Removes extra presentation from the volume @return response
# File lib/oneview-sdk/resource/api200/volume.rb, line 166 def repair response = client.rest_post(BASE_URI + '/repair', 'body' => { resourceUri: @data['uri'], type: 'ExtraManagedStorageVolumePaths' }) client.response_handler(response) end
Sets the snapshot pool to the volume @param [OneviewSDK::StoragePool] storage_pool Storage Pool to use for snapshots
# File lib/oneview-sdk/resource/api200/volume.rb, line 98 def set_snapshot_pool(storage_pool) assure_uri(storage_pool) set('snapshotPoolUri', storage_pool['uri']) end
Sets the storage pool to the volume @note The storagePoolUri attribute should not be set in the updated. Once created, this attribute is read only. @param [OneviewSDK::StoragePool] storage_pool Storage pool
# File lib/oneview-sdk/resource/api200/volume.rb, line 83 def set_storage_pool(storage_pool) assure_uri(storage_pool) self['provisioningParameters'] ||= {} self['provisioningParameters']['storagePoolUri'] = storage_pool['uri'] end
Sets the storage system to the volume @param [OneviewSDK::StorageSystem] storage_system Storage System @note The storageSystemUri attribute should not be set in the updated. Once created, this attribute is read only.
# File lib/oneview-sdk/resource/api200/volume.rb, line 75 def set_storage_system(storage_system) assure_uri(storage_system) set('storageSystemUri', storage_system['uri']) end
Adds the storage volume template to the volume @param [OneviewSDK::VolumeTemplate] storage_volume_template Storage Volume
Template
# File lib/oneview-sdk/resource/api200/volume.rb, line 91 def set_storage_volume_template(storage_volume_template) assure_uri(storage_volume_template) set('templateUri', storage_volume_template['uri']) end
Update resource attributes @param [Hash] attributes attributes to be updated @return [OneviewSDK::Volume] self
OneviewSDK::Resource#update
# File lib/oneview-sdk/resource/api200/volume.rb, line 56 def update(attributes = {}) @data.delete('provisioningParameters') super end
Private Instance Methods
Verify if the resource has a URI If not, first it tries to retrieve, and then verify for its existence @param [OneviewSDK::Resource] resource The resource object @raise [OneviewSDK::IncompleteResource] if the resource not found
# File lib/oneview-sdk/resource/api200/volume.rb, line 177 def assure_uri(resource) resource.retrieve! unless resource['uri'] raise IncompleteResource, "#{resource.class}: #{resource['name']} not found" unless resource['uri'] end
Generates the snapshot data @param [String] name The name of the snapshot @param [String] description The description of the snapshot @return [Hash] snapshot data
# File lib/oneview-sdk/resource/api200/volume.rb, line 186 def generate_snapshot_data(name, description = nil) { type: 'Snapshot', description: description, name: name } end