add-drive-opts: Correctly handle unreadable and unwritable files (RHBZ#747287).
[libguestfs.git] / erlang / examples / guestfs-erlang.pod
1 =encoding utf8
2
3 =head1 NAME
4
5 guestfs-erlang - How to use libguestfs from Erlang
6
7 =head1 SYNOPSIS
8
9  {ok, G} = guestfs:create(),
10  ok = guestfs:add_drive_opts(G, Disk,
11                              [{format, "raw"}, {readonly, true}]),
12  ok = guestfs:launch(G),
13  [Device] = guestfs:list_devices(G),
14  ok = guestfs:close(G).
15
16 =head1 DESCRIPTION
17
18 This manual page documents how to call libguestfs from the Erlang
19 programming language.  This page just documents the differences from
20 the C API and gives some examples.  If you are not familiar with using
21 libguestfs, you also need to read L<guestfs(3)>.
22
23 =head2 OPENING AND CLOSING THE HANDLE
24
25 The Erlang bindings are implemented using an external program called
26 C<erl-guestfs>.  This program must be on the current PATH, or else you
27 should specify the full path to the program:
28
29  {ok, G} = guestfs:create().
30
31  {ok, G} = guestfs:create("/path/to/erl-guestfs").
32
33 C<G> is the libguestfs handle which you should pass to other
34 functions.
35
36 To close the handle:
37
38  ok = guestfs:close(G).
39
40 =head2 FUNCTIONS WITH OPTIONAL ARGUMENTS
41
42 For functions that take optional arguments, the first arguments are
43 the non-optional ones.  The last argument is a list of tuples
44 supplying the remaining optional arguments.
45
46  ok = guestfs:add_drive_opts(G, Disk,
47                              [{format, "raw"}, {readonly, true}]).
48
49 If the last argument would be an empty list, you can also omit it:
50
51  ok = guestfs:add_drive_opts(G, Disk).
52
53 =head2 RETURN VALUES AND ERRORS
54
55 On success, most functions return a C<Result> term (which could be a
56 list, string, tuple etc.).  If there is nothing for the function to
57 return, then the atom C<ok> is returned.
58
59 On error, you would see one of the following tuples:
60
61 =over 4
62
63 =item C<{error, Msg, Errno}>
64
65 This indicates an ordinary error from the function.
66
67 C<Msg> is the error message (string) and C<Errno> is the Unix error
68 (integer).
69
70 C<Errno> can be zero.  See L<guestfs(3)/guestfs_last_errno>.
71
72 =item C<{unknown, Function}>
73
74 This indicates that the function you called is not known.  Generally
75 this means you are mixing C<erl-guestfs> from another version of
76 libguestfs, which you should not do.
77
78 C<Function> is the name of the unknown function.
79
80 =item C<{unknownarg, Arg}>
81
82 This indicates that you called a function with optional arguments,
83 with an unknown argument name.
84
85 C<Arg> is the name of the unknown argument.
86
87 =back
88
89 =head1 EXAMPLE 1: CREATE A DISK IMAGE
90
91 @EXAMPLE1@
92
93 =head1 EXAMPLE 2: INSPECT A VIRTUAL MACHINE DISK IMAGE
94
95 @EXAMPLE2@
96
97 =head1 SEE ALSO
98
99 L<guestfs(3)>,
100 L<guestfs-examples(3)>,
101 L<guestfs-java(3)>,
102 L<guestfs-ocaml(3)>,
103 L<guestfs-perl(3)>,
104 L<guestfs-python(3)>,
105 L<guestfs-recipes(1)>,
106 L<guestfs-ruby(3)>,
107 L<http://www.erlang.org/>.
108 L<http://libguestfs.org/>.
109
110 =head1 AUTHORS
111
112 Richard W.M. Jones (C<rjones at redhat dot com>)
113
114 =head1 COPYRIGHT
115
116 Copyright (C) 2011 Red Hat Inc. L<http://libguestfs.org/>
117
118 The examples in this manual page may be freely copied, modified and
119 distributed without any restrictions.
120
121 This library is free software; you can redistribute it and/or
122 modify it under the terms of the GNU Lesser General Public
123 License as published by the Free Software Foundation; either
124 version 2 of the License, or (at your option) any later version.
125
126 This library is distributed in the hope that it will be useful,
127 but WITHOUT ANY WARRANTY; without even the implied warranty of
128 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
129 Lesser General Public License for more details.
130
131 You should have received a copy of the GNU Lesser General Public
132 License along with this library; if not, write to the Free Software
133 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA