From 3d6ee32c15ef2fa69f9895bbd0bfae782d74fbf2 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Fri, 5 Nov 2010 10:45:48 -0300 Subject: [PATCH 01/22] unify generation of IpAddress between get_network_ips and get_network_ip --- .../ecloud/requests/get_network_ip.rb | 25 +++++++++++-------- .../ecloud/requests/get_network_ips.rb | 13 +--------- .../ecloud/requests/get_network_ip_spec.rb | 2 ++ .../ecloud/requests/get_network_ips_spec.rb | 6 ++--- 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/lib/fog/vcloud/terremark/ecloud/requests/get_network_ip.rb b/lib/fog/vcloud/terremark/ecloud/requests/get_network_ip.rb index db05a7f42..8462a37b0 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/get_network_ip.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/get_network_ip.rb @@ -16,16 +16,7 @@ module Fog def get_network_ip(network_ip_uri) if network_ip = mock_data.network_ip_from_href(network_ip_uri) builder = Builder::XmlMarkup.new - xml = builder.IpAddress(ecloud_xmlns) do - builder.Id network_ip.object_id - builder.Href network_ip.href - builder.Name network_ip.name - - builder.Status network_ip.status - if network_ip.used_by - builder.Server network_ip.used_by - end - end + xml = network_ip_response(builder, network_ip, ecloud_xmlns) mock_it 200, xml, { 'Content-Type' => 'application/vnd.tmrk.ecloud.ip+xml' } else @@ -33,6 +24,20 @@ module Fog end end + def network_ip_response(builder, network_ip, xmlns = {}) + builder.IpAddress(xmlns) do + builder.Id network_ip.object_id + builder.Href network_ip.href + builder.Name network_ip.name + + builder.Status network_ip.status + if network_ip.used_by + builder.Server network_ip.used_by.name + end + + builder.RnatAddress(network_ip.rnat) + end + end end end end diff --git a/lib/fog/vcloud/terremark/ecloud/requests/get_network_ips.rb b/lib/fog/vcloud/terremark/ecloud/requests/get_network_ips.rb index 39d918ae5..11ec22ca6 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/get_network_ips.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/get_network_ips.rb @@ -20,18 +20,7 @@ module Fog builder = Builder::XmlMarkup.new xml = builder.IpAddresses do network_ip_collection.ordered_ips.each do |network_ip| - builder.IpAddress do - builder.Name network_ip.name - builder.Href network_ip.href - - if network_ip.used_by - builder.Status("Assigned") - builder.Server(network_ip.used_by.name) - else - builder.Status("Available") - end - builder.RnatAddress(network_ip.rnat) - end + network_ip_response(builder, network_ip) end end diff --git a/spec/vcloud/terremark/ecloud/requests/get_network_ip_spec.rb b/spec/vcloud/terremark/ecloud/requests/get_network_ip_spec.rb index bd47bad9d..45ccf870d 100644 --- a/spec/vcloud/terremark/ecloud/requests/get_network_ip_spec.rb +++ b/spec/vcloud/terremark/ecloud/requests/get_network_ip_spec.rb @@ -23,6 +23,8 @@ if Fog.mocking? its(:Name) { should == @mock_network_ip.name } its(:Href) { should == @mock_network_ip.href } its(:Id) { should == @mock_network_ip.object_id.to_s } + its(:RnatAddress) { should == @mock_network_ip.rnat } + its(:Status) { should == @mock_network_ip.status } end end diff --git a/spec/vcloud/terremark/ecloud/requests/get_network_ips_spec.rb b/spec/vcloud/terremark/ecloud/requests/get_network_ips_spec.rb index a8e37e1cf..eb18977cb 100644 --- a/spec/vcloud/terremark/ecloud/requests/get_network_ips_spec.rb +++ b/spec/vcloud/terremark/ecloud/requests/get_network_ips_spec.rb @@ -30,16 +30,16 @@ if Fog.mocking? context "one we know is assigned" do let(:address) { @ips.body[:IpAddress][0] } - specify { address.should have(5).keys } + specify { address.should have(6).keys } specify { address[:Status].should == "Assigned" } specify { address[:Server].should == "Broom 1" } specify { address[:Name].should == "1.2.3.3" } specify { address[:RnatAddress].should == "99.1.2.3" } end - context "one we know is assigned" do + context "one we know is not assigned" do let(:address) { @ips.body[:IpAddress][100] } - specify { address.should have(4).keys } + specify { address.should have(5).keys } specify { address[:Status].should == "Available" } specify { address.has_key?(:Server).should be_false } specify { address[:Name].should == "1.2.3.103" } From ccbda1a96976fb6d2b431880d2419a90b0040f35 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Fri, 5 Nov 2010 11:53:20 -0300 Subject: [PATCH 02/22] mock configure_network_ip, delete_vapp doesn't do anything if rnat set --- lib/fog/vcloud/mock_data_classes.rb | 22 ++++---- .../ecloud/requests/configure_network_ip.rb | 24 +++++++-- .../terremark/ecloud/requests/delete_vapp.rb | 3 +- .../requests/configure_network_ip_spec.rb | 53 +++++++++++++++++++ .../ecloud/requests/delete_vapp_spec.rb | 9 ++++ 5 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 spec/vcloud/terremark/ecloud/requests/configure_network_ip_spec.rb diff --git a/lib/fog/vcloud/mock_data_classes.rb b/lib/fog/vcloud/mock_data_classes.rb index 54965cf92..ccc19e642 100644 --- a/lib/fog/vcloud/mock_data_classes.rb +++ b/lib/fog/vcloud/mock_data_classes.rb @@ -47,17 +47,7 @@ module Fog end def inspect - "<#{self.class.name} #{object_id} data=#{super} method_data=#{method_data.inspect}>" - end - - private - - def unique_methods - (public_methods - self.class.superclass.public_instance_methods).reject {|m| m.to_s =~ /!$/ } - end - - def method_data - (unique_methods + [:href]).sort_by(&:to_s).find_all {|m| method(m).arity == 0 }.inject({}) {|md, m| md.update(m => send(m)) } + "<#{self.class.name} #{object_id} data=#{super}>" end end @@ -434,6 +424,10 @@ module Fog def rnat self[:rnat] || _parent._parent.rnat end + + def rnat_set? + !!self[:rnat] + end end class MockNetworkExtensions < Base @@ -495,6 +489,12 @@ module Fog disks.inject(0) {|s, d| s + d.vcloud_size } end + def network_ip + if network = _parent.networks.detect {|n| n.ip_collection.items[ip] } + network.ip_collection.items[ip] + end + end + # from fog ecloud server's _compose_vapp_data def to_configure_vapp_hash { diff --git a/lib/fog/vcloud/terremark/ecloud/requests/configure_network_ip.rb b/lib/fog/vcloud/terremark/ecloud/requests/configure_network_ip.rb index 97d6a9347..d3fe1bed1 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/configure_network_ip.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/configure_network_ip.rb @@ -2,14 +2,19 @@ module Fog class Vcloud module Terremark class Ecloud - class Real + module Shared + private - def validate_network_ip_data(network_ip_data, configure=false) + def validate_network_ip_data(network_ip_data) valid_opts = [:id, :href, :name, :status, :server, :rnat] unless valid_opts.all? { |opt| network_ip_data.keys.include?(opt) } raise ArgumentError.new("Required data missing: #{(valid_opts - network_ip_data.keys).map(&:inspect).join(", ")}") end end + end + + class Real + include Shared def configure_network_ip(network_ip_uri, network_ip_data) validate_network_ip_data(network_ip_data) @@ -38,13 +43,24 @@ module Fog builder.RnatAddress(network_ip_data[:rnat]) } end - end class Mock + include Shared def configure_network_ip(network_ip_uri, network_ip_data) - Fog::Mock.not_implemented + validate_network_ip_data(network_ip_data) + + if network_ip = mock_data.network_ip_from_href(network_ip_uri) + network_ip[:rnat] = network_ip_data[:rnat] + + builder = Builder::XmlMarkup.new + xml = network_ip_response(builder, network_ip, ecloud_xmlns) + + mock_it 200, xml, { 'Content-Type' => 'application/vnd.tmrk.ecloud.ip+xml' } + else + mock_error 200, "401 Unauthorized" + end end end end diff --git a/lib/fog/vcloud/terremark/ecloud/requests/delete_vapp.rb b/lib/fog/vcloud/terremark/ecloud/requests/delete_vapp.rb index 270a6897e..7b7897d16 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/delete_vapp.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/delete_vapp.rb @@ -13,7 +13,8 @@ module Fog vdc = virtual_machine._parent if vdc.internet_service_collection.items.detect {|is| is.node_collection.items.any? {|isn| isn.ip_address == virtual_machine.ip } } || - virtual_machine.status != 2 + virtual_machine.status != 2 || + virtual_machine.network_ip.rnat_set? mock_it 202, '', {} else vdc.virtual_machines.delete(virtual_machine) diff --git a/spec/vcloud/terremark/ecloud/requests/configure_network_ip_spec.rb b/spec/vcloud/terremark/ecloud/requests/configure_network_ip_spec.rb new file mode 100644 index 000000000..b5d7997c3 --- /dev/null +++ b/spec/vcloud/terremark/ecloud/requests/configure_network_ip_spec.rb @@ -0,0 +1,53 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper') + +if Fog.mocking? + describe "Fog::Vcloud, initialized w/ the TMRK Ecloud module", :type => :mock_tmrk_ecloud_request do + subject { @vcloud } + + it { should respond_to :configure_network_ip } + + describe "#configure_network_ip" do + let(:original_network_ip) { @vcloud.get_network_ip(@mock_network_ip.href).body } + let(:network_ip_data) do + { + :id => original_network_ip[:Id], + :href => original_network_ip[:Href], + :name => original_network_ip[:Name], + :status => original_network_ip[:Status], + :server => original_network_ip[:Server], + :rnat => "1.2.3.4" + } + end + + context "with a valid network ip uri" do + + subject { @vcloud.configure_network_ip(@mock_network_ip.href, network_ip_data) } + + it_should_behave_like "all responses" + + describe "#body" do + subject { @vcloud.configure_network_ip(@mock_network_ip.href, network_ip_data).body } + + #Stuff that shouldn't change + its(:Href) { should == @mock_network_ip.href } + its(:Id) { should == @mock_network_ip.object_id.to_s } + its(:Name) { should == @mock_network_ip.ip } + its(:Status) { should == @mock_network_ip.status } + + #Stuff that should change + it "should change the rnat" do + expect { subject }.to change { @vcloud.get_network_ip(@mock_network_ip.href).body[:RnatAddress] }.to(network_ip_data[:rnat]) + end + end + + end + + context "with a nodes uri that doesn't exist" do + subject { lambda { @vcloud.configure_network_ip(URI.parse('https://www.fakey.c/piv8vc99'), network_ip_data) } } + + it_should_behave_like "a request for a resource that doesn't exist" + end + end + end +else +end diff --git a/spec/vcloud/terremark/ecloud/requests/delete_vapp_spec.rb b/spec/vcloud/terremark/ecloud/requests/delete_vapp_spec.rb index 6b0ae9598..5087ca5dd 100644 --- a/spec/vcloud/terremark/ecloud/requests/delete_vapp_spec.rb +++ b/spec/vcloud/terremark/ecloud/requests/delete_vapp_spec.rb @@ -69,6 +69,15 @@ if Fog.mocking? it_should_behave_like "all delete responses" it_should_behave_like "a failed vapp deletion" end + + context "when the VM's IP has an rnat set" do + before do + @mock_vm.network_ip[:rnat] = "1.2.3.4" + end + + it_should_behave_like "all delete responses" + it_should_behave_like "a failed vapp deletion" + end end context "with a vapp uri that doesn't exist" do From e22fa493e28aee5d750bf8914e4cdf1517cac81c Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Fri, 5 Nov 2010 12:02:46 -0300 Subject: [PATCH 03/22] be more sure --- .../terremark/ecloud/requests/configure_network_ip_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/vcloud/terremark/ecloud/requests/configure_network_ip_spec.rb b/spec/vcloud/terremark/ecloud/requests/configure_network_ip_spec.rb index b5d7997c3..b9dd8064d 100644 --- a/spec/vcloud/terremark/ecloud/requests/configure_network_ip_spec.rb +++ b/spec/vcloud/terremark/ecloud/requests/configure_network_ip_spec.rb @@ -36,7 +36,9 @@ if Fog.mocking? #Stuff that should change it "should change the rnat" do - expect { subject }.to change { @vcloud.get_network_ip(@mock_network_ip.href).body[:RnatAddress] }.to(network_ip_data[:rnat]) + expect { subject }.to change { @vcloud.get_network_ip(@mock_network_ip.href).body[:RnatAddress] }. + from(@mock_network.rnat). + to(network_ip_data[:rnat]) end end From 6d93fb5b0fa9905915c10793741df6f0e351e172 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Tue, 16 Nov 2010 13:39:02 -0400 Subject: [PATCH 04/22] handle this case as well --- lib/fog/vcloud/terremark/ecloud/models/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fog/vcloud/terremark/ecloud/models/server.rb b/lib/fog/vcloud/terremark/ecloud/models/server.rb index 39e5dece4..f8a1972d7 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/server.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/server.rb @@ -199,7 +199,7 @@ module Fog connection.send(op.keys.first, href + "/power/action/#{op.values.first}" ) rescue Excon::Errors::InternalServerError => e #Frankly we shouldn't get here ... - raise e unless e.to_s =~ /because it is already powered on/ + raise e unless e.to_s =~ /because it is already powered o(n|ff)/ end true end From f29948262ed169c3a0079478388721d793365afc Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Tue, 16 Nov 2010 14:03:32 -0400 Subject: [PATCH 05/22] need these now, should be fixed --- lib/fog/vcloud/terremark/ecloud.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/fog/vcloud/terremark/ecloud.rb b/lib/fog/vcloud/terremark/ecloud.rb index 0b5d29771..55d96db55 100644 --- a/lib/fog/vcloud/terremark/ecloud.rb +++ b/lib/fog/vcloud/terremark/ecloud.rb @@ -3,6 +3,9 @@ module Fog module Terremark class Ecloud < Fog::Vcloud + requires :username, :password, :versions_uri + recognizes :version + model_path 'fog/vcloud/terremark/ecloud/models' model :catalog_item model :catalog From 45f40f807fd6aed984c8bdc2eeba7f25071bd2e6 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Wed, 17 Nov 2010 13:36:17 -0400 Subject: [PATCH 06/22] start 2.5 support --- lib/fog/vcloud/terremark/ecloud.rb | 12 ++++++++---- .../ecloud/requests/add_internet_service.rb | 4 +--- lib/fog/vcloud/terremark/ecloud/requests/add_node.rb | 4 +--- .../ecloud/requests/configure_internet_service.rb | 3 +-- .../terremark/ecloud/requests/configure_network.rb | 3 +-- .../ecloud/requests/configure_network_ip.rb | 3 +-- .../ecloud/requests/get_internet_services.rb | 2 +- .../ecloud/requests/get_network_extensions.rb | 2 +- spec/vcloud/spec_helper.rb | 4 ++-- .../ecloud/requests/get_internet_services_spec.rb | 6 ------ 10 files changed, 17 insertions(+), 26 deletions(-) diff --git a/lib/fog/vcloud/terremark/ecloud.rb b/lib/fog/vcloud/terremark/ecloud.rb index 55d96db55..e8be645ca 100644 --- a/lib/fog/vcloud/terremark/ecloud.rb +++ b/lib/fog/vcloud/terremark/ecloud.rb @@ -71,7 +71,7 @@ module Fog end def self.base_url - "https://fakey.com/api/v0.8b-ext2.3" + "https://fakey.com/api/v0.8b-ext2.5" end def self.data_reset @@ -82,7 +82,7 @@ module Fog def self.data( base_url = self.base_url ) @mock_data ||= Fog::Vcloud::Mock.data(base_url).tap do |vcloud_mock_data| vcloud_mock_data.versions.clear - vcloud_mock_data.versions << MockVersion.new(:version => "v0.8b-ext2.3") + vcloud_mock_data.versions << MockVersion.new(:version => "v0.8b-ext2.5") vcloud_mock_data.organizations.detect {|o| o.name == "Boom Inc." }.tap do |mock_organization| mock_organization.vdcs.detect {|v| v.name == "Boomstick" }.tap do |mock_vdc| @@ -153,7 +153,11 @@ module Fog end def ecloud_xmlns - { :xmlns => "urn:tmrk:eCloudExtensions-2.3", :"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance" } + { + "xmlns" => "urn:tmrk:eCloudExtensions-2.5", + "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance", + # "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema" + } end def mock_data @@ -164,7 +168,7 @@ module Fog class Real < Fog::Vcloud::Real def supporting_versions - ["v0.8b-ext2.3", "0.8b-ext2.3"] + ["v0.8b-ext2.5", "0.8b-ext2.5"] end end diff --git a/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb b/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb index 9ccfa861b..26c72c913 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb @@ -59,9 +59,7 @@ module Fog def generate_internet_service_request(service_data) builder = Builder::XmlMarkup.new - builder.CreateInternetServiceRequest(:"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", - :"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema", - :xmlns => "urn:tmrk:eCloudExtensions-2.3") { + builder.CreateInternetServiceRequest(ecloud_xmlns) { builder.Name(service_data[:name]) builder.Protocol(service_data[:protocol]) builder.Port(service_data[:port]) diff --git a/lib/fog/vcloud/terremark/ecloud/requests/add_node.rb b/lib/fog/vcloud/terremark/ecloud/requests/add_node.rb index dceb654f6..d70b69a01 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/add_node.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/add_node.rb @@ -7,9 +7,7 @@ module Fog def generate_node_request(node_data) builder = Builder::XmlMarkup.new - builder.CreateNodeServiceRequest(:"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", - :"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema", - :xmlns => "urn:tmrk:eCloudExtensions-2.3") { + builder.CreateNodeServiceRequest(ecloud_xmlns) { builder.IpAddress(node_data[:ip_address]) builder.Name(node_data[:name]) builder.Port(node_data[:port]) diff --git a/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb b/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb index 12c10fd66..45e558b9e 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb @@ -7,8 +7,7 @@ module Fog def generate_internet_service_response(public_ip_internet_service) builder = Builder::XmlMarkup.new - builder.InternetService(:"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance", - :xmlns => "urn:tmrk:eCloudExtensions-2.3") { + builder.InternetService(ecloud_xmlns) { builder.Id(public_ip_internet_service.object_id) builder.Href(public_ip_internet_service.href) builder.Name(public_ip_internet_service.name) diff --git a/lib/fog/vcloud/terremark/ecloud/requests/configure_network.rb b/lib/fog/vcloud/terremark/ecloud/requests/configure_network.rb index bdbe8bcd7..4dcdbd69e 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/configure_network.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/configure_network.rb @@ -28,8 +28,7 @@ module Fog def generate_configure_network_request(network_data) builder = Builder::XmlMarkup.new - builder.Network(:"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance", - :xmlns => "urn:tmrk:eCloudExtensions-2.3") { + builder.Network(ecloud_xmlns) { builder.Id(network_data[:id]) builder.Href(network_data[:href]) builder.Name(network_data[:name]) diff --git a/lib/fog/vcloud/terremark/ecloud/requests/configure_network_ip.rb b/lib/fog/vcloud/terremark/ecloud/requests/configure_network_ip.rb index d3fe1bed1..c0caf1e19 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/configure_network_ip.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/configure_network_ip.rb @@ -33,8 +33,7 @@ module Fog def generate_configure_network_ip_request(network_ip_data) builder = Builder::XmlMarkup.new - builder.IpAddress(:"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance", - :xmlns => "urn:tmrk:eCloudExtensions-2.3") { + builder.IpAddress(ecloud_xmlns) { builder.Id(network_ip_data[:id]) builder.Href(network_ip_data[:href]) builder.Name(network_ip_data[:name]) diff --git a/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb b/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb index 008d9133a..229de669c 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb @@ -38,7 +38,7 @@ module Fog def generate_internet_services(services) builder = Builder::XmlMarkup.new - builder.InternetServices(:xmlns => "urn:tmrk:eCloudExtensions-2.3",:"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance") {|xml| + builder.InternetServices(ecloud_xmlns) {|xml| services.each do |service| xml.InternetService { xml.Id service.object_id diff --git a/lib/fog/vcloud/terremark/ecloud/requests/get_network_extensions.rb b/lib/fog/vcloud/terremark/ecloud/requests/get_network_extensions.rb index 6428ded6c..bb3997793 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/get_network_extensions.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/get_network_extensions.rb @@ -13,7 +13,7 @@ module Fog if network_extension = mock_data.network_extension_from_href(ensure_unparsed(network_extension_uri)) xml = Builder::XmlMarkup.new mock_it 200, - xml.Network(:xmlns => "urn:tmrk:eCloudExtensions-2.3", :"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance") { + xml.Network(ecloud_xmlns) { xml.Address network_extension.address xml.RnatAddress network_extension.rnat xml.Href network_extension.href diff --git a/spec/vcloud/spec_helper.rb b/spec/vcloud/spec_helper.rb index 11990f06b..eafe083d5 100644 --- a/spec/vcloud/spec_helper.rb +++ b/spec/vcloud/spec_helper.rb @@ -273,13 +273,13 @@ Spec::Runner.configure do |config| Fog::Vcloud::Mock.data_reset Fog::Vcloud::Terremark::Ecloud::Mock.data_reset setup_ecloud_mock_data - @vcloud = Fog::Vcloud::Terremark::Ecloud.new(:username => "foo", :password => "bar", :versions_uri => "http://fakey.com/api/versions", :module => "Fog::Vcloud::Terremark::Ecloud") + @vcloud = Fog::Vcloud::Terremark::Ecloud.new(:username => "foo", :password => "bar", :versions_uri => "http://fakey.com/api/versions") end config.before(:each, :type => :mock_tmrk_ecloud_model) do Fog::Vcloud::Mock.data_reset Fog::Vcloud::Terremark::Ecloud::Mock.data_reset setup_ecloud_mock_data - @vcloud = Fog::Vcloud::Terremark::Ecloud.new(:username => "foo", :password => "bar", :versions_uri => "http://fakey.com/api/versions", :module => "Fog::Vcloud::Terremark::Ecloud") + @vcloud = Fog::Vcloud::Terremark::Ecloud.new(:username => "foo", :password => "bar", :versions_uri => "http://fakey.com/api/versions") end end diff --git a/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb b/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb index 2c802bf4c..a30fdfbdd 100644 --- a/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb +++ b/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb @@ -41,9 +41,6 @@ if Fog.mocking? it { should have(3).items } - its(:xmlns) { should == "urn:tmrk:eCloudExtensions-2.3" } - its(:xmlns_i) { should == "http://www.w3.org/2001/XMLSchema-instance" } - context "[:InternetService]" do subject { @services.body[:InternetService] } @@ -74,9 +71,6 @@ if Fog.mocking? it { should have(3).items } - its(:xmlns) { should == "urn:tmrk:eCloudExtensions-2.3" } - its(:xmlns_i) { should == "http://www.w3.org/2001/XMLSchema-instance" } - context "[:InternetService]" do subject { @services.body[:InternetService] } From f910a65341aaab20a1c5938133eabd2ee0d4bbf8 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Wed, 17 Nov 2010 14:04:32 -0400 Subject: [PATCH 07/22] add additional attributes to network --- lib/fog/vcloud/mock_data_classes.rb | 12 ++++++++++ .../vcloud/terremark/ecloud/models/network.rb | 3 +++ .../ecloud/requests/get_network_extensions.rb | 22 ++++++++++--------- .../terremark/ecloud/models/network_spec.rb | 5 ++++- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/lib/fog/vcloud/mock_data_classes.rb b/lib/fog/vcloud/mock_data_classes.rb index ccc19e642..841e495cf 100644 --- a/lib/fog/vcloud/mock_data_classes.rb +++ b/lib/fog/vcloud/mock_data_classes.rb @@ -450,6 +450,18 @@ module Fog def rnat _parent.rnat end + + def type + self[:type] || "DMZ" + end + + def vlan + object_id.to_s + end + + def friendly_name + "#{name} (#{type}_#{object_id})" + end end class MockVirtualMachine < Base diff --git a/lib/fog/vcloud/terremark/ecloud/models/network.rb b/lib/fog/vcloud/terremark/ecloud/models/network.rb index b7bb8ed0b..f2e977f3d 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/network.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/network.rb @@ -18,6 +18,9 @@ module Fog attribute :address, :aliases => :Address attribute :rnat, :aliases => :RnatAddress attribute :extension_href, :aliases => :Href + attribute :network_type, :aliases => :NetworkType + attribute :vlan, :aliases => :Vlan + attribute :friendly_name, :aliases => :FriendlyName def ips load_unless_loaded! diff --git a/lib/fog/vcloud/terremark/ecloud/requests/get_network_extensions.rb b/lib/fog/vcloud/terremark/ecloud/requests/get_network_extensions.rb index bb3997793..d6a9fa4f7 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/get_network_extensions.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/get_network_extensions.rb @@ -12,16 +12,18 @@ module Fog def get_network_extensions(network_extension_uri) if network_extension = mock_data.network_extension_from_href(ensure_unparsed(network_extension_uri)) xml = Builder::XmlMarkup.new - mock_it 200, - xml.Network(ecloud_xmlns) { - xml.Address network_extension.address - xml.RnatAddress network_extension.rnat - xml.Href network_extension.href - xml.Id network_extension.object_id - xml.Name network_extension.name - xml.GatewayAddress network_extension.gateway - xml.BroadcastAddress network_extension.broadcast - }, { 'Content-Type' => "application/vnd.tmrk.ecloud.network+xml" } + mock_it 200, xml.Network(ecloud_xmlns) { + xml.Address network_extension.address + xml.RnatAddress network_extension.rnat + xml.Href network_extension.href + xml.Id network_extension.object_id + xml.Name network_extension.name + xml.GatewayAddress network_extension.gateway + xml.BroadcastAddress network_extension.broadcast + xml.NetworkType network_extension.type + xml.Vlan network_extension.vlan + xml.FriendlyName network_extension.friendly_name + }, { 'Content-Type' => "application/vnd.tmrk.ecloud.network+xml" } else mock_error 200, "401 Unauthorized" end diff --git a/spec/vcloud/terremark/ecloud/models/network_spec.rb b/spec/vcloud/terremark/ecloud/models/network_spec.rb index a5c1c7d26..6c962452e 100644 --- a/spec/vcloud/terremark/ecloud/models/network_spec.rb +++ b/spec/vcloud/terremark/ecloud/models/network_spec.rb @@ -8,7 +8,7 @@ if Fog.mocking? subject { Fog::Vcloud::Terremark::Ecloud::Network } it { should have_identity :href } - it { should have_only_these_attributes [:href, :name, :features, :links, :type, :gateway, :broadcast, :address, :rnat, :extension_href] } + it { should have_only_these_attributes [:href, :name, :features, :links, :type, :gateway, :broadcast, :address, :rnat, :extension_href, :network_type, :vlan, :friendly_name] } end context "with no uri" do @@ -32,6 +32,9 @@ if Fog.mocking? its(:address) { should == @mock_network.address } its(:rnat) { should == @mock_network.rnat } its(:extension_href) { should == @mock_network.extensions.href } + its(:network_type) { should == @mock_network.extensions.type } + its(:vlan) { should == @mock_network.extensions.vlan } + its(:friendly_name) { should == @mock_network.extensions.friendly_name } it { should have(1).features } From 73d07f4487a3ee3340901abdc87f0c6dae25d692 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Fri, 19 Nov 2010 13:41:49 -0400 Subject: [PATCH 08/22] start of backup internet service support --- lib/fog/vcloud/mock_data_classes.rb | 38 +++++++++++++++++++ lib/fog/vcloud/terremark/ecloud.rb | 5 ++- .../ecloud/models/internet_services.rb | 2 +- .../ecloud/requests/get_internet_services.rb | 17 ++++++--- .../requests/get_internet_services_spec.rb | 37 ++++++++++++++++-- 5 files changed, 88 insertions(+), 11 deletions(-) diff --git a/lib/fog/vcloud/mock_data_classes.rb b/lib/fog/vcloud/mock_data_classes.rb index 841e495cf..d65c43d4a 100644 --- a/lib/fog/vcloud/mock_data_classes.rb +++ b/lib/fog/vcloud/mock_data_classes.rb @@ -586,10 +586,48 @@ module Fog end def items + public_ip_internet_services + backup_internet_services + end + + def public_ip_internet_services _parent.public_ip_collection.items.inject([]) do |services, public_ip| services + public_ip.internet_service_collection.items end end + + def backup_internet_services + @backup_internet_services ||= [] + end + end + + class MockBackupInternetService < Base + def name + self[:name] || "Backup Internet Service #{object_id}" + end + + def protocol + self[:protocol] + end + + def port + 0 + end + + def enabled + self[:enabled].to_s.downcase != "false" + end + + def timeout + self[:timeout] || 2 + end + + def description + self[:description] || "Description for Backup Service #{name}" + end + + def redirect_url + nil + end end class MockFirewallAcls < Base diff --git a/lib/fog/vcloud/terremark/ecloud.rb b/lib/fog/vcloud/terremark/ecloud.rb index e8be645ca..29981ccc6 100644 --- a/lib/fog/vcloud/terremark/ecloud.rb +++ b/lib/fog/vcloud/terremark/ecloud.rb @@ -131,6 +131,8 @@ module Fog end mock_vdc.public_ip_collection.items << MockPublicIp.new(:name => "99.1.9.7") + + mock_vdc.internet_service_collection.backup_internet_services << MockBackupInternetService.new({ :port => 10000, :protocol => "TCP"}, self) end mock_organization.vdcs.detect {|v| v.name == "Rock-n-Roll" }.tap do |mock_vdc| @@ -155,8 +157,7 @@ module Fog def ecloud_xmlns { "xmlns" => "urn:tmrk:eCloudExtensions-2.5", - "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance", - # "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema" + "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance" } end diff --git a/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb b/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb index 144263957..c9dedcc6f 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb @@ -13,7 +13,7 @@ module Fog def all check_href! :message => "the Internet Services for the Vdc you want to enumerate" - if data = connection.get_internet_services(href).body[:InternetService] + if data = connection.get_internet_services(href).body[:InternetService].find_all {|i| i[:IsBackupService] == "false" } load(data) end end diff --git a/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb b/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb index 229de669c..02aa617b0 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb @@ -44,11 +44,15 @@ module Fog xml.Id service.object_id xml.Href service.href xml.Name service.name - xml.PublicIpAddress { - xml.Id service._parent._parent.object_id - xml.Href service._parent._parent.href - xml.Name service._parent._parent.name - } + if MockDataClasses::MockBackupInternetService === service + xml.PublicIpAddress "i:nil" => true + else + xml.PublicIpAddress { + xml.Id service._parent._parent.object_id + xml.Href service._parent._parent.href + xml.Name service._parent._parent.name + } + end xml.Port service.port xml.Protocol service.protocol xml.Enabled service.enabled @@ -56,6 +60,9 @@ module Fog xml.Description service.description xml.RedirectURL service.redirect_url xml.Monitor + xml.IsBackupService MockDataClasses::MockBackupInternetService === service + xml.BackupService "i:nil" => true + xml.BackupOf } end } diff --git a/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb b/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb index a30fdfbdd..360f16e3d 100644 --- a/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb +++ b/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb @@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper') if Fog.mocking? shared_examples_for "the expected internet service item" do specify { service.should be_an_instance_of Hash } - specify { service.should have(11).attributes } + specify { service.should have(14).attributes } specify { service[:Name].should == mock_service.name } specify { service[:Id].should == mock_service.object_id.to_s } specify { service[:Href].should == mock_service.href } @@ -21,6 +21,30 @@ if Fog.mocking? specify { service[:Description].should == mock_service.description } specify { service[:RedirectURL].should == (mock_service.redirect_url || "") } specify { service[:Monitor].should == "" } + specify { service[:IsBackupService].should == "false" } + specify { service[:BackupService].should be_nil } + specify { service[:BackupOf].should == "" } + end + + shared_examples_for "the expected backup internet service item" do + specify { service.should be_an_instance_of Hash } + specify { service.should have(14).attributes } + specify { service[:Name].should == mock_service.name } + specify { service[:Id].should == mock_service.object_id.to_s } + specify { service[:Href].should == mock_service.href } + + specify { service[:PublicIpAddress].should be_nil } + + specify { service[:Port].should == mock_service.port.to_s } + specify { service[:Protocol].should == mock_service.protocol } + specify { service[:Enabled].should == mock_service.enabled.to_s } + specify { service[:Timeout].should == mock_service.timeout.to_s } + specify { service[:Description].should == mock_service.description } + specify { service[:RedirectURL].should == (mock_service.redirect_url || "") } + specify { service[:Monitor].should == "" } + specify { service[:IsBackupService].should == "true" } + specify { service[:BackupService].should be_nil } + specify { service[:BackupOf].should == "" } end describe "Fog::Vcloud, initialized w/ the TMRK Ecloud module", :type => :mock_tmrk_ecloud_request do @@ -44,15 +68,22 @@ if Fog.mocking? context "[:InternetService]" do subject { @services.body[:InternetService] } - it { should have(4).items } + it { should have(5).items } [0,1,2,3].each do |idx| let(:service) { subject[idx] } - let(:mock_service) { @mock_vdc.public_ip_collection.items.map {|ip| ip.internet_service_collection.items }.flatten[idx] } + let(:mock_service) { @mock_vdc.internet_service_collection.items[idx] } let(:mock_ip) { mock_service._parent._parent } it_should_behave_like "the expected internet service item" end + + context "for a backup internet service" do + let(:service) { subject[4] } + let(:mock_service) { @mock_vdc.internet_service_collection.backup_internet_services.first } + + it_should_behave_like "the expected backup internet service item" + end end end end From 28487dfeb74854fe07d213cd6a7e7c0249dd62ed Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Fri, 19 Nov 2010 14:26:50 -0400 Subject: [PATCH 09/22] models --- lib/fog/vcloud/terremark/ecloud.rb | 2 + .../ecloud/models/backup_internet_service.rb | 60 +++++++++++++++++++ .../ecloud/models/backup_internet_services.rb | 36 +++++++++++ lib/fog/vcloud/terremark/ecloud/models/vdc.rb | 8 ++- spec/vcloud/spec_helper.rb | 1 + .../models/backup_internet_service_spec.rb | 49 +++++++++++++++ .../models/backup_internet_services_spec.rb | 29 +++++++++ 7 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 lib/fog/vcloud/terremark/ecloud/models/backup_internet_service.rb create mode 100644 lib/fog/vcloud/terremark/ecloud/models/backup_internet_services.rb create mode 100644 spec/vcloud/terremark/ecloud/models/backup_internet_service_spec.rb create mode 100644 spec/vcloud/terremark/ecloud/models/backup_internet_services_spec.rb diff --git a/lib/fog/vcloud/terremark/ecloud.rb b/lib/fog/vcloud/terremark/ecloud.rb index 29981ccc6..1ae8dbdf5 100644 --- a/lib/fog/vcloud/terremark/ecloud.rb +++ b/lib/fog/vcloud/terremark/ecloud.rb @@ -13,6 +13,8 @@ module Fog collection :firewall_acls model :internet_service collection :internet_services + model :backup_internet_service + collection :backup_internet_services model :ip collection :ips model :network diff --git a/lib/fog/vcloud/terremark/ecloud/models/backup_internet_service.rb b/lib/fog/vcloud/terremark/ecloud/models/backup_internet_service.rb new file mode 100644 index 000000000..89c80b0ff --- /dev/null +++ b/lib/fog/vcloud/terremark/ecloud/models/backup_internet_service.rb @@ -0,0 +1,60 @@ +module Fog + class Vcloud + module Terremark + class Ecloud + class BackupInternetService < Fog::Vcloud::Model + + identity :href, :aliases => :Href + + ignore_attributes :xmlns, :xmlns_i + + attribute :name, :aliases => :Name + attribute :id, :aliases => :Id + attribute :protocol, :aliases => :Protocol + attribute :enabled, :aliases => :Enabled + attribute :description, :aliases => :Description + attribute :timeout, :aliases => :Timeout + attribute :redirect_url, :aliases => :RedirectURL + attribute :monitor, :aliases => :Monitor + + def delete + requires :href + + connection.delete_internet_service( href ) + end + + def monitor=(new_monitor = {}) + if new_monitor.nil? || new_monitor.empty? + @monitor = nil + end + end + + def save + if new_record? + result = connection.add_internet_service( collection.href, _compose_service_data ) + merge_attributes(result.body) + else + connection.configure_internet_service( href, _compose_service_data, _compose_ip_data ) + end + end + + def nodes + @nodes ||= Fog::Vcloud::Terremark::Ecloud::Nodes.new( :connection => connection, :href => href + "/nodeServices" ) + end + + private + + def _compose_service_data + #For some reason inject didn't work + service_data = {} + self.class.attributes.select{ |attribute| !send(attribute).nil? }.each { |attribute| service_data[attribute] = send(attribute) } + service_data + end + + end + end + end + end +end + + diff --git a/lib/fog/vcloud/terremark/ecloud/models/backup_internet_services.rb b/lib/fog/vcloud/terremark/ecloud/models/backup_internet_services.rb new file mode 100644 index 000000000..f7f3d4df7 --- /dev/null +++ b/lib/fog/vcloud/terremark/ecloud/models/backup_internet_services.rb @@ -0,0 +1,36 @@ +require 'fog/vcloud/terremark/ecloud/models/backup_internet_service' + +module Fog + class Vcloud + module Terremark + class Ecloud + + class BackupInternetServices < Fog::Vcloud::Collection + + model Fog::Vcloud::Terremark::Ecloud::BackupInternetService + + attribute :href, :aliases => :Href + + def all + check_href! :message => "the Internet Services for the Vdc you want to enumerate" + if data = connection.get_internet_services(href).body[:InternetService].find_all {|i| i[:IsBackupService] == "true" } + load(data) + end + end + + # Optimize later, no need to get_internet_services again? + def get(uri) + internet_services = connection.get_internet_services(href).body[:InternetService] + internet_services = [ internet_services ] if internet_services.is_a?(Hash) + if data = internet_services.detect { |service| service[:Href] == uri } + new(data) + end + rescue Fog::Errors::NotFound + nil + end + + end + end + end + end +end diff --git a/lib/fog/vcloud/terremark/ecloud/models/vdc.rb b/lib/fog/vcloud/terremark/ecloud/models/vdc.rb index 69f329129..3436d380b 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/vdc.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/vdc.rb @@ -27,6 +27,10 @@ module Fog @internet_services ||= collection_based_on_type("application/vnd.tmrk.ecloud.internetServicesList+xml") end + def backup_internet_services + @backup_internet_services ||= collection_based_on_type("application/vnd.tmrk.ecloud.internetServicesList+xml", BackupInternetServices) + end + def networks @networks ||= Fog::Vcloud::Terremark::Ecloud::Networks. new( :connection => connection, @@ -55,14 +59,14 @@ module Fog private - def collection_based_on_type(type) + def collection_based_on_type(type, klass = nil) load_unless_loaded! if link = other_links.detect { |link| link[:type] == type } case type when "application/vnd.tmrk.ecloud.publicIpsList+xml" Fog::Vcloud::Terremark::Ecloud::PublicIps when "application/vnd.tmrk.ecloud.internetServicesList+xml" - Fog::Vcloud::Terremark::Ecloud::InternetServices + klass || Fog::Vcloud::Terremark::Ecloud::InternetServices when "application/vnd.vmware.vcloud.catalog+xml" Fog::Vcloud::Terremark::Ecloud::Catalog when "application/vnd.tmrk.ecloud.firewallAclsList+xml" diff --git a/spec/vcloud/spec_helper.rb b/spec/vcloud/spec_helper.rb index eafe083d5..13256be82 100644 --- a/spec/vcloud/spec_helper.rb +++ b/spec/vcloud/spec_helper.rb @@ -233,6 +233,7 @@ def setup_ecloud_mock_data @mock_public_ip = @mock_public_ip_collection.items.first @mock_service_collection = @mock_public_ip.internet_service_collection @mock_service = @mock_service_collection.items.first + @mock_backup_service = @mock_vdc_service_collection.backup_internet_services.first @mock_node_collection = @mock_service.node_collection @mock_node = @mock_node_collection.items.first @mock_catalog = @mock_vdc.catalog diff --git a/spec/vcloud/terremark/ecloud/models/backup_internet_service_spec.rb b/spec/vcloud/terremark/ecloud/models/backup_internet_service_spec.rb new file mode 100644 index 000000000..fb004bc11 --- /dev/null +++ b/spec/vcloud/terremark/ecloud/models/backup_internet_service_spec.rb @@ -0,0 +1,49 @@ +require File.join(File.dirname(__FILE__),'..','..','..','spec_helper') + +if Fog.mocking? + describe "Fog::Vcloud::Terremark::Ecloud::BackupInternetService", :type => :mock_tmrk_ecloud_model do + subject { @vcloud.vdcs[0].backup_internet_services[0] } + + describe :class do + subject { Fog::Vcloud::Terremark::Ecloud::BackupInternetService } + + it { should have_identity :href } + it { should have_only_these_attributes [:href, :name, :id, :protocol, :enabled, :description, :timeout, :redirect_url, :monitor] } + end + + context "with no uri" do + + subject { Fog::Vcloud::Terremark::Ecloud::BackupInternetService.new() } + it { should have_all_attributes_be_nil } + + end + + context "as a collection member" do + subject { @vcloud.vdcs[0].backup_internet_services[0].reload } + + let(:composed_service_data) { @vcloud.vdcs[0].backup_internet_services[0].send(:_compose_service_data) } + + it { should be_an_instance_of Fog::Vcloud::Terremark::Ecloud::BackupInternetService } + + its(:href) { should == @mock_backup_service.href } + its(:identity) { should == @mock_backup_service.href } + its(:name) { should == @mock_backup_service.name } + its(:id) { should == @mock_backup_service.object_id.to_s } + its(:protocol) { should == @mock_backup_service.protocol } + its(:enabled) { should == @mock_backup_service.enabled.to_s } + its(:description) { should == @mock_backup_service.description } + its(:timeout) { should == @mock_backup_service.timeout.to_s } + its(:redirect_url) { should == (@mock_backup_service.redirect_url || "") } + its(:monitor) { should == nil } + + specify { composed_service_data[:href].should == subject.href.to_s } + specify { composed_service_data[:name].should == subject.name } + specify { composed_service_data[:id].should == subject.id.to_s } + specify { composed_service_data[:protocol].should == subject.protocol } + specify { composed_service_data[:enabled].should == subject.enabled.to_s } + specify { composed_service_data[:description].should == subject.description } + specify { composed_service_data[:timeout].should == subject.timeout.to_s } + end + end +else +end diff --git a/spec/vcloud/terremark/ecloud/models/backup_internet_services_spec.rb b/spec/vcloud/terremark/ecloud/models/backup_internet_services_spec.rb new file mode 100644 index 000000000..0cd821cfc --- /dev/null +++ b/spec/vcloud/terremark/ecloud/models/backup_internet_services_spec.rb @@ -0,0 +1,29 @@ +require File.join(File.dirname(__FILE__),'..','..','..','spec_helper') + +if Fog.mocking? + describe "Fog::Vcloud::Terremark::Ecloud::InternetServices", :type => :mock_tmrk_ecloud_model do + context "as an attribute of a VDC" do + subject { @vcloud.vdcs[0] } + + it { should respond_to :backup_internet_services } + + describe :class do + subject { @vcloud.vdcs[0].backup_internet_services.class } + its(:model) { should == Fog::Vcloud::Terremark::Ecloud::BackupInternetService } + end + + describe :backup_internet_services do + subject { @vcloud.vdcs[0].backup_internet_services } + + it { should respond_to :create } + + it { should be_an_instance_of Fog::Vcloud::Terremark::Ecloud::BackupInternetServices } + + its(:length) { should == 1 } + + it { should have_members_of_the_right_model } + end + end + end +else +end From 9f9abb2c79fe2d6f76cc35ac8c4a621875327768 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Fri, 19 Nov 2010 15:33:23 -0400 Subject: [PATCH 10/22] WIP: add_backup_internet_service request --- lib/fog/vcloud/mock_data_classes.rb | 12 ++ lib/fog/vcloud/terremark/ecloud.rb | 1 + .../ecloud/models/backup_internet_service.rb | 4 +- .../requests/add_backup_internet_service.rb | 110 ++++++++++++++++++ .../add_backup_internet_service_spec.rb | 60 ++++++++++ 5 files changed, 185 insertions(+), 2 deletions(-) create mode 100644 lib/fog/vcloud/terremark/ecloud/requests/add_backup_internet_service.rb create mode 100644 spec/vcloud/terremark/ecloud/requests/add_backup_internet_service_spec.rb diff --git a/lib/fog/vcloud/mock_data_classes.rb b/lib/fog/vcloud/mock_data_classes.rb index d65c43d4a..094eeb1da 100644 --- a/lib/fog/vcloud/mock_data_classes.rb +++ b/lib/fog/vcloud/mock_data_classes.rb @@ -121,6 +121,14 @@ module Fog find_href_in(href, all_vdc_internet_service_collections) end + def all_backup_internet_services + all_vdc_internet_service_collections.map(&:backup_internet_services).flatten + end + + def backup_internet_service_from_href(href) + find_href_in(href, all_backup_internet_services) + end + def all_public_ip_collections all_vdcs.map {|v| v.public_ip_collection }.flatten end @@ -628,6 +636,10 @@ module Fog def redirect_url nil end + + def node_collection + @node_collection ||= MockPublicIpInternetServiceNodes.new({}, self) + end end class MockFirewallAcls < Base diff --git a/lib/fog/vcloud/terremark/ecloud.rb b/lib/fog/vcloud/terremark/ecloud.rb index 1ae8dbdf5..2dea2216e 100644 --- a/lib/fog/vcloud/terremark/ecloud.rb +++ b/lib/fog/vcloud/terremark/ecloud.rb @@ -32,6 +32,7 @@ module Fog request_path 'fog/vcloud/terremark/ecloud/requests' request :add_internet_service + request :add_backup_internet_service request :add_node request :clone_vapp request :configure_internet_service diff --git a/lib/fog/vcloud/terremark/ecloud/models/backup_internet_service.rb b/lib/fog/vcloud/terremark/ecloud/models/backup_internet_service.rb index 89c80b0ff..126b30dbb 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/backup_internet_service.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/backup_internet_service.rb @@ -31,10 +31,10 @@ module Fog def save if new_record? - result = connection.add_internet_service( collection.href, _compose_service_data ) + result = connection.add_backup_internet_service( collection.href, _compose_service_data ) merge_attributes(result.body) else - connection.configure_internet_service( href, _compose_service_data, _compose_ip_data ) + connection.configure_backup_internet_service( href, _compose_service_data ) end end diff --git a/lib/fog/vcloud/terremark/ecloud/requests/add_backup_internet_service.rb b/lib/fog/vcloud/terremark/ecloud/requests/add_backup_internet_service.rb new file mode 100644 index 000000000..de71e45d4 --- /dev/null +++ b/lib/fog/vcloud/terremark/ecloud/requests/add_backup_internet_service.rb @@ -0,0 +1,110 @@ +module Fog + class Vcloud + module Terremark + class Ecloud + module Shared + def validate_backup_internet_service_data(service_data, configure=false) + required_opts = [:name, :protocol, :description, :enabled] + if configure + required_opts + [ :id, :href, :timeout ] + end + unless required_opts.all? { |opt| service_data.keys.include?(opt) } + raise ArgumentError.new("Required Backup Internet Service data missing: #{(required_opts - service_data.keys).map(&:inspect).join(", ")}") + end + end + end + + class Real + include Shared + + def add_backup_internet_service(internet_services_uri, service_data) + validate_backup_internet_service_data(service_data) + if monitor = service_data[:monitor] + validate_internet_service_monitor(monitor) + ensure_monitor_defaults!(monitor) + end + + request( + :body => generate_backup_internet_service_request(service_data), + :expects => 200, + :headers => {'Content-Type' => 'application/xml'}, + :method => 'POST', + :uri => internet_services_uri, + :parse => true + ) + end + + private + + def generate_backup_internet_service_request(service_data) + builder = Builder::XmlMarkup.new + builder.CreateBackupInternetServiceRequest("xmlns" => "urn:tmrk:eCloudExtensions-2.5") { + builder.Name(service_data[:name]) + builder.Protocol(service_data[:protocol]) + builder.Enabled(service_data[:enabled]) + builder.Description(service_data[:description]) + builder.RedirectURL(service_data[:redirect_url]) + if monitor = service_data[:monitor] + generate_monitor_section(builder,monitor) + end + } + end + end + + class Mock + include Shared + + # + # Based on + # http://support.theenterprisecloud.com/kb/default.asp?id=561&Lang=1&SID= + # + + def add_backup_internet_service(internet_services_uri, service_data) + validate_backup_internet_service_data(service_data) + + internet_services_uri = ensure_unparsed(internet_services_uri) + + if vdc_internet_service_collection = mock_data.vdc_internet_service_collection_from_href(internet_services_uri) + new_backup_internet_service = MockBackupInternetService.new(service_data, vdc_internet_service_collection.backup_internet_services) + vdc_internet_service_collection.backup_internet_services << new_backup_internet_service + xml = generate_backup_internet_service_added_response(new_backup_internet_service) + + mock_it 200, xml, {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'} + else + mock_error 200, "401 Unauthorized" + end + end + + private + + def generate_backup_internet_service_added_response(new_backup_internet_service) + builder = Builder::XmlMarkup.new + builder.InternetService { + builder.Id new_backup_internet_service.object_id + builder.Href new_backup_internet_service.href + builder.Name new_backup_internet_service.name + # so broken + builder.PublicIpAddress do + builder.Id -2147483648 + builder.Id "http://totally.invalid/1234" + builder.Name + end + builder.Port new_backup_internet_service.port + builder.Protocol new_backup_internet_service.protocol + builder.Enabled new_backup_internet_service.enabled + builder.Timeout new_backup_internet_service.timeout + builder.Description new_backup_internet_service.description + builder.RedirectURL new_backup_internet_service.redirect_url + builder.Monitor "i:nil" => true + # so broken + builder.IsBackupService false + builder.BackupService "i:nil" => true + builder.BackupOf "i:nil" => true + } + end + end + end + end + end +end + diff --git a/spec/vcloud/terremark/ecloud/requests/add_backup_internet_service_spec.rb b/spec/vcloud/terremark/ecloud/requests/add_backup_internet_service_spec.rb new file mode 100644 index 000000000..031132c65 --- /dev/null +++ b/spec/vcloud/terremark/ecloud/requests/add_backup_internet_service_spec.rb @@ -0,0 +1,60 @@ +require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper') + +if Fog.mocking? + describe "Fog::Vcloud, initialized w/ the TMRK Ecloud module", :type => :mock_tmrk_ecloud_request do + subject { @vcloud } + + it { should respond_to :add_backup_internet_service } + + describe "#add_backup_internet_service" do + before do + @new_backup_service_data = { + :name => "Test Service", + :protocol => "HTTP", + :enabled => "true", + :description => "this is a test", + :redirect_url => "" + } + end + + context "with a valid vdc uri" do + subject { @vcloud.add_backup_internet_service(@mock_vdc.internet_service_collection.href, @new_backup_service_data ) } + + it "has the right number of Internet Services after" do + expect { subject }.to change { @vcloud.get_internet_services(@mock_vdc.internet_service_collection.href).body[:InternetService].size }.by(1) + end + + it_should_behave_like "all responses" + + let(:body) { subject.body } + + its(:body) { should be_an_instance_of Hash } + specify { body[:Href].should_not be_empty } + specify { body[:Name].should == @new_backup_service_data[:name] } + specify { body[:Protocol].should == @new_backup_service_data[:protocol] } + specify { body[:Enabled].should == @new_backup_service_data[:enabled] } + specify { body[:Description].should == @new_backup_service_data[:description] } + specify { body[:RedirectURL].should == @new_backup_service_data[:redirect_url] } + specify { body[:Monitor].should == nil } + # so broken + specify { body[:IsBackupService].should == "false" } + + it "should update the mock object properly" do + subject + + backup_internet_service = @vcloud.mock_data.backup_internet_service_from_href(body[:Href]) + backup_internet_service.object_id.to_s.should == body[:Id] + backup_internet_service.node_collection.items.should be_empty + end + end + + context "with a vdc uri that doesn't exist" do + subject { lambda { @vcloud.add_backup_internet_service(URI.parse('https://www.fakey.c/piv8vc99'), @new_backup_service_data ) } } + + it_should_behave_like "a request for a resource that doesn't exist" + end + end + end +else +end + From da094139d3bc9d9c0b81d4876616097d704a5570 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Fri, 19 Nov 2010 15:46:06 -0400 Subject: [PATCH 11/22] fix URL --- .../terremark/ecloud/requests/add_backup_internet_service.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/fog/vcloud/terremark/ecloud/requests/add_backup_internet_service.rb b/lib/fog/vcloud/terremark/ecloud/requests/add_backup_internet_service.rb index de71e45d4..324d7f55c 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/add_backup_internet_service.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/add_backup_internet_service.rb @@ -56,7 +56,8 @@ module Fog # # Based on - # http://support.theenterprisecloud.com/kb/default.asp?id=561&Lang=1&SID= + # http://support.theenterprisecloud.com/kb/default.asp?id=729&Lang=1&SID= + # and many tears shed. # def add_backup_internet_service(internet_services_uri, service_data) From 19d1177333f873f6a400e10ef712db7ae40ad291 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Fri, 19 Nov 2010 16:19:06 -0400 Subject: [PATCH 12/22] fix for when only one is returned --- lib/fog/vcloud/terremark/ecloud/models/internet_services.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb b/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb index c9dedcc6f..ae3dfb7c9 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb @@ -13,7 +13,7 @@ module Fog def all check_href! :message => "the Internet Services for the Vdc you want to enumerate" - if data = connection.get_internet_services(href).body[:InternetService].find_all {|i| i[:IsBackupService] == "false" } + if data = [connection.get_internet_services(href).body[:InternetService]].flatten.find_all {|i| i[:IsBackupService] == "false" } load(data) end end From 98a2f257aa0bb9b967b518f1de182def8d4a78e3 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Mon, 22 Nov 2010 10:15:23 -0400 Subject: [PATCH 13/22] internet service model returns backup service href --- lib/fog/vcloud/mock_data_classes.rb | 4 ++ .../ecloud/models/internet_service.rb | 7 ++++ .../ecloud/requests/get_internet_services.rb | 8 +++- .../ecloud/models/internet_service_spec.rb | 33 ++++++++++------- .../requests/get_internet_services_spec.rb | 37 +++++++++++++++---- 5 files changed, 67 insertions(+), 22 deletions(-) diff --git a/lib/fog/vcloud/mock_data_classes.rb b/lib/fog/vcloud/mock_data_classes.rb index 094eeb1da..6f0372c18 100644 --- a/lib/fog/vcloud/mock_data_classes.rb +++ b/lib/fog/vcloud/mock_data_classes.rb @@ -714,6 +714,10 @@ module Fog def monitor nil end + + def backup_service + self[:backup_service] + end end class MockPublicIpInternetServiceNodes < Base diff --git a/lib/fog/vcloud/terremark/ecloud/models/internet_service.rb b/lib/fog/vcloud/terremark/ecloud/models/internet_service.rb index 68f7ebefc..8901520b7 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/internet_service.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/internet_service.rb @@ -18,6 +18,7 @@ module Fog attribute :timeout, :aliases => :Timeout attribute :redirect_url, :aliases => :RedirectURL attribute :monitor, :aliases => :Monitor + attribute :backup_service_data, :aliases => :BackupService def delete requires :href @@ -58,6 +59,12 @@ module Fog @nodes ||= Fog::Vcloud::Terremark::Ecloud::Nodes.new( :connection => connection, :href => href + "/nodeServices" ) end + def backup_service_href + if backup_service_data + backup_service_data[:Href] + end + end + private def _compose_service_data diff --git a/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb b/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb index 02aa617b0..cf895e65b 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb @@ -61,7 +61,13 @@ module Fog xml.RedirectURL service.redirect_url xml.Monitor xml.IsBackupService MockDataClasses::MockBackupInternetService === service - xml.BackupService "i:nil" => true + if MockDataClasses::MockPublicIpInternetService === service && service.backup_service + xml.BackupService do + xml.Href service.backup_service.href + end + else + xml.BackupService "i:nil" => true + end xml.BackupOf } end diff --git a/spec/vcloud/terremark/ecloud/models/internet_service_spec.rb b/spec/vcloud/terremark/ecloud/models/internet_service_spec.rb index ec436084c..addfc865d 100644 --- a/spec/vcloud/terremark/ecloud/models/internet_service_spec.rb +++ b/spec/vcloud/terremark/ecloud/models/internet_service_spec.rb @@ -8,7 +8,7 @@ if Fog.mocking? subject { Fog::Vcloud::Terremark::Ecloud::InternetService } it { should have_identity :href } - it { should have_only_these_attributes [:href, :name, :id, :protocol, :port, :enabled, :description, :public_ip, :timeout, :redirect_url, :monitor] } + it { should have_only_these_attributes [:href, :name, :id, :protocol, :port, :enabled, :description, :public_ip, :timeout, :redirect_url, :monitor, :backup_service_data] } end context "with no uri" do @@ -31,18 +31,19 @@ if Fog.mocking? it { should be_an_instance_of Fog::Vcloud::Terremark::Ecloud::InternetService } - its(:href) { should == @mock_service.href } - its(:identity) { should == @mock_service.href } - its(:name) { should == @mock_service.name } - its(:id) { should == @mock_service.object_id.to_s } - its(:protocol) { should == @mock_service.protocol } - its(:port) { should == @mock_service.port.to_s } - its(:enabled) { should == @mock_service.enabled.to_s } - its(:description) { should == @mock_service.description } - its(:public_ip) { should == public_ip } - its(:timeout) { should == @mock_service.timeout.to_s } - its(:redirect_url) { should == @mock_service.redirect_url } - its(:monitor) { should == nil } + its(:href) { should == @mock_service.href } + its(:identity) { should == @mock_service.href } + its(:name) { should == @mock_service.name } + its(:id) { should == @mock_service.object_id.to_s } + its(:protocol) { should == @mock_service.protocol } + its(:port) { should == @mock_service.port.to_s } + its(:enabled) { should == @mock_service.enabled.to_s } + its(:description) { should == @mock_service.description } + its(:public_ip) { should == public_ip } + its(:timeout) { should == @mock_service.timeout.to_s } + its(:redirect_url) { should == @mock_service.redirect_url } + its(:monitor) { should == nil } + its(:backup_service_href) { should be_nil } specify { composed_public_ip_data[:href].should == public_ip[:Href].to_s } specify { composed_public_ip_data[:name].should == public_ip[:Name] } @@ -56,6 +57,12 @@ if Fog.mocking? specify { composed_service_data[:enabled].should == subject.enabled.to_s } specify { composed_service_data[:description].should == subject.description } specify { composed_service_data[:timeout].should == subject.timeout.to_s } + + context "with a backup internet service" do + before { @mock_service[:backup_service] = @mock_backup_service } + + its(:backup_service_href) { should == @mock_backup_service.href } + end end end else diff --git a/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb b/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb index 360f16e3d..34c8e8b22 100644 --- a/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb +++ b/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb @@ -1,7 +1,7 @@ require File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper') if Fog.mocking? - shared_examples_for "the expected internet service item" do + shared_examples_for "a basic internet service" do specify { service.should be_an_instance_of Hash } specify { service.should have(14).attributes } specify { service[:Name].should == mock_service.name } @@ -22,11 +22,20 @@ if Fog.mocking? specify { service[:RedirectURL].should == (mock_service.redirect_url || "") } specify { service[:Monitor].should == "" } specify { service[:IsBackupService].should == "false" } - specify { service[:BackupService].should be_nil } specify { service[:BackupOf].should == "" } end - shared_examples_for "the expected backup internet service item" do + shared_examples_for "an internet service without a backup internet service set" do + specify { service[:BackupService].should be_nil } + end + + shared_examples_for "an internet service with a backup internet service set" do + specify { service[:BackupService].should be_an_instance_of Hash } + specify { service[:BackupService].should include :Href } + specify { service[:BackupService][:Href].should == @mock_backup_service.href } + end + + shared_examples_for "a backup internet service" do specify { service.should be_an_instance_of Hash } specify { service.should have(14).attributes } specify { service[:Name].should == mock_service.name } @@ -54,7 +63,11 @@ if Fog.mocking? describe "#get_internet_services" do context "with a valid VDC internet_services_uri" do - before { @services = @vcloud.get_internet_services(@mock_vdc_service_collection.href) } + before do + @mock_vdc.internet_service_collection.items[3][:backup_service] = @mock_backup_service + @services = @vcloud.get_internet_services(@mock_vdc_service_collection.href) + end + subject { @services } it_should_behave_like "all responses" @@ -70,19 +83,27 @@ if Fog.mocking? it { should have(5).items } - [0,1,2,3].each do |idx| + [0,1,2].each do |idx| let(:service) { subject[idx] } let(:mock_service) { @mock_vdc.internet_service_collection.items[idx] } let(:mock_ip) { mock_service._parent._parent } - it_should_behave_like "the expected internet service item" + it_should_behave_like "an internet service without a backup internet service set" + end + + context "for a service with a backup internet service" do + let(:service) { subject[3] } + let(:mock_service) { @mock_vdc.internet_service_collection.items[3] } + let(:mock_ip) { mock_service._parent._parent } + + it_should_behave_like "an internet service with a backup internet service set" end context "for a backup internet service" do let(:service) { subject[4] } let(:mock_service) { @mock_vdc.internet_service_collection.backup_internet_services.first } - it_should_behave_like "the expected backup internet service item" + it_should_behave_like "a backup internet service" end end end @@ -112,7 +133,7 @@ if Fog.mocking? let(:mock_service) { @mock_service_collection.items[idx] } let(:mock_ip) { @mock_public_ip } - it_should_behave_like "the expected internet service item" + it_should_behave_like "an internet service without a backup internet service set" end end end From b8ce6df524c1828072048b08eff3eed91c21144b Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Mon, 22 Nov 2010 11:24:21 -0400 Subject: [PATCH 14/22] set backup internet service --- .../requests/configure_internet_service.rb | 11 +++- .../ecloud/requests/get_internet_services.rb | 62 ++++++++++--------- .../configure_internet_service_spec.rb | 3 + 3 files changed, 45 insertions(+), 31 deletions(-) diff --git a/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb b/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb index 45e558b9e..ca19cacc5 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb @@ -70,17 +70,24 @@ module Fog # def configure_internet_service(internet_service_uri, service_data, ip_address_data) + service_data = service_data.dup + validate_internet_service_data(service_data, true) validate_public_ip_address_data(ip_address_data) internet_service_uri = ensure_unparsed(internet_service_uri) + backup_service_uri = service_data.delete(:backup_service_uri) + backup_service = backup_service_uri && mock_data.backup_internet_service_from_href(backup_service_uri) + xml = nil - if public_ip_internet_service = mock_data.public_ip_internet_service_from_href(internet_service_uri) + if (public_ip_internet_service = mock_data.public_ip_internet_service_from_href(internet_service_uri)) && + (backup_service_uri.nil? || backup_service) public_ip_internet_service.update(service_data.reject {|k, v| [:id, :href].include?(k) }) - xml = generate_internet_service_response(public_ip_internet_service) + public_ip_internet_service[:backup_service] = backup_service + xml = generate_internet_service(Builder::XmlMarkup.new, public_ip_internet_service) end if xml diff --git a/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb b/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb index cf895e65b..325ea0e40 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb @@ -40,37 +40,41 @@ module Fog builder.InternetServices(ecloud_xmlns) {|xml| services.each do |service| - xml.InternetService { - xml.Id service.object_id - xml.Href service.href - xml.Name service.name - if MockDataClasses::MockBackupInternetService === service - xml.PublicIpAddress "i:nil" => true - else - xml.PublicIpAddress { - xml.Id service._parent._parent.object_id - xml.Href service._parent._parent.href - xml.Name service._parent._parent.name - } - end - xml.Port service.port - xml.Protocol service.protocol - xml.Enabled service.enabled - xml.Timeout service.timeout - xml.Description service.description - xml.RedirectURL service.redirect_url - xml.Monitor - xml.IsBackupService MockDataClasses::MockBackupInternetService === service - if MockDataClasses::MockPublicIpInternetService === service && service.backup_service - xml.BackupService do - xml.Href service.backup_service.href - end - else - xml.BackupService "i:nil" => true - end - xml.BackupOf + generate_internet_service(xml, service) + end + } + end + + def generate_internet_service(xml, service) + xml.InternetService { + xml.Id service.object_id + xml.Href service.href + xml.Name service.name + if MockDataClasses::MockBackupInternetService === service + xml.PublicIpAddress "i:nil" => true + else + xml.PublicIpAddress { + xml.Id service._parent._parent.object_id + xml.Href service._parent._parent.href + xml.Name service._parent._parent.name } end + xml.Port service.port + xml.Protocol service.protocol + xml.Enabled service.enabled + xml.Timeout service.timeout + xml.Description service.description + xml.RedirectURL service.redirect_url + xml.Monitor + xml.IsBackupService MockDataClasses::MockBackupInternetService === service + if MockDataClasses::MockPublicIpInternetService === service && service.backup_service + xml.BackupService do + xml.Href service.backup_service.href + end + else + xml.BackupService "i:nil" => true + end + xml.BackupOf } end end diff --git a/spec/vcloud/terremark/ecloud/requests/configure_internet_service_spec.rb b/spec/vcloud/terremark/ecloud/requests/configure_internet_service_spec.rb index 209aaaf3f..8fd419656 100644 --- a/spec/vcloud/terremark/ecloud/requests/configure_internet_service_spec.rb +++ b/spec/vcloud/terremark/ecloud/requests/configure_internet_service_spec.rb @@ -26,6 +26,7 @@ if Fog.mocking? @service_data[:description] = "TEST BOOM" @service_data[:redirect_url] = "http://google.com" @service_data[:port] = "80" + @service_data[:backup_service_uri] = @mock_backup_service.href end it "should change data" do @@ -36,12 +37,14 @@ if Fog.mocking? result.body[:Description].should == @service_data[:description] result.body[:RedirectURL].should == @service_data[:redirect_url] result.body[:Port].should == @service_data[:port] + result.body[:BackupService][:Href].should == @service_data[:backup_service_uri] new_result = @vcloud.get_internet_services(@mock_public_ip.internet_service_collection.href).body[:InternetService].first new_result[:Description].should == @service_data[:description] new_result[:RedirectURL].should == @service_data[:redirect_url] new_result[:Port].should == @service_data[:port] + new_result[:BackupService][:Href].should == @service_data[:backup_service_uri] end end end From 307c6708f547cc405557d6979de3d97c37f675a2 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Mon, 22 Nov 2010 11:54:03 -0400 Subject: [PATCH 15/22] set backup service --- .../ecloud/models/internet_service.rb | 12 ++++- .../ecloud/requests/add_internet_service.rb | 2 +- .../requests/configure_internet_service.rb | 54 ++++++++++--------- .../ecloud/requests/get_internet_services.rb | 2 +- .../ecloud/models/internet_service_spec.rb | 40 +++++++++----- .../requests/get_internet_services_spec.rb | 2 +- 6 files changed, 69 insertions(+), 43 deletions(-) diff --git a/lib/fog/vcloud/terremark/ecloud/models/internet_service.rb b/lib/fog/vcloud/terremark/ecloud/models/internet_service.rb index 8901520b7..c30a3144e 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/internet_service.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/internet_service.rb @@ -59,18 +59,26 @@ module Fog @nodes ||= Fog::Vcloud::Terremark::Ecloud::Nodes.new( :connection => connection, :href => href + "/nodeServices" ) end - def backup_service_href + def backup_service_uri if backup_service_data backup_service_data[:Href] end end + def backup_service_uri=(new_value) + self.backup_service_data = { + :Href => new_value + } + end + private def _compose_service_data #For some reason inject didn't work service_data = {} - self.class.attributes.select{ |attribute| !send(attribute).nil? }.each { |attribute| service_data[attribute] = send(attribute) } + self.class.attributes.select{ |attribute| attribute != :backup_service_data }.each { |attribute| service_data[attribute] = send(attribute) } + service_data[:backup_service_uri] = backup_service_uri + service_data.reject! {|k, v| v.nil? } service_data end diff --git a/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb b/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb index 26c72c913..42887ee7b 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb @@ -125,7 +125,7 @@ module Fog if public_ip_internet_service_collection = mock_data.public_ip_internet_service_collection_from_href(internet_services_uri) new_public_ip_internet_service = MockPublicIpInternetService.new(service_data, public_ip_internet_service_collection) public_ip_internet_service_collection.items << new_public_ip_internet_service - xml = generate_internet_service_response(new_public_ip_internet_service) + xml = generate_internet_service(Builder::XmlMarkup.new, new_public_ip_internet_service) mock_it 200, xml, {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'} else diff --git a/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb b/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb index ca19cacc5..016a33f11 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb @@ -5,29 +5,6 @@ module Fog module Shared private - def generate_internet_service_response(public_ip_internet_service) - builder = Builder::XmlMarkup.new - builder.InternetService(ecloud_xmlns) { - builder.Id(public_ip_internet_service.object_id) - builder.Href(public_ip_internet_service.href) - builder.Name(public_ip_internet_service.name) - builder.Protocol(public_ip_internet_service.protocol) - builder.Port(public_ip_internet_service.port) - builder.Enabled(public_ip_internet_service.enabled) - builder.Description(public_ip_internet_service.description) - builder.Timeout(public_ip_internet_service.timeout) - builder.RedirectURL(public_ip_internet_service.redirect_url) - builder.PublicIpAddress { - builder.Id(public_ip_internet_service._parent._parent.object_id) - builder.Href(public_ip_internet_service._parent._parent.href) - builder.Name(public_ip_internet_service._parent._parent.name) - } - if monitor = public_ip_internet_service.monitor - generate_monitor_section(builder, public_ip_internet_service.monitor) - end - } - end - def validate_public_ip_address_data(ip_address_data) valid_opts = [:name, :href, :id] unless valid_opts.all? { |opt| ip_address_data.keys.include?(opt) } @@ -50,7 +27,7 @@ module Fog end request( - :body => generate_internet_service_response(service_data, ip_address_data), + :body => generate_configure_internet_service_request(service_data, ip_address_data), :expects => 200, :headers => {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'}, :method => 'PUT', @@ -59,6 +36,35 @@ module Fog ) end + private + + def generate_configure_internet_service_request(service_data, ip_address_data) + builder = Builder::XmlMarkup.new + builder.InternetService(ecloud_xmlns) { + builder.Id(service_data[:id]) + builder.Href(service_data[:href]) + builder.Name(service_data[:name]) + builder.Protocol(service_data[:protocol]) + builder.Port(service_data[:port]) + builder.Enabled(service_data[:enabled]) + builder.Description(service_data[:description]) + builder.Timeout(service_data[:timeout]) + builder.RedirectURL(service_data[:redirect_url]) + builder.PublicIpAddress { + builder.Id(ip_address_data[:id]) + builder.Href(ip_address_data[:href]) + builder.Name(ip_address_data[:name]) + } + if monitor = public_ip_internet_service.monitor + generate_monitor_section(builder, monitor) + end + if service_data[:backup_service_uri] + builder.BackupService do + builder.Href(service_data[:backup_service_uri]) + end + end + } + end end class Mock diff --git a/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb b/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb index 325ea0e40..2b5b1ba6f 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb @@ -65,7 +65,7 @@ module Fog xml.Timeout service.timeout xml.Description service.description xml.RedirectURL service.redirect_url - xml.Monitor + xml.Monitor "i:nil" => true xml.IsBackupService MockDataClasses::MockBackupInternetService === service if MockDataClasses::MockPublicIpInternetService === service && service.backup_service xml.BackupService do diff --git a/spec/vcloud/terremark/ecloud/models/internet_service_spec.rb b/spec/vcloud/terremark/ecloud/models/internet_service_spec.rb index addfc865d..13bf16520 100644 --- a/spec/vcloud/terremark/ecloud/models/internet_service_spec.rb +++ b/spec/vcloud/terremark/ecloud/models/internet_service_spec.rb @@ -31,19 +31,19 @@ if Fog.mocking? it { should be_an_instance_of Fog::Vcloud::Terremark::Ecloud::InternetService } - its(:href) { should == @mock_service.href } - its(:identity) { should == @mock_service.href } - its(:name) { should == @mock_service.name } - its(:id) { should == @mock_service.object_id.to_s } - its(:protocol) { should == @mock_service.protocol } - its(:port) { should == @mock_service.port.to_s } - its(:enabled) { should == @mock_service.enabled.to_s } - its(:description) { should == @mock_service.description } - its(:public_ip) { should == public_ip } - its(:timeout) { should == @mock_service.timeout.to_s } - its(:redirect_url) { should == @mock_service.redirect_url } - its(:monitor) { should == nil } - its(:backup_service_href) { should be_nil } + its(:href) { should == @mock_service.href } + its(:identity) { should == @mock_service.href } + its(:name) { should == @mock_service.name } + its(:id) { should == @mock_service.object_id.to_s } + its(:protocol) { should == @mock_service.protocol } + its(:port) { should == @mock_service.port.to_s } + its(:enabled) { should == @mock_service.enabled.to_s } + its(:description) { should == @mock_service.description } + its(:public_ip) { should == public_ip } + its(:timeout) { should == @mock_service.timeout.to_s } + its(:redirect_url) { should == @mock_service.redirect_url } + its(:monitor) { should == nil } + its(:backup_service_uri) { should be_nil } specify { composed_public_ip_data[:href].should == public_ip[:Href].to_s } specify { composed_public_ip_data[:name].should == public_ip[:Name] } @@ -61,7 +61,19 @@ if Fog.mocking? context "with a backup internet service" do before { @mock_service[:backup_service] = @mock_backup_service } - its(:backup_service_href) { should == @mock_backup_service.href } + its(:backup_service_uri) { should == @mock_backup_service.href } + end + + describe "#backup_service_uri=" do + specify do + expect { subject.backup_service_uri = @mock_backup_service.href }. + to change { subject.backup_service_uri }.from(nil).to(@mock_backup_service.href) + end + + specify do + expect { subject.backup_service_uri = @mock_backup_service.href }. + to change { subject.send(:_compose_service_data)[:backup_service_uri] }.from(nil).to(@mock_backup_service.href) + end end end end diff --git a/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb b/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb index 34c8e8b22..cc8a8a026 100644 --- a/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb +++ b/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb @@ -50,7 +50,7 @@ if Fog.mocking? specify { service[:Timeout].should == mock_service.timeout.to_s } specify { service[:Description].should == mock_service.description } specify { service[:RedirectURL].should == (mock_service.redirect_url || "") } - specify { service[:Monitor].should == "" } + specify { service[:Monitor].should be_nil } specify { service[:IsBackupService].should == "true" } specify { service[:BackupService].should be_nil } specify { service[:BackupOf].should == "" } From e5c9d7da85c7439a23a6aa2a38c3792e92c32a53 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Mon, 22 Nov 2010 11:59:50 -0400 Subject: [PATCH 16/22] fixes --- lib/fog/vcloud/terremark/ecloud.rb | 18 +++++++++++------- .../requests/configure_internet_service.rb | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/fog/vcloud/terremark/ecloud.rb b/lib/fog/vcloud/terremark/ecloud.rb index 2dea2216e..a39680250 100644 --- a/lib/fog/vcloud/terremark/ecloud.rb +++ b/lib/fog/vcloud/terremark/ecloud.rb @@ -68,7 +68,17 @@ module Fog request :power_reset request :power_shutdown + module Shared + def ecloud_xmlns + { + "xmlns" => "urn:tmrk:eCloudExtensions-2.5", + "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance" + } + end + end + class Mock < Fog::Vcloud::Mock + include Shared def initialize(options={}) end @@ -157,19 +167,13 @@ module Fog end end - def ecloud_xmlns - { - "xmlns" => "urn:tmrk:eCloudExtensions-2.5", - "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance" - } - end - def mock_data Fog::Vcloud::Terremark::Ecloud::Mock.data end end class Real < Fog::Vcloud::Real + include Shared def supporting_versions ["v0.8b-ext2.5", "0.8b-ext2.5"] diff --git a/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb b/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb index 016a33f11..8df506424 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb @@ -55,7 +55,7 @@ module Fog builder.Href(ip_address_data[:href]) builder.Name(ip_address_data[:name]) } - if monitor = public_ip_internet_service.monitor + if monitor = service_data[:monitor] generate_monitor_section(builder, monitor) end if service_data[:backup_service_uri] From e9f28f067e3d30b14e857a86d4770d3e58e9859a Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Tue, 23 Nov 2010 21:16:33 -0400 Subject: [PATCH 17/22] include these --- fog.gemspec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fog.gemspec b/fog.gemspec index 303be8bcf..5f2cc9bd9 100644 --- a/fog.gemspec +++ b/fog.gemspec @@ -602,6 +602,8 @@ Gem::Specification.new do |s| lib/fog/vcloud/requests/get_versions.rb lib/fog/vcloud/requests/login.rb lib/fog/vcloud/terremark/ecloud.rb + lib/fog/vcloud/terremark/ecloud/models/backup_internet_service.rb + lib/fog/vcloud/terremark/ecloud/models/backup_internet_services.rb lib/fog/vcloud/terremark/ecloud/models/catalog.rb lib/fog/vcloud/terremark/ecloud/models/catalog_item.rb lib/fog/vcloud/terremark/ecloud/models/firewall_acl.rb From fbb122e56c74ef223e0740e733beb24c15ee2ef8 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Tue, 23 Nov 2010 21:59:49 -0400 Subject: [PATCH 18/22] change to new attribute handling --- .../ecloud/models/backup_internet_service.rb | 2 +- .../ecloud/models/internet_service.rb | 24 +++++++++---------- lib/fog/vcloud/terremark/ecloud/models/ip.rb | 2 +- .../vcloud/terremark/ecloud/models/server.rb | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/fog/vcloud/terremark/ecloud/models/backup_internet_service.rb b/lib/fog/vcloud/terremark/ecloud/models/backup_internet_service.rb index 126b30dbb..dd91a33fa 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/backup_internet_service.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/backup_internet_service.rb @@ -25,7 +25,7 @@ module Fog def monitor=(new_monitor = {}) if new_monitor.nil? || new_monitor.empty? - @monitor = nil + attributes[:monitor] = nil end end diff --git a/lib/fog/vcloud/terremark/ecloud/models/internet_service.rb b/lib/fog/vcloud/terremark/ecloud/models/internet_service.rb index c30a3144e..27dde75af 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/internet_service.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/internet_service.rb @@ -37,19 +37,19 @@ module Fog def monitor=(new_monitor = {}) if new_monitor.nil? || new_monitor.empty? - @monitor = nil + attributes[:monitor] = nil elsif new_monitor.is_a?(Hash) - @monitor = {} - @monitor[:type] = new_monitor[:MonitorType] || new_monitor[:type] - @monitor[:url_send_string] = new_monitor[:UrlSendString] || new_monitor[:url_send_string] - @monitor[:http_headers] = new_monitor[:HttpHeader] || new_monitor[:http_headers] - @monitor[:http_headers] = @monitor[:http_headers].split("\n") unless @monitor[:http_headers].is_a?(Array) - @monitor[:receive_string] = new_monitor[:ReceiveString] || new_monitor[:receive_string] - @monitor[:interval] = new_monitor[:Interval] || new_monitor[:interval] - @monitor[:response_timeout] = new_monitor[:ResponseTimeOut] || new_monitor[:response_timeout] - @monitor[:downtime] = new_monitor[:DownTime] || new_monitor[:downtime] - @monitor[:retries] = new_monitor[:Retries] || new_monitor[:retries] - @monitor[:is_enabled] = new_monitor[:IsEnabled] || new_monitor[:is_enabled] + attributes[:monitor] = {} + attributes[:monitor][:type] = new_monitor[:MonitorType] || new_monitor[:type] + attributes[:monitor][:url_send_string] = new_monitor[:UrlSendString] || new_monitor[:url_send_string] + attributes[:monitor][:http_headers] = new_monitor[:HttpHeader] || new_monitor[:http_headers] + attributes[:monitor][:http_headers] = attributes[:monitor][:http_headers].split("\n") unless attributes[:monitor][:http_headers].is_a?(Array) + attributes[:monitor][:receive_string] = new_monitor[:ReceiveString] || new_monitor[:receive_string] + attributes[:monitor][:interval] = new_monitor[:Interval] || new_monitor[:interval] + attributes[:monitor][:response_timeout] = new_monitor[:ResponseTimeOut] || new_monitor[:response_timeout] + attributes[:monitor][:downtime] = new_monitor[:DownTime] || new_monitor[:downtime] + attributes[:monitor][:retries] = new_monitor[:Retries] || new_monitor[:retries] + attributes[:monitor][:is_enabled] = new_monitor[:IsEnabled] || new_monitor[:is_enabled] else raise RuntimeError.new("monitor needs to either be nil or a Hash") end diff --git a/lib/fog/vcloud/terremark/ecloud/models/ip.rb b/lib/fog/vcloud/terremark/ecloud/models/ip.rb index 568074c91..20d0a15a7 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/ip.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/ip.rb @@ -15,7 +15,7 @@ module Fog attribute :id, :aliases => :Id, :type => :integer def rnat=(new_rnat) - @rnat = new_rnat + attribute[:rnat] = new_rnat @changed = true end diff --git a/lib/fog/vcloud/terremark/ecloud/models/server.rb b/lib/fog/vcloud/terremark/ecloud/models/server.rb index f8a1972d7..b1cd57870 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/server.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/server.rb @@ -75,7 +75,7 @@ module Fog end def name=(new_name) - @name = new_name + attributes[:name] = new_name @changed = true end From 360fa1278fc503517ac40213b1a0953489cd4710 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Mon, 29 Nov 2010 13:08:38 -0400 Subject: [PATCH 19/22] test and fix server question methods --- .../vcloud/terremark/ecloud/models/server.rb | 6 +++--- .../terremark/ecloud/models/server_spec.rb | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/fog/vcloud/terremark/ecloud/models/server.rb b/lib/fog/vcloud/terremark/ecloud/models/server.rb index b1cd57870..5eae70b37 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/server.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/server.rb @@ -33,17 +33,17 @@ module Fog def ready? load_unless_loaded! - @status == '2' + status == '2' end def on? load_unless_loaded! - @status == '4' + status == '4' end def off? load_unless_loaded! - @status == '2' + status == '2' end def power_on diff --git a/spec/vcloud/terremark/ecloud/models/server_spec.rb b/spec/vcloud/terremark/ecloud/models/server_spec.rb index e8ea884c9..e5c5c6341 100644 --- a/spec/vcloud/terremark/ecloud/models/server_spec.rb +++ b/spec/vcloud/terremark/ecloud/models/server_spec.rb @@ -26,6 +26,26 @@ if Fog.mocking? its(:cpus) { should == { :count => @mock_vm.cpus, :units => nil } } its(:memory) { should == { :amount => @mock_vm.memory, :units => nil } } its(:disks) { should == @mock_vm.to_configure_vapp_hash[:disks] } + + describe "question methods" do + describe "#ready?" do + before { subject.power_off } + + it { should be_ready } + end + + describe "#on?" do + before { subject.power_on } + + it { should be_on } + end + + describe "#off?" do + before { subject.power_off } + + it { should be_off } + end + end end context "as a new server without all info" do From f3bcca442bf7f87b86e17ea307bd75a51e274fc7 Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Mon, 29 Nov 2010 13:24:44 -0400 Subject: [PATCH 20/22] fix --- lib/fog/vcloud/terremark/ecloud/models/ip.rb | 2 +- lib/fog/vcloud/terremark/ecloud/models/network.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fog/vcloud/terremark/ecloud/models/ip.rb b/lib/fog/vcloud/terremark/ecloud/models/ip.rb index 20d0a15a7..395e8dea0 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/ip.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/ip.rb @@ -15,7 +15,7 @@ module Fog attribute :id, :aliases => :Id, :type => :integer def rnat=(new_rnat) - attribute[:rnat] = new_rnat + attributes[:rnat] = new_rnat @changed = true end diff --git a/lib/fog/vcloud/terremark/ecloud/models/network.rb b/lib/fog/vcloud/terremark/ecloud/models/network.rb index f2e977f3d..ee9be57f2 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/network.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/network.rb @@ -30,7 +30,7 @@ module Fog end def rnat=(new_rnat) - @rnat = new_rnat + attributes[:rnat] = new_rnat @changed = true end From 5d189443a692c1fc6ff7db65ae134a32b91a68bb Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Mon, 29 Nov 2010 13:42:38 -0400 Subject: [PATCH 21/22] fix --- lib/fog/vcloud/terremark/ecloud/models/internet_services.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb b/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb index ae3dfb7c9..b302b4ab5 100644 --- a/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb +++ b/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb @@ -13,8 +13,8 @@ module Fog def all check_href! :message => "the Internet Services for the Vdc you want to enumerate" - if data = [connection.get_internet_services(href).body[:InternetService]].flatten.find_all {|i| i[:IsBackupService] == "false" } - load(data) + if internet_service_data = connection.get_internet_services(href).body[:InternetService] + load(Array[internet_service_data].flatten.find_all {|i| i[:IsBackupService] == "false" }) end end From 2de864207d3ca568c078d3bbeb3d5863f7411a8a Mon Sep 17 00:00:00 2001 From: Dan Peterson Date: Tue, 30 Nov 2010 14:38:02 -0400 Subject: [PATCH 22/22] fix namespaces? --- .../ecloud/requests/add_backup_internet_service.rb | 2 +- .../terremark/ecloud/requests/add_internet_service.rb | 2 +- .../terremark/ecloud/requests/configure_internet_service.rb | 2 +- .../terremark/ecloud/requests/get_internet_services.rb | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/fog/vcloud/terremark/ecloud/requests/add_backup_internet_service.rb b/lib/fog/vcloud/terremark/ecloud/requests/add_backup_internet_service.rb index 324d7f55c..adc66c3ed 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/add_backup_internet_service.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/add_backup_internet_service.rb @@ -80,7 +80,7 @@ module Fog def generate_backup_internet_service_added_response(new_backup_internet_service) builder = Builder::XmlMarkup.new - builder.InternetService { + builder.InternetService("xmlns" => "urn:tmrk:eCloudExtensions-2.5", "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance") { builder.Id new_backup_internet_service.object_id builder.Href new_backup_internet_service.href builder.Name new_backup_internet_service.name diff --git a/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb b/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb index 42887ee7b..c9cdf2a3f 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb @@ -125,7 +125,7 @@ module Fog if public_ip_internet_service_collection = mock_data.public_ip_internet_service_collection_from_href(internet_services_uri) new_public_ip_internet_service = MockPublicIpInternetService.new(service_data, public_ip_internet_service_collection) public_ip_internet_service_collection.items << new_public_ip_internet_service - xml = generate_internet_service(Builder::XmlMarkup.new, new_public_ip_internet_service) + xml = generate_internet_service(Builder::XmlMarkup.new, new_public_ip_internet_service, true) mock_it 200, xml, {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'} else diff --git a/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb b/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb index 8df506424..b9db04508 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb @@ -93,7 +93,7 @@ module Fog (backup_service_uri.nil? || backup_service) public_ip_internet_service.update(service_data.reject {|k, v| [:id, :href].include?(k) }) public_ip_internet_service[:backup_service] = backup_service - xml = generate_internet_service(Builder::XmlMarkup.new, public_ip_internet_service) + xml = generate_internet_service(Builder::XmlMarkup.new, public_ip_internet_service, true) end if xml diff --git a/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb b/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb index 2b5b1ba6f..2394ab9f9 100644 --- a/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb +++ b/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb @@ -38,15 +38,15 @@ module Fog def generate_internet_services(services) builder = Builder::XmlMarkup.new - builder.InternetServices(ecloud_xmlns) {|xml| + builder.InternetServices("xmlns" => "urn:tmrk:eCloudExtensions-2.5", "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance") {|xml| services.each do |service| generate_internet_service(xml, service) end } end - def generate_internet_service(xml, service) - xml.InternetService { + def generate_internet_service(xml, service, by_itself = false) + xml.InternetService(by_itself ? { "xmlns" => "urn:tmrk:eCloudExtensions-2.5", "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance" } : {}) { xml.Id service.object_id xml.Href service.href xml.Name service.name