9cf9d8817735aecfcb3ee7617c4aae4efb9205bb
[libguestfs.git] / python / guestfs.py
1 # libguestfs generated file
2 # WARNING: THIS FILE IS GENERATED BY 'src/generator.ml'.
3 # ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
4 #
5 # Copyright (C) 2009 Red Hat Inc.
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
21 u"""Python bindings for libguestfs
22
23 import guestfs
24 g = guestfs.GuestFS ()
25 g.add_drive ("guest.img")
26 g.launch ()
27 g.wait_ready ()
28 parts = g.list_partitions ()
29
30 The guestfs module provides a Python binding to the libguestfs API
31 for examining and modifying virtual machine disk images.
32
33 Amongst the things this is good for: making batch configuration
34 changes to guests, getting disk used/free statistics (see also:
35 virt-df), migrating between virtualization systems (see also:
36 virt-p2v), performing partial backups, performing partial guest
37 clones, cloning guests and changing registry/UUID/hostname info, and
38 much else besides.
39
40 Libguestfs uses Linux kernel and qemu code, and can access any type of
41 guest filesystem that Linux and qemu can, including but not limited
42 to: ext2/3/4, btrfs, FAT and NTFS, LVM, many different disk partition
43 schemes, qcow, qcow2, vmdk.
44
45 Libguestfs provides ways to enumerate guest storage (eg. partitions,
46 LVs, what filesystem is in each LV, etc.).  It can also run commands
47 in the context of the guest.  Also you can access filesystems over FTP.
48
49 Errors which happen while using the API are turned into Python
50 RuntimeError exceptions.
51
52 To create a guestfs handle you usually have to perform the following
53 sequence of calls:
54
55 # Create the handle, call add_drive at least once, and possibly
56 # several times if the guest has multiple block devices:
57 g = guestfs.GuestFS ()
58 g.add_drive ("guest.img")
59
60 # Launch the qemu subprocess and wait for it to become ready:
61 g.launch ()
62 g.wait_ready ()
63
64 # Now you can issue commands, for example:
65 logvols = g.lvs ()
66
67 """
68
69 import libguestfsmod
70
71 class GuestFS:
72     """Instances of this class are libguestfs API handles."""
73
74     def __init__ (self):
75         """Create a new libguestfs handle."""
76         self._o = libguestfsmod.create ()
77
78     def __del__ (self):
79         libguestfsmod.close (self._o)
80
81     def launch (self):
82         u"""Internally libguestfs is implemented by running a
83         virtual machine using qemu(1).
84         
85         You should call this after configuring the handle (eg.
86         adding drives) but before performing any actions.
87         """
88         return libguestfsmod.launch (self._o)
89
90     def wait_ready (self):
91         u"""Internally libguestfs is implemented by running a
92         virtual machine using qemu(1).
93         
94         You should call this after "g.launch" to wait for the
95         launch to complete.
96         """
97         return libguestfsmod.wait_ready (self._o)
98
99     def kill_subprocess (self):
100         u"""This kills the qemu subprocess. You should never need to
101         call this.
102         """
103         return libguestfsmod.kill_subprocess (self._o)
104
105     def add_drive (self, filename):
106         u"""This function adds a virtual machine disk image
107         "filename" to the guest. The first time you call this
108         function, the disk appears as IDE disk 0 ("/dev/sda") in
109         the guest, the second time as "/dev/sdb", and so on.
110         
111         You don't necessarily need to be root when using
112         libguestfs. However you obviously do need sufficient
113         permissions to access the filename for whatever
114         operations you want to perform (ie. read access if you
115         just want to read the image or write access if you want
116         to modify the image).
117         
118         This is equivalent to the qemu parameter "-drive
119         file=filename".
120         """
121         return libguestfsmod.add_drive (self._o, filename)
122
123     def add_cdrom (self, filename):
124         u"""This function adds a virtual CD-ROM disk image to the
125         guest.
126         
127         This is equivalent to the qemu parameter "-cdrom
128         filename".
129         """
130         return libguestfsmod.add_cdrom (self._o, filename)
131
132     def config (self, qemuparam, qemuvalue):
133         u"""This can be used to add arbitrary qemu command line
134         parameters of the form "-param value". Actually it's not
135         quite arbitrary - we prevent you from setting some
136         parameters which would interfere with parameters that we
137         use.
138         
139         The first character of "param" string must be a "-"
140         (dash).
141         
142         "value" can be NULL.
143         """
144         return libguestfsmod.config (self._o, qemuparam, qemuvalue)
145
146     def set_qemu (self, qemu):
147         u"""Set the qemu binary that we will use.
148         
149         The default is chosen when the library was compiled by
150         the configure script.
151         
152         You can also override this by setting the
153         "LIBGUESTFS_QEMU" environment variable.
154         
155         The string "qemu" is stashed in the libguestfs handle,
156         so the caller must make sure it remains valid for the
157         lifetime of the handle.
158         
159         Setting "qemu" to "NULL" restores the default qemu
160         binary.
161         """
162         return libguestfsmod.set_qemu (self._o, qemu)
163
164     def get_qemu (self):
165         u"""Return the current qemu binary.
166         
167         This is always non-NULL. If it wasn't set already, then
168         this will return the default qemu binary name.
169         """
170         return libguestfsmod.get_qemu (self._o)
171
172     def set_path (self, path):
173         u"""Set the path that libguestfs searches for kernel and
174         initrd.img.
175         
176         The default is "$libdir/guestfs" unless overridden by
177         setting "LIBGUESTFS_PATH" environment variable.
178         
179         The string "path" is stashed in the libguestfs handle,
180         so the caller must make sure it remains valid for the
181         lifetime of the handle.
182         
183         Setting "path" to "NULL" restores the default path.
184         """
185         return libguestfsmod.set_path (self._o, path)
186
187     def get_path (self):
188         u"""Return the current search path.
189         
190         This is always non-NULL. If it wasn't set already, then
191         this will return the default path.
192         """
193         return libguestfsmod.get_path (self._o)
194
195     def set_autosync (self, autosync):
196         u"""If "autosync" is true, this enables autosync. Libguestfs
197         will make a best effort attempt to run "g.umount_all"
198         followed by "g.sync" when the handle is closed (also if
199         the program exits without closing handles).
200         
201         This is disabled by default (except in guestfish where
202         it is enabled by default).
203         """
204         return libguestfsmod.set_autosync (self._o, autosync)
205
206     def get_autosync (self):
207         u"""Get the autosync flag.
208         """
209         return libguestfsmod.get_autosync (self._o)
210
211     def set_verbose (self, verbose):
212         u"""If "verbose" is true, this turns on verbose messages (to
213         "stderr").
214         
215         Verbose messages are disabled unless the environment
216         variable "LIBGUESTFS_DEBUG" is defined and set to 1.
217         """
218         return libguestfsmod.set_verbose (self._o, verbose)
219
220     def get_verbose (self):
221         u"""This returns the verbose messages flag.
222         """
223         return libguestfsmod.get_verbose (self._o)
224
225     def is_ready (self):
226         u"""This returns true iff this handle is ready to accept
227         commands (in the "READY" state).
228         
229         For more information on states, see guestfs(3).
230         """
231         return libguestfsmod.is_ready (self._o)
232
233     def is_config (self):
234         u"""This returns true iff this handle is being configured
235         (in the "CONFIG" state).
236         
237         For more information on states, see guestfs(3).
238         """
239         return libguestfsmod.is_config (self._o)
240
241     def is_launching (self):
242         u"""This returns true iff this handle is launching the
243         subprocess (in the "LAUNCHING" state).
244         
245         For more information on states, see guestfs(3).
246         """
247         return libguestfsmod.is_launching (self._o)
248
249     def is_busy (self):
250         u"""This returns true iff this handle is busy processing a
251         command (in the "BUSY" state).
252         
253         For more information on states, see guestfs(3).
254         """
255         return libguestfsmod.is_busy (self._o)
256
257     def get_state (self):
258         u"""This returns the current state as an opaque integer.
259         This is only useful for printing debug and internal
260         error messages.
261         
262         For more information on states, see guestfs(3).
263         """
264         return libguestfsmod.get_state (self._o)
265
266     def set_busy (self):
267         u"""This sets the state to "BUSY". This is only used when
268         implementing actions using the low-level API.
269         
270         For more information on states, see guestfs(3).
271         """
272         return libguestfsmod.set_busy (self._o)
273
274     def set_ready (self):
275         u"""This sets the state to "READY". This is only used when
276         implementing actions using the low-level API.
277         
278         For more information on states, see guestfs(3).
279         """
280         return libguestfsmod.set_ready (self._o)
281
282     def mount (self, device, mountpoint):
283         u"""Mount a guest disk at a position in the filesystem.
284         Block devices are named "/dev/sda", "/dev/sdb" and so
285         on, as they were added to the guest. If those block
286         devices contain partitions, they will have the usual
287         names (eg. "/dev/sda1"). Also LVM "/dev/VG/LV"-style
288         names can be used.
289         
290         The rules are the same as for mount(2): A filesystem
291         must first be mounted on "/" before others can be
292         mounted. Other filesystems can only be mounted on
293         directories which already exist.
294         
295         The mounted filesystem is writable, if we have
296         sufficient permissions on the underlying device.
297         
298         The filesystem options "sync" and "noatime" are set with
299         this call, in order to improve reliability.
300         """
301         return libguestfsmod.mount (self._o, device, mountpoint)
302
303     def sync (self):
304         u"""This syncs the disk, so that any writes are flushed
305         through to the underlying disk image.
306         
307         You should always call this if you have modified a disk
308         image, before closing the handle.
309         """
310         return libguestfsmod.sync (self._o)
311
312     def touch (self, path):
313         u"""Touch acts like the touch(1) command. It can be used to
314         update the timestamps on a file, or, if the file does
315         not exist, to create a new zero-length file.
316         """
317         return libguestfsmod.touch (self._o, path)
318
319     def cat (self, path):
320         u"""Return the contents of the file named "path".
321         
322         Note that this function cannot correctly handle binary
323         files (specifically, files containing "\\0" character
324         which is treated as end of string). For those you need
325         to use the "g.download" function which has a more
326         complex interface.
327         
328         Because of the message protocol, there is a transfer
329         limit of somewhere between 2MB and 4MB. To transfer
330         large files you should use FTP.
331         """
332         return libguestfsmod.cat (self._o, path)
333
334     def ll (self, directory):
335         u"""List the files in "directory" (relative to the root
336         directory, there is no cwd) in the format of 'ls -la'.
337         
338         This command is mostly useful for interactive sessions.
339         It is *not* intended that you try to parse the output
340         string.
341         """
342         return libguestfsmod.ll (self._o, directory)
343
344     def ls (self, directory):
345         u"""List the files in "directory" (relative to the root
346         directory, there is no cwd). The '.' and '..' entries
347         are not returned, but hidden files are shown.
348         
349         This command is mostly useful for interactive sessions.
350         Programs should probably use "g.readdir" instead.
351         
352         This function returns a list of strings.
353         """
354         return libguestfsmod.ls (self._o, directory)
355
356     def list_devices (self):
357         u"""List all the block devices.
358         
359         The full block device names are returned, eg. "/dev/sda"
360         
361         This function returns a list of strings.
362         """
363         return libguestfsmod.list_devices (self._o)
364
365     def list_partitions (self):
366         u"""List all the partitions detected on all block devices.
367         
368         The full partition device names are returned, eg.
369         "/dev/sda1"
370         
371         This does not return logical volumes. For that you will
372         need to call "g.lvs".
373         
374         This function returns a list of strings.
375         """
376         return libguestfsmod.list_partitions (self._o)
377
378     def pvs (self):
379         u"""List all the physical volumes detected. This is the
380         equivalent of the pvs(8) command.
381         
382         This returns a list of just the device names that
383         contain PVs (eg. "/dev/sda2").
384         
385         See also "g.pvs_full".
386         
387         This function returns a list of strings.
388         """
389         return libguestfsmod.pvs (self._o)
390
391     def vgs (self):
392         u"""List all the volumes groups detected. This is the
393         equivalent of the vgs(8) command.
394         
395         This returns a list of just the volume group names that
396         were detected (eg. "VolGroup00").
397         
398         See also "g.vgs_full".
399         
400         This function returns a list of strings.
401         """
402         return libguestfsmod.vgs (self._o)
403
404     def lvs (self):
405         u"""List all the logical volumes detected. This is the
406         equivalent of the lvs(8) command.
407         
408         This returns a list of the logical volume device names
409         (eg. "/dev/VolGroup00/LogVol00").
410         
411         See also "g.lvs_full".
412         
413         This function returns a list of strings.
414         """
415         return libguestfsmod.lvs (self._o)
416
417     def pvs_full (self):
418         u"""List all the physical volumes detected. This is the
419         equivalent of the pvs(8) command. The "full" version
420         includes all fields.
421         
422         This function returns a list of PVs. Each PV is
423         represented as a dictionary.
424         """
425         return libguestfsmod.pvs_full (self._o)
426
427     def vgs_full (self):
428         u"""List all the volumes groups detected. This is the
429         equivalent of the vgs(8) command. The "full" version
430         includes all fields.
431         
432         This function returns a list of VGs. Each VG is
433         represented as a dictionary.
434         """
435         return libguestfsmod.vgs_full (self._o)
436
437     def lvs_full (self):
438         u"""List all the logical volumes detected. This is the
439         equivalent of the lvs(8) command. The "full" version
440         includes all fields.
441         
442         This function returns a list of LVs. Each LV is
443         represented as a dictionary.
444         """
445         return libguestfsmod.lvs_full (self._o)
446
447     def read_lines (self, path):
448         u"""Return the contents of the file named "path".
449         
450         The file contents are returned as a list of lines.
451         Trailing "LF" and "CRLF" character sequences are *not*
452         returned.
453         
454         Note that this function cannot correctly handle binary
455         files (specifically, files containing "\\0" character
456         which is treated as end of line). For those you need to
457         use the "g.read_file" function which has a more complex
458         interface.
459         
460         This function returns a list of strings.
461         """
462         return libguestfsmod.read_lines (self._o, path)
463
464     def aug_init (self, root, flags):
465         u"""Create a new Augeas handle for editing configuration
466         files. If there was any previous Augeas handle
467         associated with this guestfs session, then it is closed.
468         
469         You must call this before using any other "g.aug_*"
470         commands.
471         
472         "root" is the filesystem root. "root" must not be NULL,
473         use "/" instead.
474         
475         The flags are the same as the flags defined in
476         <augeas.h>, the logical *or* of the following integers:
477         
478         "AUG_SAVE_BACKUP" = 1
479         Keep the original file with a ".augsave" extension.
480         
481         "AUG_SAVE_NEWFILE" = 2
482         Save changes into a file with extension ".augnew",
483         and do not overwrite original. Overrides
484         "AUG_SAVE_BACKUP".
485         
486         "AUG_TYPE_CHECK" = 4
487         Typecheck lenses (can be expensive).
488         
489         "AUG_NO_STDINC" = 8
490         Do not use standard load path for modules.
491         
492         "AUG_SAVE_NOOP" = 16
493         Make save a no-op, just record what would have been
494         changed.
495         
496         "AUG_NO_LOAD" = 32
497         Do not load the tree in "g.aug_init".
498         
499         To close the handle, you can call "g.aug_close".
500         
501         To find out more about Augeas, see <http://augeas.net/>.
502         """
503         return libguestfsmod.aug_init (self._o, root, flags)
504
505     def aug_close (self):
506         u"""Close the current Augeas handle and free up any
507         resources used by it. After calling this, you have to
508         call "g.aug_init" again before you can use any other
509         Augeas functions.
510         """
511         return libguestfsmod.aug_close (self._o)
512
513     def aug_defvar (self, name, expr):
514         u"""Defines an Augeas variable "name" whose value is the
515         result of evaluating "expr". If "expr" is NULL, then
516         "name" is undefined.
517         
518         On success this returns the number of nodes in "expr",
519         or 0 if "expr" evaluates to something which is not a
520         nodeset.
521         """
522         return libguestfsmod.aug_defvar (self._o, name, expr)
523
524     def aug_defnode (self, name, expr, val):
525         u"""Defines a variable "name" whose value is the result of
526         evaluating "expr".
527         
528         If "expr" evaluates to an empty nodeset, a node is
529         created, equivalent to calling "g.aug_set" "expr",
530         "value". "name" will be the nodeset containing that
531         single node.
532         
533         On success this returns a pair containing the number of
534         nodes in the nodeset, and a boolean flag if a node was
535         created.
536         
537         This function returns a tuple (int, bool).
538         """
539         return libguestfsmod.aug_defnode (self._o, name, expr, val)
540
541     def aug_get (self, path):
542         u"""Look up the value associated with "path". If "path"
543         matches exactly one node, the "value" is returned.
544         """
545         return libguestfsmod.aug_get (self._o, path)
546
547     def aug_set (self, path, val):
548         u"""Set the value associated with "path" to "value".
549         """
550         return libguestfsmod.aug_set (self._o, path, val)
551
552     def aug_insert (self, path, label, before):
553         u"""Create a new sibling "label" for "path", inserting it
554         into the tree before or after "path" (depending on the
555         boolean flag "before").
556         
557         "path" must match exactly one existing node in the tree,
558         and "label" must be a label, ie. not contain "/", "*" or
559         end with a bracketed index "[N]".
560         """
561         return libguestfsmod.aug_insert (self._o, path, label, before)
562
563     def aug_rm (self, path):
564         u"""Remove "path" and all of its children.
565         
566         On success this returns the number of entries which were
567         removed.
568         """
569         return libguestfsmod.aug_rm (self._o, path)
570
571     def aug_mv (self, src, dest):
572         u"""Move the node "src" to "dest". "src" must match exactly
573         one node. "dest" is overwritten if it exists.
574         """
575         return libguestfsmod.aug_mv (self._o, src, dest)
576
577     def aug_match (self, path):
578         u"""Returns a list of paths which match the path expression
579         "path". The returned paths are sufficiently qualified so
580         that they match exactly one node in the current tree.
581         
582         This function returns a list of strings.
583         """
584         return libguestfsmod.aug_match (self._o, path)
585
586     def aug_save (self):
587         u"""This writes all pending changes to disk.
588         
589         The flags which were passed to "g.aug_init" affect
590         exactly how files are saved.
591         """
592         return libguestfsmod.aug_save (self._o)
593
594     def aug_load (self):
595         u"""Load files into the tree.
596         
597         See "aug_load" in the Augeas documentation for the full
598         gory details.
599         """
600         return libguestfsmod.aug_load (self._o)
601
602     def aug_ls (self, path):
603         u"""This is just a shortcut for listing "g.aug_match"
604         "path/*" and sorting the resulting nodes into
605         alphabetical order.
606         
607         This function returns a list of strings.
608         """
609         return libguestfsmod.aug_ls (self._o, path)
610
611     def rm (self, path):
612         u"""Remove the single file "path".
613         """
614         return libguestfsmod.rm (self._o, path)
615
616     def rmdir (self, path):
617         u"""Remove the single directory "path".
618         """
619         return libguestfsmod.rmdir (self._o, path)
620
621     def rm_rf (self, path):
622         u"""Remove the file or directory "path", recursively
623         removing the contents if its a directory. This is like
624         the "rm -rf" shell command.
625         """
626         return libguestfsmod.rm_rf (self._o, path)
627
628     def mkdir (self, path):
629         u"""Create a directory named "path".
630         """
631         return libguestfsmod.mkdir (self._o, path)
632
633     def mkdir_p (self, path):
634         u"""Create a directory named "path", creating any parent
635         directories as necessary. This is like the "mkdir -p"
636         shell command.
637         """
638         return libguestfsmod.mkdir_p (self._o, path)
639
640     def chmod (self, mode, path):
641         u"""Change the mode (permissions) of "path" to "mode". Only
642         numeric modes are supported.
643         """
644         return libguestfsmod.chmod (self._o, mode, path)
645
646     def chown (self, owner, group, path):
647         u"""Change the file owner to "owner" and group to "group".
648         
649         Only numeric uid and gid are supported. If you want to
650         use names, you will need to locate and parse the
651         password file yourself (Augeas support makes this
652         relatively easy).
653         """
654         return libguestfsmod.chown (self._o, owner, group, path)
655
656     def exists (self, path):
657         u"""This returns "true" if and only if there is a file,
658         directory (or anything) with the given "path" name.
659         
660         See also "g.is_file", "g.is_dir", "g.stat".
661         """
662         return libguestfsmod.exists (self._o, path)
663
664     def is_file (self, path):
665         u"""This returns "true" if and only if there is a file with
666         the given "path" name. Note that it returns false for
667         other objects like directories.
668         
669         See also "g.stat".
670         """
671         return libguestfsmod.is_file (self._o, path)
672
673     def is_dir (self, path):
674         u"""This returns "true" if and only if there is a directory
675         with the given "path" name. Note that it returns false
676         for other objects like files.
677         
678         See also "g.stat".
679         """
680         return libguestfsmod.is_dir (self._o, path)
681
682     def pvcreate (self, device):
683         u"""This creates an LVM physical volume on the named
684         "device", where "device" should usually be a partition
685         name such as "/dev/sda1".
686         """
687         return libguestfsmod.pvcreate (self._o, device)
688
689     def vgcreate (self, volgroup, physvols):
690         u"""This creates an LVM volume group called "volgroup" from
691         the non-empty list of physical volumes "physvols".
692         """
693         return libguestfsmod.vgcreate (self._o, volgroup, physvols)
694
695     def lvcreate (self, logvol, volgroup, mbytes):
696         u"""This creates an LVM volume group called "logvol" on the
697         volume group "volgroup", with "size" megabytes.
698         """
699         return libguestfsmod.lvcreate (self._o, logvol, volgroup, mbytes)
700
701     def mkfs (self, fstype, device):
702         u"""This creates a filesystem on "device" (usually a
703         partition or LVM logical volume). The filesystem type is
704         "fstype", for example "ext3".
705         """
706         return libguestfsmod.mkfs (self._o, fstype, device)
707
708     def sfdisk (self, device, cyls, heads, sectors, lines):
709         u"""This is a direct interface to the sfdisk(8) program for
710         creating partitions on block devices.
711         
712         "device" should be a block device, for example
713         "/dev/sda".
714         
715         "cyls", "heads" and "sectors" are the number of
716         cylinders, heads and sectors on the device, which are
717         passed directly to sfdisk as the *-C*, *-H* and *-S*
718         parameters. If you pass 0 for any of these, then the
719         corresponding parameter is omitted. Usually for 'large'
720         disks, you can just pass 0 for these, but for small
721         (floppy-sized) disks, sfdisk (or rather, the kernel)
722         cannot work out the right geometry and you will need to
723         tell it.
724         
725         "lines" is a list of lines that we feed to "sfdisk". For
726         more information refer to the sfdisk(8) manpage.
727         
728         To create a single partition occupying the whole disk,
729         you would pass "lines" as a single element list, when
730         the single element being the string "," (comma).
731         
732         This command is dangerous. Without careful use you can
733         easily destroy all your data.
734         """
735         return libguestfsmod.sfdisk (self._o, device, cyls, heads, sectors, lines)
736
737     def write_file (self, path, content, size):
738         u"""This call creates a file called "path". The contents of
739         the file is the string "content" (which can contain any
740         8 bit data), with length "size".
741         
742         As a special case, if "size" is 0 then the length is
743         calculated using "strlen" (so in this case the content
744         cannot contain embedded ASCII NULs).
745         
746         *NB.* Owing to a bug, writing content containing ASCII
747         NUL characters does *not* work, even if the length is
748         specified. We hope to resolve this bug in a future
749         version. In the meantime use "g.upload".
750         
751         Because of the message protocol, there is a transfer
752         limit of somewhere between 2MB and 4MB. To transfer
753         large files you should use FTP.
754         """
755         return libguestfsmod.write_file (self._o, path, content, size)
756
757     def umount (self, pathordevice):
758         u"""This unmounts the given filesystem. The filesystem may
759         be specified either by its mountpoint (path) or the
760         device which contains the filesystem.
761         """
762         return libguestfsmod.umount (self._o, pathordevice)
763
764     def mounts (self):
765         u"""This returns the list of currently mounted filesystems.
766         It returns the list of devices (eg. "/dev/sda1",
767         "/dev/VG/LV").
768         
769         Some internal mounts are not shown.
770         
771         This function returns a list of strings.
772         """
773         return libguestfsmod.mounts (self._o)
774
775     def umount_all (self):
776         u"""This unmounts all mounted filesystems.
777         
778         Some internal mounts are not unmounted by this call.
779         """
780         return libguestfsmod.umount_all (self._o)
781
782     def lvm_remove_all (self):
783         u"""This command removes all LVM logical volumes, volume
784         groups and physical volumes.
785         
786         This command is dangerous. Without careful use you can
787         easily destroy all your data.
788         """
789         return libguestfsmod.lvm_remove_all (self._o)
790
791     def file (self, path):
792         u"""This call uses the standard file(1) command to determine
793         the type or contents of the file. This also works on
794         devices, for example to find out whether a partition
795         contains a filesystem.
796         
797         The exact command which runs is "file -bsL path". Note
798         in particular that the filename is not prepended to the
799         output (the "-b" option).
800         """
801         return libguestfsmod.file (self._o, path)
802
803     def command (self, arguments):
804         u"""This call runs a command from the guest filesystem. The
805         filesystem must be mounted, and must contain a
806         compatible operating system (ie. something Linux, with
807         the same or compatible processor architecture).
808         
809         The single parameter is an argv-style list of arguments.
810         The first element is the name of the program to run.
811         Subsequent elements are parameters. The list must be
812         non-empty (ie. must contain a program name).
813         
814         The $PATH environment variable will contain at least
815         "/usr/bin" and "/bin". If you require a program from
816         another location, you should provide the full path in
817         the first parameter.
818         
819         Shared libraries and data files required by the program
820         must be available on filesystems which are mounted in
821         the correct places. It is the caller's responsibility to
822         ensure all filesystems that are needed are mounted at
823         the right locations.
824         """
825         return libguestfsmod.command (self._o, arguments)
826
827     def command_lines (self, arguments):
828         u"""This is the same as "g.command", but splits the result
829         into a list of lines.
830         
831         This function returns a list of strings.
832         """
833         return libguestfsmod.command_lines (self._o, arguments)
834
835     def stat (self, path):
836         u"""Returns file information for the given "path".
837         
838         This is the same as the stat(2) system call.
839         
840         This function returns a dictionary, with keys matching
841         the various fields in the stat structure.
842         """
843         return libguestfsmod.stat (self._o, path)
844
845     def lstat (self, path):
846         u"""Returns file information for the given "path".
847         
848         This is the same as "g.stat" except that if "path" is a
849         symbolic link, then the link is stat-ed, not the file it
850         refers to.
851         
852         This is the same as the lstat(2) system call.
853         
854         This function returns a dictionary, with keys matching
855         the various fields in the stat structure.
856         """
857         return libguestfsmod.lstat (self._o, path)
858
859     def statvfs (self, path):
860         u"""Returns file system statistics for any mounted file
861         system. "path" should be a file or directory in the
862         mounted file system (typically it is the mount point
863         itself, but it doesn't need to be).
864         
865         This is the same as the statvfs(2) system call.
866         
867         This function returns a dictionary, with keys matching
868         the various fields in the statvfs structure.
869         """
870         return libguestfsmod.statvfs (self._o, path)
871
872     def tune2fs_l (self, device):
873         u"""This returns the contents of the ext2, ext3 or ext4
874         filesystem superblock on "device".
875         
876         It is the same as running "tune2fs -l device". See
877         tune2fs(8) manpage for more details. The list of fields
878         returned isn't clearly defined, and depends on both the
879         version of "tune2fs" that libguestfs was built against,
880         and the filesystem itself.
881         
882         This function returns a dictionary.
883         """
884         return libguestfsmod.tune2fs_l (self._o, device)
885
886     def blockdev_setro (self, device):
887         u"""Sets the block device named "device" to read-only.
888         
889         This uses the blockdev(8) command.
890         """
891         return libguestfsmod.blockdev_setro (self._o, device)
892
893     def blockdev_setrw (self, device):
894         u"""Sets the block device named "device" to read-write.
895         
896         This uses the blockdev(8) command.
897         """
898         return libguestfsmod.blockdev_setrw (self._o, device)
899
900     def blockdev_getro (self, device):
901         u"""Returns a boolean indicating if the block device is
902         read-only (true if read-only, false if not).
903         
904         This uses the blockdev(8) command.
905         """
906         return libguestfsmod.blockdev_getro (self._o, device)
907
908     def blockdev_getss (self, device):
909         u"""This returns the size of sectors on a block device.
910         Usually 512, but can be larger for modern devices.
911         
912         (Note, this is not the size in sectors, use
913         "g.blockdev_getsz" for that).
914         
915         This uses the blockdev(8) command.
916         """
917         return libguestfsmod.blockdev_getss (self._o, device)
918
919     def blockdev_getbsz (self, device):
920         u"""This returns the block size of a device.
921         
922         (Note this is different from both *size in blocks* and
923         *filesystem block size*).
924         
925         This uses the blockdev(8) command.
926         """
927         return libguestfsmod.blockdev_getbsz (self._o, device)
928
929     def blockdev_setbsz (self, device, blocksize):
930         u"""This sets the block size of a device.
931         
932         (Note this is different from both *size in blocks* and
933         *filesystem block size*).
934         
935         This uses the blockdev(8) command.
936         """
937         return libguestfsmod.blockdev_setbsz (self._o, device, blocksize)
938
939     def blockdev_getsz (self, device):
940         u"""This returns the size of the device in units of 512-byte
941         sectors (even if the sectorsize isn't 512 bytes ...
942         weird).
943         
944         See also "g.blockdev_getss" for the real sector size of
945         the device, and "g.blockdev_getsize64" for the more
946         useful *size in bytes*.
947         
948         This uses the blockdev(8) command.
949         """
950         return libguestfsmod.blockdev_getsz (self._o, device)
951
952     def blockdev_getsize64 (self, device):
953         u"""This returns the size of the device in bytes.
954         
955         See also "g.blockdev_getsz".
956         
957         This uses the blockdev(8) command.
958         """
959         return libguestfsmod.blockdev_getsize64 (self._o, device)
960
961     def blockdev_flushbufs (self, device):
962         u"""This tells the kernel to flush internal buffers
963         associated with "device".
964         
965         This uses the blockdev(8) command.
966         """
967         return libguestfsmod.blockdev_flushbufs (self._o, device)
968
969     def blockdev_rereadpt (self, device):
970         u"""Reread the partition table on "device".
971         
972         This uses the blockdev(8) command.
973         """
974         return libguestfsmod.blockdev_rereadpt (self._o, device)
975
976     def upload (self, filename, remotefilename):
977         u"""Upload local file "filename" to "remotefilename" on the
978         filesystem.
979         
980         "filename" can also be a named pipe.
981         
982         See also "g.download".
983         """
984         return libguestfsmod.upload (self._o, filename, remotefilename)
985
986     def download (self, remotefilename, filename):
987         u"""Download file "remotefilename" and save it as "filename"
988         on the local machine.
989         
990         "filename" can also be a named pipe.
991         
992         See also "g.upload", "g.cat".
993         """
994         return libguestfsmod.download (self._o, remotefilename, filename)
995
996     def checksum (self, csumtype, path):
997         u"""This call computes the MD5, SHAx or CRC checksum of the
998         file named "path".
999         
1000         The type of checksum to compute is given by the
1001         "csumtype" parameter which must have one of the
1002         following values:
1003         
1004         "crc"
1005         Compute the cyclic redundancy check (CRC) specified
1006         by POSIX for the "cksum" command.
1007         
1008         "md5"
1009         Compute the MD5 hash (using the "md5sum" program).
1010         
1011         "sha1"
1012         Compute the SHA1 hash (using the "sha1sum" program).
1013         
1014         "sha224"
1015         Compute the SHA224 hash (using the "sha224sum"
1016         program).
1017         
1018         "sha256"
1019         Compute the SHA256 hash (using the "sha256sum"
1020         program).
1021         
1022         "sha384"
1023         Compute the SHA384 hash (using the "sha384sum"
1024         program).
1025         
1026         "sha512"
1027         Compute the SHA512 hash (using the "sha512sum"
1028         program).
1029         
1030         The checksum is returned as a printable string.
1031         """
1032         return libguestfsmod.checksum (self._o, csumtype, path)
1033
1034     def tar_in (self, tarfile, directory):
1035         u"""This command uploads and unpacks local file "tarfile"
1036         (an *uncompressed* tar file) into "directory".
1037         
1038         To upload a compressed tarball, use "g.tgz_in".
1039         """
1040         return libguestfsmod.tar_in (self._o, tarfile, directory)
1041
1042     def tar_out (self, directory, tarfile):
1043         u"""This command packs the contents of "directory" and
1044         downloads it to local file "tarfile".
1045         
1046         To download a compressed tarball, use "g.tgz_out".
1047         """
1048         return libguestfsmod.tar_out (self._o, directory, tarfile)
1049
1050     def tgz_in (self, tarball, directory):
1051         u"""This command uploads and unpacks local file "tarball" (a
1052         *gzip compressed* tar file) into "directory".
1053         
1054         To upload an uncompressed tarball, use "g.tar_in".
1055         """
1056         return libguestfsmod.tgz_in (self._o, tarball, directory)
1057
1058     def tgz_out (self, directory, tarball):
1059         u"""This command packs the contents of "directory" and
1060         downloads it to local file "tarball".
1061         
1062         To download an uncompressed tarball, use "g.tar_out".
1063         """
1064         return libguestfsmod.tgz_out (self._o, directory, tarball)
1065
1066     def mount_ro (self, device, mountpoint):
1067         u"""This is the same as the "g.mount" command, but it mounts
1068         the filesystem with the read-only (*-o ro*) flag.
1069         """
1070         return libguestfsmod.mount_ro (self._o, device, mountpoint)
1071
1072     def mount_options (self, options, device, mountpoint):
1073         u"""This is the same as the "g.mount" command, but it allows
1074         you to set the mount options as for the mount(8) *-o*
1075         flag.
1076         """
1077         return libguestfsmod.mount_options (self._o, options, device, mountpoint)
1078
1079     def mount_vfs (self, options, vfstype, device, mountpoint):
1080         u"""This is the same as the "g.mount" command, but it allows
1081         you to set both the mount options and the vfstype as for
1082         the mount(8) *-o* and *-t* flags.
1083         """
1084         return libguestfsmod.mount_vfs (self._o, options, vfstype, device, mountpoint)
1085
1086     def debug (self, subcmd, extraargs):
1087         u"""The "g.debug" command exposes some internals of
1088         "guestfsd" (the guestfs daemon) that runs inside the
1089         qemu subprocess.
1090         
1091         There is no comprehensive help for this command. You
1092         have to look at the file "daemon/debug.c" in the
1093         libguestfs source to find out what you can do.
1094         """
1095         return libguestfsmod.debug (self._o, subcmd, extraargs)
1096
1097     def lvremove (self, device):
1098         u"""Remove an LVM logical volume "device", where "device" is
1099         the path to the LV, such as "/dev/VG/LV".
1100         
1101         You can also remove all LVs in a volume group by
1102         specifying the VG name, "/dev/VG".
1103         """
1104         return libguestfsmod.lvremove (self._o, device)
1105
1106     def vgremove (self, vgname):
1107         u"""Remove an LVM volume group "vgname", (for example "VG").
1108         
1109         This also forcibly removes all logical volumes in the
1110         volume group (if any).
1111         """
1112         return libguestfsmod.vgremove (self._o, vgname)
1113
1114     def pvremove (self, device):
1115         u"""This wipes a physical volume "device" so that LVM will
1116         no longer recognise it.
1117         
1118         The implementation uses the "pvremove" command which
1119         refuses to wipe physical volumes that contain any volume
1120         groups, so you have to remove those first.
1121         """
1122         return libguestfsmod.pvremove (self._o, device)
1123
1124     def set_e2label (self, device, label):
1125         u"""This sets the ext2/3/4 filesystem label of the
1126         filesystem on "device" to "label". Filesystem labels are
1127         limited to 16 characters.
1128         
1129         You can use either "g.tune2fs_l" or "g.get_e2label" to
1130         return the existing label on a filesystem.
1131         """
1132         return libguestfsmod.set_e2label (self._o, device, label)
1133
1134     def get_e2label (self, device):
1135         u"""This returns the ext2/3/4 filesystem label of the
1136         filesystem on "device".
1137         """
1138         return libguestfsmod.get_e2label (self._o, device)
1139
1140     def set_e2uuid (self, device, uuid):
1141         u"""This sets the ext2/3/4 filesystem UUID of the filesystem
1142         on "device" to "uuid". The format of the UUID and
1143         alternatives such as "clear", "random" and "time" are
1144         described in the tune2fs(8) manpage.
1145         
1146         You can use either "g.tune2fs_l" or "g.get_e2uuid" to
1147         return the existing UUID of a filesystem.
1148         """
1149         return libguestfsmod.set_e2uuid (self._o, device, uuid)
1150
1151     def get_e2uuid (self, device):
1152         u"""This returns the ext2/3/4 filesystem UUID of the
1153         filesystem on "device".
1154         """
1155         return libguestfsmod.get_e2uuid (self._o, device)
1156
1157     def fsck (self, fstype, device):
1158         u"""This runs the filesystem checker (fsck) on "device"
1159         which should have filesystem type "fstype".
1160         
1161         The returned integer is the status. See fsck(8) for the
1162         list of status codes from "fsck".
1163         
1164         Notes:
1165         
1166         *   Multiple status codes can be summed together.
1167         
1168         *   A non-zero return code can mean "success", for
1169         example if errors have been corrected on the
1170         filesystem.
1171         
1172         *   Checking or repairing NTFS volumes is not supported
1173         (by linux-ntfs).
1174         
1175         This command is entirely equivalent to running "fsck -a
1176         -t fstype device".
1177         """
1178         return libguestfsmod.fsck (self._o, fstype, device)
1179
1180     def zero (self, device):
1181         u"""This command writes zeroes over the first few blocks of
1182         "device".
1183         
1184         How many blocks are zeroed isn't specified (but it's
1185         *not* enough to securely wipe the device). It should be
1186         sufficient to remove any partition tables, filesystem
1187         superblocks and so on.
1188         """
1189         return libguestfsmod.zero (self._o, device)
1190
1191     def grub_install (self, root, device):
1192         u"""This command installs GRUB (the Grand Unified
1193         Bootloader) on "device", with the root directory being
1194         "root".
1195         """
1196         return libguestfsmod.grub_install (self._o, root, device)
1197
1198     def cp (self, src, dest):
1199         u"""This copies a file from "src" to "dest" where "dest" is
1200         either a destination filename or destination directory.
1201         """
1202         return libguestfsmod.cp (self._o, src, dest)
1203
1204     def cp_a (self, src, dest):
1205         u"""This copies a file or directory from "src" to "dest"
1206         recursively using the "cp -a" command.
1207         """
1208         return libguestfsmod.cp_a (self._o, src, dest)
1209
1210     def mv (self, src, dest):
1211         u"""This moves a file from "src" to "dest" where "dest" is
1212         either a destination filename or destination directory.
1213         """
1214         return libguestfsmod.mv (self._o, src, dest)
1215
1216     def drop_caches (self, whattodrop):
1217         u"""This instructs the guest kernel to drop its page cache,
1218         and/or dentries and inode caches. The parameter
1219         "whattodrop" tells the kernel what precisely to drop,
1220         see <http://linux-mm.org/Drop_Caches>
1221         
1222         Setting "whattodrop" to 3 should drop everything.
1223         
1224         This automatically calls sync(2) before the operation,
1225         so that the maximum guest memory is freed.
1226         """
1227         return libguestfsmod.drop_caches (self._o, whattodrop)
1228
1229     def dmesg (self):
1230         u"""This returns the kernel messages ("dmesg" output) from
1231         the guest kernel. This is sometimes useful for extended
1232         debugging of problems.
1233         
1234         Another way to get the same information is to enable
1235         verbose messages with "g.set_verbose" or by setting the
1236         environment variable "LIBGUESTFS_DEBUG=1" before running
1237         the program.
1238         """
1239         return libguestfsmod.dmesg (self._o)
1240
1241     def ping_daemon (self):
1242         u"""This is a test probe into the guestfs daemon running
1243         inside the qemu subprocess. Calling this function checks
1244         that the daemon responds to the ping message, without
1245         affecting the daemon or attached block device(s) in any
1246         other way.
1247         """
1248         return libguestfsmod.ping_daemon (self._o)
1249
1250     def equal (self, file1, file2):
1251         u"""This compares the two files "file1" and "file2" and
1252         returns true if their content is exactly equal, or false
1253         otherwise.
1254         
1255         The external cmp(1) program is used for the comparison.
1256         """
1257         return libguestfsmod.equal (self._o, file1, file2)
1258
1259     def strings (self, path):
1260         u"""This runs the strings(1) command on a file and returns
1261         the list of printable strings found.
1262         
1263         This function returns a list of strings.
1264         
1265         Because of the message protocol, there is a transfer
1266         limit of somewhere between 2MB and 4MB. To transfer
1267         large files you should use FTP.
1268         """
1269         return libguestfsmod.strings (self._o, path)
1270
1271     def strings_e (self, encoding, path):
1272         u"""This is like the "g.strings" command, but allows you to
1273         specify the encoding.
1274         
1275         See the strings(1) manpage for the full list of
1276         encodings.
1277         
1278         Commonly useful encodings are "l" (lower case L) which
1279         will show strings inside Windows/x86 files.
1280         
1281         The returned strings are transcoded to UTF-8.
1282         
1283         This function returns a list of strings.
1284         
1285         Because of the message protocol, there is a transfer
1286         limit of somewhere between 2MB and 4MB. To transfer
1287         large files you should use FTP.
1288         """
1289         return libguestfsmod.strings_e (self._o, encoding, path)
1290
1291     def hexdump (self, path):
1292         u"""This runs "hexdump -C" on the given "path". The result
1293         is the human-readable, canonical hex dump of the file.
1294         
1295         Because of the message protocol, there is a transfer
1296         limit of somewhere between 2MB and 4MB. To transfer
1297         large files you should use FTP.
1298         """
1299         return libguestfsmod.hexdump (self._o, path)
1300