Class: OneviewSDK::API500::C7000::Volume

Inherits:
OneviewSDK::API300::C7000::Volume show all
Defined in:
lib/oneview-sdk/resource/api500/c7000/volume.rb

Overview

Volume resource implementation on API500 C7000

Constant Summary

Constants inherited from OneviewSDK::API200::Volume

OneviewSDK::API200::Volume::BASE_URI

Constants inherited from Resource

Resource::BASE_URI, 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 OneviewSDK::API200::Volume

#create!, #create_snapshot, #delete_snapshot, get_attachable_volumes, get_extra_managed_volume_paths, #get_snapshot, #get_snapshots, #repair, #set_storage_volume_template

Methods inherited from Resource

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

Constructor Details

This class inherits a constructor from OneviewSDK::Resource

Class Method Details

.add(client, storage_system, volume_name, is_shareable = false, options = {}) ⇒ OneviewSDK::Volume

Deprecated.

Use #add instead.

Note:

Volumes can be added only on the storage system and storage pools managed by the appliance.

Initiates a process to import a volume (created external to OneView) for management by the appliance.

Parameters:

  • The client object for the OneView appliance.

  • The storage system in which the volume exists to be managed.

  • The name of the volume on the actual storage system.

  • (defaults to: false)

    Describes if the volume is shareable or private.

  • (defaults to: {})

    The options to create a volume.

Options Hash (options):

  • :name (String)

    The name for new volume.

  • :description (String)

    The description for new volume.

Returns:

  • The volume imported.

Raises:

  • if storage system is not found



140
141
142
143
144
145
# File 'lib/oneview-sdk/resource/api500/c7000/volume.rb', line 140

def self.add(client, storage_system, volume_name, is_shareable = false, options = {})
  raise IncompleteResource, 'Storage system not found!' unless storage_system.retrieve!
  data = options.merge('storageSystemUri' => storage_system['uri'], 'deviceVolumeName' => volume_name, 'isShareable' => is_shareable)
  response = client.rest_post("#{BASE_URI}/from-existing", { 'body' => data }, client.api_version)
  new(client, client.response_handler(response))
end

Instance Method Details

#addOneviewSDK::Volume

Note:

Volumes can be added only on the storage system and storage pools managed by the appliance.

Initiates a process to import a volume (created external to OneView) for management by the appliance.

Returns:

  • The volume imported.

Raises:

  • if the client is not set or required attributes are missing



151
152
153
154
155
156
157
158
159
# File 'lib/oneview-sdk/resource/api500/c7000/volume.rb', line 151

def add
  ensure_client
  required_attributes = %w[deviceVolumeName isShareable storageSystemUri]
  required_attributes.each { |k| raise IncompleteResource, "Missing required attribute: '#{k}'" unless @data.key?(k) || @data.key?(k.to_sym) }
  @data['name'] ||= @data['deviceVolumeName']
  response = @client.rest_post("#{BASE_URI}/from-existing", { 'body' => @data }, @api_version)
  set_all(client.response_handler(response))
  self
end

#create(header = {}) ⇒ Resource

Note:

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

Creates the volume

Parameters:

  • (defaults to: {})

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

Returns:

  • self

Raises:

  • if the client is not set.

  • if the resource creation fails.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/oneview-sdk/resource/api500/c7000/volume.rb', line 32

def create(header = {})
  properties = Hash[@data['properties'].map { |k, v| [k.to_sym, v] }]
  family = properties[:dataProtectionLevel].nil? ? 'StoreServ' : 'StoreVirtual'
  template_data = {
    isRoot: true,
    family: family
  }
  @data['templateUri'] = get_volume_template_uri(template_data) unless @data['templateUri']

  OneviewSDK::Resource.instance_method(:create).bind(self).call(DEFAULT_REQUEST_HEADER.merge(header))
  @data.delete('properties')
  @data.delete('templateUri')
  self
end

#create_from_snapshot(snapshot_name, properties, volume_template = nil, is_permanent = true) ⇒ OneviewSDK::Volume

Note:

Volumes can only be created on storage pools managed by the appliance.

Creates a new volume on the storage system from a snapshot of a volume.

Parameters:

  • The snapshot name.

  • Storage Pool to use for snapshots.

  • (defaults to: nil)

    The Volume Template resource.

  • (defaults to: true)

    If true, indicates that the volume will persist when the profile using this volume is deleted.

Options Hash (properties):

  • :provisioningType (String)

    The provision type. Values: Full or Thin.

  • :name (String)

    The name for new volume.

  • :isShareable (String)

    Indicates whether or not the volume can be shared by multiple profiles.

Returns:

  • The volume created.

Raises:

  • if the snapshot or volume template are not found.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/oneview-sdk/resource/api500/c7000/volume.rb', line 104

def create_from_snapshot(snapshot_name, properties, volume_template = nil, is_permanent = true)
  snapshot = get_snapshot(snapshot_name)
  raise IncompleteResource, 'Snapshot not found!' unless snapshot
  storage_pool_uri = nil
  volume_template_uri = if volume_template.nil?
                          storage_pool_uri = @data['storagePoolUri']
                          get_volume_template_uri(isRoot: true, family: 'StoreServ')
                        else
                          raise IncompleteResource, 'Volume Template not found!' unless volume_template.retrieve!
                          storage_pool_uri = volume_template['storagePoolUri']
                          volume_template['uri']
                        end

  data = {
    'properties' => properties.merge('storagePool' => storage_pool_uri, 'snapshotPool' => storage_pool_uri),
    'snapshotUri' => snapshot['uri'],
    'templateUri' => volume_template_uri,
    'isPermanent' => is_permanent
  }

  response = @client.rest_post("#{BASE_URI}/from-snapshot", { 'body' => data }, @api_version)
  self.class.new(@client, client.response_handler(response))
end

#delete(flag = :all, header = {}) ⇒ true

Deletes the resource from OneView or from Oneview and storage system

Parameters:

  • (defaults to: :all)

    Delete storage system from Oneview only or in storage system as well. Flags: :all = removes the volume from oneview and storage system. :oneview = removes from oneview only.

  • (defaults to: {})

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

Returns:

  • if resource was deleted successfully.

Raises:

  • if an invalid flag is passed.



61
62
63
64
65
66
67
68
69
# File 'lib/oneview-sdk/resource/api500/c7000/volume.rb', line 61

def delete(flag = :all, header = {})
  ensure_client && ensure_uri
  raise InvalidResource, 'Invalid flag value, use :oneview or :all' unless %i[oneview all].include?(flag)
  uri = @data['uri']
  uri << '?suppressDeviceUpdates=true' if flag == :oneview
  response = @client.rest_delete(uri, DEFAULT_REQUEST_HEADER.merge(header).merge('If-Match' => @data['eTag']))
  @client.response_handler(response)
  true
end

#exists?(header = {}) ⇒ Boolean

Note:

one of the UNIQUE_IDENTIFIERS, e.g. name or uri or properties, must be specified in the resource

Check if a resource exists

Parameters:

  • (defaults to: {})

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

Returns:

  • Whether or not resource exists



178
179
180
181
182
# File 'lib/oneview-sdk/resource/api500/c7000/volume.rb', line 178

def exists?(header = {})
  header = DEFAULT_REQUEST_HEADER.merge(header)
  return super(header) unless @data['properties']
  find_by_name_in_properties(header).size == 1
end

#retrieve!(header = {}) ⇒ Boolean

Note:

one of the UNIQUE_IDENTIFIERS, e.g. name or uri or properties, must be specified in the resource

Retrieve resource details based on this resource’s name or URI.

Parameters:

  • (defaults to: {})

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

Returns:

  • Whether or not retrieve was successful



165
166
167
168
169
170
171
172
# File 'lib/oneview-sdk/resource/api500/c7000/volume.rb', line 165

def retrieve!(header = {})
  header = DEFAULT_REQUEST_HEADER.merge(header)
  return super(header) unless @data['properties']
  results = find_by_name_in_properties(header)
  return false unless results.size == 1
  set_all(results.first.data)
  true
end

#set_snapshot_pool(storage_pool) ⇒ Object

Sets the snapshot pool to the volume

Parameters:

  • Storage Pool to use for snapshots.



82
83
84
85
86
87
88
89
90
91
# File 'lib/oneview-sdk/resource/api500/c7000/volume.rb', line 82

def set_snapshot_pool(storage_pool)
  assure_uri(storage_pool)
  if @data['uri']
    @data['deviceSpecificAttributes'] ||= {}
    @data['deviceSpecificAttributes']['snapshotPoolUri'] = storage_pool['uri']
  else
    @data['properties'] ||= {}
    @data['properties']['snapshotPool'] = storage_pool['uri']
  end
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.



74
75
76
77
78
# File 'lib/oneview-sdk/resource/api500/c7000/volume.rb', line 74

def set_storage_pool(storage_pool)
  assure_uri(storage_pool)
  @data['properties'] ||= {}
  @data['properties']['storagePool'] = storage_pool['uri']
end

#set_storage_systemObject

Method is not available

Raises:

  • method is not available.



22
23
24
# File 'lib/oneview-sdk/resource/api500/c7000/volume.rb', line 22

def set_storage_system(*)
  unavailable_method
end

#update(attributes = {}) ⇒ OneviewSDK::Volume

Update resource attributes

Parameters:

  • (defaults to: {})

    attributes to be updated

Returns:

  • self



50
51
52
53
# File 'lib/oneview-sdk/resource/api500/c7000/volume.rb', line 50

def update(attributes = {})
  @data.delete('properties')
  OneviewSDK::Resource.instance_method(:update).bind(self).call(attributes)
end