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

[Vcloud] Fixup some version related stuffs

This commit is contained in:
freeformz 2010-07-10 01:57:16 +08:00 committed by Wesley Beary
parent 7f1c6d07e3
commit 658fa43d3d
3 changed files with 31 additions and 28 deletions

View file

@ -44,7 +44,7 @@ module Fog
extend Fog::Vcloud::Generators extend Fog::Vcloud::Generators
attr_accessor :login_uri attr_accessor :login_uri
attr_reader :supported_versions, :versions_uri attr_reader :versions_uri
def initialize(options = {}) def initialize(options = {})
@connections = {} @connections = {}
@ -53,7 +53,6 @@ module Fog
@version = options[:version] @version = options[:version]
@username = options[:username] @username = options[:username]
@password = options[:password] @password = options[:password]
@login_uri = get_login_uri
@persistent = options[:persistent] @persistent = options[:persistent]
end end
@ -98,6 +97,9 @@ module Fog
end end
end end
def supported_versions
@supported_versions ||= get_versions(@versions_uri).body[:VersionInfo]
end
private private
@ -118,31 +120,31 @@ module Fog
end end
def supported_version_numbers def supported_version_numbers
case @supported_versions case supported_versions
when Array when Array
@supported_versions.map { |version| version[:Version] } supported_versions.map { |version| version[:Version] }
when Hash when Hash
@supported_versions[:Version] [ supported_versions[:Version] ]
end end
end end
def get_login_uri def get_login_uri
check_versions check_versions
URI.parse case @supported_versions URI.parse case supported_versions
when Array when Array
@supported_versions.detect {|version| version[:Version] == @version }[:LoginUrl] supported_versions.detect {|version| version[:Version] == @version }[:LoginUrl]
when Hash when Hash
@supported_versions[:LoginUrl] supported_versions[:LoginUrl]
end end
end end
# Load up @all_versions and @supported_versions from the provided :versions_uri # Load up @all_versions and supported_versions from the provided :versions_uri
# If there are no supported versions raise an error # If there are no supported versions raise an error
# And choose a default version is none is specified # And choose a default version is none is specified
def check_versions def check_versions
@supported_versions = get_versions(@versions_uri).body[:VersionInfo] supported_versions = get_versions(@versions_uri).body[:VersionInfo]
if @supported_versions.empty? if supported_versions.empty?
raise UnsupportedVersion.new("No supported versions found @ #{@version_uri}") raise UnsupportedVersion.new("No supported versions found @ #{@version_uri}")
end end
@ -164,6 +166,7 @@ module Fog
# login handles the auth, but we just need the Set-Cookie # login handles the auth, but we just need the Set-Cookie
# header from that call. # header from that call.
def do_login def do_login
@login_uri ||= get_login_uri
@login_results = login @login_results = login
@cookie = @login_results.headers['Set-Cookie'] @cookie = @login_results.headers['Set-Cookie']
end end
@ -346,7 +349,6 @@ module Fog
def initialize(credentials = {}) def initialize(credentials = {})
@versions_uri = URI.parse('https://vcloud.fakey.com/api/versions') @versions_uri = URI.parse('https://vcloud.fakey.com/api/versions')
@login_uri = get_login_uri
end end
def mock_it(status, mock_data, mock_headers = {}) def mock_it(status, mock_data, mock_headers = {})

View file

@ -12,9 +12,9 @@ module Fog
end end
module #{other}::Mock module #{other}::Mock
end end
module #{other}::Versions def self.supported_versions
SUPPORTED = @versions @versions
end end
def self.extended(klass) def self.extended(klass)
unless @required unless @required
models.each do |model| models.each do |model|

View file

@ -63,7 +63,7 @@ module Fog
request :power_reset request :power_reset
request :power_shutdown request :power_shutdown
versions "v0.8b-ext2.3" versions "v0.8b-ext2.3", "0.8b-ext2.3"
module Mock module Mock
def self.base_url def self.base_url
@ -189,19 +189,20 @@ module Fog
end end
end end
module Real
private
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.
# If we don't support any versions the service does, then raise an error. def check_versions
# If the @version that super selected isn't in our supported list, then select one that is. super
def check_versions unless (supported_version_numbers & Fog::Vcloud::Terremark::Ecloud.supported_versions).length > 0
super raise UnsupportedVersion.new("\nService @ #{@versions_uri} supports: #{supported_version_numbers.join(', ')}\n" +
unless (supported_version_ids & Versions::SUPPORTED).length > 0 "Fog::Vcloud::Terremark::Ecloud supports: #{Fog::Vcloud::Terremark::Ecloud.supported_versions.join(', ')}")
raise UnsupportedVersion.new("\nService @ #{@versions_uri} supports: #{supported_version_ids.join(', ')}\n" + end
"Fog::Vcloud::Terremark::Ecloud supports: #{Versions::SUPPORTED.join(', ')}") unless supported_version_numbers.include?(@version)
end @version = (supported_version_numbers & Fog::Vcloud::Terremark::Ecloud.supported_versions).sort.first
unless supported_version_ids.include?(@version) end
@version = (supported_version_ids & Versions::SUPPORTED).sort.first
end end
end end
end end