Class: OneviewSDK::Volume

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

Overview

Volume resource implementation

Validates collapse

VALID_PROVISION_TYPES =
%w(Thin Full).freeze

Constant Summary collapse

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

Instance Attribute Summary

Attributes inherited from Resource

#api_version, #client, #data, #logger

Validates collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, #[], #[]=, #create!, #each, #eql?, #exists?, find_by, from_file, get_all, #initialize, #like?, #refresh, #retrieve!, #schema, schema, #set, #set_all, #to_file, #update

Constructor Details

This class inherits a constructor from OneviewSDK::Resource

Class Method Details

.get_attachable_volumes(client) ⇒ Array<OneviewSDK::Volume>

Get all the attachable volumes managed by the appliance

Parameters:

  • client (Client)

    The client object for the appliance

Returns:



149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/oneview-sdk/resource/volume.rb', line 149

def self.get_attachable_volumes(client)
  results = []
  uri = "#{BASE_URI}/attachable-volumes"
  loop do
    response = client.rest_get(uri)
    body = client.response_handler(response)
    members = body['members']
    members.each { |member| results.push(OneviewSDK::Volume.new(client, member)) }
    break unless body['nextPageUri']
    uri = body['nextPageUri']
  end
  results
end

.get_extra_managed_volume_paths(client) ⇒ Object

Gets the list of extra managed storage volume paths

Parameters:

Returns:

  • response



166
167
168
169
# File 'lib/oneview-sdk/resource/volume.rb', line 166

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

#createResource

Note:

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

Create the volume

Returns:

Raises:

  • (RuntimeError)

    if the client is not set

  • (RuntimeError)

    if the resource creation fails



30
31
32
33
34
35
36
37
# File 'lib/oneview-sdk/resource/volume.rb', line 30

def create
  ensure_client
  response = @client.rest_post(self.class::BASE_URI, { 'body' => @data }, @api_version)
  body = @client.response_handler(response)
  set_all(body)
  @data.delete('provisioningParameters')
  self
end

#create_snapshot(snapshot, description = nil) ⇒ true

Create 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



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/oneview-sdk/resource/volume.rb', line 89

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 = {
    type: 'Snapshot',
    description: description,
    name: name
  }
  response = @client.rest_post("#{@data['uri']}/snapshots", { 'body' => data }, @api_version)
  @client.response_handler(response)
  true
end

#delete(flag = :all) ⇒ true

Delete 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

Returns:

  • (true)

    if resource was deleted successfully



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/oneview-sdk/resource/volume.rb', line 42

def delete(flag = :all)
  ensure_client && ensure_uri
  case flag
  when :oneview
    response = @client.rest_api(:delete, @data['uri'], { 'exportOnly' => true }, @api_version)
    @client.response_handler(response)
  when :all
    response = @client.rest_api(:delete, @data['uri'], {}, @api_version)
    @client.response_handler(response)
  else
    fail 'Invalid flag value, use :oneview or :all'
  end
  true
end

#delete_snapshot(name) ⇒ true

Delete a snapshot of the volume

Parameters:

  • name (String)

    snapshot name

Returns:

  • (true)

    if snapshot was created successfully



110
111
112
113
114
115
# File 'lib/oneview-sdk/resource/volume.rb', line 110

def delete_snapshot(name)
  result = get_snapshot(name)
  response = @client.rest_api(:delete, result['uri'], {}, @api_version)
  @client.response_handler(response)
  true
end

#get_snapshot(name) ⇒ Hash

Retrieve snapshot by name

Parameters:

  • name (String)

Returns:

  • (Hash)

    snapshot data



120
121
122
123
124
125
# File 'lib/oneview-sdk/resource/volume.rb', line 120

def get_snapshot(name)
  results = get_snapshots
  results.each do |snapshot|
    return snapshot if snapshot['name'] == name
  end
end

#get_snapshotsArray

Get snapshots of this volume

Returns:

  • (Array)

    Array of snapshots



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/oneview-sdk/resource/volume.rb', line 129

def get_snapshots
  ensure_uri && ensure_client
  results = []
  uri = "#{@data['uri']}/snapshots"
  loop do
    response = @client.rest_get(uri, @api_version)
    body = @client.response_handler(response)
    members = body['members']
    members.each do |member|
      results.push(member)
    end
    break unless body['nextPageUri']
    uri = body['nextPageUri']
  end
  results
end

#repairObject

Removes extra presentation from volume

Returns:

  • response



173
174
175
176
# File 'lib/oneview-sdk/resource/volume.rb', line 173

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:



80
81
82
83
# File 'lib/oneview-sdk/resource/volume.rb', line 80

def set_snapshot_pool(storage_pool)
  assure_uri(storage_pool)
  set('snapshotPoolUri', storage_pool['uri'])
end

#set_storage_pool(storage_pool) ⇒ Object

Sets the storage pool to the volume

Parameters:



66
67
68
69
# File 'lib/oneview-sdk/resource/volume.rb', line 66

def set_storage_pool(storage_pool)
  assure_uri(storage_pool)
  set('storagePoolUri', storage_pool['uri'])
end

#set_storage_system(storage_system) ⇒ Object

Sets the storage system to the volume

Parameters:



59
60
61
62
# File 'lib/oneview-sdk/resource/volume.rb', line 59

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 storage volume template to the volume

Parameters:



73
74
75
76
# File 'lib/oneview-sdk/resource/volume.rb', line 73

def set_storage_volume_template(storage_volume_template)
  assure_uri(storage_volume_template)
  set('templateUri', storage_volume_template['uri'])
end

#validate_provisionType(value) ⇒ Object

Validate the type of provisioning

Parameters:

  • value (String)

    Must be Thin or Full



11
12
13
# File 'lib/oneview-sdk/resource/volume.rb', line 11

def validate_provisionType(value)
  fail 'Invalid provision type' unless VALID_PROVISION_TYPES.include?(value)
end