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

48 lines
1.5 KiB
Ruby
Raw Normal View History

2010-06-09 09:39:00 +08:00
module Fog
class Vcloud
2010-06-09 09:39:00 +08:00
class Real
basic_request :get_network
2010-06-09 09:39:00 +08:00
end
class Mock
def get_network(network_uri)
#
# Based off of:
# vCloud API Guide v0.8 - Page 50
#
# Did not implement AssociatedNetwork, seems redundant, haven't seen it in use yet
# Did not implement the following features: Dhcp, Nat & Firewall
#
network_uri = ensure_unparsed(network_uri)
2010-06-09 09:39:00 +08:00
type = "application/vnd.vmware.vcloud.network+xml"
response = Excon::Response.new
if network = mock_data.organizations.map { |org| org.vdcs.map { |vdc| vdc.networks } }.flatten.detect { |network| network.href == network_uri.to_s }
2010-06-09 09:39:00 +08:00
xml = Builder::XmlMarkup.new
mock_it 200,
xml.Network(xmlns.merge(:href => network.href, :name => network.name, :type => type)) {
xml.Description(network.name)
2010-06-09 09:39:00 +08:00
xml.Configuration {
xml.Gateway(network.gateway)
xml.Netmask(network.netmask)
xml.Dns(network.dns)
2010-06-09 09:39:00 +08:00
}
if network.features
2010-06-09 09:39:00 +08:00
xml.Features {
if feature = network.features.detect { |feature| feature[:type] == :FenceMode }
2010-06-09 09:39:00 +08:00
xml.FenceMode(feature[:value])
end
}
end
},
{ 'Content-Type' => type }
else
mock_error 200, "401 Unauthorized"
end
end
end
end
end