1 # Example showing how to inspect a virtual machine disk.
6 assert (len (sys.argv) == 2)
11 # Attach the disk image read-only to libguestfs.
12 g.add_drive_opts (disk, readonly=1)
14 # Run the libguestfs back-end.
17 # Ask libguestfs to inspect for operating systems.
18 roots = g.inspect_os ()
20 raise (Error ("inspect_vm: no operating systems found"))
23 print "Root device: %s" % root
25 # Print basic information about the operating system.
26 print " Product name: %s" % (g.inspect_get_product_name (root))
27 print " Version: %d.%d" % \
28 (g.inspect_get_major_version (root),
29 g.inspect_get_minor_version (root))
30 print " Type: %s" % (g.inspect_get_type (root))
31 print " Distro: %s" % (g.inspect_get_distro (root))
33 # Mount up the disks, like guestfish -i.
35 # Sort keys by length, shortest first, so that we end up
36 # mounting the filesystems in the correct order.
37 mps = g.inspect_get_mountpoints (root)
39 if len(a[0]) > len(b[0]):
41 elif len(a[0]) == len(b[0]):
48 g.mount_ro (mp_dev[1], mp_dev[0])
49 except RuntimeError as msg:
50 print "%s (ignored)" % msg
52 # If /etc/issue.net file exists, print up to 3 lines.
53 filename = "/etc/issue.net"
54 if g.is_file (filename):
55 print "--- %s ---" % filename
56 lines = g.head_n (3, filename)
57 for line in lines: print line