Skip to content

Instantly share code, notes, and snippets.

@jlsherrill
Created January 17, 2017 16:50
Show Gist options
  • Save jlsherrill/31693088bc323b43ffbd3a72dae4f98b to your computer and use it in GitHub Desktop.
Save jlsherrill/31693088bc323b43ffbd3a72dae4f98b to your computer and use it in GitHub Desktop.
virt-who hypervisor -guest list
foreman-rake console 
hypervisors = Katello::Host::SubscriptionFacet.all.select{|i| i.candlepin_consumer.consumer_attributes['type']['label'] == 'hypervisor' }

hypervisors.each do |hypervisor|
  guests = hypervisor.candlepin_consumer.virtual_guests
  puts "#{hypervisor.host.name} - #{hypervisor.host.id} - #{guests.count} guest(s)"
  guests.each do |guest|
    puts " - #{guest.name} - #{guest.id}"
  end
  puts "\n"
end
@jlsherrill
Copy link
Author

jlsherrill commented Jan 17, 2017

For Katello 2.X and Satellite 6.1:

foreman-rake console 
file = File.open('/tmp/guest_list.txt', 'w')
User.current = User.first
Katello::Hypervisor.all.each do |hypervisor|
  guests = hypervisor.virtual_guests.reject{|system| system.name.nil?}
  file.write("#{hypervisor.name} - #{hypervisor.uuid} - #{guests.count} guest(s)\n")
  guests.each do |guest|
    file.write(" - #{guest.name} - #{guest.uuid}\n")
  end
  file.write("\n")
end
file.close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment