Class: OneviewSDK::API200::Volume

Inherits:
Resource
  • Object
show all
Defined in:
lib/oneview-sdk/resource/api200/volume.rb

Overview

Volume resource implementation

Constant Summary collapse

BASE_URI =
'/rest/storage-volumes'.freeze

Constants inherited from Resource

Resource::DEFAULT_REQUEST_HEADER, Resource::UNIQUE_IDENTIFIERS

Instance Attribute Summary

Attributes inherited from Resource

#api_version, #client, #data, #logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, #[], #[]=, build_query, #deep_merge!, #each, #eql?, #exists?, find_by, find_with_pagination, from_file, get_all, get_all_with_query, #initialize, #like?, #refresh, #retrieve!, #schema, schema, #set, #set_all, #to_file

Constructor Details

This class inherits a constructor from OneviewSDK::Resource

Class Method Details

.get_attachable_volumes(client, query = nil) ⇒ Array<OneviewSDK::Volume>

Gets all the attachable volumes managed by the appliance

Parameters:

Returns:

  • (Array<OneviewSDK::Volume>)

    Array of volumes



150
151
152
153
154
# 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) ⇒ Object

Gets the list of extra managed storage volume paths

Parameters:

Returns:

  • response



159
160
161
162
# 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

Instance Method Details

#create(header = {}) ⇒ Resource

Note:

provisioning parameters are required for creation, but not afterwards; after creation, they will be removed.

Creates the volume

Parameters:

  • header (Hash) (defaults to: {})

    The header options for the request (key-value pairs)

Returns:

Raises:



34
35
36
37
38
# 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 = {}) ⇒ Resource

Note:

Calls refresh method to set additional data

Delete the resource from OneView if it exists, then create it using the current data

Parameters:

  • header (Hash) (defaults to: {})

    The header options for the request (key-value pairs)

Returns:

Raises:



46
47
48
49
50
51
# 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) ⇒ true

Creates a snapshot of the volume

Parameters:

  • snapshot (String, OneviewSDK::VolumeSnapshot)

    String or OneviewSDK::VolumeSnapshot object

  • description (String) (defaults to: nil)

    Provide a description

Returns:

  • (true)

    if snapshot was created successfully



107
108
109
110
111
112
113
114
115
116
117
118
119
# 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 = {}) ⇒ true

Deletes the resource from OneView or from Oneview and storage system

Parameters:

  • flag (Symbol) (defaults to: :all)

    Delete storage system from Oneview only or in storage system as well

  • header (Hash) (defaults to: {})

    The header options for the request (key-value pairs)

Returns:

  • (true)

    if resource was deleted successfully

Raises:



65
66
67
68
69
70
# 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) ⇒ true

Deletes a snapshot of the volume

Parameters:

  • name (String)

    snapshot name

Returns:

  • (true)

    if snapshot was created successfully



124
125
126
127
128
129
# 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' => @data['eTag'] }, @api_version)
  @client.response_handler(response)
  true
end

#get_snapshot(name) ⇒ Hash

Retrieves a snapshot by name

Parameters:

  • name (String)

Returns:

  • (Hash)

    snapshot data



134
135
136
137
# 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_snapshotsArray

Gets all the snapshots of this volume

Returns:

  • (Array)

    Array of snapshots



141
142
143
144
145
# 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

#repairObject

Removes extra presentation from the volume

Returns:

  • response



166
167
168
169
# 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) ⇒ Object

Sets the snapshot pool to the volume

Parameters:

  • storage_pool (OneviewSDK::StoragePool)

    Storage Pool to use for snapshots



98
99
100
101
# 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) ⇒ Object

Note:

The storagePoolUri attribute should not be set in the updated. Once created, this attribute is read only.

Sets the storage pool to the volume

Parameters:

  • storage_pool (OneviewSDK::StoragePool)

    Storage pool



83
84
85
86
87
# 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) ⇒ Object

Note:

The storageSystemUri attribute should not be set in the updated. Once created, this attribute is read only.

Sets the storage system to the volume

Parameters:

  • storage_system (OneviewSDK::StorageSystem)

    Storage System



75
76
77
78
# 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) ⇒ Object

Adds the storage volume template to the volume

Parameters:

  • storage_volume_template (OneviewSDK::VolumeTemplate)

    Storage Volume Template



91
92
93
94
# 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 = {}) ⇒ OneviewSDK::Volume

Update resource attributes

Parameters:

  • attributes (Hash) (defaults to: {})

    attributes to be updated

Returns:

  • (OneviewSDK::Volume)

    self



56
57
58
59
# File 'lib/oneview-sdk/resource/api200/volume.rb', line 56

def update(attributes = {})
  @data.delete('provisioningParameters')
  super
end