libguestfs has high quality Python bindings. Using rpyc you can make a remote libguestfs server with almost no effort at all.
Firstly start an rpyc server:
$ /usr/lib/python2.7/site-packages/rpyc/servers/classic_server.py [SLAVE INFO 13:21:17 tid=140019939981120] server started on 0.0.0.0:18812 [SLAVE INFO 13:21:17 tid=140019784894208] started background auto-register thread (interval = 60) [REGCLNT INFO 13:21:17] registering on 255.255.255.255:18811 [REGCLNT WARNING 13:21:19] no registry acknowledged
Now, possibly from the same machine or some other machine, you can connect to this server and use Python objects remotely as if they were local:
$ python Python 2.7.3 (default, Aug 9 2012, 17:23:57) [GCC 4.7.1 20120720 (Red Hat 4.7.1-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import rpyc >>> c = rpyc.classic.connect('localhost')
You can now create a libguestfs handle, following the example here.
>>> g = c.modules.guestfs.GuestFS() >>> g.version() {'release': 36L, 'major': 1L, 'minor': 21L, 'extra': 'fedora=20,release=1.fc20,libvirt'} >>> g.add_drive('/dev/fedora/f18x64', readonly=True) >>> g.launch() >>> roots = g.inspect_os() >>> g.inspect_get_product_name(roots[0]) 'Fedora release 18 (Spherical Cow)' >>> g.inspect_get_mountpoints(roots[0]) [('/', '/dev/mapper/fedora-root'), ('/boot', '/dev/sda1')]
As you can see, the g
object is transparently remoted without you needing to do anything.