Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 125 lines (80 sloc) 3.211 kb
d6767da @msantos NIF interface to libvirt
authored
1
2 Erlang bindings to the libvirt virtualization API.
3
01a10bf @msantos Update the README
authored
4
5 ## ALTERNATIVES
6
7 An (almost) pure Erlang libvirt binding is available here:
8
9 <https://github.com/msantos/erlang-libvirt-remote>
10
11 This version uses the libvirtd remote procotol over a Unix socket.
12
13
570d18a @msantos Add a warning about libvirt
authored
14 ## WARNING
15
e636465 @msantos Use a non-blocking interface to libvirt
authored
16 The libvirt API is not safe. It is huge, inconsistent and error
17 prone.
18
19 The current implementation calls all libvirt functions in a thread
20 so the Erlang VM will not block. If libvirt blocks, the caller will
21 receive an error immediately ({error, eagain}). This means only one
22 call from a single Erlang VM into libvirt can be running at any time.
23
24 These bindings have not been heavily tested, are still under
25 development and will undergo many changes.
570d18a @msantos Add a warning about libvirt
authored
26
27
d6767da @msantos NIF interface to libvirt
authored
28 ## HOW TO BUILD IT
29
570d18a @msantos Add a warning about libvirt
authored
30 sudo apt-get install libvirt-dev libvirt-bin
d6767da @msantos NIF interface to libvirt
authored
31 make
32
33
34 ## HOW TO USE IT
35
36 ## EXAMPLES
37
a903fb6 @msantos Add an example for suspend/resume
authored
38 ### CREATING A DOMAIN
39
fefd843 @msantos Add an example
authored
40 start(Path) ->
41 {ok, Connect} = vert:open({connect, ""}),
42 {ok, XML} = file:read_file(Path),
43 {ok, Domain} = vert:define(Connect, {domain, XML}),
44 ok = vert:create(Domain),
45
46 Active = vert:resource(Connect, {domain, active}),
47 io:format("Active Domains: ~p~n", [Active]),
48
49 {ok, Connect, Domain}.
50
51 halt(Connect, Domain) ->
52 ok = vert:destroy(Domain),
53 ok = vert:close(Connect).
54
a903fb6 @msantos Add an example for suspend/resume
authored
55
56 ### SUSPENDING AND RESUMING A DOMAIN
57
58 This example is the Erlang equivalent of a Python script to manipulate a
59 running domain. The example is taken from:
60
01a10bf @msantos Update the README
authored
61 <http://www.ibm.com/developerworks/linux/library/l-libvirt/>
a903fb6 @msantos Add an example for suspend/resume
authored
62
63
64 -module(ex6).
65
66 %% Listing 6. Sample Python script for domain control (libvtest.py)
67 %%
68 %% import libvirt
69 %%
70 %% conn = libvirt.open('qemu:///system')
71 %%
72 %% for id in conn.listDomainsID():
73 %%
74 %% dom = conn.lookupByID(id)
75 %%
76 %% print "Dom %s State %s" % ( dom.name(), dom.info()[0] )
77 %%
78 %% dom.suspend()
79 %% print "Dom %s State %s (after suspend)" % ( dom.name(), dom.info()[0] )
80 %%
81 %% dom.resume()
82 %% print "Dom %s State %s (after resume)" % ( dom.name(), dom.info()[0] )
83 %%
84 %% dom.destroy()
85 %%
86 -export([start/0]).
87
88 start() ->
89 {ok, Connect} = vert:open(""),
90 {ok, DomainIDs} = vert:resource(Connect, {domain, active}),
91
92 [ states(Connect, DomainID) || DomainID <- DomainIDs ],
93
94 ok.
95
96 states(Connect, DomainID) ->
97 {ok, Domain} = vert:resource(Connect, {domain, {id, DomainID}}),
98 io:format("running: ~p~n", [info(Domain)]),
99
100 ok = vert:suspend(Domain),
101 io:format("suspend: ~p~n", [info(Domain)]),
102
103 ok = vert:resume(Domain),
104 io:format("resumed: ~p~n", [info(Domain)]),
105
106 ok = vert:destroy(Domain).
107
108 info(Domain) ->
109 Name = vert:get(Domain, name),
110 Info = vert:get(Domain, info),
111
112 [{name, Name}, {info, Info}].
113
114
d6767da @msantos NIF interface to libvirt
authored
115 ## TODO
116
f72a223 @msantos Add TODO's
authored
117 * tests: use the libvirt test driver and make a set of tests
118
119 * review the Erlang interface
120 * find examples of code in other languages using libvirt and discover
121 how awkward the Erlang interface is by porting them
122 * then of course document the interface
123
124
Something went wrong with that request. Please try again.