40 lines
1.1 KiB
Ruby
40 lines
1.1 KiB
Ruby
Facter.add(:libvirt_activedomains) do
|
|
confine :kernel => :linux
|
|
setcode do
|
|
begin
|
|
require 'libvirt'
|
|
conn = Libvirt::open_read_only('qemu:///system')
|
|
doms = Array.new
|
|
conn.list_domains.each do |domid|
|
|
dom = conn.lookup_domain_by_id(domid)
|
|
doms << dom.name
|
|
end
|
|
conn.close
|
|
doms.sort.join(',')
|
|
rescue LoadError
|
|
Facter.debug('ruby-libvirt not available')
|
|
rescue Exception
|
|
Facter.debug('libvirt connection failed')
|
|
end
|
|
end
|
|
end
|
|
|
|
Facter.add(:libvirt_inactivedomains) do
|
|
confine :kernel => :linux
|
|
setcode do
|
|
begin
|
|
require 'libvirt'
|
|
conn = Libvirt::open_read_only('qemu:///system')
|
|
doms = Array.new
|
|
conn.list_defined_domains.each do |domname|
|
|
doms << domname
|
|
end
|
|
conn.close
|
|
doms.sort.join(',')
|
|
rescue LoadError
|
|
Facter.debug('ruby-libvirt not available')
|
|
rescue Exception
|
|
Facter.debug('libvirt connection failed')
|
|
end
|
|
end
|
|
end
|