2011-02-27 16:09:12 -05:00
|
|
|
require 'fog/core/collection'
|
2011-05-11 15:27:27 -04:00
|
|
|
require 'fog/aws/models/rds/snapshot'
|
2011-02-27 16:09:12 -05:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class RDS
|
|
|
|
|
|
|
|
class Snapshots < Fog::Collection
|
|
|
|
attribute :server
|
|
|
|
attribute :filters
|
|
|
|
model Fog::AWS::RDS::Snapshot
|
|
|
|
|
|
|
|
def initialize(attributes)
|
|
|
|
self.filters ||= {}
|
|
|
|
if attributes[:server]
|
|
|
|
filters[:identifier] = attributes[:server].id
|
|
|
|
end
|
2012-09-06 13:46:14 -04:00
|
|
|
if attributes[:type]
|
|
|
|
filters[:type] = attributes[:type]
|
|
|
|
end
|
2011-02-27 16:09:12 -05:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def all(filters = filters)
|
|
|
|
self.filters = filters
|
2012-12-22 18:30:24 -05:00
|
|
|
data = service.describe_db_snapshots(filters).body['DescribeDBSnapshotsResult']['DBSnapshots']
|
2011-02-27 16:09:12 -05:00
|
|
|
load(data) # data is an array of attribute hashes
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(identity)
|
2012-12-22 18:30:24 -05:00
|
|
|
data = service.describe_db_snapshots(:snapshot_id => identity).body['DescribeDBSnapshotsResult']['DBSnapshots'].first
|
2011-02-27 16:09:12 -05:00
|
|
|
new(data) # data is an attribute hash
|
|
|
|
rescue Fog::AWS::RDS::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def new(attributes = {})
|
|
|
|
if server
|
|
|
|
super({ :instance_id => server.id }.merge!(attributes))
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-12-22 18:30:24 -05:00
|
|
|
end
|