Added libvirt facter plugin
This commit is contained in:
parent
b3a507720a
commit
898d80e2dc
2 changed files with 44 additions and 0 deletions
40
libvirt/lib/facter/libvirt.rb
Normal file
40
libvirt/lib/facter/libvirt.rb
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
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
|
|
@ -80,5 +80,9 @@ class libvirt::kvm inherits libvirt::client {
|
||||||
enable => true,
|
enable => true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
package { "ruby-libvirt":
|
||||||
|
ensure => installed,
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue