ruby-libvirt 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/ext/libvirt/common.c CHANGED
@@ -121,7 +121,9 @@ VALUE create_error(VALUE error, const char* method, virConnectPtr conn) {
121
121
  rb_iv_set(ruby_errinfo, "@libvirt_function_name", rb_str_new2(method));
122
122
 
123
123
  if (err != NULL) {
124
- rb_iv_set(ruby_errinfo, "@libvirt_code", INT2FIX(err->code));
124
+ rb_iv_set(ruby_errinfo, "@libvirt_code", INT2NUM(err->code));
125
+ rb_iv_set(ruby_errinfo, "@libvirt_component", INT2NUM(err->domain));
126
+ rb_iv_set(ruby_errinfo, "@libvirt_level", INT2NUM(err->level));
125
127
  if (err->message != NULL)
126
128
  rb_iv_set(ruby_errinfo, "@libvirt_message",
127
129
  rb_str_new2(err->message));
@@ -24,12 +24,7 @@
24
24
  #include "extconf.h"
25
25
  #include "common.h"
26
26
  #include "domain.h"
27
- #include "interface.h"
28
27
  #include "network.h"
29
- #include "nodedevice.h"
30
- #include "nwfilter.h"
31
- #include "secret.h"
32
- #include "storage.h"
33
28
 
34
29
  static VALUE c_connect;
35
30
  static VALUE c_node_security_model;
@@ -247,7 +242,8 @@ static VALUE libvirt_conn_node_free_memory(VALUE s) {
247
242
  * to retrieve the amount of free memory in each NUMA cell on the host for
248
243
  * this connection.
249
244
  */
250
- static VALUE libvirt_conn_node_cells_free_memory(int argc, VALUE *argv, VALUE s) {
245
+ static VALUE libvirt_conn_node_cells_free_memory(int argc, VALUE *argv,
246
+ VALUE s) {
251
247
  int r;
252
248
  virConnectPtr conn = connect_get(s);
253
249
  VALUE cells;
@@ -366,7 +362,7 @@ static VALUE libvirt_conn_compare_cpu(int argc, VALUE *argv, VALUE s) {
366
362
 
367
363
  rb_scan_args(argc, argv, "11", &xml, &flags);
368
364
  if (NIL_P(flags))
369
- flags = INT2FIX(0);
365
+ flags = INT2NUM(0);
370
366
 
371
367
  gen_call_int(virConnectCompareCPU, conn(s), connect_get(s),
372
368
  StringValueCStr(xml), NUM2UINT(flags));
@@ -396,6 +392,10 @@ static VALUE libvirt_conn_baseline_cpu(int argc, VALUE *argv, VALUE s) {
396
392
  struct rb_ary_entry_arg arg;
397
393
 
398
394
  rb_scan_args(argc, argv, "11", &xmlcpus, &flags_val);
395
+ /*
396
+ * We check flags up-front here so that we get a TypeError early on if
397
+ * flags is bogus.
398
+ */
399
399
  if (NIL_P(flags_val))
400
400
  flags = 0;
401
401
  else
@@ -456,17 +456,21 @@ static int domain_event_lifecycle_callback(virConnectPtr conn,
456
456
  rb_raise(rb_eTypeError,
457
457
  "wrong domain event lifecycle callback argument type (expected Array)");
458
458
 
459
+ if (RARRAY_LEN(passthrough) != 2)
460
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
461
+ RARRAY_LEN(passthrough));
462
+
459
463
  cb = rb_ary_entry(passthrough, 0);
460
464
  cb_opaque = rb_ary_entry(passthrough, 1);
461
465
 
462
466
  newc = connect_new(conn);
463
467
  if (strcmp(rb_obj_classname(cb), "Symbol") == 0)
464
468
  rb_funcall(rb_class_of(cb), rb_to_id(cb), 5, newc,
465
- domain_new(dom, newc), INT2FIX(event), INT2FIX(detail),
469
+ domain_new(dom, newc), INT2NUM(event), INT2NUM(detail),
466
470
  cb_opaque);
467
471
  else if (strcmp(rb_obj_classname(cb), "Proc") == 0)
468
472
  rb_funcall(cb, rb_intern("call"), 5, newc, domain_new(dom, newc),
469
- INT2FIX(event), INT2FIX(detail), cb_opaque);
473
+ INT2NUM(event), INT2NUM(detail), cb_opaque);
470
474
  else
471
475
  rb_raise(rb_eTypeError,
472
476
  "wrong domain event lifecycle callback (expected Symbol or Proc)");
@@ -487,6 +491,10 @@ static int domain_event_reboot_callback(virConnectPtr conn, virDomainPtr dom,
487
491
  rb_raise(rb_eTypeError,
488
492
  "wrong domain event reboot callback argument type (expected Array)");
489
493
 
494
+ if (RARRAY_LEN(passthrough) != 2)
495
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
496
+ RARRAY_LEN(passthrough));
497
+
490
498
  cb = rb_ary_entry(passthrough, 0);
491
499
  cb_opaque = rb_ary_entry(passthrough, 1);
492
500
 
@@ -515,6 +523,10 @@ static int domain_event_rtc_callback(virConnectPtr conn, virDomainPtr dom,
515
523
  rb_raise(rb_eTypeError,
516
524
  "wrong domain event rtc callback argument type (expected Array)");
517
525
 
526
+ if (RARRAY_LEN(passthrough) != 2)
527
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
528
+ RARRAY_LEN(passthrough));
529
+
518
530
  cb = rb_ary_entry(passthrough, 0);
519
531
  cb_opaque = rb_ary_entry(passthrough, 1);
520
532
 
@@ -543,16 +555,20 @@ static int domain_event_watchdog_callback(virConnectPtr conn, virDomainPtr dom,
543
555
  rb_raise(rb_eTypeError,
544
556
  "wrong domain event watchdog callback argument type (expected Array)");
545
557
 
558
+ if (RARRAY_LEN(passthrough) != 2)
559
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
560
+ RARRAY_LEN(passthrough));
561
+
546
562
  cb = rb_ary_entry(passthrough, 0);
547
563
  cb_opaque = rb_ary_entry(passthrough, 1);
548
564
 
549
565
  newc = connect_new(conn);
550
566
  if (strcmp(rb_obj_classname(cb), "Symbol") == 0)
551
567
  rb_funcall(rb_class_of(cb), rb_to_id(cb), 4, newc,
552
- domain_new(dom, newc), INT2FIX(action), cb_opaque);
568
+ domain_new(dom, newc), INT2NUM(action), cb_opaque);
553
569
  else if (strcmp(rb_obj_classname(cb), "Proc") == 0)
554
570
  rb_funcall(cb, rb_intern("call"), 4, newc, domain_new(dom, newc),
555
- INT2FIX(action), cb_opaque);
571
+ INT2NUM(action), cb_opaque);
556
572
  else
557
573
  rb_raise(rb_eTypeError,
558
574
  "wrong domain event watchdog callback (expected Symbol or Proc)");
@@ -574,6 +590,10 @@ static int domain_event_io_error_callback(virConnectPtr conn, virDomainPtr dom,
574
590
  rb_raise(rb_eTypeError,
575
591
  "wrong domain event IO error callback argument type (expected Array)");
576
592
 
593
+ if (RARRAY_LEN(passthrough) != 2)
594
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
595
+ RARRAY_LEN(passthrough));
596
+
577
597
  cb = rb_ary_entry(passthrough, 0);
578
598
  cb_opaque = rb_ary_entry(passthrough, 1);
579
599
 
@@ -581,11 +601,11 @@ static int domain_event_io_error_callback(virConnectPtr conn, virDomainPtr dom,
581
601
  if (strcmp(rb_obj_classname(cb), "Symbol") == 0)
582
602
  rb_funcall(rb_class_of(cb), rb_to_id(cb), 6, newc,
583
603
  domain_new(dom, newc), rb_str_new2(src_path),
584
- rb_str_new2(dev_alias), INT2FIX(action), cb_opaque);
604
+ rb_str_new2(dev_alias), INT2NUM(action), cb_opaque);
585
605
  else if (strcmp(rb_obj_classname(cb), "Proc") == 0)
586
606
  rb_funcall(cb, rb_intern("call"), 6, newc, domain_new(dom, newc),
587
607
  rb_str_new2(src_path), rb_str_new2(dev_alias),
588
- INT2FIX(action), cb_opaque);
608
+ INT2NUM(action), cb_opaque);
589
609
  else
590
610
  rb_raise(rb_eTypeError,
591
611
  "wrong domain event IO error callback (expected Symbol or Proc)");
@@ -609,6 +629,10 @@ static int domain_event_io_error_reason_callback(virConnectPtr conn,
609
629
  rb_raise(rb_eTypeError,
610
630
  "wrong domain event IO error reason callback argument type (expected Array)");
611
631
 
632
+ if (RARRAY_LEN(passthrough) != 2)
633
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
634
+ RARRAY_LEN(passthrough));
635
+
612
636
  cb = rb_ary_entry(passthrough, 0);
613
637
  cb_opaque = rb_ary_entry(passthrough, 1);
614
638
 
@@ -616,12 +640,12 @@ static int domain_event_io_error_reason_callback(virConnectPtr conn,
616
640
  if (strcmp(rb_obj_classname(cb), "Symbol") == 0)
617
641
  rb_funcall(rb_class_of(cb), rb_to_id(cb), 7, newc,
618
642
  domain_new(dom, newc), rb_str_new2(src_path),
619
- rb_str_new2(dev_alias), INT2FIX(action),
643
+ rb_str_new2(dev_alias), INT2NUM(action),
620
644
  rb_str_new2(reason), cb_opaque);
621
645
  else if (strcmp(rb_obj_classname(cb), "Proc") == 0)
622
646
  rb_funcall(cb, rb_intern("call"), 7, newc, domain_new(dom, newc),
623
647
  rb_str_new2(src_path), rb_str_new2(dev_alias),
624
- INT2FIX(action), rb_str_new2(reason), cb_opaque);
648
+ INT2NUM(action), rb_str_new2(reason), cb_opaque);
625
649
  else
626
650
  rb_raise(rb_eTypeError,
627
651
  "wrong domain event IO error reason callback (expected Symbol or Proc)");
@@ -650,17 +674,21 @@ static int domain_event_graphics_callback(virConnectPtr conn, virDomainPtr dom,
650
674
  rb_raise(rb_eTypeError,
651
675
  "wrong domain event graphics callback argument type (expected Array)");
652
676
 
677
+ if (RARRAY_LEN(passthrough) != 2)
678
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
679
+ RARRAY_LEN(passthrough));
680
+
653
681
  cb = rb_ary_entry(passthrough, 0);
654
682
  cb_opaque = rb_ary_entry(passthrough, 1);
655
683
 
656
684
  local_hash = rb_hash_new();
657
- rb_hash_aset(local_hash, rb_str_new2("family"), INT2FIX(local->family));
685
+ rb_hash_aset(local_hash, rb_str_new2("family"), INT2NUM(local->family));
658
686
  rb_hash_aset(local_hash, rb_str_new2("node"), rb_str_new2(local->node));
659
687
  rb_hash_aset(local_hash, rb_str_new2("service"),
660
688
  rb_str_new2(local->service));
661
689
 
662
690
  remote_hash = rb_hash_new();
663
- rb_hash_aset(remote_hash, rb_str_new2("family"), INT2FIX(remote->family));
691
+ rb_hash_aset(remote_hash, rb_str_new2("family"), INT2NUM(remote->family));
664
692
  rb_hash_aset(remote_hash, rb_str_new2("node"), rb_str_new2(remote->node));
665
693
  rb_hash_aset(remote_hash, rb_str_new2("service"),
666
694
  rb_str_new2(remote->service));
@@ -677,12 +705,12 @@ static int domain_event_graphics_callback(virConnectPtr conn, virDomainPtr dom,
677
705
  newc = connect_new(conn);
678
706
  if (strcmp(rb_obj_classname(cb), "Symbol") == 0)
679
707
  rb_funcall(rb_class_of(cb), rb_to_id(cb), 8, newc,
680
- domain_new(dom, newc), INT2FIX(phase), local_hash,
708
+ domain_new(dom, newc), INT2NUM(phase), local_hash,
681
709
  remote_hash, rb_str_new2(authScheme), subject_array,
682
710
  cb_opaque);
683
711
  else if (strcmp(rb_obj_classname(cb), "Proc") == 0)
684
712
  rb_funcall(cb, rb_intern("call"), 8, newc, domain_new(dom, newc),
685
- INT2FIX(phase), local_hash, remote_hash,
713
+ INT2NUM(phase), local_hash, remote_hash,
686
714
  rb_str_new2(authScheme), subject_array, cb_opaque);
687
715
  else
688
716
  rb_raise(rb_eTypeError,
@@ -698,7 +726,7 @@ static int domain_event_graphics_callback(virConnectPtr conn, virDomainPtr dom,
698
726
  * Call +virConnectDomainEventRegisterAny+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegisterAny]
699
727
  * to register callback for eventID with libvirt. The eventID must be one of
700
728
  * the Libvirt::Connect::DOMAIN_EVENT_ID_* constants. The callback can either
701
- * by a Symbol (that is the name of a method to callback) or a Proc. Note that
729
+ * be a Symbol (that is the name of a method to callback) or a Proc. Note that
702
730
  * the callback must accept different numbers of arguments depending on the
703
731
  * eventID passed in. The arguments are as follows:
704
732
  *
@@ -804,7 +832,7 @@ static int domain_event_callback(virConnectPtr conn,
804
832
  *
805
833
  * Call +virConnectDomainEventRegister+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegister]
806
834
  * to register callback for domain lifecycle events with libvirt. The
807
- * callback can either by a Symbol (that is the name of a method to callback)
835
+ * callback can either be a Symbol (that is the name of a method to callback)
808
836
  * or a Proc. The callback must accept 5 parameters: Libvirt::Connect,
809
837
  * Libvirt::Domain, event, detail, opaque. The opaque parameter to
810
838
  * domain_event_register can be any valid ruby type, and will be passed into
@@ -932,7 +960,7 @@ static VALUE libvirt_conn_list_defined_domains(VALUE s) {
932
960
  *
933
961
  * Call +virDomainCreateLinux+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainCreateLinux]
934
962
  * to start a transient domain from the given XML. Deprecated; use
935
- * dom.create_xml instead.
963
+ * conn.create_domain_xml instead.
936
964
  */
937
965
  static VALUE libvirt_conn_create_linux(int argc, VALUE *argv, VALUE c) {
938
966
  virDomainPtr dom;
@@ -942,7 +970,7 @@ static VALUE libvirt_conn_create_linux(int argc, VALUE *argv, VALUE c) {
942
970
  rb_scan_args(argc, argv, "11", &xml, &flags);
943
971
 
944
972
  if (NIL_P(flags))
945
- flags = INT2FIX(0);
973
+ flags = INT2NUM(0);
946
974
 
947
975
  dom = virDomainCreateLinux(conn, StringValueCStr(xml), NUM2UINT(flags));
948
976
  _E(dom == NULL, create_error(e_Error, "virDomainCreateLinux", conn));
@@ -966,7 +994,7 @@ static VALUE libvirt_conn_create_xml(int argc, VALUE *argv, VALUE c) {
966
994
  rb_scan_args(argc, argv, "11", &xml, &flags);
967
995
 
968
996
  if (NIL_P(flags))
969
- flags = INT2FIX(0);
997
+ flags = INT2NUM(0);
970
998
 
971
999
  dom = virDomainCreateXML(conn, StringValueCStr(xml), NUM2UINT(flags));
972
1000
  _E(dom == NULL, create_error(e_Error, "virDomainCreateXML", conn));
@@ -1055,7 +1083,8 @@ static VALUE libvirt_conn_define_domain_xml(VALUE c, VALUE xml) {
1055
1083
  * Call +virConnectDomainXMLFromNative+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainXMLFromNative]
1056
1084
  * to convert a native hypervisor domain representation to libvirt XML.
1057
1085
  */
1058
- static VALUE libvirt_conn_domain_xml_from_native(int argc, VALUE *argv, VALUE s) {
1086
+ static VALUE libvirt_conn_domain_xml_from_native(int argc, VALUE *argv,
1087
+ VALUE s) {
1059
1088
  VALUE nativeFormat, xml, flags;
1060
1089
  char *ret;
1061
1090
  VALUE result;
@@ -1063,7 +1092,7 @@ static VALUE libvirt_conn_domain_xml_from_native(int argc, VALUE *argv, VALUE s)
1063
1092
  rb_scan_args(argc, argv, "21", &nativeFormat, &xml, &flags);
1064
1093
 
1065
1094
  if (NIL_P(flags))
1066
- flags = INT2FIX(0);
1095
+ flags = INT2NUM(0);
1067
1096
 
1068
1097
  ret = virConnectDomainXMLFromNative(conn(s), StringValueCStr(nativeFormat),
1069
1098
  StringValueCStr(xml), NUM2UINT(flags));
@@ -1094,7 +1123,7 @@ static VALUE libvirt_conn_domain_xml_to_native(int argc, VALUE *argv, VALUE s) {
1094
1123
  rb_scan_args(argc, argv, "21", &nativeFormat, &xml, &flags);
1095
1124
 
1096
1125
  if (NIL_P(flags))
1097
- flags = INT2FIX(0);
1126
+ flags = INT2NUM(0);
1098
1127
 
1099
1128
  ret = virConnectDomainXMLToNative(conn(s), StringValueCStr(nativeFormat),
1100
1129
  StringValueCStr(xml), NUM2UINT(flags));
@@ -1206,7 +1235,7 @@ static VALUE libvirt_conn_define_interface_xml(int argc, VALUE *argv, VALUE c) {
1206
1235
  rb_scan_args(argc, argv, "11", &xml, &flags);
1207
1236
 
1208
1237
  if (NIL_P(flags))
1209
- flags = INT2FIX(0);
1238
+ flags = INT2NUM(0);
1210
1239
 
1211
1240
  iface = virInterfaceDefineXML(conn, StringValueCStr(xml), NUM2UINT(flags));
1212
1241
  _E(iface == NULL, create_error(e_DefinitionError, "virInterfaceDefineXML",
@@ -1349,7 +1378,7 @@ static VALUE libvirt_conn_num_of_nodedevices(int argc, VALUE *argv, VALUE c) {
1349
1378
  rb_scan_args(argc, argv, "02", &cap, &flags);
1350
1379
 
1351
1380
  if (NIL_P(flags))
1352
- flags = INT2FIX(0);
1381
+ flags = INT2NUM(0);
1353
1382
 
1354
1383
  result = virNodeNumOfDevices(conn, get_string_or_nil(cap), NUM2UINT(flags));
1355
1384
  _E(result < 0, create_error(e_RetrieveError, "virNodeNumOfDevices", conn));
@@ -1424,7 +1453,8 @@ static VALUE libvirt_conn_lookup_nodedevice_by_name(VALUE c, VALUE name) {
1424
1453
  * Call +virNodeDeviceCreateXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceCreateXML]
1425
1454
  * to create a new node device from xml.
1426
1455
  */
1427
- static VALUE libvirt_conn_create_nodedevice_xml(int argc, VALUE *argv, VALUE c) {
1456
+ static VALUE libvirt_conn_create_nodedevice_xml(int argc, VALUE *argv,
1457
+ VALUE c) {
1428
1458
  virNodeDevicePtr nodedev;
1429
1459
  virConnectPtr conn = connect_get(c);
1430
1460
  VALUE xml, flags;
@@ -1432,7 +1462,7 @@ static VALUE libvirt_conn_create_nodedevice_xml(int argc, VALUE *argv, VALUE c)
1432
1462
  rb_scan_args(argc, argv, "11", &xml, &flags);
1433
1463
 
1434
1464
  if (NIL_P(flags))
1435
- flags = INT2FIX(0);
1465
+ flags = INT2NUM(0);
1436
1466
 
1437
1467
  nodedev = virNodeDeviceCreateXML(conn, StringValueCStr(xml),
1438
1468
  NUM2UINT(flags));
@@ -1573,7 +1603,8 @@ static VALUE libvirt_conn_lookup_secret_by_uuid(VALUE c, VALUE uuid) {
1573
1603
  * Call +virSecretLookupByUsage+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretLookupByUsage]
1574
1604
  * to retrieve a secret by usagetype.
1575
1605
  */
1576
- static VALUE libvirt_conn_lookup_secret_by_usage(VALUE c, VALUE usagetype, VALUE usageID) {
1606
+ static VALUE libvirt_conn_lookup_secret_by_usage(VALUE c, VALUE usagetype,
1607
+ VALUE usageID) {
1577
1608
  virSecretPtr secret;
1578
1609
  virConnectPtr conn = connect_get(c);
1579
1610
 
@@ -1600,7 +1631,7 @@ static VALUE libvirt_conn_define_secret_xml(int argc, VALUE *argv, VALUE c) {
1600
1631
  rb_scan_args(argc, argv, "11", &xml, &flags);
1601
1632
 
1602
1633
  if (NIL_P(flags))
1603
- flags = INT2FIX(0);
1634
+ flags = INT2NUM(0);
1604
1635
 
1605
1636
  secret = virSecretDefineXML(conn, StringValueCStr(xml), NUM2UINT(flags));
1606
1637
  _E(secret == NULL, create_error(e_DefinitionError, "virSecretDefineXML",
@@ -1709,7 +1740,7 @@ static VALUE libvirt_conn_create_pool_xml(int argc, VALUE *argv, VALUE c) {
1709
1740
  rb_scan_args(argc, argv, "11", &xml, &flags);
1710
1741
 
1711
1742
  if (NIL_P(flags))
1712
- flags = INT2FIX(0);
1743
+ flags = INT2NUM(0);
1713
1744
 
1714
1745
  pool = virStoragePoolCreateXML(conn, StringValueCStr(xml), NUM2UINT(flags));
1715
1746
  _E(pool == NULL, create_error(e_Error, "virStoragePoolCreateXML", conn));
@@ -1732,7 +1763,7 @@ static VALUE libvirt_conn_define_pool_xml(int argc, VALUE *argv, VALUE c) {
1732
1763
  rb_scan_args(argc, argv, "11", &xml, &flags);
1733
1764
 
1734
1765
  if (NIL_P(flags))
1735
- flags = INT2FIX(0);
1766
+ flags = INT2NUM(0);
1736
1767
 
1737
1768
  pool = virStoragePoolDefineXML(conn, StringValueCStr(xml), NUM2UINT(flags));
1738
1769
  _E(pool == NULL, create_error(e_DefinitionError, "virStoragePoolDefineXML",
@@ -1748,13 +1779,14 @@ static VALUE libvirt_conn_define_pool_xml(int argc, VALUE *argv, VALUE c) {
1748
1779
  * Call +virConnectFindStoragePoolSources+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectFindStoragePoolSources]
1749
1780
  * to find the storage pool sources corresponding to type.
1750
1781
  */
1751
- static VALUE libvirt_conn_find_storage_pool_sources(int argc, VALUE *argv, VALUE c) {
1782
+ static VALUE libvirt_conn_find_storage_pool_sources(int argc, VALUE *argv,
1783
+ VALUE c) {
1752
1784
  VALUE type, srcSpec_val, flags;
1753
1785
 
1754
1786
  rb_scan_args(argc, argv, "12", &type, &srcSpec_val, &flags);
1755
1787
 
1756
1788
  if (NIL_P(flags))
1757
- flags = INT2FIX(0);
1789
+ flags = INT2NUM(0);
1758
1790
 
1759
1791
  gen_call_string(virConnectFindStoragePoolSources, conn(c), 1,
1760
1792
  connect_get(c), StringValueCStr(type),
@@ -1762,6 +1794,110 @@ static VALUE libvirt_conn_find_storage_pool_sources(int argc, VALUE *argv, VALUE
1762
1794
  }
1763
1795
  #endif
1764
1796
 
1797
+ #if HAVE_VIRCONNECTGETSYSINFO
1798
+ /*
1799
+ * call-seq:
1800
+ * conn.sys_info(flags=0) -> string
1801
+ *
1802
+ * Call +virConnectGetSysinfo+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectGetSysinfo]
1803
+ * to get machine-specific information about the hypervisor. This may include
1804
+ * data such as the host UUID, the BIOS version, etc.
1805
+ */
1806
+ static VALUE libvirt_conn_get_sys_info(int argc, VALUE *argv, VALUE c) {
1807
+ VALUE flags;
1808
+
1809
+ rb_scan_args(argc, argv, "01", &flags);
1810
+
1811
+ if (NIL_P(flags))
1812
+ flags = INT2NUM(0);
1813
+
1814
+ gen_call_string(virConnectGetSysinfo, conn(c), 1, connect_get(c),
1815
+ NUM2UINT(flags));
1816
+ }
1817
+ #endif
1818
+
1819
+ #if HAVE_TYPE_VIRSTREAMPTR
1820
+ extern VALUE stream_new(virStreamPtr s, VALUE conn);
1821
+
1822
+ /*
1823
+ * call-seq:
1824
+ * conn.stream(flags=0) -> Libvirt::Stream
1825
+ *
1826
+ * Call +virStreamNew+[http://www.libvirt.org/html/libvirt-libvirt.html#virStreamNew]
1827
+ * to create a new stream.
1828
+ */
1829
+ static VALUE libvirt_conn_stream(int argc, VALUE *argv, VALUE c) {
1830
+ VALUE flags;
1831
+ virStreamPtr stream;
1832
+
1833
+ rb_scan_args(argc, argv, "01", &flags);
1834
+
1835
+ if (NIL_P(flags))
1836
+ flags = INT2NUM(0);
1837
+
1838
+ stream = virStreamNew(connect_get(c), NUM2UINT(flags));
1839
+
1840
+ _E(stream == NULL, create_error(e_RetrieveError, "virStreamNew", conn(c)));
1841
+
1842
+ return stream_new(stream, c);
1843
+ }
1844
+ #endif
1845
+
1846
+ #if HAVE_VIRINTERFACECHANGEBEGIN
1847
+ /*
1848
+ * call-seq:
1849
+ * conn.interface_change_begin(flags=0) -> nil
1850
+ *
1851
+ * Call +virInterfaceChangeBegin+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceChangeBegin]
1852
+ * to create a restore point for interface changes. Once changes have been
1853
+ * made, conn.interface_change_commit can be used to commit the result or
1854
+ * conn.interface_change_rollback can be used to rollback to this restore point.
1855
+ */
1856
+ static VALUE libvirt_conn_interface_change_begin(int argc, VALUE *argv,
1857
+ VALUE c) {
1858
+ VALUE flags;
1859
+
1860
+ rb_scan_args(argc, argv, "01", &flags);
1861
+
1862
+ gen_call_void(virInterfaceChangeBegin, conn(c), connect_get(c),
1863
+ NUM2UINT(flags));
1864
+ }
1865
+
1866
+ /*
1867
+ * call-seq:
1868
+ * conn.interface_change_commit(flags=0) -> nil
1869
+ *
1870
+ * Call +virInterfaceChangeCommit+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceChangeCommit]
1871
+ * to commit the interface changes since the last conn.interface_change_begin.
1872
+ */
1873
+ static VALUE libvirt_conn_interface_change_commit(int argc, VALUE *argv,
1874
+ VALUE c) {
1875
+ VALUE flags;
1876
+
1877
+ rb_scan_args(argc, argv, "01", &flags);
1878
+
1879
+ gen_call_void(virInterfaceChangeCommit, conn(c), connect_get(c),
1880
+ NUM2UINT(flags));
1881
+ }
1882
+
1883
+ /*
1884
+ * call-seq:
1885
+ * conn.interface_change_rollback(flags=0) -> nil
1886
+ *
1887
+ * Call +virInterfaceChangeRollback+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceChangeRollback]
1888
+ * to rollback to the restore point saved by conn.interface_change_begin.
1889
+ */
1890
+ static VALUE libvirt_conn_interface_change_rollback(int argc, VALUE *argv,
1891
+ VALUE c) {
1892
+ VALUE flags;
1893
+
1894
+ rb_scan_args(argc, argv, "01", &flags);
1895
+
1896
+ gen_call_void(virInterfaceChangeRollback, conn(c), connect_get(c),
1897
+ NUM2UINT(flags));
1898
+ }
1899
+ #endif
1900
+
1765
1901
  /*
1766
1902
  * Class Libvirt::Connect
1767
1903
  */
@@ -1840,7 +1976,7 @@ void init_connect()
1840
1976
  * then ADDED and REMOVED were renamed to DEFINED and UNDEFINED at
1841
1977
  * the same time that the details were added
1842
1978
  * (d3d54d2fc92e350f250eda26cee5d0342416a9cf). What this means is that
1843
- * if we have to check for HAVE_CONST_VIR_DOMAIN_EVENT_DEFINED and
1979
+ * we have to check for HAVE_CONST_VIR_DOMAIN_EVENT_DEFINED and
1844
1980
  * HAVE_CONST_VIR_DOMAIN_EVENT_STARTED to untangle these, and then we
1845
1981
  * can make a decision for many of the events based on that.
1846
1982
  */
@@ -1961,6 +2097,11 @@ void init_connect()
1961
2097
  INT2NUM(VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON));
1962
2098
  #endif
1963
2099
 
2100
+ #if HAVE_CONST_VIR_DOMAIN_EVENT_ID_CONTROL_ERROR
2101
+ rb_define_const(c_connect, "DOMAIN_EVENT_ID_CONTROL_ERROR",
2102
+ INT2NUM(VIR_DOMAIN_EVENT_ID_CONTROL_ERROR));
2103
+ #endif
2104
+
1964
2105
  #if HAVE_VIRCONNECTDOMAINEVENTREGISTER
1965
2106
  rb_define_method(c_connect, "domain_event_register",
1966
2107
  libvirt_conn_domain_event_register, -1);
@@ -2105,4 +2246,20 @@ void init_connect()
2105
2246
  rb_define_method(c_connect, "discover_storage_pool_sources",
2106
2247
  libvirt_conn_find_storage_pool_sources, -1);
2107
2248
  #endif
2249
+
2250
+ #if HAVE_VIRCONNECTGETSYSINFO
2251
+ rb_define_method(c_connect, "sys_info", libvirt_conn_get_sys_info, -1);
2252
+ #endif
2253
+ #if HAVE_TYPE_VIRSTREAMPTR
2254
+ rb_define_method(c_connect, "stream", libvirt_conn_stream, -1);
2255
+ #endif
2256
+
2257
+ #if HAVE_VIRINTERFACECHANGEBEGIN
2258
+ rb_define_method(c_connect, "interface_change_begin",
2259
+ libvirt_conn_interface_change_begin, -1);
2260
+ rb_define_method(c_connect, "interface_change_commit",
2261
+ libvirt_conn_interface_change_commit, -1);
2262
+ rb_define_method(c_connect, "interface_change_rollback",
2263
+ libvirt_conn_interface_change_rollback, -1);
2264
+ #endif
2108
2265
  }