class OneviewSDK::API200::Volume

Volume resource implementation

Constants

BASE_URI

Public Class Methods

get_attachable_volumes(client, query = nil) click to toggle source

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
get_extra_managed_volume_paths(client) click to toggle source

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

create(header = {}) click to toggle source

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

Calls superclass method 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
create!(header = {}) click to toggle source

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
create_snapshot(snapshot, description = nil) click to toggle source

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
delete(flag = :all, header = {}) click to toggle source

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

Calls superclass method 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
delete_snapshot(name) click to toggle source

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
get_snapshot(name) click to toggle source

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
get_snapshots() click to toggle source

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
repair() click to toggle source

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
set_snapshot_pool(storage_pool) click to toggle source

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
set_storage_pool(storage_pool) click to toggle source

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
set_storage_system(storage_system) click to toggle source

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
set_storage_volume_template(storage_volume_template) click to toggle source

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(attributes = {}) click to toggle source

Update resource attributes @param [Hash] attributes attributes to be updated @return [OneviewSDK::Volume] self

Calls superclass method OneviewSDK::Resource#update
# File lib/oneview-sdk/resource/api200/volume.rb, line 56
def update(attributes = {})
  @data.delete('provisioningParameters')
  super
end

Private Instance Methods

assure_uri(resource) click to toggle source

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
generate_snapshot_data(name, description = nil) click to toggle source

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