set backup service

This commit is contained in:
Dan Peterson 2010-11-22 11:54:03 -04:00
parent b8ce6df524
commit 307c6708f5
6 changed files with 69 additions and 43 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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