mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Switch network model over to get_network_complete
This has also fixed an issue where undefined attributes in the request output were not being unmarked as NonLoaded. Test adjusted accordingly. In addition, highlighted that we need the ensure_list! hack on IpRanges->IpRange.
This commit is contained in:
parent
27bd0edb26
commit
4c46c1de10
3 changed files with 33 additions and 17 deletions
|
|
@ -13,9 +13,26 @@ module Fog
|
|||
private
|
||||
|
||||
def get_by_id(item_id)
|
||||
item = service.get_network(item_id).body
|
||||
service.add_id_from_href!(item)
|
||||
item
|
||||
raw_network = service.get_network_complete(item_id).body
|
||||
data = {}
|
||||
data[:type] = raw_network[:type]
|
||||
data[:href] = raw_network[:href]
|
||||
service.add_id_from_href!(data)
|
||||
data[:name] = raw_network[:name]
|
||||
data[:description] = raw_network[:Description]
|
||||
ip_scope = raw_network[:Configuration][:IpScopes][:IpScope]
|
||||
data[:is_inherited] = ip_scope[:IsInherited]
|
||||
data[:gateway] = ip_scope[:Gateway]
|
||||
data[:netmask] = ip_scope[:Netmask]
|
||||
data[:dns1] = ip_scope[:Dns1]
|
||||
data[:dns2] = ip_scope[:Dns2]
|
||||
data[:dns_suffix] = ip_scope[:DnsSuffix]
|
||||
data[:ip_ranges] = []
|
||||
raw_ip_ranges = ip_scope[:IpRanges][:IpRange]
|
||||
data[:ip_ranges] = raw_ip_ranges.map do |ip_range|
|
||||
{ start_address: ip_range[:StartAddress], end_address: ip_range[:EndAddress] }
|
||||
end
|
||||
data
|
||||
end
|
||||
|
||||
def item_list
|
||||
|
|
|
|||
|
|
@ -14,13 +14,15 @@ module Fog
|
|||
# @see http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/operations/GET-Network.html
|
||||
# @since vCloud API version 0.9
|
||||
def get_network_complete(id)
|
||||
request(
|
||||
response = request(
|
||||
:expects => 200,
|
||||
:idempotent => true,
|
||||
:method => 'GET',
|
||||
:parser => Fog::ToHashDocument.new,
|
||||
:path => "admin/network/#{id}"
|
||||
)
|
||||
ensure_list! response.body[:Configuration][:IpScopes][:IpScope], :IpRanges, :IpRange
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
||||
|
||||
require 'pp'
|
||||
|
||||
Shindo.tests("Compute::VcloudDirector | networks", ['vclouddirector', 'all']) do
|
||||
|
||||
# unless there is at least one network we cannot run these tests
|
||||
|
|
@ -16,8 +14,12 @@ Shindo.tests("Compute::VcloudDirector | networks", ['vclouddirector', 'all']) do
|
|||
# we can explicitly test lazy loading on it, and also so
|
||||
# we stand a greater chance of having other fields populated.
|
||||
network = networks.detect do |net|
|
||||
network_raw = service.get_network(net.id).body
|
||||
network_raw[:gateway].class == String
|
||||
network_raw = service.get_network_complete(net.id).body
|
||||
begin
|
||||
network_raw[:Configuration][:IpScopes][:IpScope][:Gateway].class == String
|
||||
rescue
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
# We don't have a sufficiently populated network to test against
|
||||
|
|
@ -33,8 +35,6 @@ Shindo.tests("Compute::VcloudDirector | networks", ['vclouddirector', 'all']) do
|
|||
tests("#type").returns("application/vnd.vmware.vcloud.orgNetwork+xml"){ network.type }
|
||||
end
|
||||
|
||||
pp network
|
||||
pp network_raw
|
||||
|
||||
tests("Compute::VcloudDirector | network", ['lazy load attrs']) do
|
||||
network.lazy_load_attrs.each do |lazy_attr|
|
||||
|
|
@ -43,18 +43,15 @@ Shindo.tests("Compute::VcloudDirector | networks", ['vclouddirector', 'all']) do
|
|||
end
|
||||
|
||||
tests("Compute::VcloudDirector | network", ['load on demand']) do
|
||||
network_raw_gateway = network_raw[:Configuration][:IpScopes][:IpScope][:Gateway]
|
||||
tests("#gateway is not loaded yet").returns(NonLoaded) { network.attributes[:gateway] }
|
||||
tests("#gateway is loaded on demand").returns(network_raw[:gateway]) { network.gateway }
|
||||
tests("#gateway is loaded on demand").returns(network_raw_gateway) { network.gateway }
|
||||
tests("#gateway is now loaded").returns(true) { network.attributes[:gateway] != NonLoaded }
|
||||
end
|
||||
|
||||
tests("Compute::VcloudDirector | network", ['all available optional fields should now be loaded with data']) do
|
||||
[ :description, :dns1, :dns2, :dns_suffix, :ip_ranges, :is_inherited ].each do |field|
|
||||
next unless network_raw[field] # lazy loading does not load missing fields :/
|
||||
tests("Compute::VcloudDirector | network", ['all lazy load attrs should now be loaded with data']) do
|
||||
network.lazy_load_attrs.each do |field|
|
||||
tests("##{field.to_s} is now loaded").returns(true) { network.attributes[field] != NonLoaded }
|
||||
tests("##{field.to_s} value is as expected").returns(network_raw[field]) do
|
||||
eval "network.#{field.to_s}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue