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

organizations refactored

This commit is contained in:
Rodrigo Estebanez 2013-07-08 16:57:40 +02:00
parent da2fcd6938
commit bc8690c27d
2 changed files with 44 additions and 11 deletions

View file

@ -36,6 +36,7 @@ class VcloudngParser < Fog::Parsers::Base
end
module Fog
module Compute
class Vcloudng < Fog::Service
@ -212,6 +213,9 @@ module Fog
raise Errors::Task.new "status: #{task.status}, error: #{task.error}" unless task.success?
end
def add_id_from_href!(data={})
data[:id] = data[:href].split('/').last
end
end

View file

@ -8,19 +8,48 @@ module Fog
class Organizations < Fog::Collection
model Fog::Compute::Vcloudng::Organization
def all
data = service.get_organizations.body
org = data[:Org]
org[:id] = org[:href].split('/').last
load([org])
def all(details=false)
details ? all_with_details : index
end
def get(organization_id)
data = service.get_organization(organization_id).body
data.delete(:Link)
data[:id] = data[:href].split('/').last
new(data)
def get(org_id)
org = get_by_id(org_id)
return nil unless org
new(org)
end
def get_by_name(org_name)
org = org_links.detect{|org| org[:name] == org_name}
return nil unless org
new(org)
end
def index
load(org_links)
end
def all_with_details
orgs = org_links.map{|org| get_by_id(org[:id]) }
load(orgs)
end
# private
def get_by_id(org_id)
data = service.get_organization(org_id).body
data.delete(:Link)
service.add_id_from_href!(data)
data
end
def org_links
data = service.get_organizations.body
org = data[:Org] # there is only a single Org
org[:description]='<reload to see it>'
service.add_id_from_href!(org)
[org]
end
end
end
end