Skip to content

Commit

Permalink
[terremark_ecloud] setup login to also work like get_organizations would
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Feb 14, 2011
1 parent 54f4e8f commit a406dc6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
8 changes: 7 additions & 1 deletion lib/fog/compute/requests/terremark_ecloud/get_versions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ def get_versions
:expects => 200,
: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']
# no LoginUrl matches specified version
raise "TerremarkEcloud does not support version #{@version}"
end
response
end

end
Expand Down
3 changes: 3 additions & 0 deletions lib/fog/compute/requests/terremark_ecloud/login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class Real
require 'fog/compute/parsers/terremark_ecloud/login'

def login
unless @login_url
get_versions
end
connection = Fog::Connection.new(@login_url)
response = connection.request({
:expects => 200,
Expand Down
8 changes: 0 additions & 8 deletions lib/fog/compute/terremark_ecloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,6 @@ def request(params)
private

def get_token_and_organization
# lookup LoginUrl for specified version
response = self.get_versions
version_info = response.body['SupportedVersions'].detect {|version_info| version_info['Version'] == @version}
unless @login_url = version_info && version_info['LoginUrl']
# no LoginUrl matches specified version
raise "TerremarkEcloud does not support version #{@version}"
end

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)
Expand Down
5 changes: 5 additions & 0 deletions tests/compute/requests/terremark_ecloud/organization_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

tests('success') do

tests("#login (get_organizations)").formats({'OrgList' => [{'href' => String, 'name' => String, 'type' => String}]}) do
pending if Fog.mocking?
TerremarkEcloud[:compute].login.body
end

tests("#get_organization").formats(@organization_format) do
pending if Fog.mocking?
TerremarkEcloud[:compute].get_organization.body
Expand Down

0 comments on commit a406dc6

Please sign in to comment.