mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
a basic get_network for base vcloud
This commit is contained in:
parent
43da7a12ef
commit
b218dc3189
5 changed files with 180 additions and 3 deletions
|
@ -178,14 +178,20 @@ module Fog
|
|||
:subnet => "1.2.3.0/24",
|
||||
:gateway => "1.2.3.1",
|
||||
:netmask => "255.255.255.0",
|
||||
:fencemode => "isolated"
|
||||
:dns => "8.8.8.8",
|
||||
:features => [
|
||||
{ :type => :fencemode, :value => "isolated" }
|
||||
]
|
||||
},
|
||||
{ :href => "#{base_url}/network/32",
|
||||
:name => "4.5.6.0/24",
|
||||
:subnet => "4.5.6.0/24",
|
||||
:gateway => "4.5.6.1",
|
||||
:netmask => "255.255.255.0",
|
||||
:fencemode => "isolated"
|
||||
:dns => "8.8.8.8",
|
||||
:features => [
|
||||
{ :type => :fencemode, :value => "isolated" }
|
||||
]
|
||||
},
|
||||
],
|
||||
:vms => [
|
||||
|
@ -231,8 +237,11 @@ module Fog
|
|||
:name => "7.8.9.0/24",
|
||||
:subnet => "7.8.9.0/24",
|
||||
:gateway => "7.8.9.1",
|
||||
:dns => "8.8.8.8",
|
||||
:netmask => "255.255.255.0",
|
||||
:fencemode => "isolated"
|
||||
:features => [
|
||||
{ :type => :fencemode, :value => "isolated" }
|
||||
]
|
||||
}
|
||||
],
|
||||
:vms => [
|
||||
|
@ -313,6 +322,7 @@ module Fog
|
|||
require 'fog/vcloud/models/vdcs'
|
||||
require 'fog/vcloud/terremark/vcloud'
|
||||
require 'fog/vcloud/terremark/ecloud'
|
||||
require 'fog/vcloud/requests/get_network'
|
||||
require 'fog/vcloud/requests/get_organization'
|
||||
require 'fog/vcloud/requests/get_vdc'
|
||||
require 'fog/vcloud/requests/get_versions'
|
||||
|
@ -321,6 +331,7 @@ module Fog
|
|||
require 'fog/vcloud/parsers/get_vdc'
|
||||
require 'fog/vcloud/parsers/get_versions'
|
||||
require 'fog/vcloud/parsers/login'
|
||||
require 'fog/vcloud/parsers/network'
|
||||
|
||||
require 'builder'
|
||||
|
||||
|
@ -331,6 +342,9 @@ module Fog
|
|||
Struct.new("VcloudVersion", :version, :login_url, :supported)
|
||||
Struct.new("VcloudOrgList", :organizations, :xmlns)
|
||||
Struct.new("VcloudXCapacity", :units, :allocated, :used, :limit)
|
||||
Struct.new("VcloudNetwork", :features, :configuration, :href, :type, :name, :xmlns, :description)
|
||||
Struct.new("VcloudNetworkConfiguration", :gateway, :netmask, :dns)
|
||||
Struct.new("VcloudNetworkFenceMode", :mode)
|
||||
@required = true
|
||||
end
|
||||
|
||||
|
|
53
lib/fog/vcloud/parsers/network.rb
Normal file
53
lib/fog/vcloud/parsers/network.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module Vcloud
|
||||
|
||||
class Network < Fog::Parsers::Vcloud::Base
|
||||
|
||||
def reset
|
||||
@response = Struct::VcloudNetwork.new([])
|
||||
end
|
||||
|
||||
def start_element(name,attributes=[])
|
||||
super
|
||||
case name
|
||||
when "Network"
|
||||
handle_root(attributes)
|
||||
when "Features"
|
||||
@in = :features
|
||||
when "Configuration"
|
||||
@in = :configuration
|
||||
@response.configuration = Struct::VcloudNetworkConfiguration.new
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case @in
|
||||
when :features
|
||||
case name
|
||||
when "FenceMode"
|
||||
@response.features << Struct::VcloudNetworkFenceMode.new(@value)
|
||||
when "Features"
|
||||
@in = nil
|
||||
end
|
||||
when :configuration
|
||||
case name
|
||||
when "Gateway","Netmask","Dns"
|
||||
@response.configuration[name.downcase] = @value
|
||||
when "Configuration"
|
||||
@in = nil
|
||||
end
|
||||
else
|
||||
case name
|
||||
when "Description"
|
||||
@response.description = @value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
54
lib/fog/vcloud/requests/get_network.rb
Normal file
54
lib/fog/vcloud/requests/get_network.rb
Normal file
|
@ -0,0 +1,54 @@
|
|||
module Fog
|
||||
module Vcloud
|
||||
class Real
|
||||
|
||||
def get_network(network_uri)
|
||||
request(
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::Vcloud::Network.new,
|
||||
:uri => uri
|
||||
)
|
||||
end
|
||||
|
||||
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
|
||||
#
|
||||
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 }
|
||||
xml = Builder::XmlMarkup.new
|
||||
mock_it Fog::Parsers::Vcloud::Network.new, 200,
|
||||
xml.Network(xmlns.merge(:href => network[:href], :name => network[:name], :type => type)) {
|
||||
xml.Description(network[:name])
|
||||
xml.Configuration {
|
||||
xml.Gateway(network[:gateway])
|
||||
xml.Netmask(network[:netmask])
|
||||
xml.Dns(network[:dns])
|
||||
}
|
||||
if network[:features]
|
||||
xml.Features {
|
||||
if feature = network[:features].detect { |feature| feature[:type] == :fencemode }
|
||||
xml.FenceMode(feature[:value])
|
||||
end
|
||||
}
|
||||
end
|
||||
},
|
||||
{ 'Content-Type' => type }
|
||||
else
|
||||
mock_error 200, "401 Unauthorized"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
55
spec/vcloud/requests/get_network_spec.rb
Normal file
55
spec/vcloud/requests/get_network_spec.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe Fog::Vcloud, :type => :vcloud_request do
|
||||
subject { @vcloud }
|
||||
|
||||
it { should respond_to :get_network }
|
||||
|
||||
describe :get_network, :type => :vcloud_request do
|
||||
context "with a valid network uri" do
|
||||
before { @network = @vcloud.get_network(URI.parse(@mock_network[:href])) }
|
||||
subject { @network }
|
||||
|
||||
it_should_behave_like "all requests"
|
||||
|
||||
its(:headers) { should include "Content-Type" }
|
||||
its(:body) { should be_an_instance_of Struct::VcloudNetwork }
|
||||
|
||||
describe :headers do
|
||||
let(:header) { @network.headers["Content-Type"] }
|
||||
specify { header.should == "application/vnd.vmware.vcloud.network+xml" }
|
||||
end
|
||||
|
||||
describe :body do
|
||||
subject { @network.body }
|
||||
|
||||
it_should_behave_like "it has a vcloud v0.8 xmlns"
|
||||
|
||||
its(:configuration) { should be_an_instance_of Struct::VcloudNetworkConfiguration }
|
||||
its(:features) { should be_an_instance_of Array }
|
||||
its(:href) { should == URI.parse("https://fakey.com/api/v0.8/network/31") }
|
||||
its(:type) { should == "application/vnd.vmware.vcloud.network+xml" }
|
||||
its(:name) { should == @mock_network[:name] }
|
||||
its(:description) { should == @mock_network[:name] }
|
||||
|
||||
describe :configuration do
|
||||
subject { @network.body.configuration }
|
||||
|
||||
its(:gateway) { should == "1.2.3.1" }
|
||||
its(:netmask) { should == "255.255.255.0" }
|
||||
its(:dns) { should == "8.8.8.8" }
|
||||
end
|
||||
|
||||
describe "FenceMode Feature" do
|
||||
subject { @network.body.features.detect { |feature| feature.is_a?(Struct::VcloudNetworkFenceMode) } }
|
||||
its(:mode) { should == "isolated" }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
context "with a network uri that doesn't exist" do
|
||||
subject { lambda { @vcloud.get_network(URI.parse('https://www.fakey.com/api/v0.8/network/999')) } }
|
||||
it_should_behave_like "a request for a resource that doesn't exist"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -176,6 +176,7 @@ Spec::Runner.configure do |config|
|
|||
@mock_version = @mock_data[:versions][0]
|
||||
@mock_organization = @mock_data[:organizations][0]
|
||||
@mock_vdc = @mock_organization[:vdcs][0]
|
||||
@mock_network = @mock_vdc[:networks][0]
|
||||
end
|
||||
config.after(:all) do
|
||||
Fog::Vcloud::Mock.data_reset
|
||||
|
|
Loading…
Reference in a new issue