mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Add 'each' that iterates over all log files
Use 'select' to do an exact match when seeking a specific log file.
This commit is contained in:
parent
bb0e266f9b
commit
89b260cfc0
1 changed files with 30 additions and 7 deletions
|
@ -6,21 +6,44 @@ module Fog
|
|||
class RDS
|
||||
|
||||
class LogFiles < Fog::Collection
|
||||
attribute :filters
|
||||
attribute :rds_id
|
||||
model Fog::AWS::RDS::LogFile
|
||||
|
||||
def all
|
||||
data = service.describe_db_log_files(rds_id).body['DescribeDBLogFilesResult']['DBLogFiles']
|
||||
load(data) # data is an array of attribute hashes
|
||||
def initialize(attributes)
|
||||
self.filters ||= {}
|
||||
super
|
||||
end
|
||||
|
||||
# This method deliberately returns only a single page of results
|
||||
def all(filters=filters)
|
||||
self.filters.merge!(filters)
|
||||
|
||||
result = service.describe_db_log_files(rds_id, filters).body['DescribeDBLogFilesResult']
|
||||
self.filters[:marker] = result['Marker']
|
||||
load(result['DBLogFiles'])
|
||||
end
|
||||
|
||||
def each(filters=filters)
|
||||
if block_given?
|
||||
begin
|
||||
page = self.all(filters)
|
||||
# We need to explicitly use the base 'each' method here on the page, otherwise we get infinite recursion
|
||||
base_each = Fog::Collection.instance_method(:each)
|
||||
base_each.bind(page).call { |log_file| yield log_file }
|
||||
end while self.filters[:marker]
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
def get(file_name=nil)
|
||||
data = service.describe_db_log_files(rds_id, {:filename_contains => file_name}).body['DescribeDBLogFilesResult']['DBLogFiles'].first
|
||||
new(data) # data is an attribute hash
|
||||
if file_name
|
||||
matches = self.select {|log_file| log_file.name.upcase == file_name.upcase}
|
||||
return matches.first unless matches.empty?
|
||||
end
|
||||
rescue Fog::AWS::RDS::NotFound
|
||||
nil
|
||||
end
|
||||
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue