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

start of backup internet service support

This commit is contained in:
Dan Peterson 2010-11-19 13:41:49 -04:00
parent f910a65341
commit 73d07f4487
5 changed files with 88 additions and 11 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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
}

View file

@ -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