2012-05-16 14:12:08 -04:00
|
|
|
require 'fog/core/collection'
|
|
|
|
require 'fog/cloudstack/models/compute/image'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class Cloudstack
|
|
|
|
|
|
|
|
class Images < Fog::Collection
|
|
|
|
|
|
|
|
model Fog::Compute::Cloudstack::Image
|
|
|
|
|
|
|
|
def all(filters={})
|
2012-08-08 15:00:34 -04:00
|
|
|
options = get_filter_options(filters)
|
2012-05-16 14:12:08 -04:00
|
|
|
|
2012-12-22 18:28:53 -05:00
|
|
|
data = service.list_templates(options)["listtemplatesresponse"]["template"] || []
|
2012-05-16 14:12:08 -04:00
|
|
|
load(data)
|
|
|
|
end
|
|
|
|
|
2012-08-08 15:00:34 -04:00
|
|
|
def get(template_id, filters={})
|
|
|
|
filter_option = get_filter_options(filters)
|
|
|
|
options = filter_option.merge('id' => template_id)
|
|
|
|
|
2012-12-22 18:28:53 -05:00
|
|
|
if template = service.list_templates(options)["listtemplatesresponse"]["template"].first
|
2012-05-16 14:12:08 -04:00
|
|
|
new(template)
|
|
|
|
end
|
|
|
|
rescue Fog::Compute::Cloudstack::BadRequest
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2012-08-08 15:00:34 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def get_filter_options(filters)
|
|
|
|
default_filter = {
|
|
|
|
'templatefilter' => 'self'
|
|
|
|
}
|
|
|
|
default_filter.merge(filters)
|
|
|
|
end
|
|
|
|
end
|
2012-05-16 14:12:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|