From 75af68be5a6d5e761db9df02d04f7b7db2e563d2 Mon Sep 17 00:00:00 2001 From: Rodrigo Estebanez Date: Tue, 9 Jul 2013 15:16:00 +0200 Subject: [PATCH] refactor vapp to use the vcloud classes --- lib/fog/vcloudng/models/compute/vapp.rb | 4 +-- lib/fog/vcloudng/models/compute/vapps.rb | 43 ++++++++---------------- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/lib/fog/vcloudng/models/compute/vapp.rb b/lib/fog/vcloudng/models/compute/vapp.rb index d98a51633..831f3f227 100644 --- a/lib/fog/vcloudng/models/compute/vapp.rb +++ b/lib/fog/vcloudng/models/compute/vapp.rb @@ -4,7 +4,7 @@ module Fog module Compute class Vcloudng - class Vapp < Fog::Model + class Vapp < Model identity :id @@ -25,7 +25,7 @@ module Fog def vms requires :id - service.vms(:vapp_id => id) + service.vms(:vapp => self) end end diff --git a/lib/fog/vcloudng/models/compute/vapps.rb b/lib/fog/vcloudng/models/compute/vapps.rb index 33ff3b32c..5368105f6 100644 --- a/lib/fog/vcloudng/models/compute/vapps.rb +++ b/lib/fog/vcloudng/models/compute/vapps.rb @@ -5,40 +5,25 @@ module Fog module Compute class Vcloudng - class Vapps < Fog::Collection + class Vapps < Collection model Fog::Compute::Vcloudng::Vapp attribute :vdc - def index(vdc_id = vdc.id) - vapp_links(vdc_id).map{ |vdc| new(vdc)} - end - - def all(vdc_id = vdc.id) - vapp_ids = vapp_links(vdc_id).map {|vapp| vapp[:id] } - vapp_ids.map{ |vapp_id| get(vapp_id)} + private + + def get_by_id(item_id) + item = service.get_vapp(item_id).body + %w(:Link).each {|key_to_delete| item.delete(key_to_delete) } + service.add_id_from_href!(item) + item end - - def get(vapp_id) - data = service.get_vapp(vapp_id).body - data[:id] = data[:href].split('/').last - %w(:Link).each {|key_to_delete| data.delete(key_to_delete) } - new(data) - end - - def get_by_name(vapp_name, vdc_id = vdc.id) - vapp = vapp_links(vdc_id).detect{|vapp_link| vapp_link[:name] == vapp_name } - return nil unless vapp - get(vapp[:id]) - end - -# private - - def vapp_links(vdc_id) - data = service.get_vdc(vdc_id).body - vapps = data[:ResourceEntities][:ResourceEntity].select { |link| link[:type] == "application/vnd.vmware.vcloud.vApp+xml" } - vapps.each{|vapp| vapp[:id] = vapp[:href].split('/').last } - vapps + + def item_list + data = service.get_vdc(vdc.id).body + items = data[:ResourceEntities][:ResourceEntity].select { |link| link[:type] == "application/vnd.vmware.vcloud.vApp+xml" } + items.each{|item| service.add_id_from_href!(item) } + items end end