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:
parent
7f1c6d07e3
commit
658fa43d3d
3 changed files with 31 additions and 28 deletions
|
@ -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 = {})
|
||||||
|
|
|
@ -12,8 +12,8 @@ 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
|
||||||
|
|
|
@ -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 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 the @version that super selected isn't in our supported list, then select one that is.
|
||||||
def check_versions
|
def check_versions
|
||||||
super
|
super
|
||||||
unless (supported_version_ids & Versions::SUPPORTED).length > 0
|
unless (supported_version_numbers & Fog::Vcloud::Terremark::Ecloud.supported_versions).length > 0
|
||||||
raise UnsupportedVersion.new("\nService @ #{@versions_uri} supports: #{supported_version_ids.join(', ')}\n" +
|
raise UnsupportedVersion.new("\nService @ #{@versions_uri} supports: #{supported_version_numbers.join(', ')}\n" +
|
||||||
"Fog::Vcloud::Terremark::Ecloud supports: #{Versions::SUPPORTED.join(', ')}")
|
"Fog::Vcloud::Terremark::Ecloud supports: #{Fog::Vcloud::Terremark::Ecloud.supported_versions.join(', ')}")
|
||||||
|
end
|
||||||
|
unless supported_version_numbers.include?(@version)
|
||||||
|
@version = (supported_version_numbers & Fog::Vcloud::Terremark::Ecloud.supported_versions).sort.first
|
||||||
end
|
end
|
||||||
unless supported_version_ids.include?(@version)
|
|
||||||
@version = (supported_version_ids & Versions::SUPPORTED).sort.first
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue