mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[hp|compute_v2] Add request methods for server addresses, along with tests.
This commit is contained in:
parent
9384161dc4
commit
36a6a2206c
4 changed files with 133 additions and 3 deletions
|
@ -56,9 +56,8 @@ module Fog
|
||||||
request :list_images_detail
|
request :list_images_detail
|
||||||
request :list_key_pairs
|
request :list_key_pairs
|
||||||
request :list_metadata
|
request :list_metadata
|
||||||
#request :list_server_addresses
|
request :list_server_addresses
|
||||||
#request :list_server_private_addresses
|
request :list_server_addresses_by_network
|
||||||
#request :list_server_public_addresses
|
|
||||||
#request :list_server_volumes
|
#request :list_server_volumes
|
||||||
request :list_servers
|
request :list_servers
|
||||||
request :list_servers_detail
|
request :list_servers_detail
|
||||||
|
|
42
lib/fog/hp/requests/compute_v2/list_server_addresses.rb
Normal file
42
lib/fog/hp/requests/compute_v2/list_server_addresses.rb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class HPV2
|
||||||
|
class Real
|
||||||
|
|
||||||
|
# List all server addresses
|
||||||
|
#
|
||||||
|
# ==== Parameters
|
||||||
|
# * 'server_id'<~String> - UUId of server to list addresses for
|
||||||
|
#
|
||||||
|
# ==== Returns
|
||||||
|
# * response<~Excon::Response>:
|
||||||
|
# * body<~Hash>:
|
||||||
|
# * 'addresses'<~Hash>:
|
||||||
|
# * 'custom':<~Array> - IP addresses for the server. The network name can change based on setup.
|
||||||
|
def list_server_addresses(server_id)
|
||||||
|
request(
|
||||||
|
:expects => [200,203],
|
||||||
|
:method => 'GET',
|
||||||
|
:path => "servers/#{server_id}/ips"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
|
||||||
|
def list_server_addresses(server_id)
|
||||||
|
response = Excon::Response.new
|
||||||
|
if server = list_servers_detail.body['servers'].detect {|_| _['id'] == server_id}
|
||||||
|
response.status = 200
|
||||||
|
response.body = { 'addresses' => server['addresses'] }
|
||||||
|
response
|
||||||
|
else
|
||||||
|
raise Fog::Compute::HPV2::NotFound
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,43 @@
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class HPV2
|
||||||
|
class Real
|
||||||
|
|
||||||
|
# List private server addresses
|
||||||
|
#
|
||||||
|
# ==== Parameters
|
||||||
|
# * 'server_id'<~String> - UUId of server to list addresses for
|
||||||
|
# * 'network_id'<~String> - UUId of the network to list addresses for
|
||||||
|
#
|
||||||
|
# ==== Returns
|
||||||
|
# * response<~Excon::Response>:
|
||||||
|
# * body<~Hash>:
|
||||||
|
# * 'custom'<~Array> - IP addresses for the server, for the network. The network name can change based on setup.
|
||||||
|
def list_server_addresses_by_network(server_id, network_id)
|
||||||
|
request(
|
||||||
|
:expects => [200,203],
|
||||||
|
:method => 'GET',
|
||||||
|
:path => "servers/#{server_id}/ips/#{network_id}"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
|
||||||
|
def list_server_addresses_by_network(server_id, network_id)
|
||||||
|
response = Excon::Response.new
|
||||||
|
if server = list_servers_detail.body['servers'].detect {|_| _['id'] == server_id}
|
||||||
|
response.status = 200
|
||||||
|
# since we cannot get to networks from compute, just return all addresses
|
||||||
|
response.body = { 'addresses' => server['addresses'] }
|
||||||
|
response
|
||||||
|
else
|
||||||
|
raise Fog::Compute::HPV2::NotFound
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
46
tests/hp/requests/compute_v2/server_address_tests.rb
Normal file
46
tests/hp/requests/compute_v2/server_address_tests.rb
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
Shindo.tests("Fog::Compute::HPV2 | server address requests", ['hp', 'v2', 'compute']) do
|
||||||
|
|
||||||
|
service = Fog::Compute.new(:provider => 'HP', :version => :v2)
|
||||||
|
|
||||||
|
@base_image_id = ENV["BASE_IMAGE_ID"] || "7f60b54c-cd15-433f-8bed-00acbcd25a17"
|
||||||
|
|
||||||
|
tests('success') do
|
||||||
|
@server_name = 'fogaddresstests'
|
||||||
|
@server_id = nil
|
||||||
|
|
||||||
|
# check to see if there are any existing servers, otherwise create one
|
||||||
|
if (data = service.list_servers(:status => 'ACTIVE').body['servers'][0])
|
||||||
|
@server_id = data['id']
|
||||||
|
else
|
||||||
|
#@server = service.servers.create(:name => @server_name, :flavor_id => 100, :image_id => @base_image_id)
|
||||||
|
#@server.wait_for { ready? }
|
||||||
|
data = service.create_server(@server_name, 100, @base_image_id).body['server']
|
||||||
|
@server_id = data['id']
|
||||||
|
end
|
||||||
|
|
||||||
|
# the network name is currently named 'private'
|
||||||
|
tests("#list_server_addresses(#{@server_id})").formats({'addresses' => {'custom' => [{'version' => Integer, 'addr' => String}]}}) do
|
||||||
|
service.list_server_addresses(@server_id).body
|
||||||
|
end
|
||||||
|
|
||||||
|
tests("#list_server_addresses_by_network(#{@server_id}, 'network_uuid')").formats({'addresses' => {'custom' => [{'version' => Integer, 'addr' => String}]}}) do
|
||||||
|
service.list_server_addresses_by_network(@server_id, 'network_uuid').body
|
||||||
|
end
|
||||||
|
|
||||||
|
service.delete_server(@server_id)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('failure') do
|
||||||
|
|
||||||
|
tests('#list_server_addresses(0)').raises(Fog::Compute::HPV2::NotFound) do
|
||||||
|
service.list_server_addresses(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
tests("#list_server_addresses_by_network(0, 'network_uuid')").raises(Fog::Compute::HPV2::NotFound) do
|
||||||
|
service.list_server_addresses_by_network(0, 'network_uuid')
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in a new issue