Read /boot/grub/menu.lst file from pv guest

based on [http://everycity.co.uk/alasdair/2010/08/boot-environments-with-opensolaris-domus-on-xvm/]

Example of python script 'readfile'
#!/usr/bin/amd64/python2.7

# need copy pygrub file with .py extension for import it as python module
# Example of command line for reading menu.lst:
# ./readfile /dev/zvol/dsk/rpool/xen/dilos-pv /boot/grub/menu.lst
# 
# if we need boot pv guest from another BE need to add parameter
# --args="-B zfs-bootfs=rpool/ROOT/dilos"
# to <bootloader_args></bootloader_args>
# example:
# <bootloader_args>--args=&quot;-B zfs-bootfs=rpool/ROOT/dilos-2&quot;</bootloader_args>
# we can check how it is working by:
# ./pygrub /dev/zvol/dsk/rpool/xen/dilos-pv --args="-B zfs-bootfs=rpool/ROOT/dilos"

import sys
import pygrub
import fsimage

disk = sys.argv[1]
file = sys.argv[2]
part_offs = None
bootfsoptions = ""

# get list of offsets into file which start partitions
if part_offs is None:
    part_offs = pygrub.get_partition_offsets(disk)

for offset in part_offs:
    try:
        fs = fsimage.open(disk, offset, bootfsoptions)
        f = fs.open_file(file)
        zfsinfo = fsimage.getbootstring(fs)
        print f.read();
        print "==offset:%d, zfsinfo:%s\n" % (offset, zfsinfo)
        fs = None
    except:
        fs = None
        continue