ruby-libvirt 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,10 +2,24 @@
2
2
 
3
3
  The module Libvirt provides bindings to libvirt[http://libvirt.org]
4
4
 
5
- The various +*Ptr+ types in Libvirt map loosely to the following Ruby classes:
5
+ The various *Ptr types in Libvirt map loosely to the following Ruby classes:
6
6
 
7
7
  [virConnectPtr] Libvirt::Connect
8
8
  [virDomainPtr] Libvirt::Domain
9
9
  [virDomainInfoPtr] Libvirt::Domain::Info
10
+ [virDomainInterfaceStatsPtr] Libvirt::Domain::InterfaceInfo
11
+ [virSecurityLabelPtr] Libvirt::Domain::SecurityLabel
12
+ [virDomainBlockStatsPtr] Libvirt::Domain::BlockStats
13
+ [virDomainMemoryStatPtr] Libvirt::Domain::MemoryStats
14
+ [virDomainBlockInfoPtr] Libvirt::Domain::BlockInfo
15
+ [virDomainSnapshotPtr] Libvirt::Domain::Snapshot
10
16
  [virNetworkPtr] Libvirt::Network
11
-
17
+ [virNWFilterPtr] Libvirt::NWFilter
18
+ [virNodeDevicePtr] Libvirt::NodeDevice
19
+ [virStoragePoolPtr] Libvirt::StoragePool
20
+ [virStoragePoolInfoPtr] Libvirt::StoragePoolInfo
21
+ [virStorageVolPtr] Libvirt::StorageVol
22
+ [virStorageVolInfoPtr] Libvirt::StorageVolInfo
23
+ [virNodeInfoPtr] Libvirt::Nodeinfo
24
+ [virSecretPtr] Libvirt::Secret
25
+ [virInterfacePtr] Libvirt::Interface
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- ruby -*-
2
2
  # Rakefile: build ruby libvirt bindings
3
3
  #
4
- # Copyright (C) 2007 Red Hat, Inc.
4
+ # Copyright (C) 2007,2010 Red Hat, Inc.
5
5
  #
6
6
  # Distributed under the GNU Lesser General Public License v2.1 or later.
7
7
  # See COPYING for details
@@ -15,13 +15,14 @@ require 'rake/testtask'
15
15
  require 'rake/gempackagetask'
16
16
 
17
17
  PKG_NAME='ruby-libvirt'
18
- PKG_VERSION='0.1.0'
18
+ PKG_VERSION='0.2.0'
19
19
 
20
20
  EXT_CONF='ext/libvirt/extconf.rb'
21
21
  MAKEFILE="ext/libvirt/Makefile"
22
22
  LIBVIRT_MODULE="ext/libvirt/_libvirt.so"
23
23
  SPEC_FILE="ruby-libvirt.spec"
24
- LIBVIRT_SRC=LIBVIRT_MODULE.gsub(/.so$/, ".c")
24
+ LIBVIRT_SRC=Dir.glob("ext/libvirt/*.c")
25
+ LIBVIRT_SRC << MAKEFILE
25
26
 
26
27
  #
27
28
  # Additional files for clean/clobber
@@ -46,7 +47,7 @@ file MAKEFILE => EXT_CONF do |t|
46
47
  end
47
48
  end
48
49
  end
49
- file LIBVIRT_MODULE => [ MAKEFILE, LIBVIRT_SRC ] do |t|
50
+ file LIBVIRT_MODULE => LIBVIRT_SRC do |t|
50
51
  Dir::chdir(File::dirname(EXT_CONF)) do
51
52
  unless sh "make"
52
53
  $stderr.puts "make failed"
@@ -66,7 +67,7 @@ task :test => :build
66
67
  Rake::RDocTask.new do |rd|
67
68
  rd.main = "README.rdoc"
68
69
  rd.rdoc_dir = "doc/site/api"
69
- rd.rdoc_files.include("README.rdoc", "lib/**/*.rb", "ext/**/*.[ch]")
70
+ rd.rdoc_files.include("README.rdoc", "lib/libvirt.rb", ["ext/libvirt/_libvirt.c", "ext/libvirt/connect.c", "ext/libvirt/domain.c", "ext/libvirt/interface.c", "ext/libvirt/network.c", "ext/libvirt/nodedevice.c", "ext/libvirt/nwfilter.c", "ext/libvirt/secret.c", "ext/libvirt/storage.c"])
70
71
  end
71
72
 
72
73
  #
@@ -92,9 +93,10 @@ SPEC = Gem::Specification.new do |s|
92
93
  s.homepage = "http://libvirt.org/ruby/"
93
94
  s.summary = "Ruby bindings for LIBVIRT"
94
95
  s.files = PKG_FILES
95
- s.autorequire = "libvirt"
96
96
  s.required_ruby_version = '>= 1.8.1'
97
97
  s.extensions = "ext/libvirt/extconf.rb"
98
+ s.author = "David Lutterkort, Chris Lalancette"
99
+ s.rubyforge_project = "None"
98
100
  s.description = <<EOF
99
101
  Provides bindings for libvirt.
100
102
  EOF
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * libvirt.c: Ruby bindings for libvirt
3
3
  *
4
- * Copyright (C) 2007 Red Hat Inc.
4
+ * Copyright (C) 2007,2010 Red Hat Inc.
5
5
  *
6
6
  * This library is free software; you can redistribute it and/or
7
7
  * modify it under the terms of the GNU Lesser General Public
@@ -24,1740 +24,107 @@
24
24
  #include <libvirt/libvirt.h>
25
25
  #include <libvirt/virterror.h>
26
26
  #include "extconf.h"
27
+ #include "common.h"
28
+ #include "storage.h"
29
+ #include "connect.h"
30
+ #include "network.h"
31
+ #include "nodedevice.h"
32
+ #include "secret.h"
33
+ #include "nwfilter.h"
34
+ #include "interface.h"
35
+ #include "domain.h"
27
36
 
28
- static VALUE m_libvirt;
29
- static VALUE c_connect;
30
- static VALUE c_domain;
31
- static VALUE c_domain_info;
32
- #if HAVE_TYPE_VIRNETWORKPTR
33
- static VALUE c_network;
34
- #endif
35
37
  static VALUE c_libvirt_version;
36
- static VALUE c_node_info;
37
- #if HAVE_TYPE_VIRSTORAGEPOOLPTR
38
- static VALUE c_storage_pool;
39
- static VALUE c_storage_pool_info;
40
- #endif
41
- #if HAVE_TYPE_VIRSTORAGEVOLPTR
42
- static VALUE c_storage_vol;
43
- static VALUE c_storage_vol_info;
44
- #endif
45
38
 
39
+ VALUE m_libvirt;
46
40
 
47
41
  // define additional errors here
48
- static VALUE e_Error; // Error - generic error
49
42
  static VALUE e_ConnectionError; // ConnectionError - error durring connection establishment
50
- static VALUE e_DefinitionError; // DefinitionError - error during data definition
51
- static VALUE e_RetrieveError; // RetrievalError - error during data retrieval
43
+ VALUE e_DefinitionError;
44
+ VALUE e_RetrieveError;
45
+ VALUE e_Error;
52
46
 
53
47
  /*
54
- * Internal helpers
55
- */
56
-
57
- /* Macros to ease some of the boilerplate */
58
-
59
- #define generic_free(kind, p) \
60
- do { \
61
- int r; \
62
- r = vir##kind##Free((vir##kind##Ptr) p); \
63
- if (r < 0) \
64
- rb_raise(rb_eSystemCallError, # kind " free failed"); \
65
- } while(0);
66
-
67
- #define generic_get(kind, v) \
68
- do { \
69
- vir##kind##Ptr ptr; \
70
- Data_Get_Struct(v, vir##kind, ptr); \
71
- if (!ptr) \
72
- rb_raise(rb_eArgError, #kind " has been freed"); \
73
- return ptr; \
74
- } while (0);
75
-
76
- static VALUE generic_new(VALUE klass, void *ptr, VALUE conn,
77
- RUBY_DATA_FUNC free_func) {
78
- VALUE result;
79
- result = Data_Wrap_Struct(klass, NULL, free_func, ptr);
80
- rb_iv_set(result, "@connection", conn);
81
- return result;
82
- }
83
-
84
- /* Error handling */
85
- #define _E(cond, excep) \
86
- do { if (cond) vir_error(excep); } while(0)
87
-
88
- NORETURN(static void vir_error(VALUE exception));
89
-
90
- static void vir_error(VALUE exception) {
91
- rb_exc_raise(exception);
92
- }
93
-
94
- static VALUE create_error(VALUE error, const char* method, const char* msg,
95
- virConnectPtr conn) {
96
- VALUE ruby_errinfo;
97
- virErrorPtr err;
98
-
99
- if (msg == NULL || strlen(msg) == 0) {
100
- char *defmsg;
101
- size_t len;
102
- len = snprintf(NULL, 0, "Call to function %s failed", method) + 1;
103
- defmsg = ALLOC_N(char, len);
104
- snprintf(defmsg, len, "Call to function %s failed", method);
105
- ruby_errinfo = rb_exc_new2(error, defmsg);
106
- free(defmsg);
107
- } else {
108
- ruby_errinfo = rb_exc_new2(error, msg);
109
- }
110
- rb_iv_set(ruby_errinfo, "@libvirt_function_name", rb_str_new2(method));
111
-
112
- if (conn == NULL)
113
- err = virGetLastError();
114
- else
115
- err = virConnGetLastError(conn);
116
-
117
- if (err != NULL && err->message != NULL) {
118
- rb_iv_set(ruby_errinfo, "@libvirt_message", rb_str_new2(err->message));
119
- }
120
-
121
- return ruby_errinfo;
122
- };
123
-
124
-
125
- /* Connections */
126
- static void connect_close(void *p) {
127
- int r;
128
-
129
- if (!p)
130
- return;
131
- r = virConnectClose((virConnectPtr) p);
132
- _E(r < 0, create_error(rb_eSystemCallError, "connect_close",
133
- "Connection close failed", p));
134
- }
135
-
136
- static VALUE connect_new(virConnectPtr p) {
137
- return Data_Wrap_Struct(c_connect, NULL, connect_close, p);
138
- }
139
-
140
- static virConnectPtr connect_get(VALUE s) {
141
- generic_get(Connect, s);
142
- }
143
-
144
- static VALUE conn_attr(VALUE s) {
145
- if (rb_obj_is_instance_of(s, c_connect) != Qtrue) {
146
- s = rb_iv_get(s, "@connection");
147
- }
148
- if (rb_obj_is_instance_of(s, c_connect) != Qtrue) {
149
- rb_raise(rb_eArgError, "Expected Connection object");
150
- }
151
- return s;
152
- }
153
-
154
- static virConnectPtr conn(VALUE s) {
155
- s = conn_attr(s);
156
- virConnectPtr conn;
157
- Data_Get_Struct(s, virConnect, conn);
158
- if (!conn)
159
- rb_raise(rb_eArgError, "Connection has been closed");
160
- return conn;
161
- }
162
-
163
- /* Domains */
164
- static void domain_free(void *d) {
165
- generic_free(Domain, d);
166
- }
167
-
168
- static virDomainPtr domain_get(VALUE s) {
169
- generic_get(Domain, s);
170
- }
171
-
172
- static VALUE domain_new(virDomainPtr d, VALUE conn) {
173
- return generic_new(c_domain, d, conn, domain_free);
174
- }
175
-
176
- /* Network */
177
- #if HAVE_TYPE_VIRNETWORKPTR
178
- static void network_free(void *d) {
179
- generic_free(Network, d);
180
- }
181
-
182
- static virNetworkPtr network_get(VALUE s) {
183
- generic_get(Network, s);
184
- }
185
-
186
- static VALUE network_new(virNetworkPtr n, VALUE conn) {
187
- return generic_new(c_network, n, conn, network_free);
188
- }
189
- #endif
190
-
191
- #if HAVE_TYPE_VIRSTORAGEPOOLPTR
192
- /* StoragePool */
193
- static void pool_free(void *d) {
194
- generic_free(StoragePool, d);
195
- }
196
-
197
- static virStoragePoolPtr pool_get(VALUE s) {
198
- generic_get(StoragePool, s);
199
- }
200
-
201
- static VALUE pool_new(virStoragePoolPtr n, VALUE conn) {
202
- return generic_new(c_storage_pool, n, conn, pool_free);
203
- }
204
- #endif
205
-
206
- /* StorageVol */
207
- #if HAVE_TYPE_VIRSTORAGEVOLPTR
208
- static void vol_free(void *d) {
209
- generic_free(StorageVol, d);
210
- }
211
-
212
- static virStorageVolPtr vol_get(VALUE s) {
213
- generic_get(StorageVol, s);
214
- }
215
-
216
- static VALUE vol_new(virStorageVolPtr n, VALUE conn) {
217
- return generic_new(c_storage_vol, n, conn, vol_free);
218
- }
219
- #endif
220
-
221
- /*
222
- * Code generating macros.
223
- *
224
- * We only generate function bodies, not the whole function
225
- * declaration.
226
- */
227
-
228
- /*
229
- * Generate a call to a virConnectNumOf... function. C is the Ruby VALUE
230
- * holding the connection and OBJS is a token indicating what objects to
231
- * get the number of, e.g. 'Domains'
232
- */
233
- #define gen_conn_num_of(c, objs) \
234
- do { \
235
- int result; \
236
- virConnectPtr conn = connect_get(c); \
237
- \
238
- result = virConnectNumOf##objs(conn); \
239
- _E(result < 0, create_error(e_RetrieveError, "virConnectNumOf" # objs, "", conn)); \
240
- \
241
- return INT2NUM(result); \
242
- } while(0)
243
-
244
- /*
245
- * Generate a call to a virConnectList... function. S is the Ruby VALUE
246
- * holding the connection and OBJS is a token indicating what objects to
247
- * get the number of, e.g. 'Domains' The list function must return an array
248
- * of strings, which is returned as a Ruby array
249
- */
250
- #define gen_conn_list_names(s, objs) \
251
- do { \
252
- int i, r, num; \
253
- char **names; \
254
- virConnectPtr conn = connect_get(s); \
255
- VALUE result; \
256
- \
257
- num = virConnectNumOf##objs(conn); \
258
- _E(num < 0, create_error(e_RetrieveError, "virConnectNumOf" # objs, "", conn)); \
259
- if (num == 0) { \
260
- /* if num is 0, don't call virConnectList* function */ \
261
- result = rb_ary_new2(num); \
262
- return result; \
263
- } \
264
- names = ALLOC_N(char *, num); \
265
- r = virConnectList##objs(conn, names, num); \
266
- if (r < 0) { \
267
- free(names); \
268
- _E(r < 0, create_error(e_RetrieveError, "virConnectList" # objs, "", conn)); \
269
- } \
270
- \
271
- result = rb_ary_new2(num); \
272
- for (i=0; i<num; i++) { \
273
- rb_ary_push(result, rb_str_new2(names[i])); \
274
- free(names[i]); \
275
- } \
276
- free(names); \
277
- return result; \
278
- } while(0)
279
-
280
- /* Generate a call to a function FUNC which returns an int error, where -1
281
- * indicates error and 0 success. The Ruby function will return Qnil on
282
- * success and throw an exception on error.
283
- */
284
- #define gen_call_void(func, conn, args...) \
285
- do { \
286
- int _r_##func; \
287
- _r_##func = func(args); \
288
- _E(_r_##func < 0, create_error(e_Error, #func, "", conn)); \
289
- return Qnil; \
290
- } while(0)
291
-
292
- /* Generate a call to a function FUNC which returns a string. The Ruby
293
- * function will return the string on success and throw an exception on
294
- * error. The string returned by FUNC is freed if dealloc is true.
295
- */
296
- #define gen_call_string(func, conn, dealloc, args...) \
297
- do { \
298
- const char *str; \
299
- VALUE result; \
300
- \
301
- str = func(args); \
302
- _E(str == NULL, create_error(e_Error, # func, "", conn)); \
303
- \
304
- result = rb_str_new2(str); \
305
- if (dealloc) \
306
- free((void *) str); \
307
- return result; \
308
- } while(0)
309
-
310
- /* Generate a call to vir##KIND##Free and return Qnil. Set the the embedded
311
- * vir##KIND##Ptr to NULL. If that pointer is already NULL, do nothing.
312
- */
313
- #define gen_call_free(kind, s) \
314
- do { \
315
- vir##kind##Ptr ptr; \
316
- Data_Get_Struct(s, vir##kind, ptr); \
317
- if (ptr != NULL) { \
318
- int r = vir##kind##Free(ptr); \
319
- _E(r < 0, create_error(e_Error, "vir" #kind "Free", "", conn(s))); \
320
- DATA_PTR(s) = NULL; \
321
- } \
322
- return Qnil; \
323
- } while (0)
324
-
325
- /*
326
- * Module Libvirt
327
- */
328
-
329
- /*
330
- * call-seq:
331
- * Libvirt::version(type) -> [ libvirt_version, type_version ]
332
- *
333
- * Call
334
- * +virGetVersion+[http://www.libvirt.org/html/libvirt-libvirt.html#virGetVersion]
335
- * to get the version of libvirt and of the hypervisor TYPE. Returns an
336
- * array with two entries of type Libvirt::Version.
337
- *
338
- */
339
- VALUE libvirt_version(VALUE m, VALUE t) {
340
- unsigned long libVer;
341
- const char *type = NULL;
342
- unsigned long typeVer;
343
- int r;
344
- VALUE result, argv[2];
345
-
346
- type = StringValueCStr(t);
347
- r = virGetVersion(&libVer, type, &typeVer);
348
- if (r < 0)
349
- rb_raise(rb_eArgError, "Failed to get version for %s", type);
350
-
351
- result = rb_ary_new2(2);
352
- argv[0] = rb_str_new2("libvirt");
353
- argv[1] = ULONG2NUM(libVer);
354
- rb_ary_push(result, rb_class_new_instance(2, argv, c_libvirt_version));
355
- argv[0] = t;
356
- argv[1] = ULONG2NUM(typeVer);
357
- rb_ary_push(result, rb_class_new_instance(2, argv, c_libvirt_version));
358
- return result;
359
- }
360
-
361
- /*
362
- * call-seq:
363
- * Libvirt::open(url) -> Libvirt::Connect
364
- *
365
- * Open a connection to URL with virConnectOpen[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectOpen]
366
- */
367
- VALUE libvirt_open(VALUE m, VALUE url) {
368
- char *str = NULL;
369
-
370
- if (url) {
371
- str = StringValueCStr(url);
372
- if (!str)
373
- rb_raise(rb_eTypeError, "expected string");
374
- }
375
- virConnectPtr ptr = virConnectOpen(str);
376
- if (!ptr)
377
- rb_raise(e_ConnectionError, "Failed to open %s", str);
378
- return connect_new(ptr);
379
- }
380
-
381
- /*
382
- * call-seq:
383
- * Libvirt::openReadOnly(url) -> Libvirt::Connect
384
- *
385
- * Open a read-only connection to URL with
386
- * virConnectOpenReadOnly[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectOpenReadOnly]
387
- */
388
- VALUE libvirt_open_read_only(VALUE m, VALUE url) {
389
- char *str = NULL;
390
-
391
- if (url) {
392
- str = StringValueCStr(url);
393
- if (!str)
394
- rb_raise(rb_eTypeError, "expected string");
395
- }
396
- virConnectPtr ptr = virConnectOpenReadOnly(str);
397
- if (!ptr)
398
- rb_raise(e_ConnectionError, "Failed to open %s readonly", str);
399
- return connect_new(ptr);
400
- }
401
-
402
- /*
403
- * Class Libvirt::Connect
404
- */
405
-
406
- /*
407
- * call-seq:
408
- * conn.close
409
- *
410
- * Close the connection
411
- */
412
- VALUE libvirt_conn_close(VALUE s) {
413
- virConnectPtr conn;
414
- Data_Get_Struct(s, virConnect, conn);
415
- if (conn) {
416
- connect_close(conn);
417
- DATA_PTR(s) = NULL;
418
- }
419
- return Qnil;
420
- }
421
-
422
- /*
423
- * call-seq:
424
- * conn.closed?
425
- *
426
- * Return +true+ if the connection is closed, +false+ if it is open
427
- */
428
- VALUE libvirt_conn_closed_p(VALUE s) {
429
- virConnectPtr conn;
430
- Data_Get_Struct(s, virConnect, conn);
431
- return (conn==NULL) ? Qtrue : Qfalse;
432
- }
433
-
434
- /*
435
- * call-seq:
436
- * conn.type -> string
437
- *
438
- * Call +virConnectGetType+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectGetType]
439
- */
440
- VALUE libvirt_conn_type(VALUE s) {
441
- gen_call_string(virConnectGetType, connect_get(s), 0,
442
- connect_get(s));
443
- }
444
-
445
- /*
446
- * call-seq:
447
- * conn.version -> fixnum
448
- *
449
- * Call +virConnectGetVersion+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectGetVersion]
450
- */
451
- VALUE libvirt_conn_version(VALUE s) {
452
- int r;
453
- unsigned long v;
454
- virConnectPtr conn = connect_get(s);
455
-
456
- r = virConnectGetVersion(conn, &v);
457
- _E(r < 0, create_error(e_RetrieveError, "virConnectGetVersion", "", conn));
458
-
459
- return ULONG2NUM(v);
460
- }
461
-
462
- /*
463
- * call-seq:
464
- * conn.hostname -> string
465
- *
466
- * Call +virConnectGetHostname+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectGetHostname]
467
- */
468
- VALUE libvirt_conn_hostname(VALUE s) {
469
- gen_call_string(virConnectGetHostname, connect_get(s), 1,
470
- connect_get(s));
471
- }
472
-
473
- /*
474
- * Call +virConnectGetURI+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectGetURI]
475
- */
476
- VALUE libvirt_conn_uri(VALUE s) {
477
- virConnectPtr conn = connect_get(s);
478
- gen_call_string(virConnectGetURI, conn, 1,
479
- conn);
480
- }
481
-
482
- /*
483
- * Call +virConnectGetMaxVcpus+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectGetMaxVcpus]
484
- */
485
- VALUE libvirt_conn_max_vcpus(VALUE s, VALUE type) {
486
- int result;
487
- virConnectPtr conn = connect_get(s);
488
-
489
- result = virConnectGetMaxVcpus(conn, StringValueCStr(type));
490
- _E(result < 0, create_error(e_RetrieveError, "virConnectGetMaxVcpus", "", conn));
491
-
492
- return INT2NUM(result);
493
- }
494
-
495
- /*
496
- * Call +virNodeInfo+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeGetInfo]
497
- */
498
- VALUE libvirt_conn_node_get_info(VALUE s){
499
- int r;
500
- virConnectPtr conn = connect_get(s);
501
- virNodeInfo nodeinfo;
502
- VALUE result;
503
- VALUE modelstr;
504
-
505
- r = virNodeGetInfo(conn, &nodeinfo);
506
- _E(r < 0, create_error(e_RetrieveError, "virNodeGetInfo", "", conn));
507
-
508
- modelstr = rb_str_new2(nodeinfo.model);
509
-
510
- result = rb_class_new_instance(0, NULL, c_node_info);
511
- rb_iv_set(result, "@model", modelstr);
512
- rb_iv_set(result, "@memory", ULONG2NUM(nodeinfo.memory));
513
- rb_iv_set(result, "@cpus", UINT2NUM(nodeinfo.cpus));
514
- rb_iv_set(result, "@mhz", UINT2NUM(nodeinfo.mhz));
515
- rb_iv_set(result, "@nodes", UINT2NUM(nodeinfo.nodes));
516
- rb_iv_set(result, "@sockets", UINT2NUM(nodeinfo.sockets));
517
- rb_iv_set(result, "@cores", UINT2NUM(nodeinfo.cores));
518
- rb_iv_set(result, "@threads", UINT2NUM(nodeinfo.threads));
519
- return result;
520
- }
521
-
522
- /*
523
- * Call +virConnectGetCapabilities+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectGetCapabilities]
524
- */
525
- VALUE libvirt_conn_capabilities(VALUE s) {
526
- virConnectPtr conn = connect_get(s);
527
- gen_call_string(virConnectGetCapabilities, conn, 1,
528
- conn);
529
- }
530
-
531
- /*
532
- * Call +virConnectNumOfDomains+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfDomains]
533
- */
534
- VALUE libvirt_conn_num_of_domains(VALUE s) {
535
- gen_conn_num_of(s, Domains);
536
- }
537
-
538
- /*
539
- * Call +virConnectListDomains+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListDomains]
540
- */
541
- VALUE libvirt_conn_list_domains(VALUE s) {
542
- int i, r, num, *ids;
543
- virConnectPtr conn = connect_get(s);
544
- VALUE result;
545
-
546
- num = virConnectNumOfDomains(conn);
547
- _E(num < 0, create_error(e_RetrieveError, "virConnectNumOfDomains", "", conn));
548
- if (num == 0) {
549
- result = rb_ary_new2(num);
550
- return result;
551
- }
552
-
553
- ids = ALLOC_N(int, num);
554
- r = virConnectListDomains(conn, ids, num);
555
- if (r < 0) {
556
- free(ids);
557
- _E(r < 0, create_error(e_RetrieveError, "virConnectListDomains", "", conn));
558
- }
559
-
560
- result = rb_ary_new2(num);
561
- for (i=0; i<num; i++) {
562
- rb_ary_push(result, INT2NUM(ids[i]));
563
- }
564
- free(ids);
565
- return result;
566
- }
567
-
568
- /*
569
- * Call +virConnectNumOfDefinedDomains+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfDefinedDomains]
570
- */
571
- VALUE libvirt_conn_num_of_defined_domains(VALUE s) {
572
- gen_conn_num_of(s, DefinedDomains);
573
- }
574
-
575
- /*
576
- * Call +virConnectListDefinedDomains+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListDefinedDomains]
577
- */
578
- VALUE libvirt_conn_list_defined_domains(VALUE s) {
579
- gen_conn_list_names(s, DefinedDomains);
580
- }
581
-
582
- /*
583
- * Call +virConnectNumOfNetworks+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfNetworks]
584
- */
585
- VALUE libvirt_conn_num_of_networks(VALUE s) {
586
- gen_conn_num_of(s, Networks);
587
- }
588
-
589
- /*
590
- * Call +virConnectListNetworks+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListNetworks]
591
- */
592
- VALUE libvirt_conn_list_networks(VALUE s) {
593
- gen_conn_list_names(s, Networks);
594
- }
595
-
596
- /*
597
- * Call +virConnectNumOfDefinedNetworks+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfDefinedNetworks]
598
- */
599
- VALUE libvirt_conn_num_of_defined_networks(VALUE s) {
600
- gen_conn_num_of(s, DefinedNetworks);
601
- }
602
-
603
- /*
604
- * Call +virConnectListDefinedNetworks+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListDefinedNetworks]
605
- */
606
- VALUE libvirt_conn_list_defined_networks(VALUE s) {
607
- gen_conn_list_names(s, DefinedNetworks);
608
- }
609
-
610
- #if HAVE_TYPE_VIRSTORAGEPOOLPTR
611
- /*
612
- * Call +virConnectListStoragePools+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListStoragePools]
613
- */
614
- VALUE libvirt_conn_list_storage_pools(VALUE s) {
615
- gen_conn_list_names(s, StoragePools);
616
- }
617
-
618
- /*
619
- * Call +virConnectNumOfStoragePools+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfStoragePools]
620
- */
621
- VALUE libvirt_conn_num_of_storage_pools(VALUE s) {
622
- gen_conn_num_of(s, StoragePools);
623
- }
624
-
625
- /*
626
- * Call +virConnectListDefinedStoragePools+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListDefinedStoragePools]
627
- */
628
- VALUE libvirt_conn_list_defined_storage_pools(VALUE s) {
629
- gen_conn_list_names(s, DefinedStoragePools);
630
- }
631
-
632
- /*
633
- * Call +virConnectNumOfDefinedStoragePools+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfDefinedStoragePools]
634
- */
635
- VALUE libvirt_conn_num_of_defined_storage_pools(VALUE s) {
636
- gen_conn_num_of(s, DefinedStoragePools);
637
- }
638
- #endif
639
-
640
- static char *get_string_or_nil(VALUE arg)
641
- {
642
- if (TYPE(arg) == T_NIL)
643
- return NULL;
644
- else if (TYPE(arg) == T_STRING)
645
- return StringValueCStr(arg);
646
- else
647
- rb_raise(rb_eTypeError, "wrong argument type (expected String or nil)"); return NULL;
648
- }
649
-
650
- /*
651
- * Class Libvirt::Domain
652
- */
653
- VALUE libvirt_dom_migrate(int argc, VALUE *argv, VALUE s) {
654
- VALUE dconn, flags, dname_val, uri_val, bandwidth;
655
- virDomainPtr ddom = NULL;
656
- const char *dname;
657
- const char *uri;
658
-
659
- rb_scan_args(argc, argv, "23", &dconn, &flags, &dname_val, &uri_val,
660
- &bandwidth);
661
-
662
- dname = get_string_or_nil(dname_val);
663
- uri = get_string_or_nil(uri_val);
664
-
665
- if (NIL_P(bandwidth))
666
- bandwidth = INT2FIX(0);
667
-
668
- ddom = virDomainMigrate(domain_get(s), conn(dconn), NUM2UINT(flags),
669
- dname, uri, NUM2UINT(bandwidth));
670
-
671
- _E(ddom == NULL,
672
- create_error(e_Error, "virDomainMigrate", "", conn(dconn)));
673
-
674
- return domain_new(ddom, dconn);
675
- }
676
-
677
- /*
678
- * Call +virDomainShutdown+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainShutdown]
679
- */
680
- VALUE libvirt_dom_shutdown(VALUE s) {
681
- gen_call_void(virDomainShutdown, conn(s),
682
- domain_get(s));
683
- }
684
-
685
- /*
686
- * Call +virDomainReboot+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainReboot]
687
- */
688
- VALUE libvirt_dom_reboot(int argc, VALUE *argv, VALUE s) {
689
- VALUE flags;
690
-
691
- rb_scan_args(argc, argv, "01", &flags);
692
-
693
- if (NIL_P(flags))
694
- flags = INT2FIX(0);
695
-
696
- gen_call_void(virDomainReboot, conn(s),
697
- domain_get(s), NUM2UINT(flags));
698
- }
699
-
700
- /*
701
- * Call +virDomainDestroy+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainDestroy]
702
- */
703
- VALUE libvirt_dom_destroy(VALUE s) {
704
- gen_call_void(virDomainDestroy, conn(s),
705
- domain_get(s));
706
- }
707
-
708
- /*
709
- * Call +virDomainSuspend+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSuspend]
710
- */
711
- VALUE libvirt_dom_suspend(VALUE s) {
712
- gen_call_void(virDomainSuspend, conn(s),
713
- domain_get(s));
714
- }
715
-
716
- /*
717
- * Call +virDomainResume+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainResume]
718
- */
719
- VALUE libvirt_dom_resume(VALUE s) {
720
- gen_call_void(virDomainResume, conn(s),
721
- domain_get(s));
722
- }
723
-
724
- /*
725
- * Call +virDomainSave+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSave]
726
- */
727
- VALUE libvirt_dom_save(VALUE s, VALUE to) {
728
- gen_call_void(virDomainSave, conn(s),
729
- domain_get(s), StringValueCStr(to));
730
- }
731
-
732
- /*
733
- * Call +virDomainCoreDump+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainCoreDump]
734
- */
735
- VALUE libvirt_dom_core_dump(int argc, VALUE *argv, VALUE s) {
736
- VALUE to, flags;
737
-
738
- rb_scan_args(argc, argv, "11", &to, &flags);
739
-
740
- if (NIL_P(flags))
741
- flags = INT2FIX(0);
742
-
743
- gen_call_void(virDomainCoreDump, conn(s),
744
- domain_get(s), StringValueCStr(to), NUM2UINT(flags));
745
- }
746
-
747
- /*
748
- * Call +virDomainRestore+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainRestore]
749
- */
750
- VALUE libvirt_dom_s_restore(VALUE klass, VALUE c, VALUE from) {
751
- gen_call_void(virDomainRestore, connect_get(c),
752
- connect_get(c), StringValueCStr(from));
753
- }
754
-
755
- /*
756
- * call-seq:
757
- * domain.info -> Libvirt::Domain::Info
758
- *
759
- * Call +virDomainGetInfo+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetInfo]
760
- */
761
- VALUE libvirt_dom_info(VALUE s) {
762
- virDomainPtr dom = domain_get(s);
763
- virDomainInfo info;
764
- int r;
765
- VALUE result;
766
-
767
- r = virDomainGetInfo(dom, &info);
768
- _E(r < 0, create_error(e_RetrieveError, "virDomainGetInfo", "", conn(s)));
769
-
770
- result = rb_class_new_instance(0, NULL, c_domain_info);
771
- rb_iv_set(result, "@state", CHR2FIX(info.state));
772
- rb_iv_set(result, "@max_mem", ULONG2NUM(info.maxMem));
773
- rb_iv_set(result, "@memory", ULONG2NUM(info.memory));
774
- rb_iv_set(result, "@nr_virt_cpu", INT2FIX((int) info.nrVirtCpu));
775
- rb_iv_set(result, "@cpu_time", ULL2NUM(info.cpuTime));
776
- return result;
777
- }
778
-
779
-
780
- /*
781
- * Call +virDomainGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetName]
782
- */
783
- VALUE libvirt_dom_name(VALUE s) {
784
- gen_call_string(virDomainGetName, conn(s), 0,
785
- domain_get(s));
786
- }
787
-
788
- /*
789
- * Call +virDomainGetID+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetID]
790
- */
791
- VALUE libvirt_dom_id(VALUE s) {
792
- virDomainPtr dom = domain_get(s);
793
- unsigned int id;
794
-
795
- id = virDomainGetID(dom);
796
- _E(id < 0, create_error(e_RetrieveError, "virDomainGetID", "", conn(s)));
797
-
798
- return UINT2NUM(id);
799
- }
800
-
801
- /*
802
- * Call +virDomainGetUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetUUIDString]
803
- */
804
- VALUE libvirt_dom_uuid(VALUE s) {
805
- virDomainPtr dom = domain_get(s);
806
- char uuid[VIR_UUID_STRING_BUFLEN];
807
- int r;
808
-
809
- r = virDomainGetUUIDString(dom, uuid);
810
- _E(r < 0, create_error(e_RetrieveError, "virDomainGetUUIDString", "", conn(s)));
811
-
812
- return rb_str_new2((char *) uuid);
813
- }
814
-
815
- /*
816
- * Call +virDomainGetOSType+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetOSType]
817
- */
818
- VALUE libvirt_dom_os_type(VALUE s) {
819
- gen_call_string(virDomainGetOSType, conn(s), 1,
820
- domain_get(s));
821
- }
822
-
823
- /*
824
- * Call +virDomainGetMaxMemory+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetMaxMemory]
825
- */
826
- VALUE libvirt_dom_max_memory(VALUE s) {
827
- virDomainPtr dom = domain_get(s);
828
- unsigned long max_memory;
829
-
830
- max_memory = virDomainGetMaxMemory(dom);
831
- _E(max_memory == 0, create_error(e_RetrieveError, "virDomainGetMaxMemory", "", conn(s)));
832
-
833
- return ULONG2NUM(max_memory);
834
- }
835
-
836
- /*
837
- * Call +virDomainSetMaxMemory+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSetMaxMemory]
838
- */
839
- VALUE libvirt_dom_max_memory_set(VALUE s, VALUE max_memory) {
840
- virDomainPtr dom = domain_get(s);
841
- int r;
842
-
843
- r = virDomainSetMaxMemory(dom, NUM2ULONG(max_memory));
844
- _E(r < 0, create_error(e_DefinitionError, "virDomainSetMaxMemory", "", conn(s)));
845
-
846
- return ULONG2NUM(max_memory);
847
- }
848
-
849
- /*
850
- * Call +virDomainSetMemory+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSetMemory]
851
- */
852
- VALUE libvirt_dom_memory_set(VALUE s, VALUE memory) {
853
- virDomainPtr dom = domain_get(s);
854
- int r;
855
-
856
- r = virDomainSetMemory(dom, NUM2ULONG(memory));
857
- _E(r < 0, create_error(e_DefinitionError, "virDomainSetMemory", "", conn(s)));
858
-
859
- return ULONG2NUM(memory);
860
- }
861
-
862
- /*
863
- * Call +virDomainGetMaxVcpus+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetMaxVcpus]
864
- */
865
- VALUE libvirt_dom_max_vcpus(VALUE s) {
866
- virDomainPtr dom = domain_get(s);
867
- int vcpus;
868
-
869
- vcpus = virDomainGetMaxVcpus(dom);
870
- _E(vcpus < 0, create_error(e_RetrieveError, "virDomainGetMaxVcpus", "", conn(s)));
871
-
872
- return INT2NUM(vcpus);
873
- }
874
-
875
-
876
- /*
877
- * Call +virDomainSetVcpus+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSetVcpus]
878
- */
879
- VALUE libvirt_dom_vcpus_set(VALUE s, VALUE nvcpus) {
880
- virDomainPtr dom = domain_get(s);
881
- int r;
882
-
883
- r = virDomainSetVcpus(dom, NUM2UINT(nvcpus));
884
- _E(r < 0, create_error(e_DefinitionError, "virDomainSetVcpus", "", conn(s)));
885
-
886
- return r;
887
- }
888
-
889
- /*
890
- * Call +virDomainPinVcpu+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainPinVcpu]
891
- */
892
- VALUE libvirt_dom_pin_vcpu(VALUE s, VALUE vcpu, VALUE cpulist) {
893
- virDomainPtr dom = domain_get(s);
894
- int r, i, len, maplen;
895
- unsigned char *cpumap;
896
- virNodeInfo nodeinfo;
897
- virConnectPtr c = conn(s);
898
-
899
- r = virNodeGetInfo(c, &nodeinfo);
900
- _E(r < 0, create_error(e_RetrieveError, "virNodeGetInfo", "", c));
901
-
902
- maplen = VIR_CPU_MAPLEN(nodeinfo.cpus);
903
- cpumap = ALLOC_N(unsigned char, maplen);
904
- MEMZERO(cpumap, unsigned char, maplen);
905
-
906
- len = RARRAY(cpulist)->len;
907
- for(i = 0; i < len; i++) {
908
- VALUE e = rb_ary_entry(cpulist, i);
909
- VIR_USE_CPU(cpumap, NUM2UINT(e));
910
- }
911
-
912
- r = virDomainPinVcpu(dom, NUM2UINT(vcpu), cpumap, maplen);
913
- free(cpumap);
914
- _E(r < 0, create_error(e_RetrieveError, "virDomainPinVcpu", "", c));
915
-
916
- return r;
917
- }
918
-
919
-
920
- /*
921
- * Call +virDomainGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetXMLDesc]
922
- */
923
- VALUE libvirt_dom_xml_desc(int argc, VALUE *argv, VALUE s) {
924
- VALUE flags;
925
-
926
- rb_scan_args(argc, argv, "01", &flags);
927
-
928
- if (NIL_P(flags))
929
- flags = INT2FIX(0);
930
-
931
- gen_call_string(virDomainGetXMLDesc, conn(s), 1,
932
- domain_get(s), 0);
933
- }
934
-
935
- /*
936
- * Call +virDomainUndefine+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainUndefine]
937
- */
938
- VALUE libvirt_dom_undefine(VALUE s) {
939
- gen_call_void(virDomainUndefine, conn(s),
940
- domain_get(s));
941
- }
942
-
943
- /*
944
- * Call +virDomainCreate+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainCreate]
945
- */
946
- VALUE libvirt_dom_create(VALUE s) {
947
- gen_call_void(virDomainCreate, conn(s),
948
- domain_get(s));
949
- }
950
-
951
- /*
952
- * Call +virDomainGetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetAutostart]
953
- */
954
- VALUE libvirt_dom_autostart(VALUE s){
955
- virDomainPtr dom = domain_get(s);
956
- int r, autostart;
957
-
958
- r = virDomainGetAutostart(dom, &autostart);
959
- _E(r < 0, create_error(e_RetrieveError, "virDomainAutostart", "", conn(s)));
960
-
961
- return autostart ? Qtrue : Qfalse;
962
- }
963
-
964
- /*
965
- * Call +virDomainSetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSetAutostart]
966
- */
967
- VALUE libvirt_dom_autostart_set(VALUE s, VALUE autostart) {
968
- gen_call_void(virDomainSetAutostart, conn(s),
969
- domain_get(s), RTEST(autostart) ? 1 : 0);
970
- }
971
-
972
- /*
973
- * Call +virDomainCreateLinux+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainCreateLinux]
974
- */
975
- VALUE libvirt_conn_create_linux(int argc, VALUE *argv, VALUE c) {
976
- virDomainPtr dom;
977
- virConnectPtr conn = connect_get(c);
978
- char *xmlDesc;
979
- VALUE flags, xml;
980
-
981
- rb_scan_args(argc, argv, "11", &xml, &flags);
982
-
983
- if (NIL_P(flags))
984
- flags = INT2FIX(0);
985
-
986
- xmlDesc = StringValueCStr(xml);
987
-
988
- dom = virDomainCreateLinux(conn, xmlDesc, NUM2UINT(flags));
989
- _E(dom == NULL, create_error(e_Error, "virDomainCreateLinux", "", conn));
990
-
991
- return domain_new(dom, c);
992
- }
993
-
994
- /*
995
- * Call +virDomainLookupByName+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainLookupByName]
996
- */
997
- VALUE libvirt_conn_lookup_domain_by_name(VALUE c, VALUE name) {
998
- virDomainPtr dom;
999
- virConnectPtr conn = connect_get(c);
1000
-
1001
- dom = virDomainLookupByName(conn, StringValueCStr(name));
1002
- _E(dom == NULL, create_error(e_RetrieveError, "virDomainLookupByName", "", conn));
1003
-
1004
- return domain_new(dom, c);
1005
- }
1006
-
1007
- /*
1008
- * Call +virDomainLookupByID+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainLookupByID]
1009
- */
1010
- VALUE libvirt_conn_lookup_domain_by_id(VALUE c, VALUE id) {
1011
- virDomainPtr dom;
1012
- virConnectPtr conn = connect_get(c);
1013
-
1014
- dom = virDomainLookupByID(conn, NUM2INT(id));
1015
- _E(dom == NULL, create_error(e_RetrieveError, "virDomainLookupByID", "", conn));
1016
-
1017
- return domain_new(dom, c);
1018
- }
1019
-
1020
- /*
1021
- * Call +virDomainLookupByUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainLookupByUUIDString]
1022
- */
1023
- VALUE libvirt_conn_lookup_domain_by_uuid(VALUE c, VALUE uuid) {
1024
- virDomainPtr dom;
1025
- virConnectPtr conn = connect_get(c);
1026
-
1027
- dom = virDomainLookupByUUIDString(conn, StringValueCStr(uuid));
1028
- _E(dom == NULL, create_error(e_RetrieveError, "virDomainLookupByUUID", "", conn));
1029
-
1030
- return domain_new(dom, c);
1031
- }
1032
-
1033
- /*
1034
- * Call +virDomainDefineXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainDefineXML]
1035
- */
1036
- VALUE libvirt_conn_define_domain_xml(VALUE c, VALUE xml) {
1037
- virDomainPtr dom;
1038
- virConnectPtr conn = connect_get(c);
1039
-
1040
- dom = virDomainDefineXML(conn, StringValueCStr(xml));
1041
- _E(dom == NULL, create_error(e_DefinitionError, "virDomainDefineXML", "", conn));
1042
-
1043
- return domain_new(dom, c);
1044
- }
1045
-
1046
- /*
1047
- * Call +virDomainFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainFree]
1048
- */
1049
- VALUE libvirt_dom_free(VALUE s) {
1050
- gen_call_free(Domain, s);
1051
- }
1052
-
1053
- /*
1054
- * Class Libvirt::Network
1055
- */
1056
-
1057
- #if HAVE_TYPE_VIRNETWORKPTR
1058
- /*
1059
- * Call +virNetworkLookupByName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkLookupByName]
1060
- */
1061
- VALUE libvirt_conn_lookup_network_by_name(VALUE c, VALUE name) {
1062
- virNetworkPtr netw;
1063
- virConnectPtr conn = connect_get(c);
1064
-
1065
- netw = virNetworkLookupByName(conn, StringValueCStr(name));
1066
- _E(netw == NULL, create_error(e_RetrieveError, "virNetworkLookupByName", "", conn));
1067
-
1068
- return network_new(netw, c);
1069
- }
1070
-
1071
- /*
1072
- * Call +virNetworkLookupByUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkLookupByUUIDString]
1073
- */
1074
- VALUE libvirt_conn_lookup_network_by_uuid(VALUE c, VALUE uuid) {
1075
- virNetworkPtr netw;
1076
- virConnectPtr conn = connect_get(c);
1077
-
1078
- netw = virNetworkLookupByUUIDString(conn, StringValueCStr(uuid));
1079
- _E(netw == NULL, create_error(e_RetrieveError, "virNetworkLookupByUUID", "", conn));
1080
-
1081
- return network_new(netw, c);
1082
- }
1083
-
1084
- /*
1085
- * Call +virNetworkCreateXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkCreateXML]
1086
- */
1087
- VALUE libvirt_conn_create_network_xml(VALUE c, VALUE xml) {
1088
- virNetworkPtr netw;
1089
- virConnectPtr conn = connect_get(c);
1090
- char *xmlDesc;
1091
-
1092
- xmlDesc = StringValueCStr(xml);
1093
-
1094
- netw = virNetworkCreateXML(conn, xmlDesc);
1095
- _E(netw == NULL, create_error(e_Error, "virNetworkCreateXML", "", conn));
1096
-
1097
- return network_new(netw, c);
1098
- }
1099
-
1100
- /*
1101
- * Call +virNetworkDefineXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkDefineXML]
1102
- */
1103
- VALUE libvirt_conn_define_network_xml(VALUE c, VALUE xml) {
1104
- virNetworkPtr netw;
1105
- virConnectPtr conn = connect_get(c);
1106
-
1107
- netw = virNetworkDefineXML(conn, StringValueCStr(xml));
1108
- _E(netw == NULL, create_error(e_DefinitionError, "virNetworkDefineXML", "", conn));
1109
-
1110
- return network_new(netw, c);
1111
- }
1112
- #endif
1113
-
1114
- #if HAVE_TYPE_VIRNETWORKPTR
1115
- /*
1116
- * Call +virNetworkUndefine+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkUndefine]
1117
- */
1118
- VALUE libvirt_netw_undefine(VALUE s) {
1119
- gen_call_void(virNetworkUndefine, conn(s),
1120
- network_get(s));
1121
- }
1122
-
1123
- /*
1124
- * Call +virNetworkCreate+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkCreate]
1125
- */
1126
- VALUE libvirt_netw_create(VALUE s) {
1127
- gen_call_void(virNetworkCreate, conn(s),
1128
- network_get(s));
1129
- }
1130
-
1131
- /*
1132
- * Call +virNetworkDestroy+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkDestroy]
1133
- */
1134
- VALUE libvirt_netw_destroy(VALUE s) {
1135
- gen_call_void(virNetworkDestroy, conn(s),
1136
- network_get(s));
1137
- }
1138
-
1139
- /*
1140
- * Call +virNetworkGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkGetName]
1141
- */
1142
- VALUE libvirt_netw_name(VALUE s) {
1143
- gen_call_string(virNetworkGetName, conn(s), 0,
1144
- network_get(s));
1145
- }
1146
-
1147
- /*
1148
- * Call +virNetworkGetUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkGetUUIDString]
1149
- */
1150
- VALUE libvirt_netw_uuid(VALUE s) {
1151
- virNetworkPtr netw = network_get(s);
1152
- char uuid[VIR_UUID_STRING_BUFLEN];
1153
- int r;
1154
-
1155
- r = virNetworkGetUUIDString(netw, uuid);
1156
- _E(r < 0, create_error(e_RetrieveError, "virNetworkGetUUIDString", "", conn(s)));
1157
-
1158
- return rb_str_new2((char *) uuid);
1159
- }
1160
-
1161
- /*
1162
- * Call +virNetworkGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkGetXMLDesc]
1163
- */
1164
- VALUE libvirt_netw_xml_desc(int argc, VALUE *argv, VALUE s) {
1165
- VALUE flags;
1166
-
1167
- rb_scan_args(argc, argv, "01", &flags);
1168
-
1169
- if (NIL_P(flags))
1170
- flags = INT2FIX(0);
1171
-
1172
- gen_call_string(virNetworkGetXMLDesc, conn(s), 1,
1173
- network_get(s), NUM2UINT(flags));
1174
- }
1175
-
1176
- /*
1177
- * Call +virNetworkGetBridgeName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkGetBridgeName]
1178
- */
1179
- VALUE libvirt_netw_bridge_name(VALUE s) {
1180
- gen_call_string(virNetworkGetBridgeName, conn(s), 1,
1181
- network_get(s));
1182
- }
1183
-
1184
- /*
1185
- * Call +virNetworkGetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkGetAutostart]
1186
- */
1187
- VALUE libvirt_netw_autostart(VALUE s){
1188
- virNetworkPtr netw = network_get(s);
1189
- int r, autostart;
1190
-
1191
- r = virNetworkGetAutostart(netw, &autostart);
1192
- _E(r < 0, create_error(e_RetrieveError, "virNetworkAutostart", "", conn(s)));
1193
-
1194
- return autostart ? Qtrue : Qfalse;
1195
- }
1196
-
1197
- /*
1198
- * Call +virNetworkSetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkSetAutostart]
1199
- */
1200
- VALUE libvirt_netw_autostart_set(VALUE s, VALUE autostart) {
1201
- gen_call_void(virNetworkSetAutostart, conn(s),
1202
- network_get(s), RTEST(autostart) ? 1 : 0);
1203
- }
1204
-
1205
- /*
1206
- * Call +virNetworkFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkFree]
1207
- */
1208
- VALUE libvirt_netw_free(VALUE s) {
1209
- gen_call_free(Network, s);
1210
- }
1211
- #endif
1212
-
1213
- /*
1214
- * Libvirt::StoragePool
1215
- */
1216
-
1217
- #if HAVE_TYPE_VIRSTORAGEPOOLPTR
1218
- /*
1219
- * Call +virStoragePoolLookupByName+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolLookupByName]
1220
- */
1221
- VALUE libvirt_conn_lookup_pool_by_name(VALUE c, VALUE name) {
1222
- virStoragePoolPtr pool;
1223
- virConnectPtr conn = connect_get(c);
1224
-
1225
- pool = virStoragePoolLookupByName(conn, StringValueCStr(name));
1226
- _E(pool == NULL, create_error(e_RetrieveError, "virStoragePoolLookupByName", "", conn));
1227
-
1228
- return pool_new(pool, c);
1229
- }
1230
-
1231
- /*
1232
- * Call +virStoragePoolLookupByUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolLookupByUUIDString]
1233
- */
1234
- VALUE libvirt_conn_lookup_pool_by_uuid(VALUE c, VALUE uuid) {
1235
- virStoragePoolPtr pool;
1236
- virConnectPtr conn = connect_get(c);
1237
-
1238
- pool = virStoragePoolLookupByUUIDString(conn, StringValueCStr(uuid));
1239
- _E(pool == NULL, create_error(e_RetrieveError, "virStoragePoolLookupByUUID", "", conn));
1240
-
1241
- return pool_new(pool, c);
1242
- }
1243
-
1244
- /*
1245
- * Call +virStoragePoolLookupByVolume+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolLookupByVolume]
1246
- */
1247
- VALUE libvirt_vol_get_pool(VALUE v) {
1248
- virStoragePoolPtr pool;
1249
-
1250
- pool = virStoragePoolLookupByVolume(vol_get(v));
1251
- _E(pool == NULL, create_error(e_RetrieveError, "virStoragePoolLookupByVolume", "", conn(v)));
1252
-
1253
- return pool_new(pool, conn_attr(v));
1254
- }
1255
-
1256
- /*
1257
- * Call +virStoragePoolCreateXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolCreateXML]
1258
- */
1259
- VALUE libvirt_conn_create_pool_xml(int argc, VALUE *argv, VALUE c) {
1260
- virStoragePoolPtr pool;
1261
- virConnectPtr conn = connect_get(c);
1262
- char *xmlDesc;
1263
- VALUE xml, flags;
1264
-
1265
- rb_scan_args(argc, argv, "11", &xml, &flags);
1266
-
1267
- if (NIL_P(flags))
1268
- flags = INT2FIX(0);
1269
-
1270
- xmlDesc = StringValueCStr(xml);
1271
-
1272
- pool = virStoragePoolCreateXML(conn, xmlDesc, NUM2UINT(flags));
1273
- _E(pool == NULL, create_error(e_Error, "virStoragePoolCreateXML", "", conn));
1274
-
1275
- return pool_new(pool, c);
1276
- }
1277
-
1278
- /*
1279
- * Call +virStoragePoolDefineXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolDefineXML]
1280
- */
1281
- VALUE libvirt_conn_define_pool_xml(int argc, VALUE *argv, VALUE c) {
1282
- virStoragePoolPtr pool;
1283
- virConnectPtr conn = connect_get(c);
1284
- VALUE xml, flags;
1285
-
1286
- rb_scan_args(argc, argv, "11", &xml, &flags);
1287
-
1288
- if (NIL_P(flags))
1289
- flags = INT2FIX(0);
1290
-
1291
- pool = virStoragePoolDefineXML(conn, StringValueCStr(xml), NUM2UINT(flags));
1292
- _E(pool == NULL, create_error(e_DefinitionError, "virStoragePoolDefineXML", "", conn));
1293
-
1294
- return pool_new(pool, c);
1295
- }
1296
-
1297
- /*
1298
- * Call +virConnectFindStoragePoolSources+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectFindStoragePoolSources]
1299
- */
1300
- VALUE libvirt_conn_find_storage_pool_sources(int argc, VALUE *argv, VALUE c) {
1301
- virConnectPtr conn = connect_get(c);
1302
- VALUE type, srcSpec_val, flags;
1303
- const char *srcSpec;
1304
-
1305
- rb_scan_args(argc, argv, "12", &type, &srcSpec_val, &flags);
1306
-
1307
- srcSpec = get_string_or_nil(srcSpec_val);
1308
-
1309
- if (NIL_P(flags))
1310
- flags = INT2FIX(0);
1311
-
1312
- gen_call_string(virConnectFindStoragePoolSources, conn, 1, conn,
1313
- StringValueCStr(type), srcSpec, NUM2UINT(flags));
1314
- }
1315
-
1316
- /*
1317
- * Call +virStoragePoolBuild+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolBuild]
1318
- */
1319
- VALUE libvirt_pool_build(int argc, VALUE *argv, VALUE p) {
1320
- VALUE flags;
1321
-
1322
- rb_scan_args(argc, argv, "01", &flags);
1323
-
1324
- if (NIL_P(flags))
1325
- flags = INT2FIX(0);
1326
-
1327
- gen_call_void(virStoragePoolBuild, conn(p),
1328
- pool_get(p), NUM2UINT(flags));
1329
- }
1330
-
1331
- /*
1332
- * Call +virStoragePoolUndefine+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolUndefine]
1333
- */
1334
- VALUE libvirt_pool_undefine(VALUE p) {
1335
- gen_call_void(virStoragePoolUndefine, conn(p),
1336
- pool_get(p));
1337
- }
1338
-
1339
- /*
1340
- * Call +virStoragePoolCreate+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolCreate]
1341
- */
1342
- VALUE libvirt_pool_create(int argc, VALUE *argv, VALUE p) {
1343
- VALUE flags;
1344
-
1345
- rb_scan_args(argc, argv, "01", &flags);
1346
-
1347
- if (NIL_P(flags))
1348
- flags = INT2FIX(0);
1349
-
1350
- gen_call_void(virStoragePoolCreate, conn(p),
1351
- pool_get(p), NUM2UINT(flags));
1352
- }
1353
-
1354
- /*
1355
- * Call +virStoragePoolDestroy+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolDestroy]
1356
- */
1357
- VALUE libvirt_pool_destroy(VALUE p) {
1358
- gen_call_void(virStoragePoolDestroy, conn(p),
1359
- pool_get(p));
1360
- }
1361
-
1362
- /*
1363
- * Call +virStoragePoolDelete+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolDelete]
1364
- */
1365
- VALUE libvirt_pool_delete(int argc, VALUE *argv, VALUE p) {
1366
- VALUE flags;
1367
-
1368
- rb_scan_args(argc, argv, "01", &flags);
1369
-
1370
- if (NIL_P(flags))
1371
- flags = INT2FIX(0);
1372
-
1373
- gen_call_void(virStoragePoolDelete, conn(p),
1374
- pool_get(p), NUM2UINT(flags));
1375
- }
1376
-
1377
- /*
1378
- * Call +virStoragePoolRefresh+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolRefresh]
1379
- */
1380
- VALUE libvirt_pool_refresh(int argc, VALUE *argv, VALUE p) {
1381
- VALUE flags;
1382
-
1383
- rb_scan_args(argc, argv, "01", &flags);
1384
-
1385
- if (NIL_P(flags))
1386
- flags = INT2FIX(0);
1387
-
1388
- gen_call_void(virStoragePoolRefresh, conn(p),
1389
- pool_get(p), NUM2UINT(flags));
1390
- }
1391
-
1392
- /*
1393
- * Call +virStoragePoolGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolGetName]
1394
- */
1395
- VALUE libvirt_pool_name(VALUE s) {
1396
- const char *name;
1397
-
1398
- name = virStoragePoolGetName(pool_get(s));
1399
- _E(name == NULL, create_error(e_RetrieveError, "virStoragePoolGetName", "", conn(s)));
1400
-
1401
- return rb_str_new2(name);
1402
- }
1403
-
1404
- /*
1405
- * Call +virStoragePoolGetUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolGetUUIDString]
1406
- */
1407
- VALUE libvirt_pool_uuid(VALUE s) {
1408
- char uuid[VIR_UUID_STRING_BUFLEN];
1409
- int r;
1410
-
1411
- r = virStoragePoolGetUUIDString(pool_get(s), uuid);
1412
- _E(r < 0, create_error(e_RetrieveError, "virStoragePoolGetUUIDString", "", conn(s)));
1413
-
1414
- return rb_str_new2((char *) uuid);
1415
- }
1416
-
1417
- /*
1418
- * Call +virStoragePoolGetInfo+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolGetInfo]
48
+ * call-seq:
49
+ * Libvirt::version(type) -> [ libvirt_version, type_version ]
50
+ *
51
+ * Call
52
+ * +virGetVersion+[http://www.libvirt.org/html/libvirt-libvirt.html#virGetVersion]
53
+ * to get the version of libvirt and of the hypervisor TYPE. Returns an
54
+ * array with two entries of type Libvirt::Version.
1419
55
  */
1420
- VALUE libvirt_pool_info(VALUE s) {
1421
- virStoragePoolInfo info;
56
+ VALUE libvirt_version(int argc, VALUE *argv, VALUE m) {
57
+ unsigned long libVer;
58
+ VALUE type;
59
+ unsigned long typeVer;
1422
60
  int r;
1423
- VALUE result;
1424
-
1425
- r = virStoragePoolGetInfo(pool_get(s), &info);
1426
- _E(r < 0, create_error(e_RetrieveError, "virStoragePoolGetInfo", "", conn(s)));
1427
-
1428
- result = rb_class_new_instance(0, NULL, c_storage_pool_info);
1429
- rb_iv_set(result, "@state", INT2FIX(info.state));
1430
- rb_iv_set(result, "@capacity", ULL2NUM(info.capacity));
1431
- rb_iv_set(result, "@allocation", ULL2NUM(info.allocation));
1432
- rb_iv_set(result, "@available", ULL2NUM(info.available));
1433
-
1434
- return result;
1435
- }
1436
-
1437
- /*
1438
- * Call +virStoragePoolGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolGetXMLDesc]
1439
- */
1440
- VALUE libvirt_pool_xml_desc(int argc, VALUE *argv, VALUE s) {
1441
- VALUE flags;
1442
-
1443
- rb_scan_args(argc, argv, "01", &flags);
1444
-
1445
- if (NIL_P(flags))
1446
- flags = INT2FIX(0);
1447
-
1448
- gen_call_string(virStoragePoolGetXMLDesc, conn(s), 1,
1449
- pool_get(s), NUM2UINT(flags));
1450
- }
1451
-
1452
- /*
1453
- * Call +virStoragePoolGetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolGetAutostart]
1454
- */
1455
- VALUE libvirt_pool_autostart(VALUE s){
1456
- int r, autostart;
61
+ VALUE result, rargv[2];
1457
62
 
1458
- r = virStoragePoolGetAutostart(pool_get(s), &autostart);
1459
- _E(r < 0, create_error(e_RetrieveError, "virStoragePoolGetAutostart", "", conn(s)));
63
+ rb_scan_args(argc, argv, "01", &type);
1460
64
 
1461
- return autostart ? Qtrue : Qfalse;
1462
- }
1463
-
1464
- /*
1465
- * Call +virStoragePoolSetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolSetAutostart]
1466
- */
1467
- VALUE libvirt_pool_autostart_set(VALUE s, VALUE autostart) {
1468
- gen_call_void(virStoragePoolSetAutostart, conn(s),
1469
- pool_get(s), RTEST(autostart) ? 1 : 0);
1470
- }
1471
-
1472
- /*
1473
- * Call +virStoragePoolNumOfVolumes+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolNumOfVolumes]
1474
- */
1475
- VALUE libvirt_pool_num_of_volumes(VALUE s) {
1476
- int n = virStoragePoolNumOfVolumes(pool_get(s));
1477
- _E(n < 0, create_error(e_RetrieveError, "virStoragePoolNumOfVolumes", "", conn(s)));
65
+ r = virGetVersion(&libVer, get_string_or_nil(type), &typeVer);
66
+ _E(r < 0, create_error(rb_eArgError, "virGetVersion",
67
+ "Failed to get version", NULL));
1478
68
 
1479
- return INT2FIX(n);
1480
- }
1481
-
1482
- /*
1483
- * Call +virStoragePoolListVolumes+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolListVolumes]
1484
- */
1485
- VALUE libvirt_pool_list_volumes(VALUE s) {
1486
- int i, r, num;
1487
- char **names;
1488
- virStoragePoolPtr pool = pool_get(s);
1489
- VALUE result;
1490
-
1491
- num = virStoragePoolNumOfVolumes(pool);
1492
- _E(num < 0, create_error(e_RetrieveError, "virStoragePoolNumOfVolumes", "", conn(s)));
1493
- if (num == 0) {
1494
- result = rb_ary_new2(num);
1495
- return result;
1496
- }
1497
-
1498
- names = ALLOC_N(char *, num);
1499
- r = virStoragePoolListVolumes(pool, names, num);
1500
- if (r < 0) {
1501
- free(names);
1502
- _E(r < 0, create_error(e_RetrieveError, "virStoragePoolListVolumes", "", conn(s)));
1503
- }
1504
-
1505
- result = rb_ary_new2(num);
1506
- for (i=0; i<num; i++) {
1507
- rb_ary_push(result, rb_str_new2(names[i]));
1508
- // FIXME: Should these really be freed ?
1509
- free(names[i]);
1510
- }
1511
- free(names);
69
+ result = rb_ary_new2(2);
70
+ rargv[0] = rb_str_new2("libvirt");
71
+ rargv[1] = ULONG2NUM(libVer);
72
+ rb_ary_push(result, rb_class_new_instance(2, rargv, c_libvirt_version));
73
+ rargv[0] = type;
74
+ rargv[1] = ULONG2NUM(typeVer);
75
+ rb_ary_push(result, rb_class_new_instance(2, rargv, c_libvirt_version));
1512
76
  return result;
1513
77
  }
1514
78
 
1515
- /*
1516
- * Call +virStoragePoolFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolFree]
1517
- */
1518
- VALUE libvirt_pool_free(VALUE s) {
1519
- gen_call_free(StoragePool, s);
1520
- }
1521
- #endif
1522
-
1523
- /*
1524
- * Libvirt::StorageVol
1525
- */
1526
- #if HAVE_TYPE_VIRSTORAGEVOLPTR
1527
- /*
1528
- * Call +virStorageVolLookupByName+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolLookupByName]
1529
- */
1530
- VALUE libvirt_pool_lookup_vol_by_name(VALUE p, VALUE name) {
1531
- virStorageVolPtr vol;
1532
-
1533
- vol = virStorageVolLookupByName(pool_get(p), StringValueCStr(name));
1534
- _E(vol == NULL, create_error(e_RetrieveError, "virStorageVolLookupByName", "", conn(p)));
1535
-
1536
- return vol_new(vol, conn_attr(p));
1537
- }
1538
-
1539
- /*
1540
- * Call +virStorageVolLookupByKey+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolLookupByKey]
1541
- */
1542
- VALUE libvirt_pool_lookup_vol_by_key(VALUE p, VALUE key) {
1543
- virStorageVolPtr vol;
1544
-
1545
- // FIXME: Why does this take a connection, not a pool ?
1546
- vol = virStorageVolLookupByKey(conn(p), StringValueCStr(key));
1547
- _E(vol == NULL, create_error(e_RetrieveError, "virStorageVolLookupByKey", "", conn(p)));
1548
-
1549
- return vol_new(vol, conn_attr(p));
1550
- }
1551
-
1552
- /*
1553
- * Call +virStorageVolLookupByPath+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolLookupByPath]
1554
- */
1555
- VALUE libvirt_pool_lookup_vol_by_path(VALUE p, VALUE path) {
1556
- virStorageVolPtr vol;
1557
-
1558
- // FIXME: Why does this take a connection, not a pool ?
1559
- vol = virStorageVolLookupByPath(conn(p), StringValueCStr(path));
1560
- _E(vol == NULL, create_error(e_RetrieveError, "virStorageVolLookupByPath", "", conn(p)));
1561
-
1562
- return vol_new(vol, conn_attr(p));
1563
- }
1564
-
1565
- /*
1566
- * Call +virStorageVolGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetName]
1567
- */
1568
- VALUE libvirt_vol_name(VALUE v) {
1569
- gen_call_string(virStorageVolGetName, conn(v), 0,
1570
- vol_get(v));
1571
- }
1572
-
1573
- /*
1574
- * Call +virStorageVolGetKey+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetKey]
1575
- */
1576
- VALUE libvirt_vol_key(VALUE v) {
1577
- gen_call_string(virStorageVolGetKey, conn(v), 0,
1578
- vol_get(v));
1579
- }
1580
-
1581
- /*
1582
- * Call +virStorageVolCreateXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolCreateXML]
1583
- */
1584
- VALUE libvirt_pool_vol_create_xml(int argc, VALUE *argv, VALUE p) {
1585
- virStorageVolPtr vol;
1586
- virConnectPtr c = conn(p);
1587
- char *xmlDesc;
1588
- VALUE xml, flags;
1589
-
1590
- rb_scan_args(argc, argv, "11", &xml, &flags);
1591
-
1592
- if (NIL_P(flags))
1593
- flags = INT2FIX(0);
1594
-
1595
- xmlDesc = StringValueCStr(xml);
1596
-
1597
- vol = virStorageVolCreateXML(pool_get(p), xmlDesc, NUM2UINT(flags));
1598
- _E(vol == NULL, create_error(e_Error, "virNetworkCreateXML", "", c));
1599
-
1600
- return vol_new(vol, conn_attr(p));
1601
- }
1602
-
1603
- /*
1604
- * Call +virStorageVolDelete+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolDelete]
1605
- */
1606
- VALUE libvirt_vol_delete(int argc, VALUE *argv, VALUE v) {
1607
- VALUE flags;
1608
-
1609
- rb_scan_args(argc, argv, "01", &flags);
1610
-
1611
- if (NIL_P(flags))
1612
- flags = INT2FIX(0);
79
+ static VALUE internal_open(int argc, VALUE *argv, VALUE m, int readonly)
80
+ {
81
+ VALUE uri;
82
+ char *uri_c;
83
+ virConnectPtr conn;
1613
84
 
1614
- gen_call_void(virStorageVolDelete, conn(v),
1615
- vol_get(v), NUM2UINT(flags));
1616
- }
85
+ rb_scan_args(argc, argv, "01", &uri);
1617
86
 
1618
- /*
1619
- * Call +virStorageVolGetInfo+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetInfo]
1620
- */
1621
- VALUE libvirt_vol_info(VALUE v) {
1622
- virStorageVolInfo info;
1623
- int r;
1624
- VALUE result;
87
+ uri_c = get_string_or_nil(uri);
1625
88
 
1626
- r = virStorageVolGetInfo(vol_get(v), &info);
1627
- _E(r < 0, create_error(e_RetrieveError, "virStorageVolGetInfo", "", conn(v)));
89
+ if (readonly)
90
+ conn = virConnectOpenReadOnly(uri_c);
91
+ else
92
+ conn = virConnectOpen(uri_c);
1628
93
 
1629
- result = rb_class_new_instance(0, NULL, c_storage_vol_info);
1630
- rb_iv_set(result, "@type", INT2NUM(info.type));
1631
- rb_iv_set(result, "@capacity", ULL2NUM(info.capacity));
1632
- rb_iv_set(result, "@allocation", ULL2NUM(info.allocation));
94
+ if (conn == NULL)
95
+ rb_raise(e_ConnectionError, "Failed to open%sconnection to '%s'", readonly ? " readonly " : " ", uri_c);
1633
96
 
1634
- return result;
97
+ return connect_new(conn);
1635
98
  }
1636
99
 
1637
100
  /*
1638
- * Call +virStorageVolGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetXMLDesc]
101
+ * call-seq:
102
+ * Libvirt::open(url) -> Libvirt::Connect
103
+ *
104
+ * Call
105
+ * +virConnectOpen+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectOpen]
106
+ * to open a connection to a URL. Returns a new Libvirt::Connect object.
1639
107
  */
1640
- VALUE libvirt_vol_xml_desc(int argc, VALUE *argv, VALUE v) {
1641
- VALUE flags;
1642
-
1643
- rb_scan_args(argc, argv, "01", &flags);
1644
-
1645
- if (NIL_P(flags))
1646
- flags = INT2FIX(0);
1647
-
1648
- gen_call_string(virStorageVolGetXMLDesc, conn(v), 1,
1649
- vol_get(v), NUM2UINT(flags));
108
+ VALUE libvirt_open(int argc, VALUE *argv, VALUE m) {
109
+ return internal_open(argc, argv, m, 0);
1650
110
  }
1651
111
 
1652
112
  /*
1653
- * Call +virStorageVolGetPath+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetPath]
113
+ * call-seq:
114
+ * Libvirt::openReadOnly(url) -> Libvirt::Connect
115
+ *
116
+ * Call
117
+ * +virConnectOpenReadOnly+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectOpenReadOnly]
118
+ * to open a read-only connection to a URL. Returns a new Libvirt::Connect
119
+ * object.
1654
120
  */
1655
- VALUE libvirt_vol_path(VALUE v) {
1656
- gen_call_string(virStorageVolGetPath, conn(v), 1,
1657
- vol_get(v));
121
+ VALUE libvirt_open_read_only(int argc, VALUE *argv, VALUE m) {
122
+ return internal_open(argc, argv, m, 1);
1658
123
  }
1659
124
 
1660
125
  /*
1661
- * Call +virStorageVolFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolFree]
126
+ * Module Libvirt
1662
127
  */
1663
- VALUE libvirt_vol_free(VALUE s) {
1664
- gen_call_free(StorageVol, s);
1665
- }
1666
- #endif
1667
-
1668
- static void init_storage(void) {
1669
- /*
1670
- * Class Libvirt::StoragePool and Libvirt::StoragePoolInfo
1671
- */
1672
- #if HAVE_TYPE_VIRSTORAGEPOOLPTR
1673
- c_storage_pool_info = rb_define_class_under(m_libvirt, "StoragePoolInfo",
1674
- rb_cObject);
1675
- rb_define_attr(c_storage_pool_info, "state", 1, 0);
1676
- rb_define_attr(c_storage_pool_info, "capacity", 1, 0);
1677
- rb_define_attr(c_storage_pool_info, "allocation", 1, 0);
1678
- rb_define_attr(c_storage_pool_info, "available", 1, 0);
1679
-
1680
- c_storage_pool = rb_define_class_under(m_libvirt, "StoragePool",
1681
- rb_cObject);
1682
- #define DEF_POOLCONST(name) \
1683
- rb_define_const(c_storage_pool, #name, INT2NUM(VIR_STORAGE_POOL_##name))
1684
- /* virStoragePoolState */
1685
- DEF_POOLCONST(INACTIVE);
1686
- DEF_POOLCONST(BUILDING);
1687
- DEF_POOLCONST(RUNNING);
1688
- DEF_POOLCONST(DEGRADED);
1689
- /* virStoragePoolBuildFlags */
1690
- DEF_POOLCONST(BUILD_NEW);
1691
- DEF_POOLCONST(BUILD_REPAIR);
1692
- DEF_POOLCONST(BUILD_RESIZE);
1693
- /* virStoragePoolDeleteFlags */
1694
- DEF_POOLCONST(DELETE_NORMAL);
1695
- DEF_POOLCONST(DELETE_ZEROED);
1696
- #undef DEF_POOLCONST
1697
- /* Creating/destroying pools */
1698
- rb_define_method(c_storage_pool, "build", libvirt_pool_build, -1);
1699
- rb_define_method(c_storage_pool, "undefine", libvirt_pool_undefine, 0);
1700
- rb_define_method(c_storage_pool, "create", libvirt_pool_create, -1);
1701
- rb_define_method(c_storage_pool, "destroy", libvirt_pool_destroy, 0);
1702
- rb_define_method(c_storage_pool, "delete", libvirt_pool_delete, -1);
1703
- rb_define_method(c_storage_pool, "refresh", libvirt_pool_refresh, -1);
1704
- /* StoragePool information */
1705
- rb_define_method(c_storage_pool, "name", libvirt_pool_name, 0);
1706
- rb_define_method(c_storage_pool, "uuid", libvirt_pool_uuid, 0);
1707
- rb_define_method(c_storage_pool, "info", libvirt_pool_info, 0);
1708
- rb_define_method(c_storage_pool, "xml_desc", libvirt_pool_xml_desc, -1);
1709
- rb_define_method(c_storage_pool, "autostart", libvirt_pool_autostart, 0);
1710
- rb_define_method(c_storage_pool, "autostart=",
1711
- libvirt_pool_autostart_set, 1);
1712
- /* List/lookup storage volumes within a pool */
1713
- rb_define_method(c_storage_pool, "num_of_volumes",
1714
- libvirt_pool_num_of_volumes, 0);
1715
- rb_define_method(c_storage_pool, "list_volumes",
1716
- libvirt_pool_list_volumes, 0);
1717
- /* Lookup volumes based on various attributes */
1718
- rb_define_method(c_storage_pool, "lookup_volume_by_name",
1719
- libvirt_pool_lookup_vol_by_name, 1);
1720
- rb_define_method(c_storage_pool, "lookup_volume_by_key",
1721
- libvirt_pool_lookup_vol_by_key, 1);
1722
- rb_define_method(c_storage_pool, "lookup_volume_by_path",
1723
- libvirt_pool_lookup_vol_by_path, 1);
1724
- rb_define_method(c_storage_pool, "free", libvirt_pool_free, 0);
1725
- rb_define_method(c_storage_pool, "create_vol_xml", libvirt_pool_vol_create_xml, -1);
1726
- #endif
1727
-
1728
- #if HAVE_TYPE_VIRSTORAGEVOLPTR
1729
- /*
1730
- * Class Libvirt::StorageVol and Libvirt::StorageVolInfo
1731
- */
1732
- c_storage_vol_info = rb_define_class_under(m_libvirt, "StorageVolInfo",
1733
- rb_cObject);
1734
- rb_define_attr(c_storage_vol_info, "type", 1, 0);
1735
- rb_define_attr(c_storage_vol_info, "capacity", 1, 0);
1736
- rb_define_attr(c_storage_vol_info, "allocation", 1, 0);
1737
-
1738
- c_storage_vol = rb_define_class_under(m_libvirt, "StorageVol",
1739
- rb_cObject);
1740
- #define DEF_VOLCONST(name) \
1741
- rb_define_const(c_storage_vol, #name, INT2NUM(VIR_STORAGE_VOL_##name))
1742
- /* virStorageVolType */
1743
- DEF_VOLCONST(FILE);
1744
- DEF_VOLCONST(BLOCK);
1745
- /* virStorageVolDeleteFlags */
1746
- DEF_VOLCONST(DELETE_NORMAL);
1747
- DEF_VOLCONST(DELETE_ZEROED);
1748
- #undef DEF_VOLCONST
1749
-
1750
- rb_define_method(c_storage_vol, "pool", libvirt_vol_get_pool, 0);
1751
- rb_define_method(c_storage_vol, "name", libvirt_vol_name, 0);
1752
- rb_define_method(c_storage_vol, "key", libvirt_vol_key, 0);
1753
- rb_define_method(c_storage_vol, "delete", libvirt_vol_delete, -1);
1754
- rb_define_method(c_storage_vol, "info", libvirt_vol_info, 0);
1755
- rb_define_method(c_storage_vol, "xml_desc", libvirt_vol_xml_desc, -1);
1756
- rb_define_method(c_storage_vol, "path", libvirt_vol_path, 0);
1757
- rb_define_method(c_storage_vol, "free", libvirt_vol_free, 0);
1758
- #endif
1759
- }
1760
-
1761
128
  void Init__libvirt() {
1762
129
  int r;
1763
130
 
@@ -1770,187 +137,33 @@ void Init__libvirt() {
1770
137
  * Libvirt Errors
1771
138
  */
1772
139
  e_Error = rb_define_class_under(m_libvirt, "Error",
1773
- rb_eStandardError);
140
+ rb_eStandardError);
1774
141
  e_ConnectionError = rb_define_class_under(m_libvirt, "ConnectionError",
1775
- e_Error);
142
+ e_Error);
1776
143
  e_DefinitionError = rb_define_class_under(m_libvirt, "DefinitionError",
1777
- e_Error);
144
+ e_Error);
1778
145
  e_RetrieveError = rb_define_class_under(m_libvirt, "RetrieveError",
1779
- e_Error);
146
+ e_Error);
1780
147
 
1781
148
  // create 'libvirt_function_name' and 'vir_connect_ptr' attributes on e_Error class
1782
149
  rb_define_attr(e_Error, "libvirt_function_name", 1, 0);
1783
150
  rb_define_attr(e_Error, "libvirt_message", 1, 0);
1784
151
 
1785
- /*
1786
- * Class Libvirt::Connect
1787
- */
1788
- c_connect = rb_define_class_under(m_libvirt, "Connect", rb_cObject);
1789
-
1790
- rb_define_module_function(m_libvirt, "version", libvirt_version, 1);
1791
- rb_define_module_function(m_libvirt, "open", libvirt_open, 1);
152
+ rb_define_module_function(m_libvirt, "version", libvirt_version, -1);
153
+ rb_define_module_function(m_libvirt, "open", libvirt_open, -1);
1792
154
  rb_define_module_function(m_libvirt, "open_read_only",
1793
- libvirt_open_read_only, 1);
1794
-
1795
- rb_define_method(c_connect, "close", libvirt_conn_close, 0);
1796
- rb_define_method(c_connect, "closed?", libvirt_conn_closed_p, 0);
1797
- rb_define_method(c_connect, "type", libvirt_conn_type, 0);
1798
- rb_define_method(c_connect, "version", libvirt_conn_version, 0);
1799
- rb_define_method(c_connect, "hostname", libvirt_conn_hostname, 0);
1800
- rb_define_method(c_connect, "uri", libvirt_conn_uri, 0);
1801
- rb_define_method(c_connect, "max_vcpus", libvirt_conn_max_vcpus, 1);
1802
- rb_define_method(c_connect, "node_get_info", libvirt_conn_node_get_info, 0);
1803
- rb_define_method(c_connect, "capabilities", libvirt_conn_capabilities, 0);
1804
- rb_define_method(c_connect, "num_of_domains", libvirt_conn_num_of_domains, 0);
1805
- rb_define_method(c_connect, "list_domains", libvirt_conn_list_domains, 0);
1806
- rb_define_method(c_connect, "num_of_defined_domains",
1807
- libvirt_conn_num_of_defined_domains, 0);
1808
- rb_define_method(c_connect, "list_defined_domains",
1809
- libvirt_conn_list_defined_domains, 0);
1810
- #if HAVE_TYPE_VIRNETWORKPTR
1811
- rb_define_method(c_connect, "num_of_networks",
1812
- libvirt_conn_num_of_networks, 0);
1813
- rb_define_method(c_connect, "list_networks", libvirt_conn_list_networks, 0);
1814
- rb_define_method(c_connect, "num_of_defined_networks",
1815
- libvirt_conn_num_of_defined_networks, 0);
1816
- rb_define_method(c_connect, "list_defined_networks",
1817
- libvirt_conn_list_defined_networks, 0);
1818
- #endif
1819
- #if HAVE_TYPE_VIRSTORAGEPOOLPTR
1820
- rb_define_method(c_connect, "num_of_storage_pools",
1821
- libvirt_conn_num_of_storage_pools, 0);
1822
- rb_define_method(c_connect, "list_storage_pools",
1823
- libvirt_conn_list_storage_pools, 0);
1824
- rb_define_method(c_connect, "num_of_defined_storage_pools",
1825
- libvirt_conn_num_of_defined_storage_pools, 0);
1826
- rb_define_method(c_connect, "list_defined_storage_pools",
1827
- libvirt_conn_list_defined_storage_pools, 0);
1828
- #endif
1829
- // Domain creation/lookup
1830
- rb_define_method(c_connect, "create_domain_linux",
1831
- libvirt_conn_create_linux, -1);
1832
- rb_define_method(c_connect, "lookup_domain_by_name",
1833
- libvirt_conn_lookup_domain_by_name, 1);
1834
- rb_define_method(c_connect, "lookup_domain_by_id",
1835
- libvirt_conn_lookup_domain_by_id, 1);
1836
- rb_define_method(c_connect, "lookup_domain_by_uuid",
1837
- libvirt_conn_lookup_domain_by_uuid, 1);
1838
- rb_define_method(c_connect, "define_domain_xml",
1839
- libvirt_conn_define_domain_xml, 1);
1840
- // Network creation/lookup
1841
- #if HAVE_TYPE_VIRNETWORKPTR
1842
- rb_define_method(c_connect, "lookup_network_by_name",
1843
- libvirt_conn_lookup_network_by_name, 1);
1844
- rb_define_method(c_connect, "lookup_network_by_uuid",
1845
- libvirt_conn_lookup_network_by_uuid, 1);
1846
- rb_define_method(c_connect, "create_network_xml",
1847
- libvirt_conn_create_network_xml, 1);
1848
- rb_define_method(c_connect, "define_network_xml",
1849
- libvirt_conn_define_network_xml, 1);
1850
- #endif
1851
- // Storage pool creation/lookup
1852
- #if HAVE_TYPE_VIRSTORAGEPOOLPTR
1853
- rb_define_method(c_connect, "lookup_storage_pool_by_name",
1854
- libvirt_conn_lookup_pool_by_name, 1);
1855
- rb_define_method(c_connect, "lookup_storage_pool_by_uuid",
1856
- libvirt_conn_lookup_pool_by_uuid, 1);
1857
- rb_define_method(c_connect, "create_storage_pool_xml",
1858
- libvirt_conn_create_pool_xml, -1);
1859
- rb_define_method(c_connect, "define_storage_pool_xml",
1860
- libvirt_conn_define_pool_xml, -1);
1861
- rb_define_method(c_connect, "discover_storage_pool_sources",
1862
- libvirt_conn_find_storage_pool_sources, -1);
1863
- #endif
1864
-
1865
- /*
1866
- * Class Libvirt::Connect::Nodeinfo
1867
- */
1868
- c_node_info = rb_define_class_under(c_connect, "Nodeinfo", rb_cObject);
1869
- rb_define_attr(c_node_info, "model", 1, 0);
1870
- rb_define_attr(c_node_info, "memory", 1, 0);
1871
- rb_define_attr(c_node_info, "cpus", 1, 0);
1872
- rb_define_attr(c_node_info, "mhz", 1, 0);
1873
- rb_define_attr(c_node_info, "nodes", 1, 0);
1874
- rb_define_attr(c_node_info, "sockets", 1, 0);
1875
- rb_define_attr(c_node_info, "cores", 1, 0);
1876
- rb_define_attr(c_node_info, "threads", 1, 0);
1877
-
1878
- /*
1879
- * Class Libvirt::Domain
1880
- */
1881
- c_domain = rb_define_class_under(m_libvirt, "Domain", rb_cObject);
1882
- #define DEF_DOMSTATE(name) \
1883
- rb_define_const(c_domain, #name, INT2NUM(VIR_DOMAIN_##name))
1884
- /* virDomainState */
1885
- DEF_DOMSTATE(NOSTATE);
1886
- DEF_DOMSTATE(RUNNING);
1887
- DEF_DOMSTATE(BLOCKED);
1888
- DEF_DOMSTATE(PAUSED);
1889
- DEF_DOMSTATE(SHUTDOWN);
1890
- DEF_DOMSTATE(SHUTOFF);
1891
- DEF_DOMSTATE(CRASHED);
1892
- #undef DEF_DOMSTATE
1893
-
1894
- /* virDomainMigrateFlags */
1895
- rb_define_const(c_domain, "MIGRATE_LIVE", INT2NUM(VIR_MIGRATE_LIVE));
1896
-
1897
- rb_define_method(c_domain, "migrate", libvirt_dom_migrate, -1);
1898
- rb_define_attr(c_domain, "connection", 1, 0);
1899
- rb_define_method(c_domain, "shutdown", libvirt_dom_shutdown, 0);
1900
- rb_define_method(c_domain, "reboot", libvirt_dom_reboot, -1);
1901
- rb_define_method(c_domain, "destroy", libvirt_dom_destroy, 0);
1902
- rb_define_method(c_domain, "suspend", libvirt_dom_suspend, 0);
1903
- rb_define_method(c_domain, "resume", libvirt_dom_resume, 0);
1904
- rb_define_method(c_domain, "save", libvirt_dom_save, 1);
1905
- rb_define_singleton_method(c_domain, "restore", libvirt_dom_s_restore, 2);
1906
- rb_define_method(c_domain, "core_dump", libvirt_dom_core_dump, -1);
1907
- rb_define_method(c_domain, "info", libvirt_dom_info, 0);
1908
- rb_define_method(c_domain, "name", libvirt_dom_name, 0);
1909
- rb_define_method(c_domain, "id", libvirt_dom_id, 0);
1910
- rb_define_method(c_domain, "uuid", libvirt_dom_uuid, 0);
1911
- rb_define_method(c_domain, "os_type", libvirt_dom_os_type, 0);
1912
- rb_define_method(c_domain, "max_memory", libvirt_dom_max_memory, 0);
1913
- rb_define_method(c_domain, "max_memory=", libvirt_dom_max_memory_set, 1);
1914
- rb_define_method(c_domain, "memory=", libvirt_dom_memory_set, 1);
1915
- rb_define_method(c_domain, "max_vcpus", libvirt_dom_max_vcpus, 0);
1916
- rb_define_method(c_domain, "vcpus=", libvirt_dom_vcpus_set, 1);
1917
- rb_define_method(c_domain, "pin_vcpu", libvirt_dom_pin_vcpu, 2);
1918
- rb_define_method(c_domain, "xml_desc", libvirt_dom_xml_desc, -1);
1919
- rb_define_method(c_domain, "undefine", libvirt_dom_undefine, 0);
1920
- rb_define_method(c_domain, "create", libvirt_dom_create, 0);
1921
- rb_define_method(c_domain, "autostart", libvirt_dom_autostart, 0);
1922
- rb_define_method(c_domain, "autostart=", libvirt_dom_autostart_set, 1);
1923
- rb_define_method(c_domain, "free", libvirt_dom_free, 0);
1924
-
1925
- /*
1926
- * Class Libvirt::Domain::Info
1927
- */
1928
- c_domain_info = rb_define_class_under(c_domain, "Info", rb_cObject);
1929
- rb_define_attr(c_domain_info, "state", 1, 0);
1930
- rb_define_attr(c_domain_info, "max_mem", 1, 0);
1931
- rb_define_attr(c_domain_info, "memory", 1, 0);
1932
- rb_define_attr(c_domain_info, "nr_virt_cpu", 1, 0);
1933
- rb_define_attr(c_domain_info, "cpu_time", 1, 0);
1934
-
1935
- /*
1936
- * Class Libvirt::Network
1937
- */
1938
- #if HAVE_TYPE_VIRNETWORKPTR
1939
- c_network = rb_define_class_under(m_libvirt, "Network", rb_cObject);
1940
- rb_define_attr(c_network, "connection", 1, 0);
1941
- rb_define_method(c_network, "undefine", libvirt_netw_undefine, 0);
1942
- rb_define_method(c_network, "create", libvirt_netw_create, 0);
1943
- rb_define_method(c_network, "destroy", libvirt_netw_destroy, 0);
1944
- rb_define_method(c_network, "name", libvirt_netw_name, 0);
1945
- rb_define_method(c_network, "uuid", libvirt_netw_uuid, 0);
1946
- rb_define_method(c_network, "xml_desc", libvirt_netw_xml_desc, -1);
1947
- rb_define_method(c_network, "bridge_name", libvirt_netw_bridge_name, 0);
1948
- rb_define_method(c_network, "autostart", libvirt_netw_autostart, 0);
1949
- rb_define_method(c_network, "autostart=", libvirt_netw_autostart_set, 1);
1950
- rb_define_method(c_network, "free", libvirt_netw_free, 0);
1951
- #endif
155
+ libvirt_open_read_only, -1);
156
+ // FIXME: implement this
157
+ //rb_define_module_function(m_libvirt, "open_auth", libvirt_open_auth, -1);
1952
158
 
159
+ init_connect();
1953
160
  init_storage();
161
+ init_network();
162
+ init_nodedevice();
163
+ init_secret();
164
+ init_nwfilter();
165
+ init_interface();
166
+ init_domain();
1954
167
 
1955
168
  r = virInitialize();
1956
169
  if (r < 0)