Skip to content

Commit

Permalink
Use the eCloud version logic in vCloud proper
Browse files Browse the repository at this point in the history
  • Loading branch information
freeformz authored and Wesley Beary committed Jul 23, 2010
1 parent dea8de4 commit 21550d6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 53 deletions.
32 changes: 20 additions & 12 deletions lib/fog/vcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
require 'fog/vcloud/collection'
require 'fog/vcloud/generators'
require 'fog/vcloud/extension'
require 'fog/vcloud/terremark/vcloud'
require 'fog/vcloud/terremark/ecloud'
require 'fog/vcloud/terremark/vcloud'


module URI
class Generic
Expand Down Expand Up @@ -46,6 +47,10 @@ class Real
attr_accessor :login_uri
attr_reader :versions_uri

def supporting_versions
["v0.8"]
end

def initialize(options = {})
@connections = {}
@versions_uri = URI.parse(options[:versions_uri])
Expand Down Expand Up @@ -138,18 +143,21 @@ def get_login_uri
end
end

# Load up @all_versions and supported_versions from the provided :versions_uri
# If there are no supported versions raise an error
# And choose a default version is none is specified
# If we don't support any versions the service does, then raise an error.
# If the @version that super selected isn't in our supported list, then select one that is.
def check_versions
supported_versions = get_versions(@versions_uri).body[:VersionInfo]

if supported_versions.empty?
raise UnsupportedVersion.new("No supported versions found @ #{@version_uri}")
end

unless @version
@version = supported_version_numbers.first
if @version
unless supported_version_numbers.include?(@version.to_s)
raise UnsupportedVersion.new("#{@version} is not supported by the server.")
end
unless supporting_versions.include?(@version.to_s)
raise UnsupportedVersion.new("#{@version} is not supported by #{self.class}")
end
else
unless @version = (supported_version_numbers & supporting_versions).sort.first
raise UnsupportedVersion.new("\nService @ #{@versions_uri} supports: #{supported_version_numbers.join(', ')}\n" +
"#{self.class} supports: #{supporting_versions.join(', ')}")
end
end
end

Expand Down
7 changes: 0 additions & 7 deletions lib/fog/vcloud/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ module #{other}::Real
end
module #{other}::Mock
end
def self.supported_versions
@versions
end
def self.extended(klass)
unless @required
models.each do |model|
Expand All @@ -35,10 +32,6 @@ def self.extended(klass)
EOS
end

def versions(*args)
@versions = args
end

end
end
end
23 changes: 3 additions & 20 deletions lib/fog/vcloud/terremark/ecloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ module Ecloud
request :power_reset
request :power_shutdown

versions "v0.8b-ext2.3", "0.8b-ext2.3"

module Mock
def self.base_url
"https://fakey.com/api/v0.8b-ext2.3"
Expand Down Expand Up @@ -190,26 +188,11 @@ def mock_data
end

module Real
private

# If we don't support any versions the service does, then raise an error.
# If the @version that super selected isn't in our supported list, then select one that is.
def check_versions
if @version
unless supported_version_numbers.include?(@version.to_s)
raise UnsupportedVersion.new("#{@version} is not supported by the server.")
end
unless Fog::Vcloud::Terremark::Ecloud.supported_versions.include?(@version.to_s)
raise UnsupportedVersion.new("#{@version} is not supported by Fog::Vcloud::Terremark::Ecloud")
end
else
unless @version = (supported_version_numbers & Fog::Vcloud::Terremark::Ecloud.supported_versions).sort.first
raise UnsupportedVersion.new("\nService @ #{@versions_uri} supports: #{supported_version_numbers.join(', ')}\n" +
"Fog::Vcloud::Terremark::Ecloud supports: #{Fog::Vcloud::Terremark::Ecloud.supported_versions.join(', ')}")
end
end
def supporting_versions
["v0.8b-ext2.3", "0.8b-ext2.3"]
end
end

end
end
end
Expand Down
17 changes: 3 additions & 14 deletions lib/fog/vcloud/terremark/vcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,12 @@ module Terremark
module Vcloud
extend Fog::Vcloud::Extension

versions "v0.8"

request_path 'fog/vcloud/terremark/vcloud/requests'
request :get_vdc

private

# If we don't support any versions the service does, then raise an error.
# If the @version that super selected isn't in our supported list, then select one that is.
def check_versions
super
unless (supported_version_ids & Versions::SUPPORTED).length > 0
raise UnsupportedVersion.new("\nService @ #{@versions_uri} supports: #{supported_version_ids.join(', ')}\n" +
"Fog::Vcloud::Terremark::Vcloud supports: #{Versions::SUPPORTED.join(', ')}")
end
unless supported_version_ids.include?(@version)
@version = (supported_version_ids & Versions::SUPPORTED).sort.first
module Real
def supporting_versions
["0.8", "0.8a-ext1.6"]
end
end
end
Expand Down

0 comments on commit 21550d6

Please sign in to comment.