ruby-libvirt 0.1.0 → 0.2.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.
@@ -0,0 +1,12 @@
1
+ #ifndef CONNECT_H
2
+ #define CONNECT_H
3
+
4
+ extern VALUE c_connect;
5
+ void init_connect();
6
+
7
+ virConnectPtr conn(VALUE s);
8
+ VALUE connect_new(virConnectPtr p);
9
+ virConnectPtr connect_get(VALUE s);
10
+ VALUE conn_attr(VALUE s);
11
+
12
+ #endif
@@ -0,0 +1,1606 @@
1
+ /*
2
+ * domain.c: virDomain methods
3
+ *
4
+ * Copyright (C) 2007,2010 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
+
21
+ #include <ruby.h>
22
+ #include <libvirt/libvirt.h>
23
+ #include <libvirt/virterror.h>
24
+ #include "common.h"
25
+ #include "connect.h"
26
+ #include "extconf.h"
27
+
28
+ VALUE c_domain;
29
+ static VALUE c_domain_info;
30
+ static VALUE c_domain_ifinfo;
31
+ static VALUE c_domain_security_label;
32
+ static VALUE c_domain_block_stats;
33
+ #if HAVE_TYPE_VIRDOMAINBLOCKINFOPTR
34
+ static VALUE c_domain_block_info;
35
+ #endif
36
+ #if HAVE_TYPE_VIRDOMAINMEMORYSTATPTR
37
+ static VALUE c_domain_memory_stats;
38
+ #endif
39
+ #if HAVE_TYPE_VIRDOMAINSNAPSHOTPTR
40
+ static VALUE c_domain_snapshot;
41
+ #endif
42
+ #if HAVE_TYPE_VIRDOMAINJOBINFOPTR
43
+ static VALUE c_domain_job_info;
44
+ #endif
45
+
46
+ static void domain_free(void *d) {
47
+ generic_free(Domain, d);
48
+ }
49
+
50
+ static VALUE domain_new(virDomainPtr d, VALUE conn) {
51
+ return generic_new(c_domain, d, conn, domain_free);
52
+ }
53
+
54
+ static virDomainPtr domain_get(VALUE s) {
55
+ generic_get(Domain, s);
56
+ }
57
+
58
+ /*
59
+ * call-seq:
60
+ * conn.num_of_domains -> fixnum
61
+ *
62
+ * Call +virConnectNumOfDomains+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfDomains]
63
+ */
64
+ static VALUE libvirt_conn_num_of_domains(VALUE s) {
65
+ gen_conn_num_of(s, Domains);
66
+ }
67
+
68
+ /*
69
+ * call-seq:
70
+ * conn.list_domains -> list
71
+ *
72
+ * Call +virConnectListDomains+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListDomains]
73
+ */
74
+ static VALUE libvirt_conn_list_domains(VALUE s) {
75
+ int i, r, num, *ids;
76
+ virConnectPtr conn = connect_get(s);
77
+ VALUE result;
78
+
79
+ num = virConnectNumOfDomains(conn);
80
+ _E(num < 0, create_error(e_RetrieveError, "virConnectNumOfDomains", "", conn));
81
+ if (num == 0) {
82
+ result = rb_ary_new2(num);
83
+ return result;
84
+ }
85
+
86
+ ids = ALLOC_N(int, num);
87
+ r = virConnectListDomains(conn, ids, num);
88
+ if (r < 0) {
89
+ free(ids);
90
+ _E(r < 0, create_error(e_RetrieveError, "virConnectListDomains", "", conn));
91
+ }
92
+
93
+ result = rb_ary_new2(num);
94
+ for (i=0; i<num; i++) {
95
+ rb_ary_push(result, INT2NUM(ids[i]));
96
+ }
97
+ free(ids);
98
+ return result;
99
+ }
100
+
101
+ /*
102
+ * call-seq:
103
+ * conn.num_of_defined_domains -> fixnum
104
+ *
105
+ * Call +virConnectNumOfDefinedDomains+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfDefinedDomains]
106
+ */
107
+ static VALUE libvirt_conn_num_of_defined_domains(VALUE s) {
108
+ gen_conn_num_of(s, DefinedDomains);
109
+ }
110
+
111
+ /*
112
+ * call-seq:
113
+ * conn.list_defined_domains -> list
114
+ *
115
+ * Call +virConnectListDefinedDomains+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListDefinedDomains]
116
+ */
117
+ static VALUE libvirt_conn_list_defined_domains(VALUE s) {
118
+ gen_conn_list_names(s, DefinedDomains);
119
+ }
120
+
121
+ /*
122
+ * call-seq:
123
+ * dom.create_linux -> Libvirt::Domain
124
+ *
125
+ * Call +virDomainCreateLinux+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainCreateLinux]
126
+ */
127
+ static VALUE libvirt_conn_create_linux(int argc, VALUE *argv, VALUE c) {
128
+ virDomainPtr dom;
129
+ virConnectPtr conn = connect_get(c);
130
+ VALUE flags, xml;
131
+
132
+ rb_scan_args(argc, argv, "11", &xml, &flags);
133
+
134
+ if (NIL_P(flags))
135
+ flags = INT2FIX(0);
136
+
137
+ dom = virDomainCreateLinux(conn, StringValueCStr(xml), NUM2UINT(flags));
138
+ _E(dom == NULL, create_error(e_Error, "virDomainCreateLinux", "", conn));
139
+
140
+ return domain_new(dom, c);
141
+ }
142
+
143
+ /*
144
+ * call-seq:
145
+ * conn.lookup_domain_by_name -> Libvirt::Domain
146
+ *
147
+ * Call +virDomainLookupByName+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainLookupByName]
148
+ */
149
+ static VALUE libvirt_conn_lookup_domain_by_name(VALUE c, VALUE name) {
150
+ virDomainPtr dom;
151
+ virConnectPtr conn = connect_get(c);
152
+
153
+ dom = virDomainLookupByName(conn, StringValueCStr(name));
154
+ _E(dom == NULL, create_error(e_RetrieveError, "virDomainLookupByName", "", conn));
155
+
156
+ return domain_new(dom, c);
157
+ }
158
+
159
+ /*
160
+ * call-seq:
161
+ * conn.lookup_domain_by_id -> Libvirt::Domain
162
+ *
163
+ * Call +virDomainLookupByID+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainLookupByID]
164
+ */
165
+ static VALUE libvirt_conn_lookup_domain_by_id(VALUE c, VALUE id) {
166
+ virDomainPtr dom;
167
+ virConnectPtr conn = connect_get(c);
168
+
169
+ dom = virDomainLookupByID(conn, NUM2INT(id));
170
+ _E(dom == NULL, create_error(e_RetrieveError, "virDomainLookupByID", "", conn));
171
+
172
+ return domain_new(dom, c);
173
+ }
174
+
175
+ /*
176
+ * call-seq:
177
+ * conn.lookup_domain_by_uuid -> Libvirt::Domain
178
+ *
179
+ * Call +virDomainLookupByUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainLookupByUUIDString]
180
+ */
181
+ static VALUE libvirt_conn_lookup_domain_by_uuid(VALUE c, VALUE uuid) {
182
+ virDomainPtr dom;
183
+ virConnectPtr conn = connect_get(c);
184
+
185
+ dom = virDomainLookupByUUIDString(conn, StringValueCStr(uuid));
186
+ _E(dom == NULL, create_error(e_RetrieveError, "virDomainLookupByUUID", "", conn));
187
+
188
+ return domain_new(dom, c);
189
+ }
190
+
191
+ /*
192
+ * call-seq:
193
+ * conn.define_domain_xml -> Libvirt::Domain
194
+ *
195
+ * Call +virDomainDefineXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainDefineXML]
196
+ */
197
+ static VALUE libvirt_conn_define_domain_xml(VALUE c, VALUE xml) {
198
+ virDomainPtr dom;
199
+ virConnectPtr conn = connect_get(c);
200
+
201
+ dom = virDomainDefineXML(conn, StringValueCStr(xml));
202
+ _E(dom == NULL, create_error(e_DefinitionError, "virDomainDefineXML", "", conn));
203
+
204
+ return domain_new(dom, c);
205
+ }
206
+
207
+ #if HAVE_VIRCONNECTDOMAINXMLFROMNATIVE
208
+ /*
209
+ * call-seq:
210
+ * conn.domain_xml_from_native -> string
211
+ *
212
+ * Call +virConnectDomainXMLFromNative+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainXMLFromNative]
213
+ */
214
+ static VALUE libvirt_conn_domain_xml_from_native(int argc, VALUE *argv, VALUE s) {
215
+ VALUE nativeFormat, xml, flags;
216
+ char *ret;
217
+ VALUE result;
218
+
219
+ rb_scan_args(argc, argv, "21", &nativeFormat, &xml, &flags);
220
+
221
+ if (NIL_P(flags))
222
+ flags = INT2FIX(0);
223
+
224
+ ret = virConnectDomainXMLFromNative(conn(s), StringValueCStr(nativeFormat),
225
+ StringValueCStr(xml), NUM2UINT(flags));
226
+ _E(ret == NULL,
227
+ create_error(e_Error, "virConnectDomainXMLFromNative", "", conn(s)));
228
+
229
+ result = rb_str_new2(ret);
230
+
231
+ free(ret);
232
+
233
+ return result;
234
+ }
235
+ #endif
236
+
237
+ #if HAVE_VIRCONNECTDOMAINXMLTONATIVE
238
+ /*
239
+ * call-seq:
240
+ * conn.domain_xml_to_native -> string
241
+ *
242
+ * Call +virConnectDomainXMLToNative+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainXMLToNative]
243
+ */
244
+ static VALUE libvirt_conn_domain_xml_to_native(int argc, VALUE *argv, VALUE s) {
245
+ VALUE nativeFormat, xml, flags;
246
+ char *ret;
247
+ VALUE result;
248
+
249
+ rb_scan_args(argc, argv, "21", &nativeFormat, &xml, &flags);
250
+
251
+ if (NIL_P(flags))
252
+ flags = INT2FIX(0);
253
+
254
+ ret = virConnectDomainXMLToNative(conn(s), StringValueCStr(nativeFormat),
255
+ StringValueCStr(xml), NUM2UINT(flags));
256
+ _E(ret == NULL,
257
+ create_error(e_Error, "virConnectDomainXMLToNative", "", conn(s)));
258
+
259
+ result = rb_str_new2(ret);
260
+
261
+ free(ret);
262
+
263
+ return result;
264
+ }
265
+ #endif
266
+
267
+ /*
268
+ * call-seq:
269
+ * dom.migrate -> Libvirt::Domain
270
+ *
271
+ * Call +virDomainMigrate+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainMigrate]
272
+ */
273
+ static VALUE libvirt_dom_migrate(int argc, VALUE *argv, VALUE s) {
274
+ VALUE dconn, flags, dname_val, uri_val, bandwidth;
275
+ virDomainPtr ddom = NULL;
276
+
277
+ rb_scan_args(argc, argv, "14", &dconn, &flags, &dname_val, &uri_val,
278
+ &bandwidth);
279
+
280
+ if (NIL_P(bandwidth))
281
+ bandwidth = INT2FIX(0);
282
+ if (NIL_P(flags))
283
+ flags = INT2FIX(0);
284
+
285
+ ddom = virDomainMigrate(domain_get(s), conn(dconn), NUM2ULONG(flags),
286
+ get_string_or_nil(dname_val),
287
+ get_string_or_nil(uri_val), NUM2ULONG(bandwidth));
288
+
289
+ _E(ddom == NULL,
290
+ create_error(e_Error, "virDomainMigrate", "", conn(s)));
291
+
292
+ return domain_new(ddom, dconn);
293
+ }
294
+
295
+ #if HAVE_VIRDOMAINMIGRATETOURI
296
+ /*
297
+ * call-seq:
298
+ * dom.migrate_to_uri -> nil
299
+ *
300
+ * Call +virDomainMigrateToURI+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainMigrateToURI]
301
+ */
302
+ static VALUE libvirt_dom_migrate_to_uri(int argc, VALUE *argv, VALUE s) {
303
+ VALUE flags, dname_val, bandwidth, duri_val;
304
+ int ret;
305
+
306
+ rb_scan_args(argc, argv, "13", &duri_val, &flags, &dname_val, &bandwidth);
307
+
308
+ if (NIL_P(bandwidth))
309
+ bandwidth = INT2FIX(0);
310
+ if (NIL_P(flags))
311
+ flags = INT2FIX(0);
312
+
313
+ ret = virDomainMigrateToURI(domain_get(s), StringValueCStr(duri_val),
314
+ NUM2ULONG(flags), get_string_or_nil(dname_val),
315
+ NUM2ULONG(bandwidth));
316
+
317
+ _E(ret < 0,
318
+ create_error(e_Error, "virDomainMigrateToURI", "", conn(s)));
319
+
320
+ return Qnil;
321
+ }
322
+ #endif
323
+
324
+ #if HAVE_VIRDOMAINMIGRATESETMAXDOWNTIME
325
+ /*
326
+ * call-seq:
327
+ * dom.migrate_set_max_downtime -> nil
328
+ *
329
+ * Call +virDomainMigrateSetMaxDowntime+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainMigrateSetMaxDowntime]
330
+ */
331
+ static VALUE libvirt_dom_migrate_set_max_downtime(int argc, VALUE *argv, VALUE s) {
332
+ VALUE downtime, flags;
333
+ int ret;
334
+
335
+ rb_scan_args(argc, argv, "11", &downtime, &flags);
336
+
337
+ if (NIL_P(flags))
338
+ flags = INT2FIX(0);
339
+
340
+ ret = virDomainMigrateSetMaxDowntime(domain_get(s), NUM2ULL(downtime),
341
+ NUM2UINT(flags));
342
+
343
+ _E(ret < 0,
344
+ create_error(e_Error, "virDomainMigrateSetMaxDowntime", "", conn(s)));
345
+
346
+ return Qnil;
347
+ }
348
+ #endif
349
+
350
+ /*
351
+ * call-seq:
352
+ * dom.shutdown -> nil
353
+ *
354
+ * Call +virDomainShutdown+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainShutdown]
355
+ */
356
+ static VALUE libvirt_dom_shutdown(VALUE s) {
357
+ gen_call_void(virDomainShutdown, conn(s), domain_get(s));
358
+ }
359
+
360
+ /*
361
+ * call-seq:
362
+ * dom.reboot -> nil
363
+ *
364
+ * Call +virDomainReboot+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainReboot]
365
+ */
366
+ static VALUE libvirt_dom_reboot(int argc, VALUE *argv, VALUE s) {
367
+ VALUE flags;
368
+
369
+ rb_scan_args(argc, argv, "01", &flags);
370
+
371
+ if (NIL_P(flags))
372
+ flags = INT2FIX(0);
373
+
374
+ gen_call_void(virDomainReboot, conn(s), domain_get(s), NUM2UINT(flags));
375
+ }
376
+
377
+ /*
378
+ * call-seq:
379
+ * dom.destroy -> nil
380
+ *
381
+ * Call +virDomainDestroy+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainDestroy]
382
+ */
383
+ static VALUE libvirt_dom_destroy(VALUE s) {
384
+ gen_call_void(virDomainDestroy, conn(s), domain_get(s));
385
+ }
386
+
387
+ /*
388
+ * call-seq:
389
+ * dom.suspend -> nil
390
+ *
391
+ * Call +virDomainSuspend+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSuspend]
392
+ */
393
+ static VALUE libvirt_dom_suspend(VALUE s) {
394
+ gen_call_void(virDomainSuspend, conn(s), domain_get(s));
395
+ }
396
+
397
+ /*
398
+ * call-seq:
399
+ * dom.resume -> nil
400
+ *
401
+ * Call +virDomainResume+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainResume]
402
+ */
403
+ static VALUE libvirt_dom_resume(VALUE s) {
404
+ gen_call_void(virDomainResume, conn(s), domain_get(s));
405
+ }
406
+
407
+ /*
408
+ * call-seq:
409
+ * dom.save -> nil
410
+ *
411
+ * Call +virDomainSave+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSave]
412
+ */
413
+ static VALUE libvirt_dom_save(VALUE s, VALUE to) {
414
+ gen_call_void(virDomainSave, conn(s), domain_get(s), StringValueCStr(to));
415
+ }
416
+
417
+ #if HAVE_VIRDOMAINMANAGEDSAVE
418
+ /*
419
+ * call-seq:
420
+ * dom.managed_save -> nil
421
+ *
422
+ * Call +virDomainManagedSave+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainManagedSave]
423
+ */
424
+ static VALUE libvirt_dom_managed_save(int argc, VALUE *argv, VALUE s) {
425
+ VALUE flags;
426
+
427
+ rb_scan_args(argc, argv, "01", &flags);
428
+
429
+ if (NIL_P(flags))
430
+ flags = INT2FIX(0);
431
+
432
+ gen_call_void(virDomainManagedSave, conn(s), domain_get(s),
433
+ NUM2UINT(flags));
434
+ }
435
+
436
+ /*
437
+ * call-seq:
438
+ * dom.has_managed_save -> [true|false]
439
+ *
440
+ * Call +virDomainHasManagedSaveImage+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainHasManagedSaveImage]
441
+ */
442
+ static VALUE libvirt_dom_has_managed_save(int argc, VALUE *argv, VALUE s) {
443
+ VALUE flags;
444
+
445
+ rb_scan_args(argc, argv, "01", &flags);
446
+
447
+ if (NIL_P(flags))
448
+ flags = INT2FIX(0);
449
+
450
+ gen_call_truefalse(virDomainHasManagedSaveImage, conn(s), domain_get(s),
451
+ NUM2UINT(flags));
452
+ }
453
+
454
+ /*
455
+ * call-seq:
456
+ * dom.managed_save_remove -> nil
457
+ *
458
+ * Call +virDomainManagedSaveRemove+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainManagedSaveRemove]
459
+ */
460
+ static VALUE libvirt_dom_managed_save_remove(int argc, VALUE *argv, VALUE s) {
461
+ VALUE flags;
462
+
463
+ rb_scan_args(argc, argv, "01", &flags);
464
+
465
+ if (NIL_P(flags))
466
+ flags = INT2FIX(0);
467
+
468
+ gen_call_void(virDomainManagedSaveRemove, conn(s), domain_get(s),
469
+ NUM2UINT(flags));
470
+ }
471
+ #endif
472
+
473
+ /*
474
+ * call-seq:
475
+ * dom.core_dump -> nil
476
+ *
477
+ * Call +virDomainCoreDump+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainCoreDump]
478
+ */
479
+ static VALUE libvirt_dom_core_dump(int argc, VALUE *argv, VALUE s) {
480
+ VALUE to, flags;
481
+
482
+ rb_scan_args(argc, argv, "11", &to, &flags);
483
+
484
+ if (NIL_P(flags))
485
+ flags = INT2FIX(0);
486
+
487
+ gen_call_void(virDomainCoreDump, conn(s), domain_get(s),
488
+ StringValueCStr(to), NUM2INT(flags));
489
+ }
490
+
491
+ /*
492
+ * call-seq:
493
+ * dom.restore -> nil
494
+ *
495
+ * Call +virDomainRestore+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainRestore]
496
+ */
497
+ static VALUE libvirt_dom_s_restore(VALUE klass, VALUE c, VALUE from) {
498
+ gen_call_void(virDomainRestore, conn(c), connect_get(c),
499
+ StringValueCStr(from));
500
+ }
501
+
502
+ /*
503
+ * call-seq:
504
+ * domain.info -> Libvirt::Domain::Info
505
+ *
506
+ * Call +virDomainGetInfo+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetInfo]
507
+ */
508
+ static VALUE libvirt_dom_info(VALUE s) {
509
+ virDomainPtr dom = domain_get(s);
510
+ virDomainInfo info;
511
+ int r;
512
+ VALUE result;
513
+
514
+ r = virDomainGetInfo(dom, &info);
515
+ _E(r < 0, create_error(e_RetrieveError, "virDomainGetInfo", "", conn(s)));
516
+
517
+ result = rb_class_new_instance(0, NULL, c_domain_info);
518
+ rb_iv_set(result, "@state", CHR2FIX(info.state));
519
+ rb_iv_set(result, "@max_mem", ULONG2NUM(info.maxMem));
520
+ rb_iv_set(result, "@memory", ULONG2NUM(info.memory));
521
+ rb_iv_set(result, "@nr_virt_cpu", INT2FIX((int) info.nrVirtCpu));
522
+ rb_iv_set(result, "@cpu_time", ULL2NUM(info.cpuTime));
523
+ return result;
524
+ }
525
+
526
+ /*
527
+ * call-seq:
528
+ * domain.security_label -> Libvirt::Domain::SecurityLabel
529
+ *
530
+ * Call +virDomainGetSecurityLabel+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetSecurityLabel]
531
+ */
532
+ static VALUE libvirt_dom_security_label(VALUE s) {
533
+ virDomainPtr dom = domain_get(s);
534
+ virSecurityLabel seclabel;
535
+ int r;
536
+ VALUE result;
537
+
538
+ r = virDomainGetSecurityLabel(dom, &seclabel);
539
+ _E(r < 0, create_error(e_RetrieveError, "virDomainGetSecurityLabel", "", conn(s)));
540
+
541
+ result = rb_class_new_instance(0, NULL, c_domain_security_label);
542
+ rb_iv_set(result, "@label", rb_str_new2(seclabel.label));
543
+ rb_iv_set(result, "@enforcing", INT2NUM(seclabel.enforcing));
544
+
545
+ return result;
546
+ }
547
+
548
+ /*
549
+ * call-seq:
550
+ * domain.block_stats -> Libvirt::Domain::BlockStats
551
+ *
552
+ * Call +virDomainBlockStats+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainBlockStats]
553
+ */
554
+ static VALUE libvirt_dom_block_stats(VALUE s, VALUE path) {
555
+ virDomainPtr dom = domain_get(s);
556
+ virDomainBlockStatsStruct stats;
557
+ int r;
558
+ VALUE result;
559
+
560
+ r = virDomainBlockStats(dom, StringValueCStr(path), &stats, sizeof(stats));
561
+ _E(r < 0, create_error(e_RetrieveError, "virDomainBlockStats", "", conn(s)));
562
+
563
+ result = rb_class_new_instance(0, NULL, c_domain_block_stats);
564
+ rb_iv_set(result, "@rd_req", LL2NUM(stats.rd_req));
565
+ rb_iv_set(result, "@rd_bytes", LL2NUM(stats.rd_bytes));
566
+ rb_iv_set(result, "@wr_req", LL2NUM(stats.wr_req));
567
+ rb_iv_set(result, "@wr_bytes", LL2NUM(stats.wr_bytes));
568
+ rb_iv_set(result, "@errs", LL2NUM(stats.errs));
569
+
570
+ return result;
571
+ }
572
+
573
+ #if HAVE_TYPE_VIRDOMAINMEMORYSTATPTR
574
+ /*
575
+ * call-seq:
576
+ * domain.memory_stats -> Libvirt::Domain::MemoryStats
577
+ *
578
+ * Call +virDomainMemoryStats+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainMemoryStats]
579
+ */
580
+ static VALUE libvirt_dom_memory_stats(int argc, VALUE *argv, VALUE s) {
581
+ virDomainPtr dom = domain_get(s);
582
+ virDomainMemoryStatStruct stats[6];
583
+ int r;
584
+ VALUE result;
585
+ VALUE flags;
586
+ VALUE tmp;
587
+ int i;
588
+
589
+ rb_scan_args(argc, argv, "01", &flags);
590
+
591
+ if (NIL_P(flags))
592
+ flags = INT2FIX(0);
593
+
594
+ r = virDomainMemoryStats(dom, stats, 6, NUM2UINT(flags));
595
+ _E(r < 0, create_error(e_RetrieveError, "virDomainMemoryStats", "", conn(s)));
596
+
597
+ result = rb_ary_new2(r);
598
+ for (i=0; i<r; i++) {
599
+ tmp = rb_class_new_instance(0, NULL, c_domain_memory_stats);
600
+ rb_iv_set(tmp, "@tag", INT2NUM(stats[i].tag));
601
+ rb_iv_set(tmp, "@val", ULL2NUM(stats[i].val));
602
+
603
+ rb_ary_push(result, tmp);
604
+ } \
605
+
606
+ return result;
607
+ }
608
+ #endif
609
+
610
+ #if HAVE_TYPE_VIRDOMAINBLOCKINFOPTR
611
+ /*
612
+ * call-seq:
613
+ * domain.block_info -> Libvirt::Domain::BlockInfo
614
+ *
615
+ * Call +virDomainGetBlockInfo+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetBlockInfo]
616
+ */
617
+ static VALUE libvirt_dom_block_info(int argc, VALUE *argv, VALUE s) {
618
+ virDomainPtr dom = domain_get(s);
619
+ virDomainBlockInfo info;
620
+ int r;
621
+ VALUE result;
622
+ VALUE flags;
623
+ VALUE path;
624
+
625
+ rb_scan_args(argc, argv, "11", &path, &flags);
626
+
627
+ if (NIL_P(flags))
628
+ flags = INT2FIX(0);
629
+
630
+ r = virDomainGetBlockInfo(dom, StringValueCStr(path), &info, NUM2UINT(flags));
631
+ _E(r < 0, create_error(e_RetrieveError, "virDomainGetBlockInfo", "", conn(s)));
632
+
633
+ result = rb_class_new_instance(0, NULL, c_domain_block_info);
634
+ rb_iv_set(result, "@capacity", ULL2NUM(info.capacity));
635
+ rb_iv_set(result, "@allocation", ULL2NUM(info.allocation));
636
+ rb_iv_set(result, "@physical", ULL2NUM(info.physical));
637
+
638
+ return result;
639
+ }
640
+ #endif
641
+
642
+ /*
643
+ * call-seq:
644
+ * domain.block_peek -> string
645
+ *
646
+ * Call +virDomainBlockPeek+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainBlockPeek]
647
+ */
648
+ static VALUE libvirt_dom_block_peek(int argc, VALUE *argv, VALUE s) {
649
+ virDomainPtr dom = domain_get(s);
650
+ VALUE path, offset, size, flags;
651
+ char *buffer;
652
+ int r;
653
+ VALUE ret;
654
+
655
+ rb_scan_args(argc, argv, "31", &path, &offset, &size, &flags);
656
+
657
+ if (NIL_P(flags))
658
+ flags = INT2FIX(0);
659
+
660
+ buffer = ALLOC_N(char, size);
661
+
662
+ r = virDomainBlockPeek(dom, StringValueCStr(path),
663
+ NUM2ULL(offset), NUM2UINT(size), buffer,
664
+ NUM2UINT(flags));
665
+
666
+ _E(r < 0, create_error(e_RetrieveError, "virDomainBlockPeek", "", conn(s)));
667
+
668
+ ret = rb_str_new((char *)buffer, size);
669
+
670
+ free(buffer);
671
+
672
+ return ret;
673
+ }
674
+
675
+ /*
676
+ * call-seq:
677
+ * domain.memory_peek -> string
678
+ *
679
+ * Call +virDomainMemoryPeek+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainMemoryPeek]
680
+ */
681
+ static VALUE libvirt_dom_memory_peek(int argc, VALUE *argv, VALUE s) {
682
+ virDomainPtr dom = domain_get(s);
683
+ VALUE start, size, flags;
684
+ char *buffer;
685
+ int r;
686
+ VALUE ret;
687
+
688
+ rb_scan_args(argc, argv, "21", &start, &size, &flags);
689
+
690
+ if (NIL_P(flags))
691
+ flags = INT2FIX(0);
692
+
693
+ buffer = ALLOC_N(char, size);
694
+
695
+ r = virDomainMemoryPeek(dom, NUM2ULL(start), NUM2UINT(size), buffer,
696
+ NUM2UINT(flags));
697
+
698
+ _E(r < 0, create_error(e_RetrieveError, "virDomainMemoryPeek", "", conn(s)));
699
+
700
+ ret = rb_str_new((char *)buffer, size);
701
+
702
+ free(buffer);
703
+
704
+ return ret;
705
+ }
706
+
707
+ #if HAVE_VIRDOMAINISACTIVE
708
+ /*
709
+ * call-seq:
710
+ * domain.active? -> [true|false]
711
+ *
712
+ * Call +virDomainIsActive+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainIsActive]
713
+ */
714
+ static VALUE libvirt_dom_active_p(VALUE d) {
715
+ gen_call_truefalse(virDomainIsActive, conn(d), domain_get(d));
716
+ }
717
+ #endif
718
+
719
+ #if HAVE_VIRDOMAINISPERSISTENT
720
+ /*
721
+ * call-seq:
722
+ * domain.persistent? -> [true|false]
723
+ *
724
+ * Call +virDomainIsPersistent+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainIsPersistent]
725
+ */
726
+ static VALUE libvirt_dom_persistent_p(VALUE d) {
727
+ gen_call_truefalse(virDomainIsPersistent, conn(d), domain_get(d));
728
+ }
729
+ #endif
730
+
731
+ /*
732
+ * call-seq:
733
+ * domain.ifinfo -> Libvirt::Domain::IfInfo
734
+ *
735
+ * Call +virDomainInterfaceStats+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainInterfaceStats]
736
+ */
737
+ static VALUE libvirt_dom_if_stats(VALUE s, VALUE sif) {
738
+ virDomainPtr dom = domain_get(s);
739
+ char *ifname = get_string_or_nil(sif);
740
+ virDomainInterfaceStatsStruct ifinfo;
741
+ int r;
742
+ VALUE result = Qnil;
743
+
744
+ if (ifname) {
745
+ r = virDomainInterfaceStats(dom, ifname, &ifinfo,
746
+ sizeof(virDomainInterfaceStatsStruct));
747
+ _E(r < 0, create_error(e_RetrieveError, "virDomainInterfaceStats", "",
748
+ conn(s)));
749
+
750
+ result = rb_class_new_instance(0, NULL, c_domain_ifinfo);
751
+ rb_iv_set(result, "@rx_bytes", LL2NUM(ifinfo.rx_bytes));
752
+ rb_iv_set(result, "@rx_packets", LL2NUM(ifinfo.rx_packets));
753
+ rb_iv_set(result, "@rx_errs", LL2NUM(ifinfo.rx_errs));
754
+ rb_iv_set(result, "@rx_drop", LL2NUM(ifinfo.rx_drop));
755
+ rb_iv_set(result, "@tx_bytes", LL2NUM(ifinfo.tx_bytes));
756
+ rb_iv_set(result, "@tx_packets", LL2NUM(ifinfo.tx_packets));
757
+ rb_iv_set(result, "@tx_errs", LL2NUM(ifinfo.tx_errs));
758
+ rb_iv_set(result, "@tx_drop", LL2NUM(ifinfo.tx_drop));
759
+ }
760
+ return result;
761
+ }
762
+
763
+ /*
764
+ * call-seq:
765
+ * dom.name -> string
766
+ *
767
+ * Call +virDomainGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetName]
768
+ */
769
+ static VALUE libvirt_dom_name(VALUE s) {
770
+ gen_call_string(virDomainGetName, conn(s), 0, domain_get(s));
771
+ }
772
+
773
+ /*
774
+ * call-seq:
775
+ * dom.id -> fixnum
776
+ *
777
+ * Call +virDomainGetID+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetID]
778
+ */
779
+ static VALUE libvirt_dom_id(VALUE s) {
780
+ virDomainPtr dom = domain_get(s);
781
+ unsigned int id;
782
+ int out;
783
+
784
+ id = virDomainGetID(dom);
785
+ _E(id < 0, create_error(e_RetrieveError, "virDomainGetID", "", conn(s)));
786
+
787
+ /* we need to cast the unsigned int id to a signed int out to handle the
788
+ * -1 case
789
+ */
790
+ out = id;
791
+
792
+ return INT2NUM(out);
793
+ }
794
+
795
+ /*
796
+ * call-seq:
797
+ * dom.uuid -> string
798
+ *
799
+ * Call +virDomainGetUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetUUIDString]
800
+ */
801
+ static VALUE libvirt_dom_uuid(VALUE s) {
802
+ virDomainPtr dom = domain_get(s);
803
+ char uuid[VIR_UUID_STRING_BUFLEN];
804
+ int r;
805
+
806
+ r = virDomainGetUUIDString(dom, uuid);
807
+ _E(r < 0, create_error(e_RetrieveError, "virDomainGetUUIDString", "", conn(s)));
808
+
809
+ return rb_str_new2((char *) uuid);
810
+ }
811
+
812
+ /*
813
+ * call-seq:
814
+ * dom.os_type -> string
815
+ *
816
+ * Call +virDomainGetOSType+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetOSType]
817
+ */
818
+ static VALUE libvirt_dom_os_type(VALUE s) {
819
+ gen_call_string(virDomainGetOSType, conn(s), 1, domain_get(s));
820
+ }
821
+
822
+ /*
823
+ * call-seq:
824
+ * dom.max_memory -> fixnum
825
+ *
826
+ * Call +virDomainGetMaxMemory+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetMaxMemory]
827
+ */
828
+ static VALUE libvirt_dom_max_memory(VALUE s) {
829
+ virDomainPtr dom = domain_get(s);
830
+ unsigned long max_memory;
831
+
832
+ max_memory = virDomainGetMaxMemory(dom);
833
+ _E(max_memory == 0, create_error(e_RetrieveError, "virDomainGetMaxMemory", "", conn(s)));
834
+
835
+ return ULONG2NUM(max_memory);
836
+ }
837
+
838
+ /*
839
+ * call-seq:
840
+ * dom.max_memory_set -> nil
841
+ *
842
+ * Call +virDomainSetMaxMemory+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSetMaxMemory]
843
+ */
844
+ static VALUE libvirt_dom_max_memory_set(VALUE s, VALUE max_memory) {
845
+ virDomainPtr dom = domain_get(s);
846
+ int r;
847
+
848
+ r = virDomainSetMaxMemory(dom, NUM2ULONG(max_memory));
849
+ _E(r < 0, create_error(e_DefinitionError, "virDomainSetMaxMemory", "", conn(s)));
850
+
851
+ return ULONG2NUM(max_memory);
852
+ }
853
+
854
+ /*
855
+ * call-seq:
856
+ * dom.memory_set -> void
857
+ *
858
+ * Call +virDomainSetMemory+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSetMemory]
859
+ */
860
+ static VALUE libvirt_dom_memory_set(VALUE s, VALUE memory) {
861
+ virDomainPtr dom = domain_get(s);
862
+ int r;
863
+
864
+ r = virDomainSetMemory(dom, NUM2ULONG(memory));
865
+ _E(r < 0, create_error(e_DefinitionError, "virDomainSetMemory", "", conn(s)));
866
+
867
+ return ULONG2NUM(memory);
868
+ }
869
+
870
+ /*
871
+ * call-seq:
872
+ * dom.max_vcpus -> fixnum
873
+ *
874
+ * Call +virDomainGetMaxVcpus+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetMaxVcpus]
875
+ */
876
+ static VALUE libvirt_dom_max_vcpus(VALUE s) {
877
+ virDomainPtr dom = domain_get(s);
878
+ int vcpus;
879
+
880
+ vcpus = virDomainGetMaxVcpus(dom);
881
+ _E(vcpus < 0, create_error(e_RetrieveError, "virDomainGetMaxVcpus", "", conn(s)));
882
+
883
+ return INT2NUM(vcpus);
884
+ }
885
+
886
+
887
+ /*
888
+ * call-seq:
889
+ * dom.vcpus_set -> nil
890
+ *
891
+ * Call +virDomainSetVcpus+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSetVcpus]
892
+ */
893
+ static VALUE libvirt_dom_vcpus_set(VALUE s, VALUE nvcpus) {
894
+ gen_call_void(virDomainSetVcpus, conn(s), domain_get(s), NUM2UINT(nvcpus));
895
+ }
896
+
897
+ /*
898
+ * call-seq:
899
+ * dom.pin_vcpu -> nil
900
+ *
901
+ * Call +virDomainPinVcpu+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainPinVcpu]
902
+ */
903
+ static VALUE libvirt_dom_pin_vcpu(VALUE s, VALUE vcpu, VALUE cpulist) {
904
+ virDomainPtr dom = domain_get(s);
905
+ int r, i, len, maplen;
906
+ unsigned char *cpumap;
907
+ virNodeInfo nodeinfo;
908
+ virConnectPtr c = conn(s);
909
+
910
+ r = virNodeGetInfo(c, &nodeinfo);
911
+ _E(r < 0, create_error(e_RetrieveError, "virNodeGetInfo", "", c));
912
+
913
+ maplen = VIR_CPU_MAPLEN(nodeinfo.cpus);
914
+ cpumap = ALLOC_N(unsigned char, maplen);
915
+ MEMZERO(cpumap, unsigned char, maplen);
916
+
917
+ len = RARRAY(cpulist)->len;
918
+ for(i = 0; i < len; i++) {
919
+ VALUE e = rb_ary_entry(cpulist, i);
920
+ VIR_USE_CPU(cpumap, NUM2UINT(e));
921
+ }
922
+
923
+ r = virDomainPinVcpu(dom, NUM2UINT(vcpu), cpumap, maplen);
924
+ free(cpumap);
925
+ _E(r < 0, create_error(e_RetrieveError, "virDomainPinVcpu", "", c));
926
+
927
+ return Qnil;
928
+ }
929
+
930
+ /*
931
+ * call-seq:
932
+ * dom.xml_desc -> string
933
+ *
934
+ * Call +virDomainGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetXMLDesc]
935
+ */
936
+ static VALUE libvirt_dom_xml_desc(int argc, VALUE *argv, VALUE s) {
937
+ VALUE flags;
938
+
939
+ rb_scan_args(argc, argv, "01", &flags);
940
+
941
+ if (NIL_P(flags))
942
+ flags = INT2FIX(0);
943
+
944
+ gen_call_string(virDomainGetXMLDesc, conn(s), 1, domain_get(s),
945
+ NUM2INT(flags));
946
+ }
947
+
948
+ /*
949
+ * call-seq:
950
+ * dom.undefine -> nil
951
+ *
952
+ * Call +virDomainUndefine+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainUndefine]
953
+ */
954
+ static VALUE libvirt_dom_undefine(VALUE s) {
955
+ gen_call_void(virDomainUndefine, conn(s), domain_get(s));
956
+ }
957
+
958
+ /*
959
+ * call-seq:
960
+ * dom.create -> nil
961
+ *
962
+ * Call +virDomainCreate+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainCreate]
963
+ */
964
+ static VALUE libvirt_dom_create(VALUE s) {
965
+ gen_call_void(virDomainCreate, conn(s), domain_get(s));
966
+ }
967
+
968
+ /*
969
+ * call-seq:
970
+ * dom.autostart -> [true|false]
971
+ *
972
+ * Call +virDomainGetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetAutostart]
973
+ */
974
+ static VALUE libvirt_dom_autostart(VALUE s){
975
+ virDomainPtr dom = domain_get(s);
976
+ int r, autostart;
977
+
978
+ r = virDomainGetAutostart(dom, &autostart);
979
+ _E(r < 0, create_error(e_RetrieveError, "virDomainAutostart", "", conn(s)));
980
+
981
+ return autostart ? Qtrue : Qfalse;
982
+ }
983
+
984
+ /*
985
+ * call-seq:
986
+ * dom.autostart_set -> nil
987
+ *
988
+ * Call +virDomainSetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSetAutostart]
989
+ */
990
+ static VALUE libvirt_dom_autostart_set(VALUE s, VALUE autostart) {
991
+ gen_call_void(virDomainSetAutostart, conn(s),
992
+ domain_get(s), RTEST(autostart) ? 1 : 0);
993
+ }
994
+
995
+ /*
996
+ * call-seq:
997
+ * dom.attach_device -> nil
998
+ *
999
+ * Call +virDomainAttachDevice+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainAttachDevice]
1000
+ */
1001
+ static VALUE libvirt_dom_attach_device(VALUE s, VALUE xml) {
1002
+ gen_call_void(virDomainAttachDevice, conn(s), domain_get(s),
1003
+ StringValueCStr(xml));
1004
+ }
1005
+
1006
+ /*
1007
+ * call-seq:
1008
+ * dom.detach_device -> nil
1009
+ *
1010
+ * Call +virDomainDetachDevice+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainDetachDevice]
1011
+ */
1012
+ static VALUE libvirt_dom_detach_device(VALUE s, VALUE xml) {
1013
+ gen_call_void(virDomainDetachDevice, conn(s), domain_get(s),
1014
+ StringValueCStr(xml));
1015
+ }
1016
+
1017
+ /*
1018
+ * call-seq:
1019
+ * dom.free -> nil
1020
+ *
1021
+ * Call +virDomainFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainFree]
1022
+ */
1023
+ static VALUE libvirt_dom_free(VALUE s) {
1024
+ gen_call_free(Domain, s);
1025
+ }
1026
+
1027
+ #if HAVE_TYPE_VIRDOMAINSNAPSHOTPTR
1028
+ static void domain_snapshot_free(void *d) {
1029
+ generic_free(DomainSnapshot, d);
1030
+ }
1031
+
1032
+ static VALUE domain_snapshot_new(virDomainSnapshotPtr d, VALUE domain) {
1033
+ VALUE result;
1034
+ result = Data_Wrap_Struct(c_domain_snapshot, NULL, domain_snapshot_free, d);
1035
+ rb_iv_set(result, "@domain", domain);
1036
+ return result;
1037
+ }
1038
+
1039
+ static virDomainSnapshotPtr domain_snapshot_get(VALUE s) {
1040
+ generic_get(DomainSnapshot, s);
1041
+ }
1042
+
1043
+ /*
1044
+ * call-seq:
1045
+ * dom.snapshot_create_xml -> Libvirt::Domain::Snapshot
1046
+ *
1047
+ * Call +virDomainSnapshotCreateXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotCreateXML]
1048
+ */
1049
+ static VALUE libvirt_dom_snapshot_create_xml(int argc, VALUE *argv, VALUE d) {
1050
+ VALUE xmlDesc, flags;
1051
+ virDomainSnapshotPtr ret;
1052
+
1053
+ rb_scan_args(argc, argv, "11", &xmlDesc, &flags);
1054
+
1055
+ if (NIL_P(flags))
1056
+ flags = INT2FIX(0);
1057
+
1058
+ ret = virDomainSnapshotCreateXML(domain_get(d), StringValueCStr(xmlDesc),
1059
+ NUM2UINT(flags));
1060
+
1061
+ _E(ret == NULL, create_error(e_Error, "virDomainSnapshotCreateXML", "", conn(d)));
1062
+
1063
+ return domain_snapshot_new(ret, d);
1064
+ }
1065
+
1066
+ /*
1067
+ * call-seq:
1068
+ * dom.num_of_snapshots -> fixnum
1069
+ *
1070
+ * Call +virDomainSnapshotNum+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotNum]
1071
+ */
1072
+ static VALUE libvirt_dom_num_of_snapshots(int argc, VALUE *argv, VALUE d) {
1073
+ int result;
1074
+ virDomainPtr dom = domain_get(d);
1075
+ VALUE flags;
1076
+
1077
+ rb_scan_args(argc, argv, "01", &flags);
1078
+
1079
+ if (NIL_P(flags))
1080
+ flags = INT2FIX(0);
1081
+
1082
+ result = virDomainSnapshotNum(dom, NUM2UINT(flags));
1083
+ _E(result < 0, create_error(e_RetrieveError, "virDomainSnapshotNum", "", conn(d)));
1084
+ \
1085
+ return INT2NUM(result); \
1086
+ }
1087
+
1088
+ /*
1089
+ * call-seq:
1090
+ * dom.list_snapshots -> list
1091
+ *
1092
+ * Call +virDomainSnapshotListNames+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotListNames]
1093
+ */
1094
+ static VALUE libvirt_dom_list_snapshots(int argc, VALUE *argv, VALUE d) {
1095
+ VALUE flags;
1096
+ int r, i;
1097
+ int num;
1098
+ virDomainPtr dom = domain_get(d);
1099
+ char **names;
1100
+ VALUE result;
1101
+
1102
+ rb_scan_args(argc, argv, "01", &flags);
1103
+
1104
+ if (NIL_P(flags))
1105
+ flags = INT2FIX(0);
1106
+
1107
+ num = virDomainSnapshotNum(dom, 0);
1108
+ _E(num < 0, create_error(e_RetrieveError, "virDomainSnapshotNum", "", conn(d)));
1109
+ if (num == 0) {
1110
+ /* if num is 0, don't call virDomainSnapshotListNames function */
1111
+ result = rb_ary_new2(num);
1112
+ return result;
1113
+ }
1114
+ names = ALLOC_N(char *, num);
1115
+
1116
+ r = virDomainSnapshotListNames(domain_get(d), names, num,
1117
+ NUM2UINT(flags));
1118
+ if (r < 0) {
1119
+ free(names);
1120
+ _E(r < 0, create_error(e_RetrieveError, "virDomainSnapshotListNames", "", conn(d)));
1121
+ }
1122
+
1123
+ result = rb_ary_new2(num);
1124
+ for (i=0; i<num; i++) {
1125
+ rb_ary_push(result, rb_str_new2(names[i]));
1126
+ free(names[i]);
1127
+ }
1128
+ free(names);
1129
+ return result;
1130
+ }
1131
+
1132
+ /*
1133
+ * call-seq:
1134
+ * dom.lookup_snapshot_by_name -> Libvirt::Domain::Snapshot
1135
+ *
1136
+ * Call +virDomainSnapshotLookupByName+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotLookupByName]
1137
+ */
1138
+ static VALUE libvirt_dom_lookup_snapshot_by_name(int argc, VALUE *argv, VALUE d) {
1139
+ virDomainPtr dom = domain_get(d);
1140
+ virDomainSnapshotPtr snap;
1141
+ VALUE name, flags;
1142
+
1143
+ rb_scan_args(argc, argv, "11", &name, &flags);
1144
+
1145
+ if (NIL_P(flags))
1146
+ flags = INT2FIX(0);
1147
+
1148
+ snap = virDomainSnapshotLookupByName(dom, StringValueCStr(name),
1149
+ NUM2UINT(flags));
1150
+ _E(dom == NULL, create_error(e_RetrieveError, "virDomainSnapshotLookupByName", "", conn(d)));
1151
+
1152
+ return domain_snapshot_new(snap, d);
1153
+ }
1154
+
1155
+ /*
1156
+ * call-seq:
1157
+ * dom.has_current_snapshot? -> [true|false]
1158
+ *
1159
+ * Call +virDomainHasCurrentSnapshot+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainHasCurrentSnapshot]
1160
+ */
1161
+ static VALUE libvirt_dom_has_current_snapshot_p(int argc, VALUE *argv, VALUE d) {
1162
+ VALUE flags;
1163
+
1164
+ rb_scan_args(argc, argv, "01", &flags);
1165
+
1166
+ if (NIL_P(flags))
1167
+ flags = INT2FIX(0);
1168
+
1169
+ gen_call_truefalse(virDomainHasCurrentSnapshot, conn(d), domain_get(d),
1170
+ NUM2UINT(flags));
1171
+ }
1172
+
1173
+ /*
1174
+ * call-seq:
1175
+ * dom.revert_to_snapshot -> nil
1176
+ *
1177
+ * Call +virDomainRevertToSnapshot+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainRevertToSnapshot]
1178
+ */
1179
+ static VALUE libvirt_dom_revert_to_snapshot(int argc, VALUE *argv, VALUE d) {
1180
+ VALUE snap, flags;
1181
+ int r;
1182
+
1183
+ rb_scan_args(argc, argv, "11", &snap, &flags);
1184
+
1185
+ if (NIL_P(flags))
1186
+ flags = INT2FIX(0);
1187
+
1188
+ r = virDomainRevertToSnapshot(domain_snapshot_get(snap), NUM2UINT(flags));
1189
+ _E(r < 0, create_error(e_RetrieveError, "virDomainRevertToSnapshot", "", conn(d)));
1190
+
1191
+ return Qnil;
1192
+ }
1193
+
1194
+ /*
1195
+ * call-seq:
1196
+ * dom.current_snapshot -> Libvirt::Domain::Snapshot
1197
+ *
1198
+ * Call +virDomainCurrentSnapshot+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainCurrentSnapshot]
1199
+ */
1200
+ static VALUE libvirt_dom_current_snapshot(int argc, VALUE *argv, VALUE d) {
1201
+ VALUE flags;
1202
+ virDomainSnapshotPtr snap;
1203
+
1204
+ rb_scan_args(argc, argv, "01", &flags);
1205
+
1206
+ if (NIL_P(flags))
1207
+ flags = INT2FIX(0);
1208
+
1209
+ snap = virDomainSnapshotCurrent(domain_get(d), NUM2UINT(flags));
1210
+ _E(snap == NULL, create_error(e_RetrieveError, "virDomainSnapshotCurrent", "", conn(d)));
1211
+
1212
+ return domain_snapshot_new(snap, d);
1213
+ }
1214
+
1215
+ /*
1216
+ * call-seq:
1217
+ * snapshot.xml_desc -> string
1218
+ *
1219
+ * Call +virDomainSnapshotGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotGetXMLDesc]
1220
+ */
1221
+ static VALUE libvirt_dom_snapshot_xml_desc(int argc, VALUE *argv, VALUE s) {
1222
+ VALUE flags;
1223
+
1224
+ rb_scan_args(argc, argv, "01", &flags);
1225
+
1226
+ if (NIL_P(flags))
1227
+ flags = INT2FIX(0);
1228
+
1229
+ gen_call_string(virDomainSnapshotGetXMLDesc, conn(s), 1,
1230
+ domain_snapshot_get(s), NUM2UINT(flags));
1231
+ }
1232
+
1233
+ /*
1234
+ * call-seq:
1235
+ * snapshot.delete -> nil
1236
+ *
1237
+ * Call +virDomainSnapshotDelete+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotDelete]
1238
+ */
1239
+ static VALUE libvirt_dom_snapshot_delete(int argc, VALUE *argv, VALUE s) {
1240
+ VALUE flags;
1241
+
1242
+ rb_scan_args(argc, argv, "01", &flags);
1243
+
1244
+ if (NIL_P(flags))
1245
+ flags = INT2FIX(0);
1246
+
1247
+ gen_call_void(virDomainSnapshotDelete, conn(s),
1248
+ domain_snapshot_get(s), NUM2UINT(flags));
1249
+ }
1250
+
1251
+ /*
1252
+ * call-seq:
1253
+ * snapshot.free -> nil
1254
+ *
1255
+ * Call +virDomainSnapshotFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSnapshotFree]
1256
+ */
1257
+ static VALUE libvirt_dom_snapshot_free(VALUE s) {
1258
+ gen_call_free(DomainSnapshot, s);
1259
+ }
1260
+
1261
+ #endif
1262
+
1263
+ #if HAVE_TYPE_VIRDOMAINJOBINFOPTR
1264
+ /*
1265
+ * call-seq:
1266
+ * dom.job_info -> Libvirt::Domain::JobInfo
1267
+ *
1268
+ * Call +virDomainGetJobInfo+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetJobInfo]
1269
+ */
1270
+ static VALUE libvirt_dom_job_info(VALUE d) {
1271
+ int r;
1272
+ virDomainJobInfo info;
1273
+ VALUE result;
1274
+
1275
+ r = virDomainGetJobInfo(domain_get(d), &info);
1276
+ _E(r < 0, create_error(e_RetrieveError, "virDomainGetJobInfo", "", conn(d)));
1277
+
1278
+ result = rb_class_new_instance(0, NULL, c_domain_job_info);
1279
+ rb_iv_set(result, "@type", INT2NUM(info.type));
1280
+ rb_iv_set(result, "@time_elapsed", ULL2NUM(info.timeElapsed));
1281
+ rb_iv_set(result, "@time_remaining", ULL2NUM(info.timeRemaining));
1282
+ rb_iv_set(result, "@data_total", ULL2NUM(info.dataTotal));
1283
+ rb_iv_set(result, "@data_processed", ULL2NUM(info.dataProcessed));
1284
+ rb_iv_set(result, "@data_remaining", ULL2NUM(info.dataRemaining));
1285
+ rb_iv_set(result, "@mem_total", ULL2NUM(info.memTotal));
1286
+ rb_iv_set(result, "@mem_processed", ULL2NUM(info.memProcessed));
1287
+ rb_iv_set(result, "@mem_remaining", ULL2NUM(info.memRemaining));
1288
+ rb_iv_set(result, "@file_total", ULL2NUM(info.fileTotal));
1289
+ rb_iv_set(result, "@file_processed", ULL2NUM(info.fileProcessed));
1290
+ rb_iv_set(result, "@file_remaining", ULL2NUM(info.fileRemaining));
1291
+
1292
+ return result;
1293
+ }
1294
+
1295
+ /*
1296
+ * call-seq:
1297
+ * dom.abort_job -> nil
1298
+ *
1299
+ * Call +virDomainAbortJob+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainAbortJob]
1300
+ */
1301
+ static VALUE libvirt_dom_abort_job(VALUE d) {
1302
+ gen_call_void(virDomainAbortJob, conn(d), domain_get(d));
1303
+ }
1304
+
1305
+ #endif
1306
+
1307
+ /*
1308
+ * Class Libvirt::Domain
1309
+ */
1310
+ void init_domain()
1311
+ {
1312
+ c_domain = rb_define_class_under(m_libvirt, "Domain", rb_cObject);
1313
+
1314
+ #define DEF_DOMSTATE(name) \
1315
+ rb_define_const(c_domain, #name, INT2NUM(VIR_DOMAIN_##name))
1316
+ /* virDomainState */
1317
+ DEF_DOMSTATE(NOSTATE);
1318
+ DEF_DOMSTATE(RUNNING);
1319
+ DEF_DOMSTATE(BLOCKED);
1320
+ DEF_DOMSTATE(PAUSED);
1321
+ DEF_DOMSTATE(SHUTDOWN);
1322
+ DEF_DOMSTATE(SHUTOFF);
1323
+ DEF_DOMSTATE(CRASHED);
1324
+ #undef DEF_DOMSTATE
1325
+
1326
+ /* virDomainMigrateFlags */
1327
+ #ifdef VIR_MIGRATE_LIVE
1328
+ rb_define_const(c_domain, "MIGRATE_LIVE", INT2NUM(VIR_MIGRATE_LIVE));
1329
+ #endif
1330
+ #ifdef VIR_MIGRATE_PEER2PEER
1331
+ rb_define_const(c_domain, "MIGRATE_PEER2PEER",
1332
+ INT2NUM(VIR_MIGRATE_PEER2PEER));
1333
+ #endif
1334
+ #ifdef VIR_MIGRATE_TUNNELLED
1335
+ rb_define_const(c_domain, "MIGRATE_TUNNELLED",
1336
+ INT2NUM(VIR_MIGRATE_TUNNELLED));
1337
+ #endif
1338
+ #ifdef VIR_MIGRATE_PERSIST_DEST
1339
+ rb_define_const(c_domain, "MIGRATE_PERSIST_DEST",
1340
+ INT2NUM(VIR_MIGRATE_PERSIST_DEST));
1341
+ #endif
1342
+ #ifdef VIR_MIGRATE_UNDEFINE_SOURCE
1343
+ rb_define_const(c_domain, "MIGRATE_UNDEFINE_SOURCE",
1344
+ INT2NUM(VIR_MIGRATE_UNDEFINE_SOURCE));
1345
+ #endif
1346
+ #ifdef VIR_MIGRATE_PAUSED
1347
+ rb_define_const(c_domain, "MIGRATE_PAUSED", INT2NUM(VIR_MIGRATE_PAUSED));
1348
+ #endif
1349
+ #ifdef VIR_MIGRATE_NON_SHARED_DISK
1350
+ rb_define_const(c_domain, "MIGRATE_NON_SHARED_DISK",
1351
+ INT2NUM(VIR_MIGRATE_NON_SHARED_DISK));
1352
+ #endif
1353
+ #ifdef VIR_MIGRATE_NON_SHARED_INC
1354
+ rb_define_const(c_domain, "MIGRATE_NON_SHARED_INC",
1355
+ INT2NUM(VIR_MIGRATE_NON_SHARED_INC));
1356
+ #endif
1357
+ /* DomainGetXMLDesc flags */
1358
+ rb_define_const(c_domain, "DOMAIN_XML_SECURE",
1359
+ INT2NUM(VIR_DOMAIN_XML_SECURE));
1360
+ rb_define_const(c_domain, "DOMAIN_XML_INACTIVE",
1361
+ INT2NUM(VIR_DOMAIN_XML_INACTIVE));
1362
+ #ifdef VIR_DOMAIN_XML_UPDATE_CPU
1363
+ rb_define_const(c_domain, "DOMAIN_XML_UPDATE_CPU",
1364
+ INT2NUM(VIR_DOMAIN_XML_UPDATE_CPU));
1365
+ #endif
1366
+ rb_define_const(c_domain, "MEMORY_VIRTUAL", INT2NUM(VIR_MEMORY_VIRTUAL));
1367
+ #ifdef VIR_MEMORY_PHYSICAL
1368
+ rb_define_const(c_domain, "MEMORY_PHYSICAL", INT2NUM(VIR_MEMORY_PHYSICAL));
1369
+ #endif
1370
+
1371
+ // Domain creation/lookup
1372
+ rb_define_method(c_connect, "num_of_domains",
1373
+ libvirt_conn_num_of_domains, 0);
1374
+ rb_define_method(c_connect, "list_domains", libvirt_conn_list_domains, 0);
1375
+ rb_define_method(c_connect, "num_of_defined_domains",
1376
+ libvirt_conn_num_of_defined_domains, 0);
1377
+ rb_define_method(c_connect, "list_defined_domains",
1378
+ libvirt_conn_list_defined_domains, 0);
1379
+ rb_define_method(c_connect, "create_domain_linux",
1380
+ libvirt_conn_create_linux, -1);
1381
+ rb_define_method(c_connect, "lookup_domain_by_name",
1382
+ libvirt_conn_lookup_domain_by_name, 1);
1383
+ rb_define_method(c_connect, "lookup_domain_by_id",
1384
+ libvirt_conn_lookup_domain_by_id, 1);
1385
+ rb_define_method(c_connect, "lookup_domain_by_uuid",
1386
+ libvirt_conn_lookup_domain_by_uuid, 1);
1387
+ rb_define_method(c_connect, "define_domain_xml",
1388
+ libvirt_conn_define_domain_xml, 1);
1389
+
1390
+ #if HAVE_VIRCONNECTDOMAINXMLFROMNATIVE
1391
+ rb_define_method(c_connect, "domain_xml_from_native",
1392
+ libvirt_conn_domain_xml_from_native, -1);
1393
+ #endif
1394
+ #if HAVE_VIRCONNECTDOMAINXMLTONATIVE
1395
+ rb_define_method(c_connect, "domain_xml_to_native",
1396
+ libvirt_conn_domain_xml_to_native, -1);
1397
+ #endif
1398
+
1399
+ rb_define_method(c_domain, "migrate", libvirt_dom_migrate, -1);
1400
+ #if HAVE_VIRDOMAINMIGRATETOURI
1401
+ rb_define_method(c_domain, "migrate_to_uri",
1402
+ libvirt_dom_migrate_to_uri, -1);
1403
+ #endif
1404
+ #if HAVE_VIRDOMAINMIGRATESETMAXDOWNTIME
1405
+ rb_define_method(c_domain, "migrate_set_max_downtime",
1406
+ libvirt_dom_migrate_set_max_downtime, -1);
1407
+ #endif
1408
+ rb_define_attr(c_domain, "connection", 1, 0);
1409
+ rb_define_method(c_domain, "shutdown", libvirt_dom_shutdown, 0);
1410
+ rb_define_method(c_domain, "reboot", libvirt_dom_reboot, -1);
1411
+ rb_define_method(c_domain, "destroy", libvirt_dom_destroy, 0);
1412
+ rb_define_method(c_domain, "suspend", libvirt_dom_suspend, 0);
1413
+ rb_define_method(c_domain, "resume", libvirt_dom_resume, 0);
1414
+ rb_define_method(c_domain, "save", libvirt_dom_save, 1);
1415
+ rb_define_singleton_method(c_domain, "restore", libvirt_dom_s_restore, 2);
1416
+ rb_define_method(c_domain, "core_dump", libvirt_dom_core_dump, -1);
1417
+ rb_define_method(c_domain, "info", libvirt_dom_info, 0);
1418
+ rb_define_method(c_domain, "ifinfo", libvirt_dom_if_stats, 1);
1419
+ rb_define_method(c_domain, "name", libvirt_dom_name, 0);
1420
+ rb_define_method(c_domain, "id", libvirt_dom_id, 0);
1421
+ rb_define_method(c_domain, "uuid", libvirt_dom_uuid, 0);
1422
+ rb_define_method(c_domain, "os_type", libvirt_dom_os_type, 0);
1423
+ rb_define_method(c_domain, "max_memory", libvirt_dom_max_memory, 0);
1424
+ rb_define_method(c_domain, "max_memory=", libvirt_dom_max_memory_set, 1);
1425
+ rb_define_method(c_domain, "memory=", libvirt_dom_memory_set, 1);
1426
+ rb_define_method(c_domain, "max_vcpus", libvirt_dom_max_vcpus, 0);
1427
+ rb_define_method(c_domain, "vcpus=", libvirt_dom_vcpus_set, 1);
1428
+ rb_define_method(c_domain, "pin_vcpu", libvirt_dom_pin_vcpu, 2);
1429
+ rb_define_method(c_domain, "xml_desc", libvirt_dom_xml_desc, -1);
1430
+ rb_define_method(c_domain, "undefine", libvirt_dom_undefine, 0);
1431
+ rb_define_method(c_domain, "create", libvirt_dom_create, 0);
1432
+ rb_define_method(c_domain, "autostart", libvirt_dom_autostart, 0);
1433
+ rb_define_method(c_domain, "autostart?", libvirt_dom_autostart, 0);
1434
+ rb_define_method(c_domain, "autostart=", libvirt_dom_autostart_set, 1);
1435
+ rb_define_method(c_domain, "free", libvirt_dom_free, 0);
1436
+ /* FIXME: we should probably allow a "flags" parameter to
1437
+ * {attach,detach}_device, and then call
1438
+ * virDomain{Attach,Detach}DeviceFlags, where appropriate
1439
+ *
1440
+ * We should also make the VIR_DOMAIN_DEVICE_MODIFY_* flags consts
1441
+ */
1442
+ rb_define_method(c_domain, "attach_device", libvirt_dom_attach_device, 1);
1443
+ rb_define_method(c_domain, "detach_device", libvirt_dom_detach_device, 1);
1444
+ /* FIXME: implement this */
1445
+ // rb_define_method(c_domain, "update_device", libvirt_dom_update_device, -1);
1446
+ /* FIXME: we should probably do scheduler parameters as hashes. That is
1447
+ * virDomainGetSchedulerParameters should return a hash with all of the
1448
+ * parameters, and virDomainSetSchedulerParameters should take a hash
1449
+ * of parameters in
1450
+ */
1451
+ //rb_define_method(c_domain, "get_scheduler_params", libvirt_dom_get_scheduler_params, 0);
1452
+ //rb_define_method(c_domain, "set_scheduler_params", libvirt_dom_set_scheduler_params, 0)
1453
+ #if HAVE_VIRDOMAINMANAGEDSAVE
1454
+ rb_define_method(c_domain, "managed_save", libvirt_dom_managed_save, -1);
1455
+ rb_define_method(c_domain, "has_managed_save?",
1456
+ libvirt_dom_has_managed_save, -1);
1457
+ rb_define_method(c_domain, "managed_save_remove",
1458
+ libvirt_dom_managed_save_remove, -1);
1459
+ #endif
1460
+ rb_define_method(c_domain, "security_label",
1461
+ libvirt_dom_security_label, 0);
1462
+ rb_define_method(c_domain, "block_stats", libvirt_dom_block_stats, 1);
1463
+ #if HAVE_TYPE_VIRDOMAINMEMORYSTATPTR
1464
+ rb_define_method(c_domain, "memory_stats", libvirt_dom_memory_stats, -1);
1465
+ #endif
1466
+ rb_define_method(c_domain, "block_peek", libvirt_dom_block_peek, -1);
1467
+ #if HAVE_TYPE_VIRDOMAINBLOCKINFOPTR
1468
+ rb_define_method(c_domain, "blockinfo", libvirt_dom_block_info, -1);
1469
+ #endif
1470
+ rb_define_method(c_domain, "memory_peek", libvirt_dom_memory_peek, -1);
1471
+ /* FIXME: implement these */
1472
+ //rb_define_method(c_domain, "get_vcpus", libvirt_dom_get_vcpus, 0);
1473
+ #if HAVE_VIRDOMAINISACTIVE
1474
+ rb_define_method(c_domain, "active?", libvirt_dom_active_p, 0);
1475
+ #endif
1476
+ #if HAVE_VIRDOMAINISPERSISTENT
1477
+ rb_define_method(c_domain, "persistent?", libvirt_dom_persistent_p, 0);
1478
+ #endif
1479
+ #if HAVE_TYPE_VIRDOMAINSNAPSHOTPTR
1480
+ rb_define_method(c_domain, "snapshot_create_xml",
1481
+ libvirt_dom_snapshot_create_xml, -1);
1482
+ rb_define_method(c_domain, "num_of_snapshots",
1483
+ libvirt_dom_num_of_snapshots, -1);
1484
+ rb_define_method(c_domain, "list_snapshots",
1485
+ libvirt_dom_list_snapshots, -1);
1486
+ rb_define_method(c_domain, "lookup_snapshot_by_name",
1487
+ libvirt_dom_lookup_snapshot_by_name, -1);
1488
+ rb_define_method(c_domain, "has_current_snapshot?",
1489
+ libvirt_dom_has_current_snapshot_p, -1);
1490
+ rb_define_method(c_domain, "revert_to_snapshot",
1491
+ libvirt_dom_revert_to_snapshot, -1);
1492
+ rb_define_method(c_domain, "current_snapshot",
1493
+ libvirt_dom_current_snapshot, -1);
1494
+ #endif
1495
+
1496
+ /*
1497
+ * Class Libvirt::Domain::Info
1498
+ */
1499
+ c_domain_info = rb_define_class_under(c_domain, "Info", rb_cObject);
1500
+ rb_define_attr(c_domain_info, "state", 1, 0);
1501
+ rb_define_attr(c_domain_info, "max_mem", 1, 0);
1502
+ rb_define_attr(c_domain_info, "memory", 1, 0);
1503
+ rb_define_attr(c_domain_info, "nr_virt_cpu", 1, 0);
1504
+ rb_define_attr(c_domain_info, "cpu_time", 1, 0);
1505
+
1506
+ /*
1507
+ * Class Libvirt::Domain::InterfaceInfo
1508
+ */
1509
+ c_domain_ifinfo = rb_define_class_under(c_domain, "InterfaceInfo",
1510
+ rb_cObject);
1511
+ rb_define_attr(c_domain_ifinfo, "rx_bytes", 1, 0);
1512
+ rb_define_attr(c_domain_ifinfo, "rx_packets", 1, 0);
1513
+ rb_define_attr(c_domain_ifinfo, "rx_errs", 1, 0);
1514
+ rb_define_attr(c_domain_ifinfo, "rx_drop", 1, 0);
1515
+ rb_define_attr(c_domain_ifinfo, "tx_bytes", 1, 0);
1516
+ rb_define_attr(c_domain_ifinfo, "tx_packets", 1, 0);
1517
+ rb_define_attr(c_domain_ifinfo, "tx_errs", 1, 0);
1518
+ rb_define_attr(c_domain_ifinfo, "tx_drop", 1, 0);
1519
+
1520
+ /*
1521
+ * Class Libvirt::Domain::SecurityLabel
1522
+ */
1523
+ c_domain_security_label = rb_define_class_under(c_domain, "SecurityLabel",
1524
+ rb_cObject);
1525
+ rb_define_attr(c_domain_security_label, "label", 1, 0);
1526
+ rb_define_attr(c_domain_security_label, "enforcing", 1, 0);
1527
+
1528
+ /*
1529
+ * Class Libvirt::Domain::BlockStats
1530
+ */
1531
+ c_domain_block_stats = rb_define_class_under(c_domain, "BlockStats",
1532
+ rb_cObject);
1533
+ rb_define_attr(c_domain_block_stats, "rd_req", 1, 0);
1534
+ rb_define_attr(c_domain_block_stats, "rd_bytes", 1, 0);
1535
+ rb_define_attr(c_domain_block_stats, "wr_req", 1, 0);
1536
+ rb_define_attr(c_domain_block_stats, "wr_bytes", 1, 0);
1537
+ rb_define_attr(c_domain_block_stats, "errs", 1, 0);
1538
+
1539
+ #if HAVE_TYPE_VIRDOMAINMEMORYSTATPTR
1540
+ /*
1541
+ * Class Libvirt::Domain::MemoryStats
1542
+ */
1543
+ c_domain_memory_stats = rb_define_class_under(c_domain, "MemoryStats",
1544
+ rb_cObject);
1545
+ rb_define_attr(c_domain_memory_stats, "tag", 1, 0);
1546
+ rb_define_attr(c_domain_memory_stats, "value", 1, 0);
1547
+ #endif
1548
+
1549
+ #if HAVE_TYPE_VIRDOMAINBLOCKINFOPTR
1550
+ /*
1551
+ * Class Libvirt::Domain::BlockInfo
1552
+ */
1553
+ c_domain_block_info = rb_define_class_under(c_domain, "BlockInfo",
1554
+ rb_cObject);
1555
+ rb_define_attr(c_domain_block_info, "capacity", 1, 0);
1556
+ rb_define_attr(c_domain_block_info, "allocation", 1, 0);
1557
+ rb_define_attr(c_domain_block_info, "physical", 1, 0);
1558
+ #endif
1559
+
1560
+ #if HAVE_TYPE_VIRDOMAINSNAPSHOTPTR
1561
+ /*
1562
+ * Class Libvirt::Domain::Snapshot
1563
+ */
1564
+ c_domain_snapshot = rb_define_class_under(c_domain, "Snapshot", rb_cObject);
1565
+ rb_define_const(c_domain_snapshot, "DELETE_CHILDREN",
1566
+ INT2NUM(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN));
1567
+ rb_define_method(c_domain_snapshot, "xml_desc",
1568
+ libvirt_dom_snapshot_xml_desc, -1);
1569
+ rb_define_method(c_domain_snapshot, "delete",
1570
+ libvirt_dom_snapshot_delete, -1);
1571
+ rb_define_method(c_domain_snapshot, "free", libvirt_dom_snapshot_free, 0);
1572
+ #endif
1573
+
1574
+ #if HAVE_TYPE_VIRDOMAINJOBINFOPTR
1575
+ /*
1576
+ * Class Libvirt::Domain::JobInfo
1577
+ */
1578
+ c_domain_job_info = rb_define_class_under(c_domain, "JobInfo", rb_cObject);
1579
+ rb_define_const(c_domain_job_info, "NONE", INT2NUM(VIR_DOMAIN_JOB_NONE));
1580
+ rb_define_const(c_domain_job_info, "BOUNDED",
1581
+ INT2NUM(VIR_DOMAIN_JOB_BOUNDED));
1582
+ rb_define_const(c_domain_job_info, "UNBOUNDED",
1583
+ INT2NUM(VIR_DOMAIN_JOB_UNBOUNDED));
1584
+ rb_define_const(c_domain_job_info, "COMPLETED",
1585
+ INT2NUM(VIR_DOMAIN_JOB_COMPLETED));
1586
+ rb_define_const(c_domain_job_info, "FAILED",
1587
+ INT2NUM(VIR_DOMAIN_JOB_FAILED));
1588
+ rb_define_const(c_domain_job_info, "CANCELLED",
1589
+ INT2NUM(VIR_DOMAIN_JOB_CANCELLED));
1590
+ rb_define_attr(c_domain_job_info, "type", 1, 0);
1591
+ rb_define_attr(c_domain_job_info, "time_elapsed", 1, 0);
1592
+ rb_define_attr(c_domain_job_info, "time_remaining", 1, 0);
1593
+ rb_define_attr(c_domain_job_info, "data_total", 1, 0);
1594
+ rb_define_attr(c_domain_job_info, "data_processed", 1, 0);
1595
+ rb_define_attr(c_domain_job_info, "data_remaining", 1, 0);
1596
+ rb_define_attr(c_domain_job_info, "mem_total", 1, 0);
1597
+ rb_define_attr(c_domain_job_info, "mem_processed", 1, 0);
1598
+ rb_define_attr(c_domain_job_info, "mem_remaining", 1, 0);
1599
+ rb_define_attr(c_domain_job_info, "file_total", 1, 0);
1600
+ rb_define_attr(c_domain_job_info, "file_processed", 1, 0);
1601
+ rb_define_attr(c_domain_job_info, "file_remaining", 1, 0);
1602
+
1603
+ rb_define_method(c_domain, "job_info", libvirt_dom_job_info, 0);
1604
+ rb_define_method(c_domain, "abort_job", libvirt_dom_abort_job, 0);
1605
+ #endif
1606
+ }