mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Update mocking support for metadata to match real responses.
This commit is contained in:
parent
926e9d67e1
commit
290e9c1f9c
6 changed files with 101 additions and 25 deletions
|
@ -3,6 +3,17 @@ module Fog
|
||||||
class HP
|
class HP
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
|
# Delete metadata item for specific collections
|
||||||
|
#
|
||||||
|
# ==== Parameters
|
||||||
|
# * 'collection_name'<~String> - name of the collection i.e. images, servers for which the metadata is intented.
|
||||||
|
# * 'parent_id'<~Integer> - id of the collection i.e. image_id or the server_id
|
||||||
|
# * 'key'<~String> - key for the metadata item
|
||||||
|
#
|
||||||
|
# ==== Returns
|
||||||
|
# * response<~Excon::Response>:
|
||||||
|
# * body: Empty response body
|
||||||
|
#
|
||||||
def delete_meta(collection_name, parent_id, key)
|
def delete_meta(collection_name, parent_id, key)
|
||||||
request(
|
request(
|
||||||
:expects => 204,
|
:expects => 204,
|
||||||
|
@ -16,6 +27,22 @@ module Fog
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def delete_meta(collection_name, parent_id, key)
|
def delete_meta(collection_name, parent_id, key)
|
||||||
|
if collection_name == "images" then
|
||||||
|
if get_image_details(parent_id)
|
||||||
|
self.data[:images][parent_id]['metadata'].delete(key)
|
||||||
|
else
|
||||||
|
raise Fog::Compute::HP::NotFound
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if collection_name == "servers" then
|
||||||
|
if get_server_details(parent_id)
|
||||||
|
self.data[:servers][parent_id]['metadata'].delete(key)
|
||||||
|
else
|
||||||
|
raise Fog::Compute::HP::NotFound
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.status = 204
|
response.status = 204
|
||||||
response
|
response
|
||||||
|
|
|
@ -6,7 +6,7 @@ module Fog
|
||||||
# Get metadata item for specific collections
|
# Get metadata item for specific collections
|
||||||
#
|
#
|
||||||
# ==== Parameters
|
# ==== Parameters
|
||||||
# * 'collection_name'<~String> - name of the collection i.e. images, servers for which the metadata is intented.
|
# * 'collection_name'<~String> - name of the collection i.e. images, servers for which the metadata is intended.
|
||||||
# * 'parent_id'<~Integer> - id of the collection i.e. image_id or the server_id
|
# * 'parent_id'<~Integer> - id of the collection i.e. image_id or the server_id
|
||||||
# * 'key'<~String> - key for the metadata item
|
# * 'key'<~String> - key for the metadata item
|
||||||
#
|
#
|
||||||
|
@ -29,16 +29,16 @@ module Fog
|
||||||
|
|
||||||
def get_meta(collection_name, parent_id, key)
|
def get_meta(collection_name, parent_id, key)
|
||||||
if collection_name == "images" then
|
if collection_name == "images" then
|
||||||
if parent = get_image_details(parent_id)
|
if get_image_details(parent_id)
|
||||||
self.data[:images][parent_id]['image']['metadata'][key]
|
raise Fog::Compute::HP::NotFound unless midata = self.data[:images][parent_id]['metadata'].fetch(key, nil)
|
||||||
else
|
else
|
||||||
raise Fog::Compute::HP::NotFound
|
raise Fog::Compute::HP::NotFound
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if collection_name == "servers" then
|
if collection_name == "servers" then
|
||||||
if parent = get_server_details(parent_id)
|
if get_server_details(parent_id)
|
||||||
self.data[:servers][parent_id]['server']['metadata'][key] = value
|
raise Fog::Compute::HP::NotFound unless midata = self.data[:servers][parent_id]['metadata'].fetch(key, nil)
|
||||||
else
|
else
|
||||||
raise Fog::Compute::HP::NotFound
|
raise Fog::Compute::HP::NotFound
|
||||||
end
|
end
|
||||||
|
@ -46,7 +46,7 @@ module Fog
|
||||||
|
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.status = 200
|
response.status = 200
|
||||||
response.body = { 'meta' => {} }
|
response.body = { 'meta' => { key => midata } }
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,17 @@ module Fog
|
||||||
class HP
|
class HP
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
|
# List metadata for specific collections
|
||||||
|
#
|
||||||
|
# ==== Parameters
|
||||||
|
# * 'collection_name'<~String> - name of the collection i.e. images, servers for which the metadata is intended.
|
||||||
|
# * 'parent_id'<~Integer> - id of the collection i.e. image_id or the server_id
|
||||||
|
#
|
||||||
|
# ==== Returns
|
||||||
|
# * response<~Excon::Response>:
|
||||||
|
# * body<~Hash>:
|
||||||
|
# * metadata<~Hash>: hash of key/value pair for the metadata items found
|
||||||
|
#
|
||||||
def list_metadata(collection_name, parent_id)
|
def list_metadata(collection_name, parent_id)
|
||||||
request(
|
request(
|
||||||
:expects => [200, 203],
|
:expects => [200, 203],
|
||||||
|
@ -16,9 +27,26 @@ module Fog
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def list_metadata(collection_name, parent_id)
|
def list_metadata(collection_name, parent_id)
|
||||||
|
mdata = {}
|
||||||
|
if collection_name == "images" then
|
||||||
|
if get_image_details(parent_id)
|
||||||
|
mdata = self.data[:images][parent_id]['metadata']
|
||||||
|
else
|
||||||
|
raise Fog::Compute::HP::NotFound
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if collection_name == "servers" then
|
||||||
|
if get_server_details(parent_id)
|
||||||
|
mdata = self.data[:servers][parent_id]['metadata']
|
||||||
|
else
|
||||||
|
raise Fog::Compute::HP::NotFound
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.status = 200
|
response.status = 200
|
||||||
response.body = {}
|
response.body = {'metadata' => mdata}
|
||||||
response
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,13 @@ module Fog
|
||||||
# ==== Parameters
|
# ==== Parameters
|
||||||
# * 'collection_name'<~String> - name of the collection i.e. images, servers for which the metadata is intented.
|
# * 'collection_name'<~String> - name of the collection i.e. images, servers for which the metadata is intented.
|
||||||
# * 'parent_id'<~Integer> - id of the collection i.e. image_id or the server_id
|
# * 'parent_id'<~Integer> - id of the collection i.e. image_id or the server_id
|
||||||
#
|
# * 'metadata'<~Hash> - A hash of key/value pairs containing the metadata
|
||||||
|
|
||||||
# ==== Returns
|
# ==== Returns
|
||||||
# * response<~Excon::Response>:
|
# * response<~Excon::Response>:
|
||||||
# * body<~Hash>:
|
# * body<~Hash>:
|
||||||
|
# * metadata<~Hash> - key/value pairs of metadata items
|
||||||
|
#
|
||||||
def set_metadata(collection_name, parent_id, metadata = {})
|
def set_metadata(collection_name, parent_id, metadata = {})
|
||||||
request(
|
request(
|
||||||
:body => MultiJson.encode({ 'metadata' => metadata }),
|
:body => MultiJson.encode({ 'metadata' => metadata }),
|
||||||
|
@ -29,15 +31,19 @@ module Fog
|
||||||
def set_metadata(collection_name, parent_id, metadata = {})
|
def set_metadata(collection_name, parent_id, metadata = {})
|
||||||
|
|
||||||
if collection_name == "images" then
|
if collection_name == "images" then
|
||||||
if not list_images_detail.body['images'].detect {|_| _['id'] == parent_id}
|
if get_image_details(parent_id)
|
||||||
|
self.data[:images][parent_id]['metadata'] = metadata
|
||||||
|
else
|
||||||
raise Fog::Compute::HP::NotFound
|
raise Fog::Compute::HP::NotFound
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if collection_name == "servers" then
|
if collection_name == "servers" then
|
||||||
if not list_servers_detail.body['servers'].detect {|_| _['id'] == parent_id}
|
if get_server_details(parent_id)
|
||||||
|
self.data[:servers][parent_id]['metadata'] = metadata
|
||||||
|
else
|
||||||
raise Fog::Compute::HP::NotFound
|
raise Fog::Compute::HP::NotFound
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
|
|
|
@ -32,19 +32,19 @@ module Fog
|
||||||
def update_meta(collection_name, parent_id, key, value)
|
def update_meta(collection_name, parent_id, key, value)
|
||||||
|
|
||||||
if collection_name == "images" then
|
if collection_name == "images" then
|
||||||
if parent = get_image_details(parent_id)
|
if get_image_details(parent_id)
|
||||||
self.data[:images][parent_id]['image']['metadata'][key] = value
|
self.data[:images][parent_id]['metadata'][key] = value
|
||||||
else
|
else
|
||||||
raise Fog::Compute::HP::NotFound
|
raise Fog::Compute::HP::NotFound
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if collection_name == "servers" then
|
if collection_name == "servers" then
|
||||||
if parent = get_server_details(parent_id)
|
if get_server_details(parent_id)
|
||||||
self.data[:servers][parent_id]['server']['metadata'][key] = value
|
self.data[:servers][parent_id]['metadata'][key] = value
|
||||||
else
|
else
|
||||||
raise Fog::Compute::HP::NotFound
|
raise Fog::Compute::HP::NotFound
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
|
|
|
@ -3,6 +3,18 @@ module Fog
|
||||||
class HP
|
class HP
|
||||||
class Real
|
class Real
|
||||||
|
|
||||||
|
# Update metadata for specific collections
|
||||||
|
#
|
||||||
|
# ==== Parameters
|
||||||
|
# * 'collection_name'<~String> - name of the collection i.e. images, servers for which the metadata is intented.
|
||||||
|
# * 'parent_id'<~Integer> - id of the collection i.e. image_id or the server_id
|
||||||
|
# * 'metadata'<~Hash> - A hash of key/value pairs containing the metadata
|
||||||
|
|
||||||
|
# ==== Returns
|
||||||
|
# * response<~Excon::Response>:
|
||||||
|
# * body<~Hash>:
|
||||||
|
# * metadata<~Hash> - all key/value pairs of metadata items merged with existing metadata
|
||||||
|
#
|
||||||
def update_metadata(collection_name, parent_id, metadata = {})
|
def update_metadata(collection_name, parent_id, metadata = {})
|
||||||
request(
|
request(
|
||||||
:body => MultiJson.encode({ 'metadata' => metadata }),
|
:body => MultiJson.encode({ 'metadata' => metadata }),
|
||||||
|
@ -19,20 +31,23 @@ module Fog
|
||||||
def update_metadata(collection_name, parent_id, metadata = {})
|
def update_metadata(collection_name, parent_id, metadata = {})
|
||||||
|
|
||||||
if collection_name == "images" then
|
if collection_name == "images" then
|
||||||
if not list_images_detail.body['images'].detect {|_| _['id'] == parent_id}
|
if get_image_details(parent_id)
|
||||||
|
newmetadata = self.data[:images][parent_id]['metadata'].merge!(metadata)
|
||||||
|
else
|
||||||
raise Fog::Compute::HP::NotFound
|
raise Fog::Compute::HP::NotFound
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if collection_name == "servers" then
|
if collection_name == "servers" then
|
||||||
if not list_servers_detail.body['servers'].detect {|_| _['id'] == parent_id}
|
if get_server_details(parent_id)
|
||||||
|
newmetadata = self.data[:servers][parent_id]['metadata'].merge!(metadata)
|
||||||
|
else
|
||||||
raise Fog::Compute::HP::NotFound
|
raise Fog::Compute::HP::NotFound
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#FIXME join w/ existing metadata here
|
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.body = { "metadata" => metadata }
|
response.body = { "metadata" => newmetadata }
|
||||||
response.status = 200
|
response.status = 200
|
||||||
response
|
response
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue