Class: Fog::AWS::Compute::Snapshots

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

Instance Attribute Summary

Attributes inherited from Collection

#connection

Instance Method Summary collapse

Methods inherited from Collection

#clear, #create, #inspect, #load, model, #model, #reload, #table, #to_json

Methods included from Fog::Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Attributes::InstanceMethods

#_dump, #attributes, #identity, #identity=, #merge_attributes, #new_record?, #requires

Constructor Details

#initialize(attributes) ⇒ Snapshots

Returns a new instance of Snapshots.



15
16
17
18
# File 'lib/fog/compute/models/aws/snapshots.rb', line 15

def initialize(attributes)
  self.filters ||= { 'RestorableBy' => 'self' }
  super
end

Instance Method Details

#all(filters = filters, options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/compute/models/aws/snapshots.rb', line 20

def all(filters = filters, options = {})
  unless filters.is_a?(Hash)
    Formatador.display_line("[yellow][WARN] all with #{filters.class} param is deprecated, use all('snapshot-id' => []) instead[/] [light_black](#{caller.first})[/]")
    filters = {'snapshot-id' => [*filters]}
  end
  self.filters = filters
  data = connection.describe_snapshots(filters.merge!(options)).body
  load(data['snapshotSet'])
  if volume
    self.replace(self.select {|snapshot| snapshot.volume_id == volume.id})
  end
  self
end

#get(snapshot_id) ⇒ Object



34
35
36
37
38
# File 'lib/fog/compute/models/aws/snapshots.rb', line 34

def get(snapshot_id)
  if snapshot_id
    self.class.new(:connection => connection).all('snapshot-id' => snapshot_id).first
  end
end

#new(attributes = {}) ⇒ Object



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

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