def autostart_guests
running = @guests.find_all {|g| g.running?}.map {|g| g.name}
auto_dir = xen_host? ? "/etc/xen/auto" : "/etc/libvirt/qemu/autostart"
autostartable = Dir[File.join(auto_dir, "*")].map {|f| File.basename(f, ".xml")}
(autostartable - running).each do |g|
$LOG.debug("Starting #{g}")
IO.popen("virsh start #{g} 2>&1") do |io|
$LOG.debug(io.read)
end
if $?.exitstatus != 0
guest = Cloudhost::Models::Guest.find(:first, :conditions => "name = '#{g}'")
guest.status = "failed"
guest.save!
end
end
end