1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[terremark] mock get_network

This commit is contained in:
Edward Muller 2010-04-29 06:50:18 +08:00 committed by Wesley Beary
parent 849f48154a
commit c430e980f5

View file

@ -26,7 +26,44 @@ module Fog
module Mock
def get_network(network_id)
raise MockNotImplemented.new("Contributions welcome!")
response = Excon::Response.new
if network = @data[:organizations].map { |org| org[:vdcs].map { |vdc| vdc[:networks] } }.flatten.detect { |network| network[:id] == network_id }
body = { "links" => [],
"type" => "application/vnd.vmware.vcloud.network+xml",
"href" => "#{@base_url}/network/#{network_id}" }
network.each_key do |key|
body[key.to_s] = network[key]
end
link = { "name" => "IP Addresses",
"rel" => "down",
"type" => "application/xml" }
link["href"] = case self
when Fog::Terremark::Ecloud::Mock
"#{@base_url}/extensions/network/#{network_id}/ips"
when Fog::Terremark::Vcloud::Mock
"#{@base_url}/network/#{network_id}/ipAddresses"
end
body["links"] << link
response.status = 200
response.body = body
response.headers = Fog::Terremark::Shared::Mock.headers(response.body,
case self
when Fog::Terremark::Ecloud::Mock
"application/vnd.vmware.vcloud.network+xml"
when Fog::Terremark::Vcloud::Mock
"application/xml; charset=utf-8"
end
)
else
response.status = Fog::Terremark::Shared::Mock.unathorized_status
response.headers = Fog::Terremark::Shared::Mock.error_headers
end
response
end
end