Class: Fog::AWS::Compute::Volume
- Inherits:
-
Model
- Object
- Model
- Fog::AWS::Compute::Volume
- Defined in:
- lib/fog/aws/models/compute/volume.rb
Instance Method Summary collapse
- #attach(new_server, new_device) ⇒ Object
- #destroy ⇒ Object
- #detach(force = false) ⇒ Object
- #force_detach ⇒ Object
-
#initialize(attributes = {}) ⇒ Volume
constructor
A new instance of Volume.
- #modification_in_progress? ⇒ Boolean
- #modifications ⇒ Object
- #ready? ⇒ Boolean
- #save ⇒ Object
- #server ⇒ Object
- #server=(_) ⇒ Object
- #snapshot(description) ⇒ Object
- #snapshots ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Volume
Returns a new instance of Volume.
22 23 24 25 26 |
# File 'lib/fog/aws/models/compute/volume.rb', line 22 def initialize(attributes = {}) # assign server first to prevent race condition with persisted? @server = attributes.delete(:server) super end |
Instance Method Details
#attach(new_server, new_device) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/fog/aws/models/compute/volume.rb', line 98 def attach(new_server, new_device) if !persisted? @server = new_server self.availability_zone = new_server.availability_zone elsif new_server wait_for { ready? } @server = nil self.server_id = new_server.id service.attach_volume(server_id, id, new_device) reload end end |
#destroy ⇒ Object
28 29 30 31 32 33 |
# File 'lib/fog/aws/models/compute/volume.rb', line 28 def destroy requires :id service.delete_volume(id) true end |
#detach(force = false) ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/fog/aws/models/compute/volume.rb', line 111 def detach(force = false) @server = nil self.server_id = nil if persisted? service.detach_volume(id, 'Force' => force) reload end end |
#force_detach ⇒ Object
94 95 96 |
# File 'lib/fog/aws/models/compute/volume.rb', line 94 def force_detach detach(true) end |
#modification_in_progress? ⇒ Boolean
39 40 41 |
# File 'lib/fog/aws/models/compute/volume.rb', line 39 def modification_in_progress? modifications.any? { |m| m['modificationState'] != 'completed' } end |
#modifications ⇒ Object
43 44 45 46 |
# File 'lib/fog/aws/models/compute/volume.rb', line 43 def modifications requires :identity service.describe_volumes_modifications('volume-id' => self.identity).body['volumeModificationSet'] end |
#ready? ⇒ Boolean
35 36 37 |
# File 'lib/fog/aws/models/compute/volume.rb', line 35 def ready? state == 'available' end |
#save ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/fog/aws/models/compute/volume.rb', line 48 def save if identity update_params = { 'Size' => self.size, 'Iops' => self.iops, 'VolumeType' => self.type } service.modify_volume(self.identity, update_params) true else requires :availability_zone requires_one :size, :snapshot_id requires :iops if type == 'io1' data = service.create_volume(availability_zone, size, create_params).body merge_attributes(data) if = self. # expect eventual consistency Fog.wait_for { service.volumes.get(identity) } service.(identity, ) end attach(@server, device) if @server && device end true end |
#server ⇒ Object
79 80 81 82 |
# File 'lib/fog/aws/models/compute/volume.rb', line 79 def server requires :server_id service.servers.get(server_id) end |
#server=(_) ⇒ Object
120 121 122 |
# File 'lib/fog/aws/models/compute/volume.rb', line 120 def server=(_) raise NoMethodError, 'use Fog::AWS::Compute::Volume#attach(server, device)' end |
#snapshot(description) ⇒ Object
89 90 91 92 |
# File 'lib/fog/aws/models/compute/volume.rb', line 89 def snapshot(description) requires :id service.create_snapshot(id, description) end |
#snapshots ⇒ Object
84 85 86 87 |
# File 'lib/fog/aws/models/compute/volume.rb', line 84 def snapshots requires :id service.snapshots(:volume => self) end |