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