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

Merge branch 'dpiddy'

This commit is contained in:
geemus 2010-12-17 15:06:52 -08:00
commit b3bb74183d
35 changed files with 811 additions and 167 deletions

View file

@ -601,6 +601,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

View file

@ -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
@ -131,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
@ -434,6 +432,10 @@ module Fog
def rnat
self[:rnat] || _parent._parent.rnat
end
def rnat_set?
!!self[:rnat]
end
end
class MockNetworkExtensions < Base
@ -456,6 +458,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
@ -495,6 +509,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
{
@ -574,10 +594,52 @@ 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
def node_collection
@node_collection ||= MockPublicIpInternetServiceNodes.new({}, self)
end
end
class MockFirewallAcls < Base
@ -652,6 +714,10 @@ module Fog
def monitor
nil
end
def backup_service
self[:backup_service]
end
end
class MockPublicIpInternetServiceNodes < Base

View file

@ -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
@ -10,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
@ -27,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
@ -62,13 +68,23 @@ 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
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
@ -79,7 +95,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|
@ -128,6 +144,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|
@ -149,19 +167,16 @@ module Fog
end
end
def ecloud_xmlns
{ :xmlns => "urn:tmrk:eCloudExtensions-2.3", :"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.3", "0.8b-ext2.3"]
["v0.8b-ext2.5", "0.8b-ext2.5"]
end
end

View file

@ -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?
attributes[:monitor] = nil
end
end
def save
if new_record?
result = connection.add_backup_internet_service( collection.href, _compose_service_data )
merge_attributes(result.body)
else
connection.configure_backup_internet_service( href, _compose_service_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

View file

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

View file

@ -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
@ -36,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
@ -58,12 +59,26 @@ module Fog
@nodes ||= Fog::Vcloud::Terremark::Ecloud::Nodes.new( :connection => connection, :href => href + "/nodeServices" )
end
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

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

View file

@ -15,7 +15,7 @@ module Fog
attribute :id, :aliases => :Id, :type => :integer
def rnat=(new_rnat)
@rnat = new_rnat
attributes[:rnat] = new_rnat
@changed = true
end

View file

@ -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!
@ -27,7 +30,7 @@ module Fog
end
def rnat=(new_rnat)
@rnat = new_rnat
attributes[:rnat] = new_rnat
@changed = true
end

View file

@ -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
@ -75,7 +75,7 @@ module Fog
end
def name=(new_name)
@name = new_name
attributes[:name] = new_name
@changed = true
end
@ -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

View file

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

View file

@ -0,0 +1,111 @@
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=729&Lang=1&SID=
# and many tears shed.
#
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("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
# 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

View file

@ -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])
@ -127,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, true)
mock_it 200, xml, {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'}
else

View file

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

View file

@ -5,30 +5,6 @@ module Fog
module Shared
private
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.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) }
@ -51,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',
@ -60,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 = service_data[: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
@ -71,17 +76,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, true)
end
if xml

View file

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

View file

@ -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)
@ -28,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])
@ -38,13 +42,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

View file

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

View file

@ -38,26 +38,43 @@ 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("xmlns" => "urn:tmrk:eCloudExtensions-2.5", "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance") {|xml|
services.each do |service|
xml.InternetService {
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
}
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
generate_internet_service(xml, service)
end
}
end
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
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 "i:nil" => true
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

View file

@ -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(:xmlns => "urn:tmrk:eCloudExtensions-2.3", :"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance") {
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

View file

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

View file

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

View file

@ -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
@ -273,13 +274,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

View file

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

View file

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

View file

@ -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_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] }
@ -56,6 +57,24 @@ 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_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
else

View file

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

View file

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

View file

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

View file

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

View file

@ -0,0 +1,55 @@
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] }.
from(@mock_network.rnat).
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

View file

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

View file

@ -1,9 +1,9 @@
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(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,39 @@ 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[:BackupOf].should == "" }
end
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 }
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 be_nil }
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
@ -30,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"
@ -41,20 +78,32 @@ 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] }
it { should have(4).items }
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.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"
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 "a backup internet service"
end
end
end
@ -74,9 +123,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] }
@ -87,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

View file

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

View file

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