2012-06-07 12:50:11 -04:00
|
|
|
require 'fog/ecloud/models/compute/catalog_item'
|
|
|
|
|
2011-02-17 13:44:46 -05:00
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
class Ecloud
|
2011-02-17 13:44:46 -05:00
|
|
|
class Catalog < Fog::Ecloud::Collection
|
|
|
|
|
2012-06-07 12:50:11 -04:00
|
|
|
identity :href
|
2011-02-17 13:44:46 -05:00
|
|
|
|
2012-06-07 12:50:11 -04:00
|
|
|
model Fog::Compute::Ecloud::CatalogItem
|
2011-02-17 13:44:46 -05:00
|
|
|
|
|
|
|
def all
|
2012-12-22 18:27:38 -05:00
|
|
|
data = service.get_catalog(href).body#[:Locations][:Location][:Catalog][:CatalogEntry]
|
2012-06-07 12:50:11 -04:00
|
|
|
if data[:Locations][:Location].is_a?(Hash)
|
|
|
|
data = [] if data[:Locations][:Location][:Catalog].is_a?(String) && data[:Locations][:Location][:Catalog].empty?
|
2011-02-17 13:44:46 -05:00
|
|
|
load(data)
|
2012-06-07 12:50:11 -04:00
|
|
|
elsif data[:Locations][:Location].is_a?(Array)
|
|
|
|
r_data = []
|
|
|
|
data[:Locations][:Location].each do |d|
|
|
|
|
unless d[:Catalog].is_a?(String) && d[:Catalog].empty?
|
|
|
|
d[:Catalog][:CatalogEntry].each do |c|
|
|
|
|
r_data << c
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
load(r_data)
|
2011-02-17 13:44:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get(uri)
|
2012-12-22 18:27:38 -05:00
|
|
|
if data = service.get_catalog_item(uri)
|
2011-02-17 13:44:46 -05:00
|
|
|
new(data.body)
|
|
|
|
end
|
|
|
|
rescue Fog::Errors::NotFound
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|