ruby-libvirt-catphish 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/COPYING +510 -0
- data/NEWS +141 -0
- data/README +219 -0
- data/README.rdoc +28 -0
- data/Rakefile +166 -0
- data/ext/libvirt/_libvirt.c +1033 -0
- data/ext/libvirt/common.c +490 -0
- data/ext/libvirt/common.h +285 -0
- data/ext/libvirt/connect.c +3501 -0
- data/ext/libvirt/connect.h +12 -0
- data/ext/libvirt/domain.c +5907 -0
- data/ext/libvirt/domain.h +11 -0
- data/ext/libvirt/extconf.h +392 -0
- data/ext/libvirt/extconf.rb +506 -0
- data/ext/libvirt/interface.c +200 -0
- data/ext/libvirt/interface.h +8 -0
- data/ext/libvirt/network.c +555 -0
- data/ext/libvirt/network.h +8 -0
- data/ext/libvirt/nodedevice.c +299 -0
- data/ext/libvirt/nodedevice.h +8 -0
- data/ext/libvirt/nwfilter.c +138 -0
- data/ext/libvirt/nwfilter.h +8 -0
- data/ext/libvirt/secret.c +268 -0
- data/ext/libvirt/secret.h +8 -0
- data/ext/libvirt/storage.c +1022 -0
- data/ext/libvirt/storage.h +6 -0
- data/ext/libvirt/stream.c +392 -0
- data/ext/libvirt/stream.h +9 -0
- data/lib/libvirt.rb +40 -0
- data/tests/test_conn.rb +818 -0
- data/tests/test_domain.rb +1443 -0
- data/tests/test_interface.rb +100 -0
- data/tests/test_network.rb +175 -0
- data/tests/test_nodedevice.rb +90 -0
- data/tests/test_nwfilter.rb +60 -0
- data/tests/test_open.rb +250 -0
- data/tests/test_secret.rb +114 -0
- data/tests/test_storage.rb +527 -0
- data/tests/test_stream.rb +171 -0
- data/tests/test_utils.rb +254 -0
- metadata +84 -0
@@ -0,0 +1,1033 @@
|
|
1
|
+
/*
|
2
|
+
* libvirt.c: Ruby bindings for libvirt
|
3
|
+
*
|
4
|
+
* Copyright (C) 2007,2010 Red Hat Inc.
|
5
|
+
* Copyright (C) 2013-2016 Chris Lalancette <clalancette@gmail.com>
|
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.1 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
20
|
+
*
|
21
|
+
* Author: David Lutterkort <dlutter@redhat.com>
|
22
|
+
*/
|
23
|
+
|
24
|
+
#include <ruby.h>
|
25
|
+
#include <libvirt/libvirt.h>
|
26
|
+
#include <libvirt/virterror.h>
|
27
|
+
#if HAVE_VIRDOMAINLXCENTERSECURITYLABEL
|
28
|
+
#include <libvirt/libvirt-lxc.h>
|
29
|
+
#endif
|
30
|
+
#include "extconf.h"
|
31
|
+
#include "common.h"
|
32
|
+
#include "storage.h"
|
33
|
+
#include "connect.h"
|
34
|
+
#include "network.h"
|
35
|
+
#include "nodedevice.h"
|
36
|
+
#include "secret.h"
|
37
|
+
#include "nwfilter.h"
|
38
|
+
#include "interface.h"
|
39
|
+
#include "domain.h"
|
40
|
+
#include "stream.h"
|
41
|
+
|
42
|
+
static VALUE c_libvirt_version;
|
43
|
+
|
44
|
+
VALUE m_libvirt;
|
45
|
+
|
46
|
+
/* define additional errors here */
|
47
|
+
static VALUE e_ConnectionError; /* ConnectionError - error during connection establishment */
|
48
|
+
VALUE e_DefinitionError;
|
49
|
+
VALUE e_RetrieveError;
|
50
|
+
VALUE e_Error;
|
51
|
+
VALUE e_NoSupportError;
|
52
|
+
|
53
|
+
/* custom error function to suppress libvirt printing to stderr */
|
54
|
+
static void rubyLibvirtErrorFunc(void *RUBY_LIBVIRT_UNUSED(userdata),
|
55
|
+
virErrorPtr RUBY_LIBVIRT_UNUSED(err))
|
56
|
+
{
|
57
|
+
}
|
58
|
+
|
59
|
+
/*
|
60
|
+
* call-seq:
|
61
|
+
* Libvirt::version(type=nil) -> [ libvirt_version, type_version ]
|
62
|
+
*
|
63
|
+
* Call virGetVersion[http://www.libvirt.org/html/libvirt-libvirt-host.html#virGetVersion]
|
64
|
+
* to get the version of libvirt and of the hypervisor TYPE.
|
65
|
+
*/
|
66
|
+
static VALUE libvirt_version(int argc, VALUE *argv,
|
67
|
+
VALUE RUBY_LIBVIRT_UNUSED(m))
|
68
|
+
{
|
69
|
+
unsigned long libVer, typeVer;
|
70
|
+
VALUE type, result, rargv[2];
|
71
|
+
int r;
|
72
|
+
|
73
|
+
rb_scan_args(argc, argv, "01", &type);
|
74
|
+
|
75
|
+
r = virGetVersion(&libVer, ruby_libvirt_get_cstring_or_null(type),
|
76
|
+
&typeVer);
|
77
|
+
ruby_libvirt_raise_error_if(r < 0, rb_eArgError, "virGetVersion", NULL);
|
78
|
+
|
79
|
+
result = rb_ary_new2(2);
|
80
|
+
rargv[0] = rb_str_new2("libvirt");
|
81
|
+
rargv[1] = ULONG2NUM(libVer);
|
82
|
+
rb_ary_store(result, 0, rb_class_new_instance(2, rargv, c_libvirt_version));
|
83
|
+
rargv[0] = type;
|
84
|
+
rargv[1] = ULONG2NUM(typeVer);
|
85
|
+
rb_ary_store(result, 1, rb_class_new_instance(2, rargv, c_libvirt_version));
|
86
|
+
return result;
|
87
|
+
}
|
88
|
+
|
89
|
+
/*
|
90
|
+
* call-seq:
|
91
|
+
* Libvirt::open(uri=nil) -> Libvirt::Connect
|
92
|
+
*
|
93
|
+
* Call virConnectOpen[http://www.libvirt.org/html/libvirt-libvirt-host.html#virConnectOpen]
|
94
|
+
* to open a connection to a URL.
|
95
|
+
*/
|
96
|
+
static VALUE libvirt_open(int argc, VALUE *argv, VALUE RUBY_LIBVIRT_UNUSED(m))
|
97
|
+
{
|
98
|
+
VALUE uri;
|
99
|
+
virConnectPtr conn;
|
100
|
+
|
101
|
+
rb_scan_args(argc, argv, "01", &uri);
|
102
|
+
|
103
|
+
conn = virConnectOpen(ruby_libvirt_get_cstring_or_null(uri));
|
104
|
+
ruby_libvirt_raise_error_if(conn == NULL, e_ConnectionError,
|
105
|
+
"virConnectOpen", NULL);
|
106
|
+
|
107
|
+
return ruby_libvirt_connect_new(conn);
|
108
|
+
}
|
109
|
+
|
110
|
+
/*
|
111
|
+
* call-seq:
|
112
|
+
* Libvirt::open_read_only(uri=nil) -> Libvirt::Connect
|
113
|
+
*
|
114
|
+
* Call virConnectOpenReadOnly[http://www.libvirt.org/html/libvirt-libvirt-host.html#virConnectOpenReadOnly]
|
115
|
+
* to open a read-only connection to a URL.
|
116
|
+
*/
|
117
|
+
static VALUE libvirt_open_read_only(int argc, VALUE *argv,
|
118
|
+
VALUE RUBY_LIBVIRT_UNUSED(m))
|
119
|
+
{
|
120
|
+
VALUE uri;
|
121
|
+
virConnectPtr conn;
|
122
|
+
|
123
|
+
rb_scan_args(argc, argv, "01", &uri);
|
124
|
+
|
125
|
+
conn = virConnectOpenReadOnly(ruby_libvirt_get_cstring_or_null(uri));
|
126
|
+
|
127
|
+
ruby_libvirt_raise_error_if(conn == NULL, e_ConnectionError,
|
128
|
+
"virConnectOpenReadOnly", NULL);
|
129
|
+
|
130
|
+
return ruby_libvirt_connect_new(conn);
|
131
|
+
}
|
132
|
+
|
133
|
+
#if HAVE_VIRCONNECTOPENAUTH
|
134
|
+
static int libvirt_auth_callback_wrapper(virConnectCredentialPtr cred,
|
135
|
+
unsigned int ncred, void *cbdata)
|
136
|
+
{
|
137
|
+
VALUE userdata, newcred, result;
|
138
|
+
unsigned int i;
|
139
|
+
|
140
|
+
userdata = (VALUE)cbdata;
|
141
|
+
|
142
|
+
if (!rb_block_given_p()) {
|
143
|
+
rb_raise(rb_eRuntimeError, "No block given, this should never happen!\n");
|
144
|
+
}
|
145
|
+
|
146
|
+
for (i = 0; i < ncred; i++) {
|
147
|
+
newcred = rb_hash_new();
|
148
|
+
|
149
|
+
rb_hash_aset(newcred, rb_str_new2("type"), INT2NUM(cred[i].type));
|
150
|
+
rb_hash_aset(newcred, rb_str_new2("prompt"),
|
151
|
+
rb_str_new2(cred[i].prompt));
|
152
|
+
if (cred[i].challenge) {
|
153
|
+
rb_hash_aset(newcred, rb_str_new2("challenge"),
|
154
|
+
rb_str_new2(cred[i].challenge));
|
155
|
+
}
|
156
|
+
else {
|
157
|
+
rb_hash_aset(newcred, rb_str_new2("challenge"), Qnil);
|
158
|
+
}
|
159
|
+
if (cred[i].defresult) {
|
160
|
+
rb_hash_aset(newcred, rb_str_new2("defresult"),
|
161
|
+
rb_str_new2(cred[i].defresult));
|
162
|
+
}
|
163
|
+
else {
|
164
|
+
rb_hash_aset(newcred, rb_str_new2("defresult"), Qnil);
|
165
|
+
}
|
166
|
+
rb_hash_aset(newcred, rb_str_new2("result"), Qnil);
|
167
|
+
rb_hash_aset(newcred, rb_str_new2("userdata"), userdata);
|
168
|
+
|
169
|
+
result = rb_yield(newcred);
|
170
|
+
if (NIL_P(result)) {
|
171
|
+
cred[i].result = NULL;
|
172
|
+
cred[i].resultlen = 0;
|
173
|
+
}
|
174
|
+
else {
|
175
|
+
cred[i].result = strdup(StringValueCStr(result));
|
176
|
+
cred[i].resultlen = strlen(cred[i].result);
|
177
|
+
}
|
178
|
+
}
|
179
|
+
|
180
|
+
return 0;
|
181
|
+
}
|
182
|
+
|
183
|
+
/*
|
184
|
+
* call-seq:
|
185
|
+
* Libvirt::open_auth(uri=nil, credlist=nil, userdata=nil, flags=0) {|...| authentication block} -> Libvirt::Connect
|
186
|
+
*
|
187
|
+
* Call virConnectOpenAuth[http://www.libvirt.org/html/libvirt-libvirt-host.html#virConnectOpenAuth]
|
188
|
+
* to open a connection to a libvirt URI, with a possible authentication block.
|
189
|
+
* If an authentication block is desired, then credlist should be an array that
|
190
|
+
* specifies which credentials the authentication block is willing to support;
|
191
|
+
* the full list is available at http://libvirt.org/html/libvirt-libvirt.html#virConnectCredentialType.
|
192
|
+
* If userdata is not nil and an authentication block is given, userdata will
|
193
|
+
* be passed unaltered into the authentication block. The flags parameter
|
194
|
+
* controls how to open connection. The only options currently available for
|
195
|
+
* flags are 0 for a read/write connection and Libvirt::CONNECT_RO for a
|
196
|
+
* read-only connection.
|
197
|
+
*
|
198
|
+
* If the credlist is not empty, and an authentication block is given, the
|
199
|
+
* authentication block will be called once for each credential necessary
|
200
|
+
* to complete the authentication. The authentication block will be passed a
|
201
|
+
* single parameter, which is a hash of values containing information necessary
|
202
|
+
* to complete authentication. This hash contains 5 elements:
|
203
|
+
*
|
204
|
+
* type - the type of credential to be examined
|
205
|
+
*
|
206
|
+
* prompt - a suggested prompt to show to the user
|
207
|
+
*
|
208
|
+
* challenge - any additional challenge information
|
209
|
+
*
|
210
|
+
* defresult - a default result to use if credentials could not be obtained
|
211
|
+
*
|
212
|
+
* userdata - the userdata passed into open_auth initially
|
213
|
+
*
|
214
|
+
* The authentication block should return the result of collecting the
|
215
|
+
* information; these results will then be sent to libvirt for authentication.
|
216
|
+
*/
|
217
|
+
static VALUE libvirt_open_auth(int argc, VALUE *argv,
|
218
|
+
VALUE RUBY_LIBVIRT_UNUSED(m))
|
219
|
+
{
|
220
|
+
virConnectAuthPtr auth;
|
221
|
+
VALUE uri, credlist, userdata, flags, tmp;
|
222
|
+
virConnectPtr conn;
|
223
|
+
unsigned int i;
|
224
|
+
|
225
|
+
rb_scan_args(argc, argv, "04", &uri, &credlist, &userdata, &flags);
|
226
|
+
|
227
|
+
if (rb_block_given_p()) {
|
228
|
+
auth = alloca(sizeof(virConnectAuth));
|
229
|
+
|
230
|
+
if (TYPE(credlist) == T_NIL) {
|
231
|
+
auth->ncredtype = 0;
|
232
|
+
}
|
233
|
+
else if (TYPE(credlist) == T_ARRAY) {
|
234
|
+
auth->ncredtype = RARRAY_LEN(credlist);
|
235
|
+
}
|
236
|
+
else {
|
237
|
+
rb_raise(rb_eTypeError,
|
238
|
+
"wrong argument type (expected Array or nil)");
|
239
|
+
}
|
240
|
+
auth->credtype = NULL;
|
241
|
+
if (auth->ncredtype > 0) {
|
242
|
+
auth->credtype = alloca(sizeof(int) * auth->ncredtype);
|
243
|
+
|
244
|
+
for (i = 0; i < auth->ncredtype; i++) {
|
245
|
+
tmp = rb_ary_entry(credlist, i);
|
246
|
+
auth->credtype[i] = NUM2INT(tmp);
|
247
|
+
}
|
248
|
+
}
|
249
|
+
|
250
|
+
auth->cb = libvirt_auth_callback_wrapper;
|
251
|
+
auth->cbdata = (void *)userdata;
|
252
|
+
}
|
253
|
+
else {
|
254
|
+
auth = virConnectAuthPtrDefault;
|
255
|
+
}
|
256
|
+
|
257
|
+
conn = virConnectOpenAuth(ruby_libvirt_get_cstring_or_null(uri), auth,
|
258
|
+
ruby_libvirt_value_to_uint(flags));
|
259
|
+
|
260
|
+
ruby_libvirt_raise_error_if(conn == NULL, e_ConnectionError,
|
261
|
+
"virConnectOpenAuth", NULL);
|
262
|
+
|
263
|
+
return ruby_libvirt_connect_new(conn);
|
264
|
+
}
|
265
|
+
#endif
|
266
|
+
|
267
|
+
#if HAVE_VIREVENTREGISTERIMPL
|
268
|
+
static VALUE add_handle, update_handle, remove_handle;
|
269
|
+
static VALUE add_timeout, update_timeout, remove_timeout;
|
270
|
+
|
271
|
+
/*
|
272
|
+
* call-seq:
|
273
|
+
* Libvirt::event_invoke_handle_callback(handle, fd, events, opaque) -> Qnil
|
274
|
+
*
|
275
|
+
* Unlike most of the other functions in the ruby-libvirt bindings, this one
|
276
|
+
* does not directly correspond to a libvirt API function. Instead, this
|
277
|
+
* module method (and event_invoke_timeout_callback) are meant to be called
|
278
|
+
* when there is an event of interest to libvirt on one of the file descriptors
|
279
|
+
* that libvirt uses. The application is notified of the file descriptors
|
280
|
+
* that libvirt uses via the callbacks from Libvirt::event_register_impl. When
|
281
|
+
* there is an event of interest, the application must call
|
282
|
+
* event_invoke_timeout_callback to ensure proper operation.
|
283
|
+
*
|
284
|
+
* Libvirt::event_invoke_handle_callback takes 4 arguments:
|
285
|
+
*
|
286
|
+
* handle - an application specific handle ID. This can be any integer, but must be unique from all other libvirt handles in the application.
|
287
|
+
*
|
288
|
+
* fd - the file descriptor of interest. This was given to the application as a callback to add_handle of Libvirt::event_register_impl
|
289
|
+
*
|
290
|
+
* events - the events that have occured on the fd. Note that the events are libvirt specific, and are some combination of Libvirt::EVENT_HANDLE_READABLE, Libvirt::EVENT_HANDLE_WRITABLE, Libvirt::EVENT_HANDLE_ERROR, Libvirt::EVENT_HANDLE_HANGUP. To notify libvirt of more than one event at a time, these values should be logically OR'ed together.
|
291
|
+
*
|
292
|
+
* opaque - the opaque data passed from libvirt during the Libvirt::event_register_impl add_handle callback. To ensure proper operation this data must be passed through to event_invoke_handle_callback without modification.
|
293
|
+
*/
|
294
|
+
static VALUE libvirt_event_invoke_handle_callback(VALUE RUBY_LIBVIRT_UNUSED(m),
|
295
|
+
VALUE handle, VALUE fd,
|
296
|
+
VALUE events, VALUE opaque)
|
297
|
+
{
|
298
|
+
virEventHandleCallback cb;
|
299
|
+
void *op;
|
300
|
+
VALUE libvirt_cb, libvirt_opaque;
|
301
|
+
|
302
|
+
Check_Type(opaque, T_HASH);
|
303
|
+
|
304
|
+
libvirt_cb = rb_hash_aref(opaque, rb_str_new2("libvirt_cb"));
|
305
|
+
|
306
|
+
/* This is equivalent to Data_Get_Struct; I reproduce it here because
|
307
|
+
* I don't want the additional type-cast that Data_Get_Struct does
|
308
|
+
*/
|
309
|
+
Check_Type(libvirt_cb, T_DATA);
|
310
|
+
cb = DATA_PTR(libvirt_cb);
|
311
|
+
|
312
|
+
if (cb) {
|
313
|
+
libvirt_opaque = rb_hash_aref(opaque, rb_str_new2("opaque"));
|
314
|
+
Data_Get_Struct(libvirt_opaque, void *, op);
|
315
|
+
cb(NUM2INT(handle), NUM2INT(fd), NUM2INT(events), op);
|
316
|
+
}
|
317
|
+
|
318
|
+
return Qnil;
|
319
|
+
}
|
320
|
+
|
321
|
+
/*
|
322
|
+
* call-seq:
|
323
|
+
* Libvirt::event_invoke_timeout_callback(timer, opaque) -> Qnil
|
324
|
+
*
|
325
|
+
* Unlike most of the other functions in the ruby-libvirt bindings, this one
|
326
|
+
* does not directly correspond to a libvirt API function. Instead, this
|
327
|
+
* module method (and event_invoke_handle_callback) are meant to be called
|
328
|
+
* when there is a timeout of interest to libvirt. The application is
|
329
|
+
* notified of the timers that libvirt uses via the callbacks from
|
330
|
+
* Libvirt::event_register_impl. When a timeout expires, the application must
|
331
|
+
* call event_invoke_timeout_callback to ensure proper operation.
|
332
|
+
*
|
333
|
+
* Libvirt::event_invoke_timeout_callback takes 2 arguments:
|
334
|
+
*
|
335
|
+
* handle - an application specific timer ID. This can be any integer, but must be unique from all other libvirt timers in the application.
|
336
|
+
*
|
337
|
+
* opaque - the opaque data passed from libvirt during the Libvirt::event_register_impl add_handle callback. To ensure proper operation this data must be passed through to event_invoke_handle_callback without modification.
|
338
|
+
*/
|
339
|
+
static VALUE libvirt_event_invoke_timeout_callback(VALUE RUBY_LIBVIRT_UNUSED(m),
|
340
|
+
VALUE timer, VALUE opaque)
|
341
|
+
{
|
342
|
+
virEventTimeoutCallback cb;
|
343
|
+
void *op;
|
344
|
+
VALUE libvirt_cb, libvirt_opaque;
|
345
|
+
|
346
|
+
Check_Type(opaque, T_HASH);
|
347
|
+
|
348
|
+
libvirt_cb = rb_hash_aref(opaque, rb_str_new2("libvirt_cb"));
|
349
|
+
|
350
|
+
/* This is equivalent to Data_Get_Struct; I reproduce it here because
|
351
|
+
* I don't want the additional type-cast that Data_Get_Struct does
|
352
|
+
*/
|
353
|
+
Check_Type(libvirt_cb, T_DATA);
|
354
|
+
cb = DATA_PTR(libvirt_cb);
|
355
|
+
|
356
|
+
if (cb) {
|
357
|
+
libvirt_opaque = rb_hash_aref(opaque, rb_str_new2("opaque"));
|
358
|
+
Data_Get_Struct(libvirt_opaque, void *, op);
|
359
|
+
cb(NUM2INT(timer), op);
|
360
|
+
}
|
361
|
+
|
362
|
+
return Qnil;
|
363
|
+
}
|
364
|
+
|
365
|
+
static int internal_add_handle_func(int fd, int events,
|
366
|
+
virEventHandleCallback cb, void *opaque,
|
367
|
+
virFreeCallback ff)
|
368
|
+
{
|
369
|
+
VALUE rubyargs, res;
|
370
|
+
|
371
|
+
rubyargs = rb_hash_new();
|
372
|
+
rb_hash_aset(rubyargs, rb_str_new2("libvirt_cb"),
|
373
|
+
Data_Wrap_Struct(rb_class_of(add_handle), NULL, NULL, cb));
|
374
|
+
rb_hash_aset(rubyargs, rb_str_new2("opaque"),
|
375
|
+
Data_Wrap_Struct(rb_class_of(add_handle), NULL, NULL, opaque));
|
376
|
+
rb_hash_aset(rubyargs, rb_str_new2("free_func"),
|
377
|
+
Data_Wrap_Struct(rb_class_of(add_handle), NULL, NULL, ff));
|
378
|
+
|
379
|
+
/* call out to the ruby object */
|
380
|
+
if (strcmp(rb_obj_classname(add_handle), "Symbol") == 0) {
|
381
|
+
res = rb_funcall(rb_class_of(add_handle), rb_to_id(add_handle), 3,
|
382
|
+
INT2NUM(fd), INT2NUM(events), rubyargs);
|
383
|
+
}
|
384
|
+
else if (strcmp(rb_obj_classname(add_handle), "Proc") == 0) {
|
385
|
+
res = rb_funcall(add_handle, rb_intern("call"), 3, INT2NUM(fd),
|
386
|
+
INT2NUM(events), rubyargs);
|
387
|
+
}
|
388
|
+
else {
|
389
|
+
rb_raise(rb_eTypeError,
|
390
|
+
"wrong add handle callback argument type (expected Symbol or Proc)");
|
391
|
+
}
|
392
|
+
|
393
|
+
if (TYPE(res) != T_FIXNUM) {
|
394
|
+
rb_raise(rb_eTypeError,
|
395
|
+
"expected integer return from add_handle callback");
|
396
|
+
}
|
397
|
+
|
398
|
+
return NUM2INT(res);
|
399
|
+
}
|
400
|
+
|
401
|
+
static void internal_update_handle_func(int watch, int event)
|
402
|
+
{
|
403
|
+
/* call out to the ruby object */
|
404
|
+
if (strcmp(rb_obj_classname(update_handle), "Symbol") == 0) {
|
405
|
+
rb_funcall(rb_class_of(update_handle), rb_to_id(update_handle), 2,
|
406
|
+
INT2NUM(watch), INT2NUM(event));
|
407
|
+
}
|
408
|
+
else if (strcmp(rb_obj_classname(update_handle), "Proc") == 0) {
|
409
|
+
rb_funcall(update_handle, rb_intern("call"), 2, INT2NUM(watch),
|
410
|
+
INT2NUM(event));
|
411
|
+
}
|
412
|
+
else {
|
413
|
+
rb_raise(rb_eTypeError,
|
414
|
+
"wrong update handle callback argument type (expected Symbol or Proc)");
|
415
|
+
}
|
416
|
+
}
|
417
|
+
|
418
|
+
static int internal_remove_handle_func(int watch)
|
419
|
+
{
|
420
|
+
VALUE res, libvirt_opaque, ff;
|
421
|
+
virFreeCallback ff_cb;
|
422
|
+
void *op;
|
423
|
+
|
424
|
+
/* call out to the ruby object */
|
425
|
+
if (strcmp(rb_obj_classname(remove_handle), "Symbol") == 0) {
|
426
|
+
res = rb_funcall(rb_class_of(remove_handle), rb_to_id(remove_handle),
|
427
|
+
1, INT2NUM(watch));
|
428
|
+
}
|
429
|
+
else if (strcmp(rb_obj_classname(remove_handle), "Proc") == 0) {
|
430
|
+
res = rb_funcall(remove_handle, rb_intern("call"), 1, INT2NUM(watch));
|
431
|
+
}
|
432
|
+
else {
|
433
|
+
rb_raise(rb_eTypeError,
|
434
|
+
"wrong remove handle callback argument type (expected Symbol or Proc)");
|
435
|
+
}
|
436
|
+
|
437
|
+
if (TYPE(res) != T_HASH) {
|
438
|
+
rb_raise(rb_eTypeError,
|
439
|
+
"expected opaque hash returned from remove_handle callback");
|
440
|
+
}
|
441
|
+
|
442
|
+
ff = rb_hash_aref(res, rb_str_new2("free_func"));
|
443
|
+
if (!NIL_P(ff)) {
|
444
|
+
/* This is equivalent to Data_Get_Struct; I reproduce it here because
|
445
|
+
* I don't want the additional type-cast that Data_Get_Struct does
|
446
|
+
*/
|
447
|
+
Check_Type(ff, T_DATA);
|
448
|
+
ff_cb = DATA_PTR(ff);
|
449
|
+
if (ff_cb) {
|
450
|
+
libvirt_opaque = rb_hash_aref(res, rb_str_new2("opaque"));
|
451
|
+
Data_Get_Struct(libvirt_opaque, void *, op);
|
452
|
+
|
453
|
+
(*ff_cb)(op);
|
454
|
+
}
|
455
|
+
}
|
456
|
+
|
457
|
+
return 0;
|
458
|
+
}
|
459
|
+
|
460
|
+
static int internal_add_timeout_func(int interval, virEventTimeoutCallback cb,
|
461
|
+
void *opaque, virFreeCallback ff)
|
462
|
+
{
|
463
|
+
VALUE rubyargs, res;
|
464
|
+
|
465
|
+
rubyargs = rb_hash_new();
|
466
|
+
|
467
|
+
rb_hash_aset(rubyargs, rb_str_new2("libvirt_cb"),
|
468
|
+
Data_Wrap_Struct(rb_class_of(add_timeout), NULL, NULL, cb));
|
469
|
+
rb_hash_aset(rubyargs, rb_str_new2("opaque"),
|
470
|
+
Data_Wrap_Struct(rb_class_of(add_timeout), NULL, NULL,
|
471
|
+
opaque));
|
472
|
+
rb_hash_aset(rubyargs, rb_str_new2("free_func"),
|
473
|
+
Data_Wrap_Struct(rb_class_of(add_timeout), NULL, NULL, ff));
|
474
|
+
|
475
|
+
/* call out to the ruby object */
|
476
|
+
if (strcmp(rb_obj_classname(add_timeout), "Symbol") == 0) {
|
477
|
+
res = rb_funcall(rb_class_of(add_timeout), rb_to_id(add_timeout), 2,
|
478
|
+
INT2NUM(interval), rubyargs);
|
479
|
+
}
|
480
|
+
else if (strcmp(rb_obj_classname(add_timeout), "Proc") == 0) {
|
481
|
+
res = rb_funcall(add_timeout, rb_intern("call"), 2, INT2NUM(interval),
|
482
|
+
rubyargs);
|
483
|
+
}
|
484
|
+
else {
|
485
|
+
rb_raise(rb_eTypeError,
|
486
|
+
"wrong add timeout callback argument type (expected Symbol or Proc)");
|
487
|
+
}
|
488
|
+
|
489
|
+
if (TYPE(res) != T_FIXNUM) {
|
490
|
+
rb_raise(rb_eTypeError,
|
491
|
+
"expected integer return from add_timeout callback");
|
492
|
+
}
|
493
|
+
|
494
|
+
return NUM2INT(res);
|
495
|
+
}
|
496
|
+
|
497
|
+
static void internal_update_timeout_func(int timer, int timeout)
|
498
|
+
{
|
499
|
+
/* call out to the ruby object */
|
500
|
+
if (strcmp(rb_obj_classname(update_timeout), "Symbol") == 0) {
|
501
|
+
rb_funcall(rb_class_of(update_timeout), rb_to_id(update_timeout), 2,
|
502
|
+
INT2NUM(timer), INT2NUM(timeout));
|
503
|
+
}
|
504
|
+
else if (strcmp(rb_obj_classname(update_timeout), "Proc") == 0) {
|
505
|
+
rb_funcall(update_timeout, rb_intern("call"), 2, INT2NUM(timer),
|
506
|
+
INT2NUM(timeout));
|
507
|
+
}
|
508
|
+
else {
|
509
|
+
rb_raise(rb_eTypeError,
|
510
|
+
"wrong update timeout callback argument type (expected Symbol or Proc)");
|
511
|
+
}
|
512
|
+
}
|
513
|
+
|
514
|
+
static int internal_remove_timeout_func(int timer)
|
515
|
+
{
|
516
|
+
VALUE res, libvirt_opaque, ff;
|
517
|
+
virFreeCallback ff_cb;
|
518
|
+
void *op;
|
519
|
+
|
520
|
+
/* call out to the ruby object */
|
521
|
+
if (strcmp(rb_obj_classname(remove_timeout), "Symbol") == 0) {
|
522
|
+
res = rb_funcall(rb_class_of(remove_timeout), rb_to_id(remove_timeout),
|
523
|
+
1, INT2NUM(timer));
|
524
|
+
}
|
525
|
+
else if (strcmp(rb_obj_classname(remove_timeout), "Proc") == 0) {
|
526
|
+
res = rb_funcall(remove_timeout, rb_intern("call"), 1, INT2NUM(timer));
|
527
|
+
}
|
528
|
+
else {
|
529
|
+
rb_raise(rb_eTypeError,
|
530
|
+
"wrong remove timeout callback argument type (expected Symbol or Proc)");
|
531
|
+
}
|
532
|
+
|
533
|
+
if (TYPE(res) != T_HASH) {
|
534
|
+
rb_raise(rb_eTypeError,
|
535
|
+
"expected opaque hash returned from remove_timeout callback");
|
536
|
+
}
|
537
|
+
|
538
|
+
ff = rb_hash_aref(res, rb_str_new2("free_func"));
|
539
|
+
if (!NIL_P(ff)) {
|
540
|
+
/* This is equivalent to Data_Get_Struct; I reproduce it here because
|
541
|
+
* I don't want the additional type-cast that Data_Get_Struct does
|
542
|
+
*/
|
543
|
+
Check_Type(ff, T_DATA);
|
544
|
+
ff_cb = DATA_PTR(ff);
|
545
|
+
if (ff_cb) {
|
546
|
+
libvirt_opaque = rb_hash_aref(res, rb_str_new2("opaque"));
|
547
|
+
Data_Get_Struct(libvirt_opaque, void *, op);
|
548
|
+
|
549
|
+
(*ff_cb)(op);
|
550
|
+
}
|
551
|
+
}
|
552
|
+
|
553
|
+
return 0;
|
554
|
+
}
|
555
|
+
|
556
|
+
#define set_event_func_or_null(type) \
|
557
|
+
do { \
|
558
|
+
if (NIL_P(type)) { \
|
559
|
+
type##_temp = NULL; \
|
560
|
+
} \
|
561
|
+
else { \
|
562
|
+
type##_temp = internal_##type##_func; \
|
563
|
+
} \
|
564
|
+
} while(0)
|
565
|
+
|
566
|
+
static int is_symbol_proc_or_nil(VALUE handle)
|
567
|
+
{
|
568
|
+
if (NIL_P(handle)) {
|
569
|
+
return 1;
|
570
|
+
}
|
571
|
+
return ruby_libvirt_is_symbol_or_proc(handle);
|
572
|
+
}
|
573
|
+
|
574
|
+
/*
|
575
|
+
* call-seq:
|
576
|
+
* Libvirt::event_register_impl(add_handle=nil, update_handle=nil, remove_handle=nil, add_timeout=nil, update_timeout=nil, remove_timeout=nil) -> Qnil
|
577
|
+
*
|
578
|
+
* Call virEventRegisterImpl[http://www.libvirt.org/html/libvirt-libvirt-event.html#virEventRegisterImpl]
|
579
|
+
* to register callback handlers for handles and timeouts. These handles and
|
580
|
+
* timeouts are used as part of the libvirt infrastructure for generating
|
581
|
+
* domain events. Each callback must be a Symbol (that is the name of a
|
582
|
+
* method to callback), a Proc, or nil (to disable the callback). In the
|
583
|
+
* end-user application program, these callbacks are typically used to track
|
584
|
+
* the file descriptors or timers that libvirt is interested in (and is intended
|
585
|
+
* to be integrated into the "main loop" of a UI program). The individual
|
586
|
+
* callbacks will be given a certain number of arguments, and must return
|
587
|
+
* certain values. Those arguments and return types are:
|
588
|
+
*
|
589
|
+
* add_handle(fd, events, opaque) => Fixnum
|
590
|
+
*
|
591
|
+
* update_handle(handleID, event) => nil
|
592
|
+
*
|
593
|
+
* remove_handle(handleID) => opaque data from add_handle
|
594
|
+
*
|
595
|
+
* add_timeout(interval, opaque) => Fixnum
|
596
|
+
*
|
597
|
+
* update_timeout(timerID, timeout) => nil
|
598
|
+
*
|
599
|
+
* remove_timeout(timerID) => opaque data from add_timeout
|
600
|
+
*
|
601
|
+
* Any arguments marked as "opaque" must be accepted from the library and saved
|
602
|
+
* without modification. The values passed to the callbacks are meant to be
|
603
|
+
* passed to the event_invoke_handle_callback and event_invoke_timeout_callback
|
604
|
+
* module methods; see the documentation for those methods for more details.
|
605
|
+
*/
|
606
|
+
static VALUE libvirt_conn_event_register_impl(int argc, VALUE *argv,
|
607
|
+
VALUE RUBY_LIBVIRT_UNUSED(c))
|
608
|
+
{
|
609
|
+
virEventAddHandleFunc add_handle_temp;
|
610
|
+
virEventUpdateHandleFunc update_handle_temp;
|
611
|
+
virEventRemoveHandleFunc remove_handle_temp;
|
612
|
+
virEventAddTimeoutFunc add_timeout_temp;
|
613
|
+
virEventUpdateTimeoutFunc update_timeout_temp;
|
614
|
+
virEventRemoveTimeoutFunc remove_timeout_temp;
|
615
|
+
|
616
|
+
/*
|
617
|
+
* subtle; we put the arguments (callbacks) directly into the global
|
618
|
+
* add_handle, update_handle, etc. variables. Then we register the
|
619
|
+
* internal functions as the callbacks with virEventRegisterImpl
|
620
|
+
*/
|
621
|
+
rb_scan_args(argc, argv, "06", &add_handle, &update_handle, &remove_handle,
|
622
|
+
&add_timeout, &update_timeout, &remove_timeout);
|
623
|
+
|
624
|
+
if (!is_symbol_proc_or_nil(add_handle) ||
|
625
|
+
!is_symbol_proc_or_nil(update_handle) ||
|
626
|
+
!is_symbol_proc_or_nil(remove_handle) ||
|
627
|
+
!is_symbol_proc_or_nil(add_timeout) ||
|
628
|
+
!is_symbol_proc_or_nil(update_timeout) ||
|
629
|
+
!is_symbol_proc_or_nil(remove_timeout)) {
|
630
|
+
rb_raise(rb_eTypeError,
|
631
|
+
"wrong argument type (expected Symbol, Proc, or nil)");
|
632
|
+
}
|
633
|
+
|
634
|
+
set_event_func_or_null(add_handle);
|
635
|
+
set_event_func_or_null(update_handle);
|
636
|
+
set_event_func_or_null(remove_handle);
|
637
|
+
set_event_func_or_null(add_timeout);
|
638
|
+
set_event_func_or_null(update_timeout);
|
639
|
+
set_event_func_or_null(remove_timeout);
|
640
|
+
|
641
|
+
/* virEventRegisterImpl returns void, so no error checking here */
|
642
|
+
virEventRegisterImpl(add_handle_temp, update_handle_temp,
|
643
|
+
remove_handle_temp, add_timeout_temp,
|
644
|
+
update_timeout_temp, remove_timeout_temp);
|
645
|
+
|
646
|
+
return Qnil;
|
647
|
+
}
|
648
|
+
#endif
|
649
|
+
|
650
|
+
#if HAVE_VIRDOMAINLXCENTERSECURITYLABEL
|
651
|
+
/*
|
652
|
+
* call-seq:
|
653
|
+
* Libvirt::lxc_enter_security_label(model, label, flags=0) -> Libvirt::Domain::SecurityLabel
|
654
|
+
*
|
655
|
+
* Call virDomainLxcEnterSecurityLabel
|
656
|
+
* to attach to the security label specified by label in the security model
|
657
|
+
* specified by model. The return object is a Libvirt::Domain::SecurityLabel
|
658
|
+
* which may be able to be used to move back to the previous label.
|
659
|
+
*/
|
660
|
+
static VALUE libvirt_domain_lxc_enter_security_label(int argc, VALUE *argv,
|
661
|
+
VALUE RUBY_LIBVIRT_UNUSED(c))
|
662
|
+
{
|
663
|
+
VALUE model = RUBY_Qnil, label = RUBY_Qnil, flags = RUBY_Qnil, result, modiv, doiiv, labiv;
|
664
|
+
virSecurityModel mod;
|
665
|
+
char *modstr, *doistr, *labstr;
|
666
|
+
virSecurityLabel lab, oldlab;
|
667
|
+
int ret;
|
668
|
+
|
669
|
+
rb_scan_args(argc, argv, "21", &model, &label, &flags);
|
670
|
+
|
671
|
+
if (rb_class_of(model) != c_node_security_model) {
|
672
|
+
rb_raise(rb_eTypeError,
|
673
|
+
"wrong argument type (expected Libvirt::Connect::NodeSecurityModel)");
|
674
|
+
}
|
675
|
+
|
676
|
+
if (rb_class_of(label) != c_domain_security_label) {
|
677
|
+
rb_raise(rb_eTypeError,
|
678
|
+
"wrong argument type (expected Libvirt::Domain::SecurityLabel)");
|
679
|
+
}
|
680
|
+
|
681
|
+
modiv = rb_iv_get(model, "@model");
|
682
|
+
modstr = StringValueCStr(modiv);
|
683
|
+
memcpy(mod.model, modstr, strlen(modstr));
|
684
|
+
doiiv = rb_iv_get(model, "@doi");
|
685
|
+
doistr = StringValueCStr(doiiv);
|
686
|
+
memcpy(mod.doi, doistr, strlen(doistr));
|
687
|
+
|
688
|
+
labiv = rb_iv_get(label, "@label");
|
689
|
+
labstr = StringValueCStr(labiv);
|
690
|
+
memcpy(lab.label, labstr, strlen(labstr));
|
691
|
+
lab.enforcing = NUM2INT(rb_iv_get(label, "@enforcing"));
|
692
|
+
|
693
|
+
ret = virDomainLxcEnterSecurityLabel(&mod, &lab, &oldlab,
|
694
|
+
ruby_libvirt_value_to_uint(flags));
|
695
|
+
ruby_libvirt_raise_error_if(ret < 0, e_RetrieveError,
|
696
|
+
"virDomainLxcEnterSecurityLabel", NULL);
|
697
|
+
|
698
|
+
result = rb_class_new_instance(0, NULL, c_domain_security_label);
|
699
|
+
rb_iv_set(result, "@label", rb_str_new2(oldlab.label));
|
700
|
+
rb_iv_set(result, "@enforcing", INT2NUM(oldlab.enforcing));
|
701
|
+
|
702
|
+
return result;
|
703
|
+
}
|
704
|
+
#endif
|
705
|
+
|
706
|
+
/*
|
707
|
+
* Module Libvirt
|
708
|
+
*/
|
709
|
+
void Init__libvirt(void)
|
710
|
+
{
|
711
|
+
m_libvirt = rb_define_module("Libvirt");
|
712
|
+
c_libvirt_version = rb_define_class_under(m_libvirt, "Version",
|
713
|
+
rb_cObject);
|
714
|
+
|
715
|
+
#if HAVE_VIRCONNECTOPENAUTH
|
716
|
+
rb_define_const(m_libvirt, "CONNECT_RO", INT2NUM(VIR_CONNECT_RO));
|
717
|
+
|
718
|
+
rb_define_const(m_libvirt, "CRED_USERNAME", INT2NUM(VIR_CRED_USERNAME));
|
719
|
+
rb_define_const(m_libvirt, "CRED_AUTHNAME", INT2NUM(VIR_CRED_AUTHNAME));
|
720
|
+
rb_define_const(m_libvirt, "CRED_LANGUAGE", INT2NUM(VIR_CRED_LANGUAGE));
|
721
|
+
rb_define_const(m_libvirt, "CRED_CNONCE", INT2NUM(VIR_CRED_CNONCE));
|
722
|
+
rb_define_const(m_libvirt, "CRED_PASSPHRASE", INT2NUM(VIR_CRED_PASSPHRASE));
|
723
|
+
rb_define_const(m_libvirt, "CRED_ECHOPROMPT", INT2NUM(VIR_CRED_ECHOPROMPT));
|
724
|
+
rb_define_const(m_libvirt, "CRED_NOECHOPROMPT",
|
725
|
+
INT2NUM(VIR_CRED_NOECHOPROMPT));
|
726
|
+
rb_define_const(m_libvirt, "CRED_REALM", INT2NUM(VIR_CRED_REALM));
|
727
|
+
rb_define_const(m_libvirt, "CRED_EXTERNAL", INT2NUM(VIR_CRED_EXTERNAL));
|
728
|
+
#endif
|
729
|
+
|
730
|
+
#if HAVE_CONST_VIR_CONNECT_NO_ALIASES
|
731
|
+
rb_define_const(m_libvirt, "CONNECT_NO_ALIASES",
|
732
|
+
INT2NUM(VIR_CONNECT_NO_ALIASES));
|
733
|
+
#endif
|
734
|
+
|
735
|
+
/*
|
736
|
+
* Libvirt Errors
|
737
|
+
*/
|
738
|
+
e_Error = rb_define_class_under(m_libvirt, "Error",
|
739
|
+
rb_eStandardError);
|
740
|
+
e_ConnectionError = rb_define_class_under(m_libvirt, "ConnectionError",
|
741
|
+
e_Error);
|
742
|
+
e_DefinitionError = rb_define_class_under(m_libvirt, "DefinitionError",
|
743
|
+
e_Error);
|
744
|
+
e_RetrieveError = rb_define_class_under(m_libvirt, "RetrieveError",
|
745
|
+
e_Error);
|
746
|
+
e_NoSupportError = rb_define_class_under(m_libvirt, "NoSupportError",
|
747
|
+
e_Error);
|
748
|
+
|
749
|
+
rb_define_attr(e_Error, "libvirt_function_name", 1, 0);
|
750
|
+
rb_define_attr(e_Error, "libvirt_message", 1, 0);
|
751
|
+
rb_define_attr(e_Error, "libvirt_code", 1, 0);
|
752
|
+
rb_define_attr(e_Error, "libvirt_component", 1, 0);
|
753
|
+
rb_define_attr(e_Error, "libvirt_level", 1, 0);
|
754
|
+
|
755
|
+
/* libvirt error components (domains) */
|
756
|
+
rb_define_const(e_Error, "FROM_NONE", INT2NUM(VIR_FROM_NONE));
|
757
|
+
rb_define_const(e_Error, "FROM_XEN", INT2NUM(VIR_FROM_XEN));
|
758
|
+
rb_define_const(e_Error, "FROM_XEND", INT2NUM(VIR_FROM_XEND));
|
759
|
+
rb_define_const(e_Error, "FROM_XENSTORE", INT2NUM(VIR_FROM_XENSTORE));
|
760
|
+
rb_define_const(e_Error, "FROM_SEXPR", INT2NUM(VIR_FROM_SEXPR));
|
761
|
+
rb_define_const(e_Error, "FROM_XML", INT2NUM(VIR_FROM_XML));
|
762
|
+
rb_define_const(e_Error, "FROM_DOM", INT2NUM(VIR_FROM_DOM));
|
763
|
+
rb_define_const(e_Error, "FROM_RPC", INT2NUM(VIR_FROM_RPC));
|
764
|
+
rb_define_const(e_Error, "FROM_PROXY", INT2NUM(VIR_FROM_PROXY));
|
765
|
+
rb_define_const(e_Error, "FROM_CONF", INT2NUM(VIR_FROM_CONF));
|
766
|
+
rb_define_const(e_Error, "FROM_QEMU", INT2NUM(VIR_FROM_QEMU));
|
767
|
+
rb_define_const(e_Error, "FROM_NET", INT2NUM(VIR_FROM_NET));
|
768
|
+
rb_define_const(e_Error, "FROM_TEST", INT2NUM(VIR_FROM_TEST));
|
769
|
+
rb_define_const(e_Error, "FROM_REMOTE", INT2NUM(VIR_FROM_REMOTE));
|
770
|
+
rb_define_const(e_Error, "FROM_OPENVZ", INT2NUM(VIR_FROM_OPENVZ));
|
771
|
+
#if HAVE_CONST_VIR_FROM_VMWARE
|
772
|
+
rb_define_const(e_Error, "FROM_VMWARE", INT2NUM(VIR_FROM_VMWARE));
|
773
|
+
#endif
|
774
|
+
#if HAVE_CONST_VIR_FROM_XENXM
|
775
|
+
rb_define_const(e_Error, "FROM_XENXM", INT2NUM(VIR_FROM_XENXM));
|
776
|
+
#endif
|
777
|
+
#if HAVE_CONST_VIR_FROM_STATS_LINUX
|
778
|
+
rb_define_const(e_Error, "FROM_STATS_LINUX", INT2NUM(VIR_FROM_STATS_LINUX));
|
779
|
+
#endif
|
780
|
+
#if HAVE_TYPE_VIR_FROM_LXC
|
781
|
+
rb_define_const(e_Error, "FROM_LXC", INT2NUM(VIR_FROM_LXC));
|
782
|
+
#endif
|
783
|
+
#if HAVE_TYPE_VIRSTORAGEPOOLPTR
|
784
|
+
rb_define_const(e_Error, "FROM_STORAGE", INT2NUM(VIR_FROM_STORAGE));
|
785
|
+
#endif
|
786
|
+
#if HAVE_CONST_VIR_FROM_NETWORK
|
787
|
+
rb_define_const(e_Error, "FROM_NETWORK", INT2NUM(VIR_FROM_NETWORK));
|
788
|
+
#endif
|
789
|
+
#if HAVE_CONST_VIR_FROM_DOMAIN
|
790
|
+
rb_define_const(e_Error, "FROM_DOMAIN", INT2NUM(VIR_FROM_DOMAIN));
|
791
|
+
#endif
|
792
|
+
#if HAVE_CONST_VIR_FROM_UML
|
793
|
+
rb_define_const(e_Error, "FROM_UML", INT2NUM(VIR_FROM_UML));
|
794
|
+
#endif
|
795
|
+
#if HAVE_TYPE_VIRNODEDEVICEPTR
|
796
|
+
rb_define_const(e_Error, "FROM_NODEDEV", INT2NUM(VIR_FROM_NODEDEV));
|
797
|
+
#endif
|
798
|
+
#if HAVE_CONST_VIR_FROM_XEN_INOTIFY
|
799
|
+
rb_define_const(e_Error, "FROM_XEN_INOTIFY", INT2NUM(VIR_FROM_XEN_INOTIFY));
|
800
|
+
#endif
|
801
|
+
#if HAVE_CONST_VIR_FROM_SECURITY
|
802
|
+
rb_define_const(e_Error, "FROM_SECURITY", INT2NUM(VIR_FROM_SECURITY));
|
803
|
+
#endif
|
804
|
+
#if HAVE_CONST_VIR_FROM_VBOX
|
805
|
+
rb_define_const(e_Error, "FROM_VBOX", INT2NUM(VIR_FROM_VBOX));
|
806
|
+
#endif
|
807
|
+
#if HAVE_TYPE_VIRINTERFACEPTR
|
808
|
+
rb_define_const(e_Error, "FROM_INTERFACE", INT2NUM(VIR_FROM_INTERFACE));
|
809
|
+
#endif
|
810
|
+
#if HAVE_CONST_VIR_FROM_ONE
|
811
|
+
rb_define_const(e_Error, "FROM_ONE", INT2NUM(VIR_FROM_ONE));
|
812
|
+
#endif
|
813
|
+
#if HAVE_CONST_VIR_FROM_ESX
|
814
|
+
rb_define_const(e_Error, "FROM_ESX", INT2NUM(VIR_FROM_ESX));
|
815
|
+
#endif
|
816
|
+
#if HAVE_CONST_VIR_FROM_PHYP
|
817
|
+
rb_define_const(e_Error, "FROM_PHYP", INT2NUM(VIR_FROM_PHYP));
|
818
|
+
#endif
|
819
|
+
#if HAVE_TYPE_VIRSECRETPTR
|
820
|
+
rb_define_const(e_Error, "FROM_SECRET", INT2NUM(VIR_FROM_SECRET));
|
821
|
+
#endif
|
822
|
+
#if HAVE_VIRCONNECTCOMPARECPU
|
823
|
+
rb_define_const(e_Error, "FROM_CPU", INT2NUM(VIR_FROM_CPU));
|
824
|
+
#endif
|
825
|
+
#if HAVE_CONST_VIR_FROM_XENAPI
|
826
|
+
rb_define_const(e_Error, "FROM_XENAPI", INT2NUM(VIR_FROM_XENAPI));
|
827
|
+
#endif
|
828
|
+
#if HAVE_TYPE_VIRNWFILTERPTR
|
829
|
+
rb_define_const(e_Error, "FROM_NWFILTER", INT2NUM(VIR_FROM_NWFILTER));
|
830
|
+
#endif
|
831
|
+
#if HAVE_CONST_VIR_FROM_HOOK
|
832
|
+
rb_define_const(e_Error, "FROM_HOOK", INT2NUM(VIR_FROM_HOOK));
|
833
|
+
#endif
|
834
|
+
#if HAVE_TYPE_VIRDOMAINSNAPSHOTPTR
|
835
|
+
rb_define_const(e_Error, "FROM_DOMAIN_SNAPSHOT",
|
836
|
+
INT2NUM(VIR_FROM_DOMAIN_SNAPSHOT));
|
837
|
+
#endif
|
838
|
+
#if HAVE_CONST_VIR_FROM_AUDIT
|
839
|
+
rb_define_const(e_Error, "FROM_AUDIT", INT2NUM(VIR_FROM_AUDIT));
|
840
|
+
#endif
|
841
|
+
#if HAVE_CONST_VIR_FROM_SYSINFO
|
842
|
+
rb_define_const(e_Error, "FROM_SYSINFO", INT2NUM(VIR_FROM_SYSINFO));
|
843
|
+
#endif
|
844
|
+
#if HAVE_CONST_VIR_FROM_STREAMS
|
845
|
+
rb_define_const(e_Error, "FROM_STREAMS", INT2NUM(VIR_FROM_STREAMS));
|
846
|
+
#endif
|
847
|
+
|
848
|
+
/* libvirt error codes */
|
849
|
+
rb_define_const(e_Error, "ERR_OK", INT2NUM(VIR_ERR_OK));
|
850
|
+
rb_define_const(e_Error, "ERR_INTERNAL_ERROR",
|
851
|
+
INT2NUM(VIR_ERR_INTERNAL_ERROR));
|
852
|
+
rb_define_const(e_Error, "ERR_NO_MEMORY", INT2NUM(VIR_ERR_NO_MEMORY));
|
853
|
+
rb_define_const(e_Error, "ERR_NO_SUPPORT", INT2NUM(VIR_ERR_NO_SUPPORT));
|
854
|
+
rb_define_const(e_Error, "ERR_UNKNOWN_HOST", INT2NUM(VIR_ERR_UNKNOWN_HOST));
|
855
|
+
rb_define_const(e_Error, "ERR_NO_CONNECT", INT2NUM(VIR_ERR_NO_CONNECT));
|
856
|
+
rb_define_const(e_Error, "ERR_INVALID_CONN", INT2NUM(VIR_ERR_INVALID_CONN));
|
857
|
+
rb_define_const(e_Error, "ERR_INVALID_DOMAIN",
|
858
|
+
INT2NUM(VIR_ERR_INVALID_DOMAIN));
|
859
|
+
rb_define_const(e_Error, "ERR_INVALID_ARG", INT2NUM(VIR_ERR_INVALID_ARG));
|
860
|
+
rb_define_const(e_Error, "ERR_OPERATION_FAILED",
|
861
|
+
INT2NUM(VIR_ERR_OPERATION_FAILED));
|
862
|
+
rb_define_const(e_Error, "ERR_GET_FAILED", INT2NUM(VIR_ERR_GET_FAILED));
|
863
|
+
rb_define_const(e_Error, "ERR_POST_FAILED", INT2NUM(VIR_ERR_POST_FAILED));
|
864
|
+
rb_define_const(e_Error, "ERR_HTTP_ERROR", INT2NUM(VIR_ERR_HTTP_ERROR));
|
865
|
+
rb_define_const(e_Error, "ERR_SEXPR_SERIAL", INT2NUM(VIR_ERR_SEXPR_SERIAL));
|
866
|
+
rb_define_const(e_Error, "ERR_NO_XEN", INT2NUM(VIR_ERR_NO_XEN));
|
867
|
+
rb_define_const(e_Error, "ERR_XEN_CALL", INT2NUM(VIR_ERR_XEN_CALL));
|
868
|
+
rb_define_const(e_Error, "ERR_OS_TYPE", INT2NUM(VIR_ERR_OS_TYPE));
|
869
|
+
rb_define_const(e_Error, "ERR_NO_KERNEL", INT2NUM(VIR_ERR_NO_KERNEL));
|
870
|
+
rb_define_const(e_Error, "ERR_NO_ROOT", INT2NUM(VIR_ERR_NO_ROOT));
|
871
|
+
rb_define_const(e_Error, "ERR_NO_SOURCE", INT2NUM(VIR_ERR_NO_SOURCE));
|
872
|
+
rb_define_const(e_Error, "ERR_NO_TARGET", INT2NUM(VIR_ERR_NO_TARGET));
|
873
|
+
rb_define_const(e_Error, "ERR_NO_NAME", INT2NUM(VIR_ERR_NO_NAME));
|
874
|
+
rb_define_const(e_Error, "ERR_NO_OS", INT2NUM(VIR_ERR_NO_OS));
|
875
|
+
rb_define_const(e_Error, "ERR_NO_DEVICE", INT2NUM(VIR_ERR_NO_DEVICE));
|
876
|
+
rb_define_const(e_Error, "ERR_NO_XENSTORE", INT2NUM(VIR_ERR_NO_XENSTORE));
|
877
|
+
rb_define_const(e_Error, "ERR_DRIVER_FULL", INT2NUM(VIR_ERR_DRIVER_FULL));
|
878
|
+
rb_define_const(e_Error, "ERR_CALL_FAILED", INT2NUM(VIR_ERR_CALL_FAILED));
|
879
|
+
rb_define_const(e_Error, "ERR_XML_ERROR", INT2NUM(VIR_ERR_XML_ERROR));
|
880
|
+
rb_define_const(e_Error, "ERR_DOM_EXIST", INT2NUM(VIR_ERR_DOM_EXIST));
|
881
|
+
rb_define_const(e_Error, "ERR_OPERATION_DENIED",
|
882
|
+
INT2NUM(VIR_ERR_OPERATION_DENIED));
|
883
|
+
rb_define_const(e_Error, "ERR_OPEN_FAILED", INT2NUM(VIR_ERR_OPEN_FAILED));
|
884
|
+
rb_define_const(e_Error, "ERR_READ_FAILED", INT2NUM(VIR_ERR_READ_FAILED));
|
885
|
+
rb_define_const(e_Error, "ERR_PARSE_FAILED", INT2NUM(VIR_ERR_PARSE_FAILED));
|
886
|
+
rb_define_const(e_Error, "ERR_CONF_SYNTAX", INT2NUM(VIR_ERR_CONF_SYNTAX));
|
887
|
+
rb_define_const(e_Error, "ERR_WRITE_FAILED", INT2NUM(VIR_ERR_WRITE_FAILED));
|
888
|
+
rb_define_const(e_Error, "ERR_XML_DETAIL", INT2NUM(VIR_ERR_XML_DETAIL));
|
889
|
+
rb_define_const(e_Error, "ERR_INVALID_NETWORK",
|
890
|
+
INT2NUM(VIR_ERR_INVALID_NETWORK));
|
891
|
+
rb_define_const(e_Error, "ERR_NETWORK_EXIST",
|
892
|
+
INT2NUM(VIR_ERR_NETWORK_EXIST));
|
893
|
+
rb_define_const(e_Error, "ERR_SYSTEM_ERROR", INT2NUM(VIR_ERR_SYSTEM_ERROR));
|
894
|
+
rb_define_const(e_Error, "ERR_RPC", INT2NUM(VIR_ERR_RPC));
|
895
|
+
rb_define_const(e_Error, "ERR_GNUTLS_ERROR", INT2NUM(VIR_ERR_GNUTLS_ERROR));
|
896
|
+
rb_define_const(e_Error, "WAR_NO_NETWORK", INT2NUM(VIR_WAR_NO_NETWORK));
|
897
|
+
rb_define_const(e_Error, "ERR_NO_DOMAIN", INT2NUM(VIR_ERR_NO_DOMAIN));
|
898
|
+
rb_define_const(e_Error, "ERR_NO_NETWORK", INT2NUM(VIR_ERR_NO_NETWORK));
|
899
|
+
rb_define_const(e_Error, "ERR_INVALID_MAC", INT2NUM(VIR_ERR_INVALID_MAC));
|
900
|
+
#if HAVE_CONST_VIR_ERR_AUTH_FAILED
|
901
|
+
rb_define_const(e_Error, "ERR_AUTH_FAILED", INT2NUM(VIR_ERR_AUTH_FAILED));
|
902
|
+
#endif
|
903
|
+
#if HAVE_TYPE_VIRSTORAGEPOOLPTR
|
904
|
+
rb_define_const(e_Error, "ERR_INVALID_STORAGE_POOL",
|
905
|
+
INT2NUM(VIR_ERR_INVALID_STORAGE_POOL));
|
906
|
+
rb_define_const(e_Error, "ERR_INVALID_STORAGE_VOL",
|
907
|
+
INT2NUM(VIR_ERR_INVALID_STORAGE_VOL));
|
908
|
+
rb_define_const(e_Error, "WAR_NO_STORAGE", INT2NUM(VIR_WAR_NO_STORAGE));
|
909
|
+
rb_define_const(e_Error, "ERR_NO_STORAGE_POOL",
|
910
|
+
INT2NUM(VIR_ERR_NO_STORAGE_POOL));
|
911
|
+
rb_define_const(e_Error, "ERR_NO_STORAGE_VOL",
|
912
|
+
INT2NUM(VIR_ERR_NO_STORAGE_VOL));
|
913
|
+
#endif
|
914
|
+
#if HAVE_TYPE_VIRNODEDEVICEPTR
|
915
|
+
rb_define_const(e_Error, "WAR_NO_NODE", INT2NUM(VIR_WAR_NO_NODE));
|
916
|
+
rb_define_const(e_Error, "ERR_INVALID_NODE_DEVICE",
|
917
|
+
INT2NUM(VIR_ERR_INVALID_NODE_DEVICE));
|
918
|
+
rb_define_const(e_Error, "ERR_NO_NODE_DEVICE",
|
919
|
+
INT2NUM(VIR_ERR_NO_NODE_DEVICE));
|
920
|
+
#endif
|
921
|
+
#if HAVE_CONST_VIR_ERR_NO_SECURITY_MODEL
|
922
|
+
rb_define_const(e_Error, "ERR_NO_SECURITY_MODEL",
|
923
|
+
INT2NUM(VIR_ERR_NO_SECURITY_MODEL));
|
924
|
+
#endif
|
925
|
+
#if HAVE_CONST_VIR_ERR_OPERATION_INVALID
|
926
|
+
rb_define_const(e_Error, "ERR_OPERATION_INVALID",
|
927
|
+
INT2NUM(VIR_ERR_OPERATION_INVALID));
|
928
|
+
#endif
|
929
|
+
#if HAVE_TYPE_VIRINTERFACEPTR
|
930
|
+
rb_define_const(e_Error, "WAR_NO_INTERFACE", INT2NUM(VIR_WAR_NO_INTERFACE));
|
931
|
+
rb_define_const(e_Error, "ERR_NO_INTERFACE", INT2NUM(VIR_ERR_NO_INTERFACE));
|
932
|
+
rb_define_const(e_Error, "ERR_INVALID_INTERFACE",
|
933
|
+
INT2NUM(VIR_ERR_INVALID_INTERFACE));
|
934
|
+
rb_define_const(e_Error, "ERR_MULTIPLE_INTERFACES",
|
935
|
+
INT2NUM(VIR_ERR_MULTIPLE_INTERFACES));
|
936
|
+
#endif
|
937
|
+
#if HAVE_TYPE_VIRNWFILTERPTR
|
938
|
+
rb_define_const(e_Error, "WAR_NO_NWFILTER", INT2NUM(VIR_WAR_NO_NWFILTER));
|
939
|
+
rb_define_const(e_Error, "ERR_INVALID_NWFILTER",
|
940
|
+
INT2NUM(VIR_ERR_INVALID_NWFILTER));
|
941
|
+
rb_define_const(e_Error, "ERR_NO_NWFILTER", INT2NUM(VIR_ERR_NO_NWFILTER));
|
942
|
+
rb_define_const(e_Error, "ERR_BUILD_FIREWALL",
|
943
|
+
INT2NUM(VIR_ERR_BUILD_FIREWALL));
|
944
|
+
#endif
|
945
|
+
#if HAVE_TYPE_VIRSECRETPTR
|
946
|
+
rb_define_const(e_Error, "WAR_NO_SECRET", INT2NUM(VIR_WAR_NO_SECRET));
|
947
|
+
rb_define_const(e_Error, "ERR_INVALID_SECRET",
|
948
|
+
INT2NUM(VIR_ERR_INVALID_SECRET));
|
949
|
+
rb_define_const(e_Error, "ERR_NO_SECRET", INT2NUM(VIR_ERR_NO_SECRET));
|
950
|
+
#endif
|
951
|
+
#if HAVE_CONST_VIR_ERR_CONFIG_UNSUPPORTED
|
952
|
+
rb_define_const(e_Error, "ERR_CONFIG_UNSUPPORTED",
|
953
|
+
INT2NUM(VIR_ERR_CONFIG_UNSUPPORTED));
|
954
|
+
#endif
|
955
|
+
#if HAVE_CONST_VIR_ERR_OPERATION_TIMEOUT
|
956
|
+
rb_define_const(e_Error, "ERR_OPERATION_TIMEOUT",
|
957
|
+
INT2NUM(VIR_ERR_OPERATION_TIMEOUT));
|
958
|
+
#endif
|
959
|
+
#if HAVE_CONST_VIR_ERR_MIGRATE_PERSIST_FAILED
|
960
|
+
rb_define_const(e_Error, "ERR_MIGRATE_PERSIST_FAILED",
|
961
|
+
INT2NUM(VIR_ERR_MIGRATE_PERSIST_FAILED));
|
962
|
+
#endif
|
963
|
+
#if HAVE_CONST_VIR_ERR_HOOK_SCRIPT_FAILED
|
964
|
+
rb_define_const(e_Error, "ERR_HOOK_SCRIPT_FAILED",
|
965
|
+
INT2NUM(VIR_ERR_HOOK_SCRIPT_FAILED));
|
966
|
+
#endif
|
967
|
+
#if HAVE_TYPE_VIRDOMAINSNAPSHOTPTR
|
968
|
+
rb_define_const(e_Error, "ERR_INVALID_DOMAIN_SNAPSHOT",
|
969
|
+
INT2NUM(VIR_ERR_INVALID_DOMAIN_SNAPSHOT));
|
970
|
+
rb_define_const(e_Error, "ERR_NO_DOMAIN_SNAPSHOT",
|
971
|
+
INT2NUM(VIR_ERR_NO_DOMAIN_SNAPSHOT));
|
972
|
+
#endif
|
973
|
+
|
974
|
+
/* libvirt levels */
|
975
|
+
rb_define_const(e_Error, "LEVEL_NONE", INT2NUM(VIR_ERR_NONE));
|
976
|
+
rb_define_const(e_Error, "LEVEL_WARNING", INT2NUM(VIR_ERR_WARNING));
|
977
|
+
rb_define_const(e_Error, "LEVEL_ERROR", INT2NUM(VIR_ERR_ERROR));
|
978
|
+
|
979
|
+
rb_define_module_function(m_libvirt, "version", libvirt_version, -1);
|
980
|
+
rb_define_module_function(m_libvirt, "open", libvirt_open, -1);
|
981
|
+
rb_define_module_function(m_libvirt, "open_read_only",
|
982
|
+
libvirt_open_read_only, -1);
|
983
|
+
#if HAVE_VIRCONNECTOPENAUTH
|
984
|
+
rb_define_module_function(m_libvirt, "open_auth", libvirt_open_auth, -1);
|
985
|
+
#endif
|
986
|
+
|
987
|
+
#if HAVE_VIREVENTREGISTERIMPL
|
988
|
+
rb_define_const(m_libvirt, "EVENT_HANDLE_READABLE",
|
989
|
+
INT2NUM(VIR_EVENT_HANDLE_READABLE));
|
990
|
+
rb_define_const(m_libvirt, "EVENT_HANDLE_WRITABLE",
|
991
|
+
INT2NUM(VIR_EVENT_HANDLE_WRITABLE));
|
992
|
+
rb_define_const(m_libvirt, "EVENT_HANDLE_ERROR",
|
993
|
+
INT2NUM(VIR_EVENT_HANDLE_ERROR));
|
994
|
+
rb_define_const(m_libvirt, "EVENT_HANDLE_HANGUP",
|
995
|
+
INT2NUM(VIR_EVENT_HANDLE_HANGUP));
|
996
|
+
|
997
|
+
/* since we are using globals, we have to register with the gc */
|
998
|
+
rb_global_variable(&add_handle);
|
999
|
+
rb_global_variable(&update_handle);
|
1000
|
+
rb_global_variable(&remove_handle);
|
1001
|
+
rb_global_variable(&add_timeout);
|
1002
|
+
rb_global_variable(&update_timeout);
|
1003
|
+
rb_global_variable(&remove_timeout);
|
1004
|
+
|
1005
|
+
rb_define_module_function(m_libvirt, "event_register_impl",
|
1006
|
+
libvirt_conn_event_register_impl, -1);
|
1007
|
+
rb_define_module_function(m_libvirt, "event_invoke_handle_callback",
|
1008
|
+
libvirt_event_invoke_handle_callback, 4);
|
1009
|
+
rb_define_module_function(m_libvirt, "event_invoke_timeout_callback",
|
1010
|
+
libvirt_event_invoke_timeout_callback, 2);
|
1011
|
+
#endif
|
1012
|
+
|
1013
|
+
#if HAVE_VIRDOMAINLXCENTERSECURITYLABEL
|
1014
|
+
rb_define_method(m_libvirt, "lxc_enter_security_label",
|
1015
|
+
libvirt_domain_lxc_enter_security_label, -1);
|
1016
|
+
#endif
|
1017
|
+
|
1018
|
+
ruby_libvirt_connect_init();
|
1019
|
+
ruby_libvirt_storage_init();
|
1020
|
+
ruby_libvirt_network_init();
|
1021
|
+
ruby_libvirt_nodedevice_init();
|
1022
|
+
ruby_libvirt_secret_init();
|
1023
|
+
ruby_libvirt_nwfilter_init();
|
1024
|
+
ruby_libvirt_interface_init();
|
1025
|
+
ruby_libvirt_domain_init();
|
1026
|
+
ruby_libvirt_stream_init();
|
1027
|
+
|
1028
|
+
virSetErrorFunc(NULL, rubyLibvirtErrorFunc);
|
1029
|
+
|
1030
|
+
if (virInitialize() < 0) {
|
1031
|
+
rb_raise(rb_eSystemCallError, "virInitialize failed");
|
1032
|
+
}
|
1033
|
+
}
|