Class: Fog::AWS::EC2::Snapshots

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

Instance Method Summary collapse

Methods inherited from Collection

#_dump, _load, aliases, attribute, attributes, #attributes, #connection, #connection=, #create, #inspect, #merge_attributes, model, #model, #reload

Constructor Details

#initialize(attributes) ⇒ Snapshots

Returns a new instance of Snapshots.



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

def initialize(attributes)
  @snapshot_id ||= []
  super
end

Instance Method Details

#all(snapshot_id = @snapshot_id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/aws/models/ec2/snapshots.rb', line 23

def all(snapshot_id = @snapshot_id)
  data = connection.describe_snapshots(snapshot_id).body
  snapshots = Fog::AWS::EC2::Snapshots.new({
    :connection   => connection,
    :snapshot_id  => snapshot_id
  }.merge!(attributes))
  data['snapshotSet'].each do |snapshot|
    snapshots << Fog::AWS::EC2::Snapshot.new({
      :collection => snapshots,
      :connection => connection
    }.merge!(snapshot))
  end
  if volume
    snapshots = snapshots.select {|snapshot| snapshot.volume_id == volume.id}
  end
  snapshots
end

#get(snapshot_id) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/fog/aws/models/ec2/snapshots.rb', line 41

def get(snapshot_id)
  if snapshot_id
    all(snapshot_id).first
  end
rescue Excon::Errors::BadRequest
  nil
end

#new(attributes = {}) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/fog/aws/models/ec2/snapshots.rb', line 49

def new(attributes = {})
  if volume
    super({ :volume_id => volume.id }.merge!(attributes))
  else
    super
  end
end