mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
models
This commit is contained in:
parent
73d07f4487
commit
28487dfeb7
7 changed files with 183 additions and 2 deletions
|
@ -13,6 +13,8 @@ module Fog
|
||||||
collection :firewall_acls
|
collection :firewall_acls
|
||||||
model :internet_service
|
model :internet_service
|
||||||
collection :internet_services
|
collection :internet_services
|
||||||
|
model :backup_internet_service
|
||||||
|
collection :backup_internet_services
|
||||||
model :ip
|
model :ip
|
||||||
collection :ips
|
collection :ips
|
||||||
model :network
|
model :network
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
@ -27,6 +27,10 @@ module Fog
|
||||||
@internet_services ||= collection_based_on_type("application/vnd.tmrk.ecloud.internetServicesList+xml")
|
@internet_services ||= collection_based_on_type("application/vnd.tmrk.ecloud.internetServicesList+xml")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def backup_internet_services
|
||||||
|
@backup_internet_services ||= collection_based_on_type("application/vnd.tmrk.ecloud.internetServicesList+xml", BackupInternetServices)
|
||||||
|
end
|
||||||
|
|
||||||
def networks
|
def networks
|
||||||
@networks ||= Fog::Vcloud::Terremark::Ecloud::Networks.
|
@networks ||= Fog::Vcloud::Terremark::Ecloud::Networks.
|
||||||
new( :connection => connection,
|
new( :connection => connection,
|
||||||
|
@ -55,14 +59,14 @@ module Fog
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def collection_based_on_type(type)
|
def collection_based_on_type(type, klass = nil)
|
||||||
load_unless_loaded!
|
load_unless_loaded!
|
||||||
if link = other_links.detect { |link| link[:type] == type }
|
if link = other_links.detect { |link| link[:type] == type }
|
||||||
case type
|
case type
|
||||||
when "application/vnd.tmrk.ecloud.publicIpsList+xml"
|
when "application/vnd.tmrk.ecloud.publicIpsList+xml"
|
||||||
Fog::Vcloud::Terremark::Ecloud::PublicIps
|
Fog::Vcloud::Terremark::Ecloud::PublicIps
|
||||||
when "application/vnd.tmrk.ecloud.internetServicesList+xml"
|
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"
|
when "application/vnd.vmware.vcloud.catalog+xml"
|
||||||
Fog::Vcloud::Terremark::Ecloud::Catalog
|
Fog::Vcloud::Terremark::Ecloud::Catalog
|
||||||
when "application/vnd.tmrk.ecloud.firewallAclsList+xml"
|
when "application/vnd.tmrk.ecloud.firewallAclsList+xml"
|
||||||
|
|
|
@ -233,6 +233,7 @@ def setup_ecloud_mock_data
|
||||||
@mock_public_ip = @mock_public_ip_collection.items.first
|
@mock_public_ip = @mock_public_ip_collection.items.first
|
||||||
@mock_service_collection = @mock_public_ip.internet_service_collection
|
@mock_service_collection = @mock_public_ip.internet_service_collection
|
||||||
@mock_service = @mock_service_collection.items.first
|
@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_collection = @mock_service.node_collection
|
||||||
@mock_node = @mock_node_collection.items.first
|
@mock_node = @mock_node_collection.items.first
|
||||||
@mock_catalog = @mock_vdc.catalog
|
@mock_catalog = @mock_vdc.catalog
|
||||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in a new issue