mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[aws|compute] Add mock for create_tags
This commit is contained in:
parent
ffca675023
commit
3b20e45902
2 changed files with 45 additions and 3 deletions
|
@ -113,7 +113,8 @@ module Fog
|
|||
}
|
||||
},
|
||||
:snapshots => {},
|
||||
:volumes => {}
|
||||
:volumes => {},
|
||||
:tags => []
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -36,10 +36,51 @@ module Fog
|
|||
class Mock
|
||||
|
||||
def create_tags(resources, tags)
|
||||
Fog::Mock.not_implemented
|
||||
response = Excon::Response.new
|
||||
resources = [*resources]
|
||||
resource_tags = {}
|
||||
objects = resources.map do |resource_id|
|
||||
if resource = @data[:instances][resource_id]
|
||||
[resource, 'instance']
|
||||
elsif resource = @data[:images][resource_id]
|
||||
[resource, 'image']
|
||||
elsif resource = @data[:volumes][resource_id]
|
||||
[resource, 'volume']
|
||||
elsif resource = @data[:snapshots][resource_id]
|
||||
[resource, 'snapshot']
|
||||
end
|
||||
end
|
||||
|
||||
if objects.all?
|
||||
response.status = 200
|
||||
@data[:tags] ||= []
|
||||
tags.each do |key, value|
|
||||
resources.each_with_index do |resource_id, i|
|
||||
object, resource_type = objects[i]
|
||||
object['tagSet'] ||= {}
|
||||
object['tagSet'][key] = value
|
||||
@data[:tags] << {
|
||||
'key' => key,
|
||||
'value' => value,
|
||||
'resourceId' => resource_id,
|
||||
'resourceType' => resource_type
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
response.body = {
|
||||
'requestId' => Fog::AWS::Mock.request_id,
|
||||
'return' => 'true'
|
||||
}
|
||||
else
|
||||
response.status = 400
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
response
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue