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

Inherits:
Collection
  • Object
show all
Defined in:
lib/fog/aws/models/compute/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.



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

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

Instance Method Details

#all(snapshot_id = @snapshot_id, options = {}) ⇒ Object



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

def all(snapshot_id = @snapshot_id, options = {})
  options = {
    'Owner' => @owner || 'self',
    'RestorableBy' => @restorable_by
  }
  options = options.reject {|key,value| value.nil? || value.to_s.empty?}
  merge_attributes(options)
  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



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

def get(snapshot_id)
  if snapshot_id
    all(snapshot_id).first
  end
rescue Fog::Errors::NotFound
  nil
end

#new(attributes = {}) ⇒ Object



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

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