Class: Fog::HP::BlockStorage::Volume
- Inherits:
-
Model
- Object
- Model
- Fog::HP::BlockStorage::Volume
- Defined in:
- lib/fog/hp/models/block_storage/volume.rb
Instance Attribute Summary collapse
-
#device ⇒ Object
readonly
Returns the value of attribute device.
-
#server_id ⇒ Object
readonly
Returns the value of attribute server_id.
Instance Method Summary collapse
-
#attach(new_server_id, device) ⇒ Object
volume can be attached to only one server at a time.
- #destroy ⇒ Object
- #detach ⇒ Object
-
#has_attachments? ⇒ Boolean
a volume can be attached to only one server at a time.
-
#image_id=(new_image_id) ⇒ Object
used for creating bootable volumes.
- #in_use? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Volume
constructor
A new instance of Volume.
- #ready? ⇒ Boolean
- #save ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Volume
Returns a new instance of Volume.
24 25 26 27 28 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 24 def initialize(attributes = {}) # assign these attributes first to prevent race condition with new_record? self.image_id = attributes.delete(:image_id) super end |
Instance Attribute Details
#device ⇒ Object (readonly)
Returns the value of attribute device.
22 23 24 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 22 def device @device end |
#server_id ⇒ Object (readonly)
Returns the value of attribute server_id.
21 22 23 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 21 def server_id @server_id end |
Instance Method Details
#attach(new_server_id, device) ⇒ Object
volume can be attached to only one server at a time
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 57 def attach(new_server_id, device) requires :id unless in_use? data = service.compute.attach_volume(new_server_id, id, device) merge_attributes(:attachments => << data.body['volumeAttachment']) true else false end end |
#destroy ⇒ Object
76 77 78 79 80 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 76 def destroy requires :id service.delete_volume(id) true end |
#detach ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 68 def detach requires :id if service.compute.detach_volume(server_id, id) end true end |
#has_attachments? ⇒ Boolean
a volume can be attached to only one server at a time
44 45 46 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 44 def !(.nil? || .empty? || [0].empty?) end |
#image_id=(new_image_id) ⇒ Object
used for creating bootable volumes
39 40 41 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 39 def image_id=(new_image_id) @image_id = new_image_id end |
#in_use? ⇒ Boolean
48 49 50 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 48 def in_use? self.status == 'in-use' end |
#ready? ⇒ Boolean
52 53 54 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 52 def ready? self.status == 'available' end |
#save ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 82 def save raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted? requires :name, :size = { 'metadata' => , 'snapshot_id' => snapshot_id, 'imageRef' => @image_id } = .reject {|key, value| value.nil?} data = service.create_volume(name, description, size, ) merge_attributes(data.body['volume']) true end |