-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvminfo.rb
executable file
·58 lines (48 loc) · 1.05 KB
/
vminfo.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
55
56
57
#!/usr/bin/env ruby
class Vm
def getNics(name)
# get the nic info
vmname = name
virshnics_raw = `virsh domiflist #{vmname}`.split("\n")
virshnics_raw.shift
virshnics_raw.shift
virshnics = virshnics_raw
return virshnics
end
def getVnc
# get vnc info
end
def initialize(name, id, status)
@name=name
@id=id
@status=status
if status == 'running'
vncport = getVnc()
@nics = getNics(@name)
$out_data += [[ @id, @name, @status, @nics]]
else
$out_data += [[ @id, @name, @status]]
end
end
end
virshlist = `virsh list --all`.split("\n")
# remove the two header lines
virshlist.shift
virshlist.shift
vmList = virshlist
$out_data = []
# start the data gathering
vmList.each { |dom|
dom_info = dom.split
dom_id = dom_info[0]
dom_name = dom_info[1]
dom_stat = dom_info[2]
Vm.new(dom_name, dom_id, dom_stat)
}
# spit out what we've found
print "test data:\n"
print $out_data
print "\n-------------------\n"
$out_data.each { |vm|
print vm.join(" - ") + "\n"
}