mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2040 from bgentry/asg-filters
[AWS|ASG] Filters for ASGs.
This commit is contained in:
commit
45687f68c1
2 changed files with 15 additions and 4 deletions
|
@ -4,19 +4,22 @@ module Fog
|
||||||
module AWS
|
module AWS
|
||||||
class AutoScaling
|
class AutoScaling
|
||||||
class Groups < Fog::Collection
|
class Groups < Fog::Collection
|
||||||
|
|
||||||
model Fog::AWS::AutoScaling::Group
|
model Fog::AWS::AutoScaling::Group
|
||||||
|
|
||||||
|
attribute :filters
|
||||||
|
|
||||||
# Creates a new auto scaling group.
|
# Creates a new auto scaling group.
|
||||||
def initialize(attributes={})
|
def initialize(attributes={})
|
||||||
|
self.filters = attributes
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def all
|
def all(filters = filters)
|
||||||
data = []
|
data = []
|
||||||
next_token = nil
|
next_token = nil
|
||||||
|
self.filters = filters
|
||||||
loop do
|
loop do
|
||||||
result = service.describe_auto_scaling_groups('NextToken' => next_token).body['DescribeAutoScalingGroupsResult']
|
result = service.describe_auto_scaling_groups(filters.merge('NextToken' => next_token)).body['DescribeAutoScalingGroupsResult']
|
||||||
data += result['AutoScalingGroups']
|
data += result['AutoScalingGroups']
|
||||||
next_token = result['NextToken']
|
next_token = result['NextToken']
|
||||||
break if next_token.nil?
|
break if next_token.nil?
|
||||||
|
|
|
@ -111,7 +111,15 @@ module Fog
|
||||||
|
|
||||||
def describe_auto_scaling_groups(options = {})
|
def describe_auto_scaling_groups(options = {})
|
||||||
results = { 'AutoScalingGroups' => [] }
|
results = { 'AutoScalingGroups' => [] }
|
||||||
self.data[:auto_scaling_groups].each do |asg_name, asg_data|
|
asg_set = self.data[:auto_scaling_groups]
|
||||||
|
|
||||||
|
if !options["AutoScalingGroupNames"].nil?
|
||||||
|
asg_set = asg_set.reject do |asg_name, asg_data|
|
||||||
|
![*options["AutoScalingGroupNames"]].include?(asg_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
asg_set.each do |asg_name, asg_data|
|
||||||
results['AutoScalingGroups'] << {
|
results['AutoScalingGroups'] << {
|
||||||
'AutoScalingGroupName' => asg_name
|
'AutoScalingGroupName' => asg_name
|
||||||
}.merge!(asg_data)
|
}.merge!(asg_data)
|
||||||
|
|
Loading…
Add table
Reference in a new issue