mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
added server metadata operations for Fog::Compute::RackspaceV2
This commit is contained in:
parent
da091c7429
commit
68254a3f1d
8 changed files with 228 additions and 0 deletions
|
@ -53,6 +53,13 @@ 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
|
||||
|
||||
class Mock
|
||||
|
||||
def initialize(options)
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def delete_server_metadata_item(server_id, key)
|
||||
request(
|
||||
:expects => 204,
|
||||
:method => 'DELETE',
|
||||
:path => "/servers/#{server_id}/metadata/#{key}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def delete_server_metadata_item(server_id, key)
|
||||
raise Fog::Compute::RackspaceV2::NotFound if server_id == 0
|
||||
|
||||
response = Excon::Response.new
|
||||
response.body = ""
|
||||
response.status = 204
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def get_server_metadata_item(server_id, key)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:path => "/servers/#{server_id}/metadata/#{key}"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def get_server_metadata_item(server_id, key)
|
||||
raise Fog::Compute::RackspaceV2::NotFound if server_id == 0
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 202
|
||||
response.body = {"meta" => {"environment" => "dev"}}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def list_server_metadata(server_id)
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
:method => 'GET',
|
||||
:path => "/servers/#{server_id}/metadata"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_server_metadata(server_id)
|
||||
raise Fog::Compute::RackspaceV2::NotFound if server_id == 0
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 202
|
||||
response.body = { "metadata"=>{"Tag"=>"Database"} }
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
28
lib/fog/rackspace/requests/compute_v2/set_server_metadata.rb
Normal file
28
lib/fog/rackspace/requests/compute_v2/set_server_metadata.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def set_server_metadata(server_id, metadata = {})
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
:method => 'PUT',
|
||||
:path => "/servers/#{server_id}/metadata",
|
||||
:body => Fog::JSON.encode('metadata' => metadata)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class Mock
|
||||
def set_server_metadata(server_id, metadata = {})
|
||||
raise Fog::Compute::RackspaceV2::NotFound if server_id == 0
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 202
|
||||
response.body = {"metadata"=>{"environment"=>"dev"}}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,27 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def set_server_metadata_item(server_id, key, value)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'PUT',
|
||||
:path => "/servers/#{server_id}/metadata/#{key}",
|
||||
:body => Fog::JSON.encode('meta' => { key => value })
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def set_server_metadata_item(server_id, key, value)
|
||||
raise Fog::Compute::RackspaceV2::NotFound if server_id == 0
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 202
|
||||
response.body = {"meta" => {"environment", "test"}}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,27 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class RackspaceV2
|
||||
class Real
|
||||
def update_server_metadata(server_id, metadata = {})
|
||||
request(
|
||||
:expects => [200, 203],
|
||||
:method => 'POST',
|
||||
:path => "/servers/#{server_id}/metadata",
|
||||
:body => Fog::JSON.encode('metadata' => metadata)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def update_server_metadata(server_id, metadata = {})
|
||||
raise Fog::Compute::RackspaceV2::NotFound if server_id == 0
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 202
|
||||
response.body = {"metadata" => {"environment" => "dev", "Tag" => "Database"}}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
61
tests/rackspace/requests/compute_v2/metadata_tests.rb
Normal file
61
tests/rackspace/requests/compute_v2/metadata_tests.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
Shindo.tests('Fog::Compute::RackspaceV2 | metadata_tests', ['rackspace']) do
|
||||
|
||||
@service = Fog::Compute.new(:provider => 'Rackspace', :version => 'V2')
|
||||
|
||||
tests('success') do
|
||||
begin
|
||||
metadata = {"Tag" => "Database"}
|
||||
|
||||
unless Fog.mocking?
|
||||
@server = @service.servers.create(:name => "fog-server-metadata-#{Time.now.to_i}",
|
||||
:flavor_id => 2,
|
||||
:image_id => '3afe97b2-26dc-49c5-a2cc-a2fc8d80c001',
|
||||
: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
|
||||
end
|
||||
ensure
|
||||
@server.destroy if @server
|
||||
end
|
||||
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")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
Reference in a new issue