2 # dominfo - print some information about a domain
11 print('Usage: %s DOMAIN' % sys
.argv
[0])
12 print(' Print information about the domain DOMAIN')
14 def print_section(title
):
18 def print_entry(key
, value
):
19 print("%-10s %-10s" % (key
, value
))
21 def print_xml(key
, ctx
, path
):
22 res
= ctx
.xpathEval(path
)
23 if res
is None or len(res
) == 0:
26 value
= res
[0].content
27 print_entry(key
, value
)
30 if len(sys
.argv
) != 2:
37 conn
= libvirt
.openReadOnly(None)
39 print('Failed to open connection to the hypervisor')
43 dom
= conn
.lookupByName(name
)
44 # Annoyiingly, libvirt prints its own error message here
45 except libvirt
.libvirtError
:
46 print("Domain %s is not running" % name
)
50 print_section("Domain info")
51 print_entry("State:", info
[0])
52 print_entry("MaxMem:", info
[1])
53 print_entry("UsedMem:", info
[2])
54 print_entry("VCPUs:", info
[3])
56 # Read some info from the XML desc
57 xmldesc
= dom
.XMLDesc(0)
58 doc
= libxml2
.parseDoc(xmldesc
)
59 ctx
= doc
.xpathNewContext()
60 print_section("Kernel")
61 print_xml("Type:", ctx
, "/domain/os/type")
62 print_xml("Kernel:", ctx
, "/domain/os/kernel")
63 print_xml("initrd:", ctx
, "/domain/os/initrd")
64 print_xml("cmdline:", ctx
, "/domain/os/cmdline")
66 print_section("Devices")
67 devs
= ctx
.xpathEval("/domain/devices/*")
71 type = print_xml("Type:", ctx
, "@type")
73 print_xml("Source:", ctx
, "source/@file")
74 print_xml("Target:", ctx
, "target/@dev")
76 print_xml("Source:", ctx
, "source/@dev")
77 print_xml("Target:", ctx
, "target/@dev")
78 elif type == "bridge":
79 print_xml("Source:", ctx
, "source/@bridge")
80 print_xml("MAC Addr:", ctx
, "mac/@address")