Class: Fog::AWS::EC2::Volume

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/aws/models/ec2/volume.rb

Instance Attribute Summary

Attributes inherited from Model

#connection

Instance Method Summary collapse

Methods inherited from Model

#_dump, _load, aliases, attribute, attributes, #attributes, #collection, identity, #identity, #inspect, #merge_attributes, #new_record?, #reload, #requires, #wait_for

Constructor Details

#initialize(attributes = {}) ⇒ Volume

Returns a new instance of Volume.



18
19
20
21
22
23
# File 'lib/fog/aws/models/ec2/volume.rb', line 18

def initialize(attributes = {})
  if attributes['attachmentSet']
    attributes.merge!(attributes.delete('attachmentSet').first || {})
  end
  super
end

Instance Method Details

#destroyObject



25
26
27
28
29
30
# File 'lib/fog/aws/models/ec2/volume.rb', line 25

def destroy
  requires :id

  connection.delete_volume(@id)
  true
end

#saveObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fog/aws/models/ec2/volume.rb', line 40

def save
  requires :availability_zone, :size

  data = connection.create_volume(@availability_zone, @size, @snapshot_id).body
  new_attributes = data.reject {|key,value| key == 'requestId'}
  merge_attributes(new_attributes)
  if @server
    self.server = @server
  end
  true
end

#server=(new_server) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/fog/aws/models/ec2/volume.rb', line 32

def server=(new_server)
  if new_server
    attach(new_server)
  else
    detach
  end
end

#snapshotsObject



52
53
54
55
56
# File 'lib/fog/aws/models/ec2/volume.rb', line 52

def snapshots
  requires :id

  connection.snapshots(:volume => self)
end