-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlibvirt_host.rb
54 lines (48 loc) · 1.58 KB
/
libvirt_host.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Chef
class Knife
class LibvirtHostList < Knife
deps do
require 'chef/knife/bootstrap'
Chef::Knife::Bootstrap.load_deps
end
banner "knife libvirt host list (options)"
def run
#TODO change hosts config in knife.rb, list hosts
end
end
class LibvirtHostShow < Knife
deps do
require 'chef/knife/bootstrap'
require 'libvirt'
Chef::Knife::Bootstrap.load_deps
end
def to_mb(kb)
(kb/1024.0).round(2)
end
banner "knife libvirt host show HOST (options)"
def run
#TODO format for display
@name_args.each do |host|
puts "Host: #{host}"
uri = "qemu+tls://#{host}/system?pkipath=#{Chef::Config[:knife][:libvirt_tls_path]}/#{host}"
connection = Libvirt::open(uri)
info = connection.node_get_info
puts "URI: #{connection.uri}"
puts "Encrypted connection: #{connection.encrypted?}"
puts "Secure connection: #{connection.secure?}"
puts "Hypervisor: #{connection.type}"
puts "Hypervisor Version: #{connection.version}"
puts "Libvirt Version: #{connection.libversion}"
puts "Architecture: #{info.model}"
puts "Total Memory: #{to_mb(info.memory)} MB"
puts "CPUs: #{info.cpus}"
puts "Speed: #{info.mhz}"
puts "Nodes: #{info.nodes}"
puts "Sockets: #{info.sockets}"
puts "Cores: #{info.cores}"
puts "Threads: #{info.threads}"
end
end
end
end
end