ruby-libvirt 0.1.0

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.
data/NEWS ADDED
@@ -0,0 +1,36 @@
1
+ 2008-11-18 0.1.0
2
+ * Add binding for virConnectFindStoragePoolSources (clalance)
3
+ * Fix dom_migrate (clalance)
4
+ * Add the MIGRATE_LIVE (enum virDomainMigrateFlags) flag
5
+ * Slight improvements of the unit tests
6
+
7
+ 2008-04-15 0.0.7
8
+ * Binding for virDomainMigrate
9
+ * Fix crash caused by using virResetError
10
+ * More sensible message included in exceptions
11
+
12
+ 2008-04-02 0.0.6
13
+ * Fix test failure exposed by the Fedora builders
14
+
15
+ 2008-04-02 0.0.5
16
+ * Explicit free methods for various objects (based on a patch by
17
+ Vadim Zaliva)
18
+ * Make the FLAGS argument for various calls optional, and default it
19
+ to 0. (Chris Lalancette)
20
+ * More finegrained exceptions on errors, containing libvirt error message
21
+ (Mohammed Morsi)
22
+
23
+ 2008-04-01 0.0.4
24
+ * Bindings for the libvirt storage API (requires libvirt 0.4.1)
25
+ * Suppress some bindings if the underlying libvirt doesn't support it
26
+ * Bindings for virDomainSetMemory, virDomainPinVcpu, and
27
+ virDomainSetVcpus (Vadim Zaliva)
28
+
29
+ 2007-12-06 0.0.2
30
+ * Add virNodeGetInfo binding
31
+
32
+ * Convert Ruby API from StudlyCaps to under_score_separation, since that's
33
+ the Ruby convention
34
+
35
+ 2007-11-19 0.0.1
36
+ * Initial release
data/README ADDED
@@ -0,0 +1,26 @@
1
+ ruby-libvirt
2
+ ============
3
+
4
+ Ruby bindings for libvirt (http://libvirt.org)
5
+
6
+ Usage
7
+ -----
8
+
9
+ In your ruby code, do a "require 'libvirt'"; to obtain a connection, use
10
+ 'Libvirt::open' or 'Libvirt::openReadOnly'. See tests/*.rb for more
11
+ examples.
12
+
13
+ Hacking
14
+ -------
15
+
16
+ On a Fedora machine, run
17
+ yum install libvirt-devel ruby-devel rubygem-rake
18
+ and then
19
+ rake build
20
+ rake test
21
+
22
+ To run against the checkout, make sure you set RUBYLIB (assuming DIR is the
23
+ toplevel of your source checkout):
24
+
25
+ export RUBYLIB=$dir/lib:$dir/ext/libvirt
26
+ ruby -rlibvirt -e 'puts Libvirt::version("xen")[0]'
data/README.rdoc ADDED
@@ -0,0 +1,11 @@
1
+ = Ruby bindings for libvirt
2
+
3
+ The module Libvirt provides bindings to libvirt[http://libvirt.org]
4
+
5
+ The various +*Ptr+ types in Libvirt map loosely to the following Ruby classes:
6
+
7
+ [virConnectPtr] Libvirt::Connect
8
+ [virDomainPtr] Libvirt::Domain
9
+ [virDomainInfoPtr] Libvirt::Domain::Info
10
+ [virNetworkPtr] Libvirt::Network
11
+
data/Rakefile ADDED
@@ -0,0 +1,138 @@
1
+ # -*- ruby -*-
2
+ # Rakefile: build ruby libvirt bindings
3
+ #
4
+ # Copyright (C) 2007 Red Hat, Inc.
5
+ #
6
+ # Distributed under the GNU Lesser General Public License v2.1 or later.
7
+ # See COPYING for details
8
+ #
9
+ # David Lutterkort <dlutter@redhat.com>
10
+
11
+ # Rakefile for ruby-rpm -*- ruby -*-
12
+ require 'rake/clean'
13
+ require 'rake/rdoctask'
14
+ require 'rake/testtask'
15
+ require 'rake/gempackagetask'
16
+
17
+ PKG_NAME='ruby-libvirt'
18
+ PKG_VERSION='0.1.0'
19
+
20
+ EXT_CONF='ext/libvirt/extconf.rb'
21
+ MAKEFILE="ext/libvirt/Makefile"
22
+ LIBVIRT_MODULE="ext/libvirt/_libvirt.so"
23
+ SPEC_FILE="ruby-libvirt.spec"
24
+ LIBVIRT_SRC=LIBVIRT_MODULE.gsub(/.so$/, ".c")
25
+
26
+ #
27
+ # Additional files for clean/clobber
28
+ #
29
+
30
+ CLEAN.include [ "ext/**/*.o", LIBVIRT_MODULE,
31
+ "ext/**/depend" ]
32
+
33
+ CLOBBER.include [ "config.save", "ext/**/mkmf.log",
34
+ MAKEFILE ]
35
+
36
+ #
37
+ # Build locally
38
+ #
39
+ # FIXME: We can't get rid of install.rb yet, since there's no way
40
+ # to pass config options to extconf.rb
41
+ file MAKEFILE => EXT_CONF do |t|
42
+ Dir::chdir(File::dirname(EXT_CONF)) do
43
+ unless sh "ruby #{File::basename(EXT_CONF)}"
44
+ $stderr.puts "Failed to run extconf"
45
+ break
46
+ end
47
+ end
48
+ end
49
+ file LIBVIRT_MODULE => [ MAKEFILE, LIBVIRT_SRC ] do |t|
50
+ Dir::chdir(File::dirname(EXT_CONF)) do
51
+ unless sh "make"
52
+ $stderr.puts "make failed"
53
+ break
54
+ end
55
+ end
56
+ end
57
+ desc "Build the native library"
58
+ task :build => LIBVIRT_MODULE
59
+
60
+ Rake::TestTask.new(:test) do |t|
61
+ t.test_files = FileList['tests/tc_*.rb']
62
+ t.libs = [ 'lib', 'ext/libvirt' ]
63
+ end
64
+ task :test => :build
65
+
66
+ Rake::RDocTask.new do |rd|
67
+ rd.main = "README.rdoc"
68
+ rd.rdoc_dir = "doc/site/api"
69
+ rd.rdoc_files.include("README.rdoc", "lib/**/*.rb", "ext/**/*.[ch]")
70
+ end
71
+
72
+ #
73
+ # Package tasks
74
+ #
75
+
76
+ PKG_FILES = FileList[
77
+ "Rakefile", "COPYING", "README", "NEWS", "README.rdoc",
78
+ "lib/**/*.rb",
79
+ "ext/**/*.[ch]", "ext/**/MANIFEST", "ext/**/extconf.rb",
80
+ "tests/**/*",
81
+ "spec/**/*"
82
+ ]
83
+
84
+ DIST_FILES = FileList[
85
+ "pkg/*.src.rpm", "pkg/*.gem", "pkg/*.zip", "pkg/*.tgz"
86
+ ]
87
+
88
+ SPEC = Gem::Specification.new do |s|
89
+ s.name = PKG_NAME
90
+ s.version = PKG_VERSION
91
+ s.email = "libvir-list@redhat.com"
92
+ s.homepage = "http://libvirt.org/ruby/"
93
+ s.summary = "Ruby bindings for LIBVIRT"
94
+ s.files = PKG_FILES
95
+ s.autorequire = "libvirt"
96
+ s.required_ruby_version = '>= 1.8.1'
97
+ s.extensions = "ext/libvirt/extconf.rb"
98
+ s.description = <<EOF
99
+ Provides bindings for libvirt.
100
+ EOF
101
+ end
102
+
103
+ Rake::GemPackageTask.new(SPEC) do |pkg|
104
+ pkg.need_tar = true
105
+ pkg.need_zip = true
106
+ end
107
+
108
+ desc "Update the ruby-libvirt site"
109
+ task :site => [ :rdoc ] do |t|
110
+ system("rsync -av doc/site/ libvirt:/data/www/libvirt.org/ruby/")
111
+ if $? != 0
112
+ raise "rsync failed: #{$?}"
113
+ end
114
+ end
115
+
116
+ desc "Build (S)RPM for #{PKG_NAME}"
117
+ task :rpm => [ :package ] do |t|
118
+ system("sed -e 's/@VERSION@/#{PKG_VERSION}/' #{SPEC_FILE} > pkg/#{SPEC_FILE}")
119
+ Dir::chdir("pkg") do |dir|
120
+ dir = File::expand_path(".")
121
+ system("rpmbuild --define '_topdir #{dir}' --define '_sourcedir #{dir}' --define '_srcrpmdir #{dir}' --define '_rpmdir #{dir}' --define '_builddir #{dir}' -ba #{SPEC_FILE} > rpmbuild.log 2>&1")
122
+ if $? != 0
123
+ raise "rpmbuild failed"
124
+ end
125
+ end
126
+ end
127
+
128
+ desc "Release a version to the site"
129
+ task :dist => [ :rpm ] do |t|
130
+ puts "Copying files"
131
+ unless sh "scp -p #{DIST_FILES.to_s} libvirt:/data/www/libvirt.org/ruby/download"
132
+ $stderr.puts "Copy to libvirt failed"
133
+ break
134
+ end
135
+ puts "Commit and tag #{PKG_VERSION}"
136
+ system "hg commit -m 'Released version #{PKG_VERSION}'"
137
+ system "hg tag -m 'Tag release #{PKG_VERSION}' #{PKG_NAME}-#{PKG_VERSION}"
138
+ end
@@ -0,0 +1,1967 @@
1
+ /*
2
+ * libvirt.c: Ruby bindings for libvirt
3
+ *
4
+ * Copyright (C) 2007 Red Hat Inc.
5
+ *
6
+ * This library is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * This library is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with this library; if not, write to the Free Software
18
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ *
20
+ * Author: David Lutterkort <dlutter@redhat.com>
21
+ */
22
+
23
+ #include <ruby.h>
24
+ #include <libvirt/libvirt.h>
25
+ #include <libvirt/virterror.h>
26
+ #include "extconf.h"
27
+
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
+ 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
+
46
+
47
+ // define additional errors here
48
+ static VALUE e_Error; // Error - generic error
49
+ 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
52
+
53
+ /*
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]
1419
+ */
1420
+ VALUE libvirt_pool_info(VALUE s) {
1421
+ virStoragePoolInfo info;
1422
+ 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;
1457
+
1458
+ r = virStoragePoolGetAutostart(pool_get(s), &autostart);
1459
+ _E(r < 0, create_error(e_RetrieveError, "virStoragePoolGetAutostart", "", conn(s)));
1460
+
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)));
1478
+
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);
1512
+ return result;
1513
+ }
1514
+
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);
1613
+
1614
+ gen_call_void(virStorageVolDelete, conn(v),
1615
+ vol_get(v), NUM2UINT(flags));
1616
+ }
1617
+
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;
1625
+
1626
+ r = virStorageVolGetInfo(vol_get(v), &info);
1627
+ _E(r < 0, create_error(e_RetrieveError, "virStorageVolGetInfo", "", conn(v)));
1628
+
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));
1633
+
1634
+ return result;
1635
+ }
1636
+
1637
+ /*
1638
+ * Call +virStorageVolGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetXMLDesc]
1639
+ */
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));
1650
+ }
1651
+
1652
+ /*
1653
+ * Call +virStorageVolGetPath+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetPath]
1654
+ */
1655
+ VALUE libvirt_vol_path(VALUE v) {
1656
+ gen_call_string(virStorageVolGetPath, conn(v), 1,
1657
+ vol_get(v));
1658
+ }
1659
+
1660
+ /*
1661
+ * Call +virStorageVolFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolFree]
1662
+ */
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
+ void Init__libvirt() {
1762
+ int r;
1763
+
1764
+ m_libvirt = rb_define_module("Libvirt");
1765
+ c_libvirt_version = rb_define_class_under(m_libvirt, "Version",
1766
+ rb_cObject);
1767
+
1768
+
1769
+ /*
1770
+ * Libvirt Errors
1771
+ */
1772
+ e_Error = rb_define_class_under(m_libvirt, "Error",
1773
+ rb_eStandardError);
1774
+ e_ConnectionError = rb_define_class_under(m_libvirt, "ConnectionError",
1775
+ e_Error);
1776
+ e_DefinitionError = rb_define_class_under(m_libvirt, "DefinitionError",
1777
+ e_Error);
1778
+ e_RetrieveError = rb_define_class_under(m_libvirt, "RetrieveError",
1779
+ e_Error);
1780
+
1781
+ // create 'libvirt_function_name' and 'vir_connect_ptr' attributes on e_Error class
1782
+ rb_define_attr(e_Error, "libvirt_function_name", 1, 0);
1783
+ rb_define_attr(e_Error, "libvirt_message", 1, 0);
1784
+
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);
1792
+ 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
1952
+
1953
+ init_storage();
1954
+
1955
+ r = virInitialize();
1956
+ if (r < 0)
1957
+ rb_raise(rb_eSystemCallError, "virInitialize failed");
1958
+ }
1959
+
1960
+ /*
1961
+ * Local variables:
1962
+ * indent-tabs-mode: nil
1963
+ * c-indent-level: 4
1964
+ * c-basic-offset: 4
1965
+ * tab-width: 4
1966
+ * End:
1967
+ */