mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[terremark_ecloud] make get_versions and login more generic
This commit is contained in:
parent
b5c1d10b0b
commit
54f4e8f235
3 changed files with 31 additions and 24 deletions
|
@ -12,10 +12,6 @@ module Fog
|
|||
:method => 'GET',
|
||||
:parser => Fog::Parsers::TerremarkEcloud::Compute::GetVersions.new
|
||||
});
|
||||
version_info = response.body['SupportedVersions'].detect {|version_info| version_info['Version'] == @version}
|
||||
unless login_url = version_info && version_info['LoginUrl']
|
||||
raise "TerremarkEcloud does not support version #{@version}"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
26
lib/fog/compute/requests/terremark_ecloud/login.rb
Normal file
26
lib/fog/compute/requests/terremark_ecloud/login.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
module Fog
|
||||
module TerremarkEcloud
|
||||
class Compute
|
||||
class Real
|
||||
|
||||
require 'fog/compute/parsers/terremark_ecloud/login'
|
||||
|
||||
def login
|
||||
connection = Fog::Connection.new(@login_url)
|
||||
response = connection.request({
|
||||
:expects => 200,
|
||||
:method => 'POST',
|
||||
:headers => {
|
||||
'Authorization' => ('Basic ' << Base64.encode64("#{@username}:#{@password}").chomp!),
|
||||
'Content-Type' => 'application/vnd.vmware.vcloud.orgList+xml'
|
||||
},
|
||||
:parser => Fog::Parsers::TerremarkEcloud::Compute::Login.new
|
||||
})
|
||||
@token = response.headers['Set-Cookie']
|
||||
response
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -16,7 +16,9 @@ module Fog
|
|||
request :get_organization
|
||||
request :get_task
|
||||
request :get_task_list
|
||||
request :get_versions
|
||||
request :get_vdc
|
||||
request :login
|
||||
|
||||
class Mock
|
||||
|
||||
|
@ -79,31 +81,14 @@ module Fog
|
|||
|
||||
def get_token_and_organization
|
||||
# lookup LoginUrl for specified version
|
||||
connection = Fog::Connection.new(@versions_endpoint)
|
||||
response = connection.request({
|
||||
:expects => 200,
|
||||
:method => 'GET',
|
||||
:parser => Fog::Parsers::TerremarkEcloud::Compute::GetVersions.new
|
||||
});
|
||||
response = self.get_versions
|
||||
version_info = response.body['SupportedVersions'].detect {|version_info| version_info['Version'] == @version}
|
||||
unless login_url = version_info && version_info['LoginUrl']
|
||||
unless @login_url = version_info && version_info['LoginUrl']
|
||||
# no LoginUrl matches specified version
|
||||
raise "TerremarkEcloud does not support version #{@version}"
|
||||
end
|
||||
|
||||
connection = Fog::Connection.new(login_url)
|
||||
response = connection.request({
|
||||
:expects => 200,
|
||||
:method => 'POST',
|
||||
:headers => {
|
||||
'Authorization' => ('Basic ' << Base64.encode64("#{@username}:#{@password}").chomp!),
|
||||
'Content-Type' => 'application/vnd.vmware.vcloud.orgList+xml'
|
||||
},
|
||||
:parser => Fog::Parsers::TerremarkEcloud::Compute::Login.new
|
||||
})
|
||||
|
||||
@token = response.headers['Set-Cookie']
|
||||
|
||||
response = self.login
|
||||
# if there is only one organization we will note it as a starting point
|
||||
if (response.body['OrgList'].length == 1) && (organization = response.body['OrgList'].first)
|
||||
@organization_href = organization['href']
|
||||
|
|
Loading…
Add table
Reference in a new issue