diff --git a/lib/fog/rackspace/compute_v2.rb b/lib/fog/rackspace/compute_v2.rb index 73e3e1f26..a425d43c5 100644 --- a/lib/fog/rackspace/compute_v2.rb +++ b/lib/fog/rackspace/compute_v2.rb @@ -53,12 +53,12 @@ module Fog request :list_attachments request :delete_attachment - request :list_server_metadata - request :set_server_metadata - request :update_server_metadata - request :get_server_metadata_item - request :set_server_metadata_item - request :delete_server_metadata_item + request :list_metadata + request :set_metadata + request :update_metadata + request :get_metadata_item + request :set_metadata_item + request :delete_metadata_item class Mock diff --git a/lib/fog/rackspace/requests/compute_v2/delete_server_metadata_item.rb b/lib/fog/rackspace/requests/compute_v2/delete_metadata_item.rb similarity index 71% rename from lib/fog/rackspace/requests/compute_v2/delete_server_metadata_item.rb rename to lib/fog/rackspace/requests/compute_v2/delete_metadata_item.rb index 0e1dd25b5..6d8d41776 100644 --- a/lib/fog/rackspace/requests/compute_v2/delete_server_metadata_item.rb +++ b/lib/fog/rackspace/requests/compute_v2/delete_metadata_item.rb @@ -2,17 +2,17 @@ module Fog module Compute class RackspaceV2 class Real - def delete_server_metadata_item(server_id, key) + def delete_metadata_item(collection, server_id, key) request( :expects => 204, :method => 'DELETE', - :path => "/servers/#{server_id}/metadata/#{key}" + :path => "/#{collection}/#{server_id}/metadata/#{key}" ) end end class Mock - def delete_server_metadata_item(server_id, key) + def delete_metadata_item(collection, server_id, key) raise Fog::Compute::RackspaceV2::NotFound if server_id == 0 response = Excon::Response.new diff --git a/lib/fog/rackspace/requests/compute_v2/get_server_metadata_item.rb b/lib/fog/rackspace/requests/compute_v2/get_metadata_item.rb similarity index 72% rename from lib/fog/rackspace/requests/compute_v2/get_server_metadata_item.rb rename to lib/fog/rackspace/requests/compute_v2/get_metadata_item.rb index c4c8380bb..cef3f0242 100644 --- a/lib/fog/rackspace/requests/compute_v2/get_server_metadata_item.rb +++ b/lib/fog/rackspace/requests/compute_v2/get_metadata_item.rb @@ -2,17 +2,17 @@ module Fog module Compute class RackspaceV2 class Real - def get_server_metadata_item(server_id, key) + def get_metadata_item(collection, server_id, key) request( :expects => 200, :method => 'GET', - :path => "/servers/#{server_id}/metadata/#{key}" + :path => "/#{collection}/#{server_id}/metadata/#{key}" ) end end class Mock - def get_server_metadata_item(server_id, key) + def get_metadata_item(collection, server_id, key) raise Fog::Compute::RackspaceV2::NotFound if server_id == 0 response = Excon::Response.new diff --git a/lib/fog/rackspace/requests/compute_v2/list_server_metadata.rb b/lib/fog/rackspace/requests/compute_v2/list_metadata.rb similarity index 75% rename from lib/fog/rackspace/requests/compute_v2/list_server_metadata.rb rename to lib/fog/rackspace/requests/compute_v2/list_metadata.rb index 9c8cdb0cf..7623f1f95 100644 --- a/lib/fog/rackspace/requests/compute_v2/list_server_metadata.rb +++ b/lib/fog/rackspace/requests/compute_v2/list_metadata.rb @@ -2,17 +2,17 @@ module Fog module Compute class RackspaceV2 class Real - def list_server_metadata(server_id) + def list_metadata(collection, server_id) request( :expects => [200, 203], :method => 'GET', - :path => "/servers/#{server_id}/metadata" + :path => "/#{collection}/#{server_id}/metadata" ) end end class Mock - def list_server_metadata(server_id) + def list_metadata(collection, server_id) raise Fog::Compute::RackspaceV2::NotFound if server_id == 0 response = Excon::Response.new diff --git a/lib/fog/rackspace/requests/compute_v2/set_server_metadata.rb b/lib/fog/rackspace/requests/compute_v2/set_metadata.rb similarity index 75% rename from lib/fog/rackspace/requests/compute_v2/set_server_metadata.rb rename to lib/fog/rackspace/requests/compute_v2/set_metadata.rb index 29d6dbdc0..fa2eddfe2 100644 --- a/lib/fog/rackspace/requests/compute_v2/set_server_metadata.rb +++ b/lib/fog/rackspace/requests/compute_v2/set_metadata.rb @@ -2,11 +2,11 @@ module Fog module Compute class RackspaceV2 class Real - def set_server_metadata(server_id, metadata = {}) + def set_metadata(collection, server_id, metadata = {}) request( :expects => [200, 203], :method => 'PUT', - :path => "/servers/#{server_id}/metadata", + :path => "/#{collection}/#{server_id}/metadata", :body => Fog::JSON.encode('metadata' => metadata) ) end @@ -14,7 +14,7 @@ module Fog class Mock - def set_server_metadata(server_id, metadata = {}) + def set_metadata(collection, server_id, metadata = {}) raise Fog::Compute::RackspaceV2::NotFound if server_id == 0 response = Excon::Response.new diff --git a/lib/fog/rackspace/requests/compute_v2/set_server_metadata_item.rb b/lib/fog/rackspace/requests/compute_v2/set_metadata_item.rb similarity index 74% rename from lib/fog/rackspace/requests/compute_v2/set_server_metadata_item.rb rename to lib/fog/rackspace/requests/compute_v2/set_metadata_item.rb index 825844f31..2c2d47d4f 100644 --- a/lib/fog/rackspace/requests/compute_v2/set_server_metadata_item.rb +++ b/lib/fog/rackspace/requests/compute_v2/set_metadata_item.rb @@ -2,18 +2,18 @@ module Fog module Compute class RackspaceV2 class Real - def set_server_metadata_item(server_id, key, value) + def set_metadata_item(collection, server_id, key, value) request( :expects => 200, :method => 'PUT', - :path => "/servers/#{server_id}/metadata/#{key}", + :path => "/#{collection}/#{server_id}/metadata/#{key}", :body => Fog::JSON.encode('meta' => { key => value }) ) end end class Mock - def set_server_metadata_item(server_id, key, value) + def set_metadata_item(collection, server_id, key, value) raise Fog::Compute::RackspaceV2::NotFound if server_id == 0 response = Excon::Response.new diff --git a/lib/fog/rackspace/requests/compute_v2/update_server_metadata.rb b/lib/fog/rackspace/requests/compute_v2/update_metadata.rb similarity index 75% rename from lib/fog/rackspace/requests/compute_v2/update_server_metadata.rb rename to lib/fog/rackspace/requests/compute_v2/update_metadata.rb index a2c3d07ac..6ee360b08 100644 --- a/lib/fog/rackspace/requests/compute_v2/update_server_metadata.rb +++ b/lib/fog/rackspace/requests/compute_v2/update_metadata.rb @@ -2,18 +2,18 @@ module Fog module Compute class RackspaceV2 class Real - def update_server_metadata(server_id, metadata = {}) + def update_metadata(collection, server_id, metadata = {}) request( :expects => [200, 203], :method => 'POST', - :path => "/servers/#{server_id}/metadata", + :path => "/#{collection}/#{server_id}/metadata", :body => Fog::JSON.encode('metadata' => metadata) ) end end class Mock - def update_server_metadata(server_id, metadata = {}) + def update_metadata(collection, server_id, metadata = {}) raise Fog::Compute::RackspaceV2::NotFound if server_id == 0 response = Excon::Response.new diff --git a/tests/rackspace/requests/compute_v2/metadata_tests.rb b/tests/rackspace/requests/compute_v2/metadata_tests.rb index 25777a106..54344f8ea 100644 --- a/tests/rackspace/requests/compute_v2/metadata_tests.rb +++ b/tests/rackspace/requests/compute_v2/metadata_tests.rb @@ -13,23 +13,29 @@ Shindo.tests('Fog::Compute::RackspaceV2 | metadata_tests', ['rackspace']) do :metadata => {"Tag" => "Database"}) @server.wait_for(timeout = 1200) { ready? } end - tests('list_server_metadata').returns("metadata" => metadata) do - @service.list_server_metadata(@server.id).body - end - tests('set_server_metadata').returns("metadata" => {"environment" => "dev"}) do - @service.set_server_metadata(@server.id, {"environment" => "dev"}).body - end - tests('update_server_metadata').returns("metadata" => {"environment" => "dev", "Tag" => "Database"}) do - @service.update_server_metadata(@server.id, {"environment" => "dev", "Tag" => "Database"}).body - end - tests('get_server_metadata_item').returns("meta" => {"environment" => "dev"}) do - @service.get_server_metadata_item(@server.id, "environment").body - end - tests('set_server_metadata_item').returns("meta" => {"environment", "test"}) do - @service.set_server_metadata_item(@server.id, "environment", "test").body - end - tests('delete_server_metadata_item').succeeds do - @service.delete_server_metadata_item(@server.id, "environment").body + [['server', @server.id]].each do |params| + collection = params[0] + id = params[1] + tests(collection) do + tests('list_metadata').returns("metadata" => metadata) do + @service.list_metadata(collection, id).body + end + tests('set_metadata').returns("metadata" => {"environment" => "dev"}) do + @service.set_metadata(collection, id, {"environment" => "dev"}).body + end + tests('update_metadata').returns("metadata" => {"environment" => "dev", "Tag" => "Database"}) do + @service.update_metadata(collection, id, {"environment" => "dev", "Tag" => "Database"}).body + end + tests('get_metadata_item').returns("meta" => {"environment" => "dev"}) do + @service.get_metadata_item(collection, id, "environment").body + end + tests('set_metadata_item').returns("meta" => {"environment", "test"}) do + @service.set_metadata_item(collection, id, "environment", "test").body + end + tests('delete_metadata_item').succeeds do + @service.delete_metadata_item(collection, id, "environment").body + end + end end ensure @server.destroy if @server @@ -37,23 +43,27 @@ Shindo.tests('Fog::Compute::RackspaceV2 | metadata_tests', ['rackspace']) do end tests('failure') do - tests('list_server_metadata').raises(Fog::Compute::RackspaceV2::NotFound) do - @service.list_server_metadata(0) - end - tests('set_server_metadata').raises(Fog::Compute::RackspaceV2::NotFound) do - @service.set_server_metadata(0, {"environment" => "dev"}) - end - tests('update_server_metadata').raises(Fog::Compute::RackspaceV2::NotFound) do - @service.update_server_metadata(0, {"environment" => "dev", "Tag" => "Database"}) - end - tests('get_server_metadata_item').raises(Fog::Compute::RackspaceV2::NotFound) do - @service.get_server_metadata_item(0, "environment") - end - tests('set_server_metadata_item').raises(Fog::Compute::RackspaceV2::NotFound) do - @service.set_server_metadata_item(0, "environment", "test") - end - tests('delete_server_metadata_item').raises(Fog::Compute::RackspaceV2::NotFound) do - @service.delete_server_metadata_item(0, "environment") + ['server'].each do |collection| + tests(collection) do + tests('list_metadata').raises(Fog::Compute::RackspaceV2::NotFound) do + @service.list_metadata(collection, 0) + end + tests('set_server_metadata').raises(Fog::Compute::RackspaceV2::NotFound) do + @service.set_metadata(collection, 0, {"environment" => "dev"}) + end + tests('update_server_metadata').raises(Fog::Compute::RackspaceV2::NotFound) do + @service.update_metadata(collection, 0, {"environment" => "dev", "Tag" => "Database"}) + end + tests('get_server_metadata_item').raises(Fog::Compute::RackspaceV2::NotFound) do + @service.get_metadata_item(collection, 0, "environment") + end + tests('set_server_metadata_item').raises(Fog::Compute::RackspaceV2::NotFound) do + @service.set_metadata_item(collection, 0, "environment", "test") + end + tests('delete_server_metadata_item').raises(Fog::Compute::RackspaceV2::NotFound) do + @service.delete_metadata_item(collection, 0, "environment") + end + end end end end