[vcloud|compute] method to find catalog item by name across all catalogs

This commit is contained in:
Lincoln Stoll 2011-06-16 11:28:30 +10:00
parent 9aeeb5abe1
commit c865ec6d16
2 changed files with 12 additions and 1 deletions

View File

@ -22,6 +22,17 @@ module Fog
@organization_uri ||= connection.default_organization_uri @organization_uri ||= connection.default_organization_uri
end end
def item_by_name(name)
res = nil
items = all.collect { |catalog| catalog.catalog_items }
items.each do |i|
i.collect do |ii|
res = ii if ii.name == name
end
end
res
end
end end
end end
end end

View File

@ -4,7 +4,7 @@ class Vcloud
def self.template def self.template
template_name = ENV['VCLOUD_TEMPLATE'] template_name = ENV['VCLOUD_TEMPLATE']
raise "Specify VApp template name in VCLOUD_TEMPLATE env var" unless template_name raise "Specify VApp template name in VCLOUD_TEMPLATE env var" unless template_name
template_res = Vcloud.catalogs.first.catalog_items.select {|ci| ci.name == template_name }[0] template_res = Vcloud.catalogs.item_by_name template_name
raise "URI Not found for specified template - check template name" unless template_res raise "URI Not found for specified template - check template name" unless template_res
template_res.href template_res.href
end end