mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Allow tag filtering for images.
This commit is contained in:
parent
b6f2a9ff33
commit
efd3f84557
1 changed files with 8 additions and 9 deletions
|
@ -59,8 +59,8 @@ module Fog
|
|||
|
||||
def describe_images(filters = {})
|
||||
unless filters.is_a?(Hash)
|
||||
Formatador.display_line("[yellow][WARN] describe_images with #{filters.class} param is deprecated, use describe_snapshots('snapshot-id' => []) instead[/] [light_black](#{caller.first})[/]")
|
||||
filters = {'snapshot-id' => [*filters]}
|
||||
Formatador.display_line("[yellow][WARN] describe_images with #{filters.class} param is deprecated, use describe_images('image-id' => []) instead[/] [light_black](#{caller.first})[/]")
|
||||
filters = {'image-id' => [*filters]}
|
||||
end
|
||||
|
||||
if filters.keys.any? {|key| key =~ /^block-device/}
|
||||
|
@ -68,11 +68,6 @@ module Fog
|
|||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
if filters.keys.any? {|key| key =~ /^tag/}
|
||||
Formatador.display_line("[yellow][WARN] describe_images tag filters are not yet mocked[/] [light_black](#{caller.first})[/]")
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
response = Excon::Response.new
|
||||
|
||||
aliases = {
|
||||
|
@ -96,8 +91,12 @@ module Fog
|
|||
image_set = self.data[:images].values
|
||||
|
||||
for filter_key, filter_value in filters
|
||||
aliased_key = aliases[filter_key]
|
||||
image_set = image_set.reject{|image| ![*filter_value].include?(image[aliased_key])}
|
||||
if tag_key = filter_key.split('tag:')[1]
|
||||
image_set = image_set.reject{|image| ![*filter_value].include?(image['tagSet'][tag_key])}
|
||||
else
|
||||
aliased_key = aliases[filter_key]
|
||||
image_set = image_set.reject{|image| ![*filter_value].include?(image[aliased_key])}
|
||||
end
|
||||
end
|
||||
|
||||
response.status = 200
|
||||
|
|
Loading…
Add table
Reference in a new issue