Class: 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.
Attributes inherited from Model
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
Methods inherited from Model
#inspect, #reload, #symbolize_keys, #to_json, #wait_for
Methods included from Attributes::ClassMethods
#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes
Methods included from Core::DeprecatedConnectionAccessors
#connection, #connection=, #prepare_service_value
Methods included from Attributes::InstanceMethods
#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one
Constructor Details
#initialize(attributes = {}) ⇒ Volume
Returns a new instance of Volume.
26 27 28 29 30 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 26 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.
24 25 26 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 24 def device @device end |
#server_id ⇒ Object (readonly)
Returns the value of attribute server_id.
23 24 25 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 23 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
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 59 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
78 79 80 81 82 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 78 def destroy requires :id service.delete_volume(id) true end |
#detach ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 70 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
46 47 48 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 46 def !(.nil? || .empty? || [0].empty?) end |
#image_id=(new_image_id) ⇒ Object
used for creating bootable volumes
41 42 43 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 41 def image_id=(new_image_id) @image_id = new_image_id end |
#in_use? ⇒ Boolean
50 51 52 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 50 def in_use? self.status == 'in-use' end |
#ready? ⇒ Boolean
54 55 56 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 54 def ready? self.status == 'available' end |
#save ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fog/hp/models/block_storage/volume.rb', line 84 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 |