Class: OneviewSDK::API200::Volume
- Defined in:
- lib/oneview-sdk/resource/api200/volume.rb
Overview
Volume resource implementation
Direct Known Subclasses
OneviewSDK::API300::C7000::Volume, OneviewSDK::API300::Synergy::Volume
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
-
.get_attachable_volumes(client) ⇒ Array<OneviewSDK::Volume>
Gets all the attachable volumes managed by the appliance.
-
.get_extra_managed_volume_paths(client) ⇒ Object
Gets the list of extra managed storage volume paths.
Instance Method Summary collapse
-
#create ⇒ Resource
Creates the volume.
-
#create_snapshot(snapshot, description = nil) ⇒ true
Creates a snapshot of the volume.
-
#delete(flag = :all) ⇒ true
Deletes the resource from OneView or from Oneview and storage system.
-
#delete_snapshot(name) ⇒ true
Deletes a snapshot of the volume.
-
#get_snapshot(name) ⇒ Hash
Retrieves a snapshot by name.
-
#get_snapshots ⇒ Array
Gets all the snapshots of this volume.
-
#repair ⇒ Object
Removes extra presentation from the volume.
-
#set_snapshot_pool(storage_pool) ⇒ Object
Sets the snapshot pool to the volume.
-
#set_storage_pool(storage_pool) ⇒ Object
Sets the storage pool to the volume.
-
#set_storage_system(storage_system) ⇒ Object
Sets the storage system to the volume.
-
#set_storage_volume_template(storage_volume_template) ⇒ Object
Adds the storage volume template to the volume.
-
#update(attributes = {}) ⇒ OneviewSDK::Volume
Update resource attributes.
Methods inherited from Resource
#==, #[], #[]=, build_query, #create!, #deep_merge!, #each, #eql?, #exists?, find_by, find_with_pagination, from_file, get_all, #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) ⇒ Array<OneviewSDK::Volume>
Gets all the attachable volumes managed by the appliance
146 147 148 149 |
# File 'lib/oneview-sdk/resource/api200/volume.rb', line 146 def self.get_attachable_volumes(client) uri = "#{BASE_URI}/attachable-volumes" find_by(client, {}, uri) end |
.get_extra_managed_volume_paths(client) ⇒ Object
Gets the list of extra managed storage volume paths
154 155 156 157 |
# File 'lib/oneview-sdk/resource/api200/volume.rb', line 154 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 ⇒ Resource
provisioning parameters are required for creation, but not afterwards; after creation, they will be removed.
Creates the volume
33 34 35 36 37 38 39 40 |
# File 'lib/oneview-sdk/resource/api200/volume.rb', line 33 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
Creates a snapshot of the volume
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/oneview-sdk/resource/api200/volume.rb', line 103 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) ⇒ true
Deletes the resource from OneView or from Oneview and storage system
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/oneview-sdk/resource/api200/volume.rb', line 53 def delete(flag = :all) ensure_client && ensure_uri case flag when :oneview response = @client.rest_delete(@data['uri'], { 'exportOnly' => true }, @api_version) @client.response_handler(response) when :all response = @client.rest_delete(@data['uri'], {}, @api_version) @client.response_handler(response) else raise InvalidResource, 'Invalid flag value, use :oneview or :all' end true end |
#delete_snapshot(name) ⇒ true
Deletes a snapshot of the volume
120 121 122 123 124 125 |
# File 'lib/oneview-sdk/resource/api200/volume.rb', line 120 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
130 131 132 133 |
# File 'lib/oneview-sdk/resource/api200/volume.rb', line 130 def get_snapshot(name) results = get_snapshots results.find { |snap| snap['name'] == name } end |
#get_snapshots ⇒ Array
Gets all the snapshots of this volume
137 138 139 140 141 |
# File 'lib/oneview-sdk/resource/api200/volume.rb', line 137 def get_snapshots ensure_uri && ensure_client uri = "#{@data['uri']}/snapshots" self.class.find_with_pagination(@client, uri) end |
#repair ⇒ Object
Removes extra presentation from the volume
161 162 163 164 |
# File 'lib/oneview-sdk/resource/api200/volume.rb', line 161 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
94 95 96 97 |
# File 'lib/oneview-sdk/resource/api200/volume.rb', line 94 def set_snapshot_pool(storage_pool) assure_uri(storage_pool) set('snapshotPoolUri', storage_pool['uri']) end |
#set_storage_pool(storage_pool) ⇒ Object
The storagePoolUri attribute should not be set in the updated. Once created, this attribute is read only.
Sets the storage pool to the volume
79 80 81 82 83 |
# File 'lib/oneview-sdk/resource/api200/volume.rb', line 79 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
The storageSystemUri attribute should not be set in the updated. Once created, this attribute is read only.
Sets the storage system to the volume
71 72 73 74 |
# File 'lib/oneview-sdk/resource/api200/volume.rb', line 71 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
87 88 89 90 |
# File 'lib/oneview-sdk/resource/api200/volume.rb', line 87 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
45 46 47 48 |
# File 'lib/oneview-sdk/resource/api200/volume.rb', line 45 def update(attributes = {}) @data.delete('provisioningParameters') super end |