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

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

Instance Method Summary collapse

Methods inherited from Model

aliases, attribute, attributes, #attributes, #inspect, #merge_attributes

Constructor Details

#initialize(attributes = {}) ⇒ Volume

Returns a new instance of Volume.



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

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

Instance Method Details

#destroyObject



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

def destroy
  connection.delete_volume(@volume_id)
  true
end

#instance=(new_instance) ⇒ Object



29
30
31
32
# File 'lib/fog/aws/models/ec2/volume.rb', line 29

def instance=(new_instance)
  @instance_id = new_instance.instance_id
  connection.attach_volume(@instance_id, @volume_id, @device)
end

#reloadObject



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

def reload
  new_attributes = volumes.get(@volume_id).attributes
  merge_attributes(new_attributes)
end

#saveObject



39
40
41
42
43
44
# File 'lib/fog/aws/models/ec2/volume.rb', line 39

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

#snapshotsObject



46
47
48
# File 'lib/fog/aws/models/ec2/volume.rb', line 46

def snapshots
  connection.snapshots(:volume_id => volume_id)
end

#volumesObject



50
51
52
# File 'lib/fog/aws/models/ec2/volume.rb', line 50

def volumes
  @volumes
end