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, #load, #merge_attributes, model, #model, #reload, #table, #to_json

Constructor Details

#initialize(attributes) ⇒ Snapshots

Returns a new instance of Snapshots.


31
32
33
34
# File 'lib/fog/aws/models/ec2/snapshots.rb', line 31

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

Instance Method Details

#all(snapshot_id = @snapshot_id) ⇒ Object


36
37
38
39
40
41
42
43
44
# File 'lib/fog/aws/models/ec2/snapshots.rb', line 36

def all(snapshot_id = @snapshot_id)
  @snapshot_id = snapshot_id
  data = connection.describe_snapshots(snapshot_id).body
  load(data['snapshotSet'])
  if volume
    self.replace(self.select {|snapshot| snapshot.volume_id == volume.id})
  end
  self
end

#get(snapshot_id) ⇒ Object


46
47
48
49
50
51
52
# File 'lib/fog/aws/models/ec2/snapshots.rb', line 46

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

#new(attributes = {}) ⇒ Object


54
55
56
57
58
59
60
# File 'lib/fog/aws/models/ec2/snapshots.rb', line 54

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