1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[aws] Add tag filtering to mocks for snapshots, volumes, instances.

This commit is contained in:
Matt Griffin 2011-03-23 13:33:27 -04:00
parent 74c8566099
commit bd506e0e73
4 changed files with 20 additions and 18 deletions

View file

@ -146,6 +146,18 @@ module Fog
@data = self.class.data[@region][@aws_access_key_id]
end
def apply_tag_filters(resources, filters)
tag_filters = {}
filters.keys.each do |key|
tag_filters[key.gsub('tag:', '')] = filters.delete(key) if /^tag:/ =~ key
end
for tag_key, tag_value in tag_filters
resources = resources.reject{|r| r['tagSet'][tag_key] != tag_value}
end
resources
end
end
class Real

View file

@ -74,15 +74,11 @@ module Fog
filters = {'instance-id' => [*filters]}
end
if filters.keys.any? {|key| key =~ /^tag/}
Formatador.display_line("[yellow][WARN] describe_instances tag filters are not yet mocked[/] [light_black](#{caller.first})[/]")
Fog::Mock.not_implemented
end
response = Excon::Response.new
instance_set = @data[:instances].values
instance_set = apply_tag_filters(instance_set, filters)
aliases = {
'architecture' => 'architecture',
'availability-zone' => 'availabilityZone',

View file

@ -59,11 +59,6 @@ module Fog
Formatador.display_line("[yellow][WARN] describe_snapshots with a second param is deprecated, use describe_snapshots(options) instead[/] [light_black](#{caller.first})[/]")
end
if filters.keys.any? {|key| key =~ /^tag/}
Formatador.display_line("[yellow][WARN] describe_snapshots tag filters are not yet mocked[/] [light_black](#{caller.first})[/]")
Fog::Mock.not_implemented
end
response = Excon::Response.new
snapshot_set = @data[:snapshots].values
@ -75,6 +70,8 @@ module Fog
Formatador.display_line("[yellow][WARN] describe_snapshots with RestorableBy is not mocked[/] [light_black](#{caller.first})[/]")
end
snapshot_set = apply_tag_filters(snapshot_set, filters)
aliases = {
'description' => 'description',
'owner-id' => 'ownerId',
@ -85,11 +82,12 @@ module Fog
'volume-id' => 'volumeId',
'volume-size' => 'volumeSize'
}
for filter_key, filter_value in filters
aliased_key = aliases[filter_key]
snapshot_set = snapshot_set.reject{|snapshot| ![*filter_value].include?(snapshot[aliased_key])}
end
snapshot_set.each do |snapshot|
case snapshot['status']
when 'in progress', 'pending'

View file

@ -50,15 +50,11 @@ module Fog
filters = {'volume-id' => [*filters]}
end
if filters.keys.any? {|key| key =~ /^tag/}
Formatador.display_line("[yellow][WARN] describe_volumes tag filters are not yet mocked[/] [light_black](#{caller.first})[/]")
Fog::Mock.not_implemented
end
response = Excon::Response.new
volume_set = @data[:volumes].values
volume_set = apply_tag_filters(volume_set, filters)
aliases = {
'availability-zone' => 'availabilityZone',
'create-time' => 'createTime',