1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/vcloudng/models/compute/vapps.rb

47 lines
1.3 KiB
Ruby
Raw Normal View History

2013-06-20 13:36:34 -04:00
require 'fog/core/collection'
require 'fog/vcloudng/models/compute/vapp'
module Fog
module Compute
class Vcloudng
class Vapps < Fog::Collection
model Fog::Compute::Vcloudng::Vapp
attribute :vdc
2013-06-24 07:46:30 -04:00
def index(vdc_id = vdc.id)
vapp_links(vdc_id).map{ |vdc| new(vdc)}
end
2013-06-20 13:36:34 -04:00
def all(vdc_id = vdc.id)
2013-06-24 07:46:30 -04:00
vapp_ids = vapp_links(vdc_id).map {|vapp| vapp[:id] }
2013-06-20 13:36:34 -04:00
vapp_ids.map{ |vapp_id| get(vapp_id)}
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
2013-06-24 07:46:30 -04:00
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
end
2013-06-20 13:36:34 -04:00
end
end
end
end