def images(credentials, opts=nil)
cloud = new_client(credentials)
img_arr = []
safely do
if opts[:id]
template_vms = [ find_vm(credentials, opts[:id]) ].select { |vm| vm[:instance] }.compact
else
template_vms = list_virtual_machines(credentials).select { |vm| vm[:instance] && vm[:instance].summary.config[:template] }
end
img_arr = template_vms.collect do |image_hash|
image, realm = image_hash[:instance], image_hash[:datastore]
config = image.summary.config
instance_state = convert_state(:instance, image.summary.runtime[:powerState])
properties = {
:name => config[:name],
:full_name => config[:guestFullName]
}
image_state = convert_state(:image, image.summary.runtime[:powerState])
image_architecture = extract_architecture(properties[:full_name]) || 'x86_64'
Image.new(
:id => properties[:name],
:name => properties[:name],
:architecture => image_architecture,
:owner_id => credentials.user,
:description => properties[:full_name],
:state => image_state
)
end
end
img_arr = filter_on( img_arr, :architecture, opts )
img_arr.sort_by{|e| [e.owner_id, e.name]}
end