From c4b9d0f611992c2af70b426ce793f64cc2971f91 Mon Sep 17 00:00:00 2001 From: Rodrigo Estebanez Date: Tue, 9 Jul 2013 15:09:08 +0200 Subject: [PATCH] refactor vdc to use vcloud classes --- lib/fog/vcloudng/models/compute/vdc.rb | 2 +- lib/fog/vcloudng/models/compute/vdcs.rb | 41 ++++++++----------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/lib/fog/vcloudng/models/compute/vdc.rb b/lib/fog/vcloudng/models/compute/vdc.rb index 532579adb..230809ccd 100644 --- a/lib/fog/vcloudng/models/compute/vdc.rb +++ b/lib/fog/vcloudng/models/compute/vdc.rb @@ -4,7 +4,7 @@ module Fog module Compute class Vcloudng - class Vdc < Fog::Model + class Vdc < Model identity :id diff --git a/lib/fog/vcloudng/models/compute/vdcs.rb b/lib/fog/vcloudng/models/compute/vdcs.rb index bdace3f68..5d32dea44 100644 --- a/lib/fog/vcloudng/models/compute/vdcs.rb +++ b/lib/fog/vcloudng/models/compute/vdcs.rb @@ -5,40 +5,25 @@ module Fog module Compute class Vcloudng - class Vdcs < Fog::Collection + class Vdcs < Collection model Fog::Compute::Vcloudng::Vdc attribute :organization - - def index(organization_id = organization.id) - vdc_links(organization_id).map{ |vdc| new(vdc)} - end - - def all(organization_id = organization.id) - vdc_ids = vdc_links(organization_id).map {|vdc| vdc[:id] } - vdc_ids.map{ |vdc_id| get(vdc_id)} - end - def get(vdc_id) - data = service.get_vdc(vdc_id).body - data[:id] = data[:href].split('/').last - %w(:VdcItems :Link :ResourceEntities).each {|key_to_delete| data.delete(key_to_delete) } - new(data) - end - - def get_by_name(vdc_name, organization_id = organization.id) - vdc = vdc_links(organization_id).detect{|vdc_link| vdc_link[:name] == vdc_name } - return nil unless vdc - get(vdc[:id]) - end - private - def vdc_links(organization_id) - data = service.get_organization(organization_id).body - vdcs = data[:Link].select { |link| link[:type] == "application/vnd.vmware.vcloud.vdc+xml" } - vdcs.each{|vdc| vdc[:id] = vdc[:href].split('/').last } - vdcs + def get_by_id(item_id) + item = service.get_vdc(item_id).body + %w(:VdcItems :Link :ResourceEntities).each {|key_to_delete| item.delete(key_to_delete) } + service.add_id_from_href!(item) + item + end + + def item_list + data = service.get_organization(organization.id).body + items = data[:Link].select { |link| link[:type] == "application/vnd.vmware.vcloud.vdc+xml" } + items.each{|item| service.add_id_from_href!(item) } + items end end