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/domain.c CHANGED
@@ -18,7 +18,9 @@
18
18
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
19
  */
20
20
 
21
+ #include <stdint.h>
21
22
  #include <ruby.h>
23
+ #include <st.h>
22
24
  #include <libvirt/libvirt.h>
23
25
  #if HAVE_VIRDOMAINQEMUMONITORCOMMAND
24
26
  #include <libvirt/libvirt-qemu.h>
@@ -27,8 +29,35 @@
27
29
  #include "common.h"
28
30
  #include "connect.h"
29
31
  #include "extconf.h"
32
+ #include "stream.h"
33
+
34
+ #ifndef HAVE_TYPE_VIRTYPEDPARAMETERPTR
35
+ #define VIR_TYPED_PARAM_INT VIR_DOMAIN_SCHED_FIELD_INT
36
+ #define VIR_TYPED_PARAM_UINT VIR_DOMAIN_SCHED_FIELD_UINT
37
+ #define VIR_TYPED_PARAM_LLONG VIR_DOMAIN_SCHED_FIELD_LLONG
38
+ #define VIR_TYPED_PARAM_ULLONG VIR_DOMAIN_SCHED_FIELD_ULLONG
39
+ #define VIR_TYPED_PARAM_DOUBLE VIR_DOMAIN_SCHED_FIELD_DOUBLE
40
+ #define VIR_TYPED_PARAM_BOOLEAN VIR_DOMAIN_SCHED_FIELD_BOOLEAN
41
+
42
+ #define VIR_TYPED_PARAM_FIELD_LENGTH 80
43
+ typedef struct _virTypedParameter virTypedParameter;
44
+ struct _virTypedParameter {
45
+ char field[VIR_TYPED_PARAM_FIELD_LENGTH]; /* parameter name */
46
+ int type; /* parameter type, virTypedParameterType */
47
+ union {
48
+ int i; /* type is INT */
49
+ unsigned int ui; /* type is UINT */
50
+ long long int l; /* type is LLONG */
51
+ unsigned long long int ul; /* type is ULLONG */
52
+ double d; /* type is DOUBLE */
53
+ char b; /* type is BOOLEAN */
54
+ } value; /* parameter value */
55
+ };
56
+ typedef virTypedParameter *virTypedParameterPtr;
30
57
 
31
- VALUE c_domain;
58
+ #endif
59
+
60
+ static VALUE c_domain;
32
61
  static VALUE c_domain_info;
33
62
  static VALUE c_domain_ifinfo;
34
63
  static VALUE c_domain_security_label;
@@ -47,7 +76,7 @@ static VALUE c_domain_job_info;
47
76
  #endif
48
77
  static VALUE c_domain_vcpuinfo;
49
78
 
50
- void domain_free(void *d) {
79
+ static void domain_free(void *d) {
51
80
  generic_free(Domain, d);
52
81
  }
53
82
 
@@ -75,9 +104,9 @@ static VALUE libvirt_dom_migrate(int argc, VALUE *argv, VALUE s) {
75
104
  &bandwidth);
76
105
 
77
106
  if (NIL_P(bandwidth))
78
- bandwidth = INT2FIX(0);
107
+ bandwidth = INT2NUM(0);
79
108
  if (NIL_P(flags))
80
- flags = INT2FIX(0);
109
+ flags = INT2NUM(0);
81
110
 
82
111
  ddom = virDomainMigrate(domain_get(s), conn(dconn), NUM2ULONG(flags),
83
112
  get_string_or_nil(dname_val),
@@ -98,18 +127,18 @@ static VALUE libvirt_dom_migrate(int argc, VALUE *argv, VALUE s) {
98
127
  * libvirt URI is duri.
99
128
  */
100
129
  static VALUE libvirt_dom_migrate_to_uri(int argc, VALUE *argv, VALUE s) {
101
- VALUE flags, dname_val, bandwidth, duri_val;
130
+ VALUE duri, flags, dname, bandwidth;
102
131
 
103
- rb_scan_args(argc, argv, "13", &duri_val, &flags, &dname_val, &bandwidth);
132
+ rb_scan_args(argc, argv, "13", &duri, &flags, &dname, &bandwidth);
104
133
 
105
134
  if (NIL_P(bandwidth))
106
- bandwidth = INT2FIX(0);
135
+ bandwidth = INT2NUM(0);
107
136
  if (NIL_P(flags))
108
- flags = INT2FIX(0);
137
+ flags = INT2NUM(0);
109
138
 
110
139
  gen_call_void(virDomainMigrateToURI, conn(s), domain_get(s),
111
- StringValueCStr(duri_val), NUM2ULONG(flags),
112
- get_string_or_nil(dname_val), NUM2ULONG(bandwidth));
140
+ StringValueCStr(duri), NUM2ULONG(flags),
141
+ get_string_or_nil(dname), NUM2ULONG(bandwidth));
113
142
  }
114
143
  #endif
115
144
 
@@ -128,13 +157,89 @@ static VALUE libvirt_dom_migrate_set_max_downtime(int argc, VALUE *argv,
128
157
  rb_scan_args(argc, argv, "11", &downtime, &flags);
129
158
 
130
159
  if (NIL_P(flags))
131
- flags = INT2FIX(0);
160
+ flags = INT2NUM(0);
132
161
 
133
162
  gen_call_void(virDomainMigrateSetMaxDowntime, conn(s), domain_get(s),
134
163
  NUM2ULL(downtime), NUM2UINT(flags));
135
164
  }
136
165
  #endif
137
166
 
167
+ #if HAVE_VIRDOMAINMIGRATE2
168
+ /*
169
+ * call-seq:
170
+ * dom.migrate2(dconn, dxml=nil, flags=0, dname=nil, uri=nil, bandwidth=0) -> Libvirt::Domain
171
+ *
172
+ * Call +virDomainMigrate2+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainMigrate2]
173
+ * to migrate a domain from the host on this connection to the connection
174
+ * referenced in dconn.
175
+ */
176
+ static VALUE libvirt_dom_migrate2(int argc, VALUE *argv, VALUE s) {
177
+ VALUE dconn, dxml, flags, dname_val, uri_val, bandwidth;
178
+ virDomainPtr ddom = NULL;
179
+
180
+ rb_scan_args(argc, argv, "15", &dconn, &dxml, &flags, &dname_val, &uri_val,
181
+ &bandwidth);
182
+
183
+ if (NIL_P(bandwidth))
184
+ bandwidth = INT2NUM(0);
185
+ if (NIL_P(flags))
186
+ flags = INT2NUM(0);
187
+
188
+ ddom = virDomainMigrate2(domain_get(s), conn(dconn),
189
+ get_string_or_nil(dxml), NUM2ULONG(flags),
190
+ get_string_or_nil(dname_val),
191
+ get_string_or_nil(uri_val), NUM2ULONG(bandwidth));
192
+
193
+ _E(ddom == NULL, create_error(e_Error, "virDomainMigrate2", conn(s)));
194
+
195
+ return domain_new(ddom, dconn);
196
+ }
197
+
198
+ /*
199
+ * call-seq:
200
+ * dom.migrate_to_uri2(duri=nil, migrate_uri=nil, dxml=nil, flags=0, dname=nil, bandwidth=0) -> nil
201
+ *
202
+ * Call +virDomainMigrateToURI2+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainMigrateToURI2]
203
+ * to migrate a domain from the host on this connection to the host whose
204
+ * libvirt URI is duri.
205
+ */
206
+ static VALUE libvirt_dom_migrate_to_uri2(int argc, VALUE *argv, VALUE s) {
207
+ VALUE duri, migrate_uri, dxml, flags, dname, bandwidth;
208
+
209
+ rb_scan_args(argc, argv, "06", &duri, &migrate_uri, &dxml, &flags, &dname,
210
+ &bandwidth);
211
+
212
+ if (NIL_P(bandwidth))
213
+ bandwidth = INT2NUM(0);
214
+ if (NIL_P(flags))
215
+ flags = INT2NUM(0);
216
+
217
+ gen_call_void(virDomainMigrateToURI2, conn(s), domain_get(s),
218
+ get_string_or_nil(duri), get_string_or_nil(migrate_uri),
219
+ get_string_or_nil(dxml), NUM2ULONG(flags),
220
+ get_string_or_nil(dname), NUM2ULONG(bandwidth));
221
+ }
222
+
223
+ /*
224
+ * call-seq:
225
+ * dom.migrate_set_max_speed(bandwidth, flags=0) -> nil
226
+ *
227
+ * Call +virDomainMigrateSetMaxSpeed+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainMigrateSetMaxSpeed]
228
+ * to set the maximum bandwidth allowed for live migration.
229
+ */
230
+ static VALUE libvirt_dom_migrate_set_max_speed(int argc, VALUE *argv, VALUE s) {
231
+ VALUE bandwidth, flags;
232
+
233
+ rb_scan_args(argc, argv, "11", &bandwidth, &flags);
234
+
235
+ if (NIL_P(flags))
236
+ flags = INT2NUM(0);
237
+
238
+ gen_call_void(virDomainMigrateSetMaxSpeed, conn(s), domain_get(s),
239
+ NUM2ULONG(bandwidth), NUM2UINT(flags));
240
+ }
241
+ #endif
242
+
138
243
  /*
139
244
  * call-seq:
140
245
  * dom.shutdown -> nil
@@ -161,7 +266,7 @@ static VALUE libvirt_dom_reboot(int argc, VALUE *argv, VALUE s) {
161
266
  rb_scan_args(argc, argv, "01", &flags);
162
267
 
163
268
  if (NIL_P(flags))
164
- flags = INT2FIX(0);
269
+ flags = INT2NUM(0);
165
270
 
166
271
  gen_call_void(virDomainReboot, conn(s), domain_get(s), NUM2UINT(flags));
167
272
  }
@@ -228,7 +333,7 @@ static VALUE libvirt_dom_managed_save(int argc, VALUE *argv, VALUE s) {
228
333
  rb_scan_args(argc, argv, "01", &flags);
229
334
 
230
335
  if (NIL_P(flags))
231
- flags = INT2FIX(0);
336
+ flags = INT2NUM(0);
232
337
 
233
338
  gen_call_void(virDomainManagedSave, conn(s), domain_get(s),
234
339
  NUM2UINT(flags));
@@ -247,7 +352,7 @@ static VALUE libvirt_dom_has_managed_save(int argc, VALUE *argv, VALUE s) {
247
352
  rb_scan_args(argc, argv, "01", &flags);
248
353
 
249
354
  if (NIL_P(flags))
250
- flags = INT2FIX(0);
355
+ flags = INT2NUM(0);
251
356
 
252
357
  gen_call_truefalse(virDomainHasManagedSaveImage, conn(s), domain_get(s),
253
358
  NUM2UINT(flags));
@@ -266,7 +371,7 @@ static VALUE libvirt_dom_managed_save_remove(int argc, VALUE *argv, VALUE s) {
266
371
  rb_scan_args(argc, argv, "01", &flags);
267
372
 
268
373
  if (NIL_P(flags))
269
- flags = INT2FIX(0);
374
+ flags = INT2NUM(0);
270
375
 
271
376
  gen_call_void(virDomainManagedSaveRemove, conn(s), domain_get(s),
272
377
  NUM2UINT(flags));
@@ -286,7 +391,7 @@ static VALUE libvirt_dom_core_dump(int argc, VALUE *argv, VALUE s) {
286
391
  rb_scan_args(argc, argv, "11", &to, &flags);
287
392
 
288
393
  if (NIL_P(flags))
289
- flags = INT2FIX(0);
394
+ flags = INT2NUM(0);
290
395
 
291
396
  gen_call_void(virDomainCoreDump, conn(s), domain_get(s),
292
397
  StringValueCStr(to), NUM2INT(flags));
@@ -336,7 +441,7 @@ static VALUE libvirt_dom_info(VALUE s) {
336
441
  rb_iv_set(result, "@state", CHR2FIX(info.state));
337
442
  rb_iv_set(result, "@max_mem", ULONG2NUM(info.maxMem));
338
443
  rb_iv_set(result, "@memory", ULONG2NUM(info.memory));
339
- rb_iv_set(result, "@nr_virt_cpu", INT2FIX((int) info.nrVirtCpu));
444
+ rb_iv_set(result, "@nr_virt_cpu", INT2NUM((int) info.nrVirtCpu));
340
445
  rb_iv_set(result, "@cpu_time", ULL2NUM(info.cpuTime));
341
446
 
342
447
  return result;
@@ -414,7 +519,7 @@ static VALUE libvirt_dom_memory_stats(int argc, VALUE *argv, VALUE s) {
414
519
  rb_scan_args(argc, argv, "01", &flags);
415
520
 
416
521
  if (NIL_P(flags))
417
- flags = INT2FIX(0);
522
+ flags = INT2NUM(0);
418
523
 
419
524
  r = virDomainMemoryStats(dom, stats, 6, NUM2UINT(flags));
420
525
  _E(r < 0, create_error(e_RetrieveError, "virDomainMemoryStats", conn(s)));
@@ -461,7 +566,7 @@ static VALUE libvirt_dom_block_info(int argc, VALUE *argv, VALUE s) {
461
566
  rb_scan_args(argc, argv, "11", &path, &flags);
462
567
 
463
568
  if (NIL_P(flags))
464
- flags = INT2FIX(0);
569
+ flags = INT2NUM(0);
465
570
 
466
571
  r = virDomainGetBlockInfo(dom, StringValueCStr(path), &info,
467
572
  NUM2UINT(flags));
@@ -502,7 +607,7 @@ static VALUE libvirt_dom_block_peek(int argc, VALUE *argv, VALUE s) {
502
607
  &flags_val);
503
608
 
504
609
  if (NIL_P(flags_val))
505
- flags_val = INT2FIX(0);
610
+ flags_val = INT2NUM(0);
506
611
 
507
612
  path = StringValueCStr(path_val);
508
613
  offset = NUM2ULL(offset_val);
@@ -554,7 +659,7 @@ static VALUE libvirt_dom_memory_peek(int argc, VALUE *argv, VALUE s) {
554
659
  rb_scan_args(argc, argv, "21", &start_val, &size_val, &flags_val);
555
660
 
556
661
  if (NIL_P(flags_val))
557
- flags_val = INT2FIX(VIR_MEMORY_VIRTUAL);
662
+ flags_val = INT2NUM(VIR_MEMORY_VIRTUAL);
558
663
 
559
664
  start = NUM2UINT(start_val);
560
665
  size = NUM2UINT(size_val);
@@ -581,6 +686,46 @@ static VALUE libvirt_dom_memory_peek(int argc, VALUE *argv, VALUE s) {
581
686
  }
582
687
  #endif
583
688
 
689
+ struct create_vcpu_array_args {
690
+ virVcpuInfoPtr cpuinfo;
691
+ unsigned char *cpumap;
692
+ int nr_virt_cpu;
693
+ int maxcpus;
694
+ };
695
+
696
+ static VALUE create_vcpu_array(VALUE input) {
697
+ struct create_vcpu_array_args *args;
698
+ VALUE result;
699
+ int i;
700
+ VALUE vcpuinfo;
701
+ VALUE p2vcpumap;
702
+ int j;
703
+
704
+ args = (struct create_vcpu_array_args *)input;
705
+
706
+ result = rb_ary_new();
707
+
708
+ for (i = 0; i < args->nr_virt_cpu; i++) {
709
+ vcpuinfo = rb_class_new_instance(0, NULL, c_domain_vcpuinfo);
710
+ rb_iv_set(vcpuinfo, "@number", UINT2NUM((args->cpuinfo)[i].number));
711
+ rb_iv_set(vcpuinfo, "@state", INT2NUM((args->cpuinfo)[i].state));
712
+ rb_iv_set(vcpuinfo, "@cpu_time", ULL2NUM((args->cpuinfo)[i].cpuTime));
713
+ rb_iv_set(vcpuinfo, "@cpu", INT2NUM((args->cpuinfo)[i].cpu));
714
+
715
+ p2vcpumap = rb_ary_new();
716
+
717
+ for (j = 0; j < args->maxcpus; j++)
718
+ rb_ary_push(p2vcpumap,
719
+ (VIR_CPU_USABLE(args->cpumap,
720
+ VIR_CPU_MAPLEN(args->maxcpus), i, j)) ? Qtrue : Qfalse);
721
+ rb_iv_set(vcpuinfo, "@cpumap", p2vcpumap);
722
+
723
+ rb_ary_push(result, vcpuinfo);
724
+ }
725
+
726
+ return result;
727
+ }
728
+
584
729
  /* call-seq:
585
730
  * dom.get_vcpus -> [ Libvirt::Domain::VCPUInfo ]
586
731
  *
@@ -594,14 +739,10 @@ static VALUE libvirt_dom_get_vcpus(VALUE s) {
594
739
  virVcpuInfoPtr cpuinfo;
595
740
  unsigned char *cpumap;
596
741
  int cpumaplen;
597
- int r, i, j;
598
- VALUE vcpuinfo;
599
- VALUE p2vcpumap;
742
+ int r;
600
743
  VALUE result;
601
744
  int exception = 0;
602
- struct rb_ary_push_arg args;
603
- struct rb_iv_set_arg iv_args;
604
- struct rb_class_new_instance_arg klass_args;
745
+ struct create_vcpu_array_args args;
605
746
 
606
747
  r = virNodeGetInfo(conn(s), &nodeinfo);
607
748
  _E(r < 0, create_error(e_RetrieveError, "virNodeGetInfo", conn(s)));
@@ -630,97 +771,17 @@ static VALUE libvirt_dom_get_vcpus(VALUE s) {
630
771
  conn(s)));
631
772
  }
632
773
 
633
- result = rb_protect(rb_ary_new_wrap, (VALUE)NULL, &exception);
774
+ args.cpuinfo = cpuinfo;
775
+ args.cpumap = cpumap;
776
+ args.nr_virt_cpu = dominfo.nrVirtCpu;
777
+ args.maxcpus = VIR_NODEINFO_MAXCPUS(nodeinfo);
778
+ result = rb_protect(create_vcpu_array, (VALUE)&args, &exception);
634
779
  if (exception) {
635
780
  xfree(cpuinfo);
636
781
  free(cpumap);
637
782
  rb_jump_tag(exception);
638
783
  }
639
784
 
640
- for (i = 0; i < dominfo.nrVirtCpu; i++) {
641
- klass_args.argc = 0;
642
- klass_args.argv = NULL;
643
- klass_args.klass = c_domain_vcpuinfo;
644
- vcpuinfo = rb_protect(rb_class_new_instance_wrap, (VALUE)&klass_args,
645
- &exception);
646
- if (exception) {
647
- xfree(cpuinfo);
648
- free(cpumap);
649
- rb_jump_tag(exception);
650
- }
651
-
652
- iv_args.klass = vcpuinfo;
653
- iv_args.member = "@number";
654
- iv_args.value = UINT2NUM(cpuinfo[i].number);
655
- rb_protect(rb_iv_set_wrap, (VALUE)&iv_args, &exception);
656
- if (exception) {
657
- xfree(cpuinfo);
658
- free(cpumap);
659
- rb_jump_tag(exception);
660
- }
661
- iv_args.member = "@state";
662
- iv_args.value = INT2NUM(cpuinfo[i].state);
663
- rb_protect(rb_iv_set_wrap, (VALUE)&iv_args, &exception);
664
- if (exception) {
665
- xfree(cpuinfo);
666
- free(cpumap);
667
- rb_jump_tag(exception);
668
- }
669
- iv_args.member = "@cpu_time";
670
- iv_args.value = ULL2NUM(cpuinfo[i].cpuTime);
671
- rb_protect(rb_iv_set_wrap, (VALUE)&iv_args, &exception);
672
- if (exception) {
673
- xfree(cpuinfo);
674
- free(cpumap);
675
- rb_jump_tag(exception);
676
- }
677
- iv_args.member = "@cpu";
678
- iv_args.value = INT2NUM(cpuinfo[i].cpu);
679
- rb_protect(rb_iv_set_wrap, (VALUE)&iv_args, &exception);
680
- if (exception) {
681
- xfree(cpuinfo);
682
- free(cpumap);
683
- rb_jump_tag(exception);
684
- }
685
-
686
- p2vcpumap = rb_protect(rb_ary_new_wrap, (VALUE)NULL, &exception);
687
- if (exception) {
688
- xfree(cpuinfo);
689
- free(cpumap);
690
- rb_jump_tag(exception);
691
- }
692
-
693
- for (j = 0; j < VIR_NODEINFO_MAXCPUS(nodeinfo); j++) {
694
- args.arr = p2vcpumap;
695
- args.value = (VIR_CPU_USABLE(cpumap, cpumaplen, i, j)) ? Qtrue : Qfalse;
696
- rb_protect(rb_ary_push_wrap, (VALUE)&args, &exception);
697
- if (exception) {
698
- xfree(cpuinfo);
699
- free(cpumap);
700
- rb_jump_tag(exception);
701
- }
702
- }
703
-
704
- iv_args.klass = vcpuinfo;
705
- iv_args.member = "@cpumap";
706
- iv_args.value = p2vcpumap;
707
- rb_protect(rb_iv_set_wrap, (VALUE)&iv_args, &exception);
708
- if (exception) {
709
- xfree(cpuinfo);
710
- free(cpumap);
711
- rb_jump_tag(exception);
712
- }
713
-
714
- args.arr = result;
715
- args.value = vcpuinfo;
716
- rb_protect(rb_ary_push_wrap, (VALUE)&args, &exception);
717
- if (exception) {
718
- xfree(cpuinfo);
719
- free(cpumap);
720
- rb_jump_tag(exception);
721
- }
722
- }
723
-
724
785
  free(cpumap);
725
786
  xfree(cpuinfo);
726
787
 
@@ -811,13 +872,12 @@ static VALUE libvirt_dom_id(VALUE s) {
811
872
  int out;
812
873
 
813
874
  id = virDomainGetID(dom);
814
- _E(id == (unsigned int)-1, create_error(e_RetrieveError, "virDomainGetID",
815
- conn(s)));
816
875
 
817
876
  /* we need to cast the unsigned int id to a signed int out to handle the
818
877
  * -1 case
819
878
  */
820
879
  out = id;
880
+ _E(out == -1, create_error(e_RetrieveError, "virDomainGetID", conn(s)));
821
881
 
822
882
  return INT2NUM(out);
823
883
  }
@@ -893,19 +953,44 @@ static VALUE libvirt_dom_max_memory_set(VALUE s, VALUE max_memory) {
893
953
 
894
954
  /*
895
955
  * call-seq:
896
- * dom.memory = Fixnum
956
+ * dom.memory = Fixnum,flags=0
897
957
  *
898
958
  * Call +virDomainSetMemory+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSetMemory]
899
959
  * to set the amount of memory (in kilobytes) this domain should currently
900
960
  * have. Note this will only succeed if both the hypervisor and the domain on
901
961
  * this connection support ballooning.
902
962
  */
903
- static VALUE libvirt_dom_memory_set(VALUE s, VALUE memory) {
963
+ static VALUE libvirt_dom_memory_set(VALUE s, VALUE in) {
964
+ VALUE memory;
965
+ VALUE flags;
904
966
  virDomainPtr dom = domain_get(s);
905
967
  int r;
906
968
 
969
+ if (TYPE(in) == T_FIXNUM) {
970
+ memory = in;
971
+ flags = INT2NUM(0);
972
+ }
973
+ else if (TYPE(in) == T_ARRAY) {
974
+ if (RARRAY_LEN(in) != 2)
975
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)",
976
+ RARRAY_LEN(in));
977
+ memory = rb_ary_entry(in, 0);
978
+ flags = rb_ary_entry(in, 1);
979
+ }
980
+ else
981
+ rb_raise(rb_eTypeError,
982
+ "wrong argument type (expected Number or Array)");
983
+
984
+ #if HAVE_VIRDOMAINSETMEMORYFLAGS
985
+ r = virDomainSetMemoryFlags(dom, NUM2ULONG(memory), NUM2UINT(flags));
986
+ _E(r < 0, create_error(e_DefinitionError, "virDomainSetMemoryFlags",
987
+ conn(s)));
988
+ #else
989
+ if (NUM2UINT(flags) != 0)
990
+ rb_raise(e_NoSupportError, "Non-zero flags not supported");
907
991
  r = virDomainSetMemory(dom, NUM2ULONG(memory));
908
992
  _E(r < 0, create_error(e_DefinitionError, "virDomainSetMemory", conn(s)));
993
+ #endif
909
994
 
910
995
  return ULONG2NUM(memory);
911
996
  }
@@ -964,7 +1049,7 @@ static VALUE libvirt_dom_vcpus_set_flags(VALUE s, VALUE vcpus) {
964
1049
  Check_Type(vcpus, T_ARRAY);
965
1050
 
966
1051
  if (RARRAY_LEN(vcpus) != 2)
967
- rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
1052
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
968
1053
  RARRAY_LEN(vcpus));
969
1054
 
970
1055
  nvcpus = rb_ary_entry(vcpus, 0);
@@ -1028,7 +1113,7 @@ static VALUE libvirt_dom_xml_desc(int argc, VALUE *argv, VALUE s) {
1028
1113
  rb_scan_args(argc, argv, "01", &flags);
1029
1114
 
1030
1115
  if (NIL_P(flags))
1031
- flags = INT2FIX(0);
1116
+ flags = INT2NUM(0);
1032
1117
 
1033
1118
  gen_call_string(virDomainGetXMLDesc, conn(s), 1, domain_get(s),
1034
1119
  NUM2INT(flags));
@@ -1059,10 +1144,11 @@ static VALUE libvirt_dom_create(int argc, VALUE *argv, VALUE s) {
1059
1144
  rb_scan_args(argc, argv, "01", &flags);
1060
1145
 
1061
1146
  if (NIL_P(flags))
1062
- flags = INT2FIX(0);
1147
+ flags = INT2NUM(0);
1063
1148
 
1064
1149
  #if HAVE_VIRDOMAINCREATEWITHFLAGS
1065
- gen_call_void(virDomainCreateWithFlags, conn(s), domain_get(s), NUM2UINT(flags));
1150
+ gen_call_void(virDomainCreateWithFlags, conn(s), domain_get(s),
1151
+ NUM2UINT(flags));
1066
1152
  #else
1067
1153
  if (NUM2UINT(flags) != 0)
1068
1154
  rb_raise(e_NoSupportError, "Non-zero flags not supported");
@@ -1117,7 +1203,7 @@ static VALUE libvirt_dom_attach_device(int argc, VALUE *argv, VALUE s) {
1117
1203
  rb_scan_args(argc, argv, "11", &xml, &flags);
1118
1204
 
1119
1205
  if (NIL_P(flags))
1120
- flags = INT2FIX(0);
1206
+ flags = INT2NUM(0);
1121
1207
 
1122
1208
  #if HAVE_VIRDOMAINATTACHDEVICEFLAGS
1123
1209
  gen_call_void(virDomainAttachDeviceFlags, conn(s), domain_get(s),
@@ -1144,7 +1230,7 @@ static VALUE libvirt_dom_detach_device(int argc, VALUE *argv, VALUE s) {
1144
1230
  rb_scan_args(argc, argv, "11", &xml, &flags);
1145
1231
 
1146
1232
  if (NIL_P(flags))
1147
- flags = INT2FIX(0);
1233
+ flags = INT2NUM(0);
1148
1234
 
1149
1235
  #if HAVE_VIRDOMAINDETACHDEVICEFLAGS
1150
1236
  gen_call_void(virDomainDetachDeviceFlags, conn(s), domain_get(s),
@@ -1172,7 +1258,7 @@ static VALUE libvirt_dom_update_device(int argc, VALUE *argv, VALUE s) {
1172
1258
  rb_scan_args(argc, argv, "11", &xml, &flags);
1173
1259
 
1174
1260
  if (NIL_P(flags))
1175
- flags = INT2FIX(0);
1261
+ flags = INT2NUM(0);
1176
1262
 
1177
1263
  gen_call_void(virDomainUpdateDeviceFlags, conn(s), domain_get(s),
1178
1264
  StringValueCStr(xml), NUM2UINT(flags));
@@ -1220,7 +1306,7 @@ static VALUE libvirt_dom_snapshot_create_xml(int argc, VALUE *argv, VALUE d) {
1220
1306
  rb_scan_args(argc, argv, "11", &xmlDesc, &flags);
1221
1307
 
1222
1308
  if (NIL_P(flags))
1223
- flags = INT2FIX(0);
1309
+ flags = INT2NUM(0);
1224
1310
 
1225
1311
  ret = virDomainSnapshotCreateXML(domain_get(d), StringValueCStr(xmlDesc),
1226
1312
  NUM2UINT(flags));
@@ -1244,7 +1330,7 @@ static VALUE libvirt_dom_num_of_snapshots(int argc, VALUE *argv, VALUE d) {
1244
1330
  rb_scan_args(argc, argv, "01", &flags);
1245
1331
 
1246
1332
  if (NIL_P(flags))
1247
- flags = INT2FIX(0);
1333
+ flags = INT2NUM(0);
1248
1334
 
1249
1335
  gen_call_int(virDomainSnapshotNum, conn(d), domain_get(d),
1250
1336
  NUM2UINT(flags));
@@ -1305,7 +1391,7 @@ static VALUE libvirt_dom_lookup_snapshot_by_name(int argc, VALUE *argv, VALUE d)
1305
1391
  rb_scan_args(argc, argv, "11", &name, &flags);
1306
1392
 
1307
1393
  if (NIL_P(flags))
1308
- flags = INT2FIX(0);
1394
+ flags = INT2NUM(0);
1309
1395
 
1310
1396
  snap = virDomainSnapshotLookupByName(dom, StringValueCStr(name),
1311
1397
  NUM2UINT(flags));
@@ -1328,7 +1414,7 @@ static VALUE libvirt_dom_has_current_snapshot_p(int argc, VALUE *argv, VALUE d)
1328
1414
  rb_scan_args(argc, argv, "01", &flags);
1329
1415
 
1330
1416
  if (NIL_P(flags))
1331
- flags = INT2FIX(0);
1417
+ flags = INT2NUM(0);
1332
1418
 
1333
1419
  gen_call_truefalse(virDomainHasCurrentSnapshot, conn(d), domain_get(d),
1334
1420
  NUM2UINT(flags));
@@ -1347,7 +1433,7 @@ static VALUE libvirt_dom_revert_to_snapshot(int argc, VALUE *argv, VALUE d) {
1347
1433
  rb_scan_args(argc, argv, "11", &snap, &flags);
1348
1434
 
1349
1435
  if (NIL_P(flags))
1350
- flags = INT2FIX(0);
1436
+ flags = INT2NUM(0);
1351
1437
 
1352
1438
  gen_call_void(virDomainRevertToSnapshot, conn(d),
1353
1439
  domain_snapshot_get(snap), NUM2UINT(flags));
@@ -1367,7 +1453,7 @@ static VALUE libvirt_dom_current_snapshot(int argc, VALUE *argv, VALUE d) {
1367
1453
  rb_scan_args(argc, argv, "01", &flags);
1368
1454
 
1369
1455
  if (NIL_P(flags))
1370
- flags = INT2FIX(0);
1456
+ flags = INT2NUM(0);
1371
1457
 
1372
1458
  snap = virDomainSnapshotCurrent(domain_get(d), NUM2UINT(flags));
1373
1459
  _E(snap == NULL, create_error(e_RetrieveError, "virDomainSnapshotCurrent",
@@ -1389,7 +1475,7 @@ static VALUE libvirt_dom_snapshot_xml_desc(int argc, VALUE *argv, VALUE s) {
1389
1475
  rb_scan_args(argc, argv, "01", &flags);
1390
1476
 
1391
1477
  if (NIL_P(flags))
1392
- flags = INT2FIX(0);
1478
+ flags = INT2NUM(0);
1393
1479
 
1394
1480
  gen_call_string(virDomainSnapshotGetXMLDesc, conn(s), 1,
1395
1481
  domain_snapshot_get(s), NUM2UINT(flags));
@@ -1408,7 +1494,7 @@ static VALUE libvirt_dom_snapshot_delete(int argc, VALUE *argv, VALUE s) {
1408
1494
  rb_scan_args(argc, argv, "01", &flags);
1409
1495
 
1410
1496
  if (NIL_P(flags))
1411
- flags = INT2FIX(0);
1497
+ flags = INT2NUM(0);
1412
1498
 
1413
1499
  gen_call_void(virDomainSnapshotDelete, conn(s),
1414
1500
  domain_snapshot_get(s), NUM2UINT(flags));
@@ -1474,6 +1560,24 @@ static VALUE libvirt_dom_abort_job(VALUE d) {
1474
1560
 
1475
1561
  #endif
1476
1562
 
1563
+ struct create_sched_type_args {
1564
+ char *type;
1565
+ int nparams;
1566
+ };
1567
+
1568
+ static VALUE create_sched_type_array(VALUE input) {
1569
+ struct create_sched_type_args *args;
1570
+ VALUE result;
1571
+
1572
+ args = (struct create_sched_type_args *)input;
1573
+
1574
+ result = rb_ary_new();
1575
+ rb_ary_push(result, rb_str_new2(args->type));
1576
+ rb_ary_push(result, INT2NUM(args->nparams));
1577
+
1578
+ return result;
1579
+ }
1580
+
1477
1581
  /*
1478
1582
  * call-seq:
1479
1583
  * dom.scheduler_type -> [type, #params]
@@ -1486,107 +1590,166 @@ static VALUE libvirt_dom_scheduler_type(VALUE d) {
1486
1590
  char *type;
1487
1591
  VALUE result;
1488
1592
  int exception = 0;
1489
- struct rb_ary_push_arg args;
1593
+ struct create_sched_type_args args;
1490
1594
 
1491
1595
  type = virDomainGetSchedulerType(domain_get(d), &nparams);
1492
1596
 
1493
1597
  _E(type == NULL, create_error(e_RetrieveError, "virDomainGetSchedulerType",
1494
1598
  conn(d)));
1495
1599
 
1496
- result = rb_protect(rb_ary_new_wrap, (VALUE)NULL, &exception);
1600
+ args.type = type;
1601
+ args.nparams = nparams;
1602
+ result = rb_protect(create_sched_type_array, (VALUE)&args, &exception);
1497
1603
  if (exception) {
1498
1604
  free(type);
1499
1605
  rb_jump_tag(exception);
1500
1606
  }
1501
1607
 
1502
- args.arr = result;
1503
- args.value = rb_protect(rb_str_new2_wrap, (VALUE)&type, &exception);
1504
- if (exception) {
1505
- free(type);
1506
- rb_jump_tag(exception);
1507
- }
1508
- rb_protect(rb_ary_push_wrap, (VALUE)&args, &exception);
1509
- if (exception) {
1510
- free(type);
1511
- rb_jump_tag(exception);
1512
- }
1608
+ return result;
1609
+ }
1610
+
1611
+ #if HAVE_VIRDOMAINQEMUMONITORCOMMAND
1612
+ /*
1613
+ * call-seq:
1614
+ * dom.qemu_monitor_command(cmd, flags=0) -> string
1615
+ *
1616
+ * Call virDomainQemuMonitorCommand
1617
+ * to send a qemu command directly to the monitor. Note that this will only
1618
+ * work on qemu hypervisors, and the input and output formats are not
1619
+ * guaranteed to be stable. Also note that using this command can severly
1620
+ * impede libvirt's ability to manage the domain; use with caution!
1621
+ */
1622
+ static VALUE libvirt_dom_qemu_monitor_command(int argc, VALUE *argv, VALUE d) {
1623
+ VALUE cmd, flags;
1624
+ char *result;
1625
+ VALUE ret;
1626
+ int exception;
1627
+ virConnectPtr c;
1628
+ const char *type;
1629
+ int r;
1630
+
1631
+ rb_scan_args(argc, argv, "11", &cmd, &flags);
1632
+
1633
+ if (NIL_P(flags))
1634
+ flags = INT2NUM(0);
1635
+
1636
+ c = conn(d);
1637
+ type = virConnectGetType(c);
1638
+ _E(type == NULL, create_error(e_Error, "virConnectGetType", c));
1639
+ if (strcmp(type, "QEMU") != 0)
1640
+ rb_raise(rb_eTypeError,
1641
+ "Tried to use virDomainQemuMonitor command on %s connection",
1642
+ type);
1643
+
1644
+ r = virDomainQemuMonitorCommand(domain_get(d), StringValueCStr(cmd),
1645
+ &result, NUM2UINT(flags));
1646
+ _E(r < 0, create_error(e_RetrieveError, "virDomainQemuMonitorCommand", c));
1513
1647
 
1514
- args.arr = result;
1515
- args.value = INT2FIX(nparams);
1516
- rb_protect(rb_ary_push_wrap, (VALUE)&args, &exception);
1517
- free(type);
1648
+ ret = rb_protect(rb_str_new2_wrap, (VALUE)&result, &exception);
1649
+ free(result);
1518
1650
  if (exception)
1519
1651
  rb_jump_tag(exception);
1520
1652
 
1521
- return result;
1653
+ return ret;
1522
1654
  }
1655
+ #endif
1523
1656
 
1657
+ #if HAVE_VIRDOMAINISUPDATED
1524
1658
  /*
1525
1659
  * call-seq:
1526
- * dom.scheduler_parameters -> Hash
1527
- *
1528
- * Call +virDomainGetSchedulerParameters+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetSchedulerParameters]
1529
- * to retrieve all of the scheduler parameters for this domain. The keys and
1530
- * values in the hash that is returned are hypervisor specific.
1660
+ * dom.updated? -> [True|False]
1661
+ * Call +virDomainIsUpdated+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainIsUpdated]
1662
+ * to determine whether the definition for this domain has been updated.
1531
1663
  */
1532
- static VALUE libvirt_dom_scheduler_parameters(VALUE d) {
1664
+ static VALUE libvirt_dom_is_updated(VALUE d) {
1665
+ gen_call_truefalse(virDomainIsUpdated, conn(d), domain_get(d));
1666
+ }
1667
+ #endif
1668
+
1669
+ struct field_to_value {
1670
+ VALUE result;
1671
+ virTypedParameterPtr param;
1672
+ };
1673
+
1674
+ static VALUE typed_field_to_value(VALUE input) {
1675
+ struct field_to_value *ftv = (struct field_to_value *)input;
1676
+ VALUE val;
1677
+
1678
+ switch(ftv->param->type) {
1679
+ case VIR_TYPED_PARAM_INT:
1680
+ val = INT2NUM(ftv->param->value.i);
1681
+ break;
1682
+ case VIR_TYPED_PARAM_UINT:
1683
+ val = UINT2NUM(ftv->param->value.ui);
1684
+ break;
1685
+ case VIR_TYPED_PARAM_LLONG:
1686
+ val = LL2NUM(ftv->param->value.l);
1687
+ break;
1688
+ case VIR_TYPED_PARAM_ULLONG:
1689
+ val = ULL2NUM(ftv->param->value.ul);
1690
+ break;
1691
+ case VIR_TYPED_PARAM_DOUBLE:
1692
+ val = rb_float_new(ftv->param->value.d);
1693
+ break;
1694
+ case VIR_TYPED_PARAM_BOOLEAN:
1695
+ val = (ftv->param->value.b == 0) ? Qfalse : Qtrue;
1696
+ break;
1697
+ default:
1698
+ rb_raise(rb_eArgError, "Invalid parameter type");
1699
+ }
1700
+
1701
+ rb_hash_aset(ftv->result, rb_str_new2(ftv->param->field), val);
1702
+
1703
+ return Qnil;
1704
+ }
1705
+
1706
+ static VALUE internal_get_parameters(int argc, VALUE *argv, VALUE d,
1707
+ int (*nparams_cb)(VALUE d,
1708
+ unsigned int flags),
1709
+ char *(*get_cb)(VALUE d,
1710
+ unsigned int flags,
1711
+ virTypedParameterPtr params,
1712
+ int *nparams)) {
1533
1713
  int nparams;
1534
- char *type;
1535
- virSchedParameterPtr params;
1714
+ virTypedParameterPtr params;
1536
1715
  VALUE result;
1537
- virDomainPtr dom;
1538
- int r;
1539
1716
  int i;
1540
- VALUE val;
1717
+ int exception;
1718
+ char *errname;
1719
+ struct field_to_value ftv;
1720
+ unsigned int flags;
1721
+ VALUE flags_val;
1541
1722
 
1542
- dom = domain_get(d);
1723
+ rb_scan_args(argc, argv, "01", &flags_val);
1543
1724
 
1544
- type = virDomainGetSchedulerType(dom, &nparams);
1725
+ if (NIL_P(flags_val))
1726
+ flags = 0;
1727
+ else
1728
+ flags = NUM2UINT(flags_val);
1545
1729
 
1546
- _E(type == NULL, create_error(e_RetrieveError, "virDomainGetSchedulerType",
1547
- conn(d)));
1730
+ nparams = nparams_cb(d, flags);
1548
1731
 
1549
- xfree(type);
1732
+ result = rb_hash_new();
1550
1733
 
1551
- params = ALLOC_N(virSchedParameter, nparams);
1734
+ if (nparams == 0)
1735
+ return result;
1552
1736
 
1553
- r = virDomainGetSchedulerParameters(dom, params, &nparams);
1554
- if (r < 0) {
1737
+ params = ALLOC_N(virTypedParameter, nparams);
1738
+
1739
+ errname = get_cb(d, flags, params, &nparams);
1740
+ if (errname != NULL) {
1555
1741
  xfree(params);
1556
- rb_exc_raise(create_error(e_RetrieveError,
1557
- "virDomainGetSchedulerParameters", conn(d)));
1742
+ rb_exc_raise(create_error(e_RetrieveError, errname, conn(d)));
1558
1743
  }
1559
1744
 
1560
- /* just to shut the compiler up */
1561
- val = Qnil;
1562
-
1563
- result = rb_hash_new();
1564
1745
  for (i = 0; i < nparams; i++) {
1565
- switch(params[i].type) {
1566
- case VIR_DOMAIN_SCHED_FIELD_INT:
1567
- val = INT2FIX(params[i].value.i);
1568
- break;
1569
- case VIR_DOMAIN_SCHED_FIELD_UINT:
1570
- val = UINT2NUM(params[i].value.ui);
1571
- break;
1572
- case VIR_DOMAIN_SCHED_FIELD_LLONG:
1573
- val = LL2NUM(params[i].value.l);
1574
- break;
1575
- case VIR_DOMAIN_SCHED_FIELD_ULLONG:
1576
- val = ULL2NUM(params[i].value.ul);
1577
- break;
1578
- case VIR_DOMAIN_SCHED_FIELD_DOUBLE:
1579
- val = rb_float_new(params[i].value.d);
1580
- break;
1581
- case VIR_DOMAIN_SCHED_FIELD_BOOLEAN:
1582
- val = (params[i].value.b == 0) ? Qfalse : Qtrue;
1583
- break;
1584
- default:
1746
+ ftv.result = result;
1747
+ ftv.param = &params[i];
1748
+ rb_protect(typed_field_to_value, (VALUE)&ftv, &exception);
1749
+ if (exception) {
1585
1750
  xfree(params);
1586
- rb_raise(rb_eArgError, "Invalid parameter type");
1751
+ rb_jump_tag(exception);
1587
1752
  }
1588
-
1589
- rb_hash_aset(result, rb_str_new2(params[i].field), val);
1590
1753
  }
1591
1754
 
1592
1755
  xfree(params);
@@ -1594,76 +1757,121 @@ static VALUE libvirt_dom_scheduler_parameters(VALUE d) {
1594
1757
  return result;
1595
1758
  }
1596
1759
 
1597
- /*
1598
- * call-seq:
1599
- * dom.scheduler_parameters = Hash
1600
- *
1601
- * Call +virDomainSetSchedulerParameters+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSetSchedulerParameters]
1602
- * to set the scheduler parameters for this domain. The keys and values in
1603
- * the input hash are hypervisor specific.
1604
- */
1605
- static VALUE libvirt_dom_scheduler_parameters_set(VALUE d, VALUE input) {
1760
+ struct value_to_field {
1761
+ virTypedParameterPtr param;
1762
+ VALUE input;
1763
+ };
1764
+
1765
+ static VALUE typed_value_to_field(VALUE in) {
1766
+ struct value_to_field *vtf = (struct value_to_field *)in;
1767
+ VALUE val;
1768
+
1769
+ val = rb_hash_aref(vtf->input, rb_str_new2(vtf->param->field));
1770
+ if (NIL_P(val))
1771
+ return Qnil;
1772
+
1773
+ switch(vtf->param->type) {
1774
+ case VIR_TYPED_PARAM_INT:
1775
+ vtf->param->value.i = NUM2INT(val);
1776
+ break;
1777
+ case VIR_TYPED_PARAM_UINT:
1778
+ vtf->param->value.ui = NUM2UINT(val);
1779
+ break;
1780
+ case VIR_TYPED_PARAM_LLONG:
1781
+ vtf->param->value.l = NUM2LL(val);
1782
+ break;
1783
+ case VIR_TYPED_PARAM_ULLONG:
1784
+ vtf->param->value.ul = NUM2ULL(val);
1785
+ break;
1786
+ case VIR_TYPED_PARAM_DOUBLE:
1787
+ vtf->param->value.d = NUM2DBL(val);
1788
+ break;
1789
+ case VIR_TYPED_PARAM_BOOLEAN:
1790
+ vtf->param->value.b = (val == Qtrue) ? 1 : 0;
1791
+ break;
1792
+ default:
1793
+ rb_raise(rb_eArgError, "Invalid parameter type");
1794
+ }
1795
+
1796
+ return Qnil;
1797
+ }
1798
+
1799
+ static VALUE internal_set_parameters(VALUE d, VALUE in,
1800
+ int (*nparams_cb)(VALUE d,
1801
+ unsigned int flags),
1802
+ char *(*get_cb)(VALUE d,
1803
+ unsigned int flags,
1804
+ virTypedParameterPtr params,
1805
+ int *nparams),
1806
+ char *(*set_cb)(VALUE d,
1807
+ unsigned int flags,
1808
+ virTypedParameterPtr params,
1809
+ int nparams)) {
1606
1810
  int nparams;
1607
- char *type;
1608
- virSchedParameterPtr params;
1609
- virDomainPtr dom;
1610
- int r;
1811
+ virTypedParameterPtr params;
1812
+ int exception;
1611
1813
  int i;
1612
- VALUE val;
1814
+ char *errname;
1815
+ struct value_to_field vtf;
1816
+ VALUE input;
1817
+ VALUE flags_val;
1818
+ unsigned int flags;
1819
+
1820
+ if (TYPE(in) == T_HASH) {
1821
+ input = in;
1822
+ flags_val = INT2NUM(0);
1823
+ }
1824
+ else if (TYPE(in) == T_ARRAY) {
1825
+ if (RARRAY_LEN(in) != 2)
1826
+ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)",
1827
+ RARRAY_LEN(in));
1828
+ input = rb_ary_entry(in, 0);
1829
+ flags_val = rb_ary_entry(in, 1);
1830
+ }
1831
+ else
1832
+ rb_raise(rb_eTypeError, "wrong argument type (expected Hash or Array)");
1613
1833
 
1614
1834
  Check_Type(input, T_HASH);
1615
1835
 
1616
- dom = domain_get(d);
1836
+ /* we do this up-front for proper argument error checking */
1837
+ flags = NUM2UINT(flags_val);
1617
1838
 
1618
- type = virDomainGetSchedulerType(dom, &nparams);
1839
+ if (RHASH_SIZE(input) == 0)
1840
+ return Qnil;
1619
1841
 
1620
- _E(type == NULL, create_error(e_RetrieveError, "virDomainGetSchedulerType",
1621
- conn(d)));
1842
+ /* Complicated. The below all stems from the fact that we have no way to
1843
+ * have no way to discover what type each parameter should be based on the
1844
+ * be based on the input. Instead, we ask libvirt to give us the current
1845
+ * us the current parameters and types, and then we replace the values with
1846
+ * the values with the new values. That way we find out what the old types
1847
+ * what the old types were, and if the new types don't match, libvirt will
1848
+ * throw an error.
1849
+ */
1622
1850
 
1623
- xfree(type);
1851
+ nparams = nparams_cb(d, flags);
1624
1852
 
1625
- params = ALLOC_N(virSchedParameter, nparams);
1853
+ params = ALLOC_N(virTypedParameter, nparams);
1626
1854
 
1627
- r = virDomainGetSchedulerParameters(dom, params, &nparams);
1628
- if (r < 0) {
1855
+ errname = get_cb(d, flags, params, &nparams);
1856
+ if (errname != NULL) {
1629
1857
  xfree(params);
1630
- rb_exc_raise(create_error(e_RetrieveError,
1631
- "virDomainGetSchedulerParameters", conn(d)));
1858
+ rb_exc_raise(create_error(e_RetrieveError, errname, conn(d)));
1632
1859
  }
1633
1860
 
1634
1861
  for (i = 0; i < nparams; i++) {
1635
- val = rb_hash_aref(input, rb_str_new2(params[i].field));
1636
-
1637
- switch(params[i].type) {
1638
- case VIR_DOMAIN_SCHED_FIELD_INT:
1639
- params[i].value.i = NUM2INT(val);
1640
- break;
1641
- case VIR_DOMAIN_SCHED_FIELD_UINT:
1642
- params[i].value.ui = NUM2UINT(val);
1643
- break;
1644
- case VIR_DOMAIN_SCHED_FIELD_LLONG:
1645
- params[i].value.l = NUM2LL(val);
1646
- break;
1647
- case VIR_DOMAIN_SCHED_FIELD_ULLONG:
1648
- params[i].value.ul = NUM2ULL(val);
1649
- break;
1650
- case VIR_DOMAIN_SCHED_FIELD_DOUBLE:
1651
- params[i].value.d = NUM2DBL(val);
1652
- break;
1653
- case VIR_DOMAIN_SCHED_FIELD_BOOLEAN:
1654
- params[i].value.b = (val == Qtrue) ? 1 : 0;
1655
- break;
1656
- default:
1862
+ vtf.param = &params[i];
1863
+ vtf.input = input;
1864
+ rb_protect(typed_value_to_field, (VALUE)&vtf, &exception);
1865
+ if (exception) {
1657
1866
  xfree(params);
1658
- rb_raise(rb_eArgError, "Invalid parameter type");
1867
+ rb_jump_tag(exception);
1659
1868
  }
1660
1869
  }
1661
1870
 
1662
- r = virDomainSetSchedulerParameters(dom, params, nparams);
1663
- if (r < 0) {
1871
+ errname = set_cb(d, flags, params, nparams);
1872
+ if (errname != NULL) {
1664
1873
  xfree(params);
1665
- rb_exc_raise(create_error(e_RetrieveError,
1666
- "virDomainSetSchedulerParameters", conn(d)));
1874
+ rb_exc_raise(create_error(e_RetrieveError, errname, conn(d)));
1667
1875
  }
1668
1876
 
1669
1877
  xfree(params);
@@ -1671,48 +1879,303 @@ static VALUE libvirt_dom_scheduler_parameters_set(VALUE d, VALUE input) {
1671
1879
  return Qnil;
1672
1880
  }
1673
1881
 
1674
- #if HAVE_VIRDOMAINQEMUMONITORCOMMAND
1882
+ static int scheduler_nparams(VALUE d, unsigned int flags) {
1883
+ int nparams;
1884
+ char *type;
1885
+
1886
+ type = virDomainGetSchedulerType(domain_get(d), &nparams);
1887
+ _E(type == NULL, create_error(e_RetrieveError, "virDomainGetSchedulerType",
1888
+ conn(d)));
1889
+ xfree(type);
1890
+
1891
+ return nparams;
1892
+ }
1893
+
1894
+ static char *scheduler_get(VALUE d, unsigned int flags,
1895
+ virTypedParameterPtr params, int *nparams) {
1896
+ #ifdef HAVE_TYPE_VIRTYPEDPARAMETERPTR
1897
+ if (virDomainGetSchedulerParametersFlags(domain_get(d), params, nparams,
1898
+ flags) < 0)
1899
+ return "virDomainGetSchedulerParameters";
1900
+ #else
1901
+ if (flags != 0)
1902
+ rb_raise(e_NoSupportError, "Non-zero flags not supported");
1903
+ if (virDomainGetSchedulerParameters(domain_get(d),
1904
+ (virSchedParameterPtr)params,
1905
+ nparams) < 0)
1906
+ return "virDomainGetSchedulerParameters";
1907
+ #endif
1908
+
1909
+ return NULL;
1910
+ }
1911
+
1912
+ static char *scheduler_set(VALUE d, unsigned int flags,
1913
+ virTypedParameterPtr params, int nparams) {
1914
+ #if HAVE_TYPE_VIRTYPEDPARAMETERPTR
1915
+ if (virDomainSetSchedulerParametersFlags(domain_get(d), params, nparams,
1916
+ flags) < 0)
1917
+ return "virDomainSetSchedulerParameters";
1918
+ #else
1919
+ if (flags != 0)
1920
+ rb_raise(e_NoSupportError, "Non-zero flags not supported");
1921
+ if (virDomainSetSchedulerParameters(domain_get(d),
1922
+ (virSchedParameterPtr)params,
1923
+ nparams) < 0)
1924
+ return "virDomainSetSchedulerParameters";
1925
+ #endif
1926
+
1927
+ return NULL;
1928
+ }
1929
+
1675
1930
  /*
1676
1931
  * call-seq:
1677
- * dom.qemu_monitor_command(cmd, flags=0) -> string
1932
+ * dom.scheduler_parameters(flags=0) -> Hash
1678
1933
  *
1679
- * Call virDomainQemuMonitorCommand
1680
- * to send a qemu command directly to the monitor. Note that this will only
1681
- * work on qemu hypervisors, and the input and output formats are not
1682
- * guaranteed to be stable. Also note that using this command can severly
1683
- * impede libvirt's ability to manage the domain; use with caution!
1934
+ * Call +virDomainGetSchedulerParameters+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetSchedulerParameters]
1935
+ * to retrieve all of the scheduler parameters for this domain. The keys and
1936
+ * values in the hash that is returned are hypervisor specific.
1684
1937
  */
1685
- static VALUE libvirt_dom_qemu_monitor_command(int argc, VALUE *argv, VALUE d) {
1686
- VALUE cmd, flags;
1687
- virDomainPtr dom;
1688
- char *result;
1689
- VALUE ret;
1690
- int exception;
1691
- virConnectPtr c;
1938
+ static VALUE libvirt_dom_get_scheduler_parameters(int argc, VALUE *argv,
1939
+ VALUE d) {
1940
+ return internal_get_parameters(argc, argv, d, scheduler_nparams,
1941
+ scheduler_get);
1942
+ }
1692
1943
 
1693
- rb_scan_args(argc, argv, "11", &cmd, &flags);
1944
+ /*
1945
+ * call-seq:
1946
+ * dom.scheduler_parameters = Hash,flags=0
1947
+ *
1948
+ * Call +virDomainSetSchedulerParameters+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSetSchedulerParameters]
1949
+ * to set the scheduler parameters for this domain. The keys and values in
1950
+ * the input hash are hypervisor specific. If an empty hash is given, no
1951
+ * changes are made (and no error is raised).
1952
+ */
1953
+ static VALUE libvirt_dom_set_scheduler_parameters(VALUE d, VALUE input) {
1954
+ return internal_set_parameters(d, input, scheduler_nparams, scheduler_get,
1955
+ scheduler_set);
1956
+ }
1957
+
1958
+ #if HAVE_VIRDOMAINSETMEMORYPARAMETERS
1959
+ static int memory_nparams(VALUE d, unsigned int flags) {
1960
+ int nparams = 0;
1961
+ int ret;
1962
+
1963
+ ret = virDomainGetMemoryParameters(domain_get(d), NULL, &nparams, flags);
1964
+ _E(ret < 0, create_error(e_RetrieveError, "virDomainGetMemoryParameters",
1965
+ conn(d)));
1966
+
1967
+ return nparams;
1968
+ }
1969
+
1970
+ static char *memory_get(VALUE d, unsigned int flags,
1971
+ virTypedParameterPtr params, int *nparams) {
1972
+ #ifdef HAVE_TYPE_VIRTYPEDPARAMETERPTR
1973
+ if (virDomainGetMemoryParameters(domain_get(d), params, nparams, flags) < 0)
1974
+ #else
1975
+ if (virDomainGetMemoryParameters(domain_get(d),
1976
+ (virMemoryParameterPtr)params, nparams,
1977
+ flags) < 0)
1978
+ #endif
1979
+ return "virDomainGetMemoryParameters";
1980
+
1981
+ return NULL;
1982
+ }
1983
+
1984
+ static char *memory_set(VALUE d, unsigned int flags,
1985
+ virTypedParameterPtr params, int nparams) {
1986
+ #ifdef HAVE_TYPE_VIRTYPEDPARAMETERPTR
1987
+ if (virDomainSetMemoryParameters(domain_get(d), params, nparams, flags) < 0)
1988
+ #else
1989
+ if (virDomainSetMemoryParameters(domain_get(d),
1990
+ (virMemoryParameterPtr)params, nparams,
1991
+ flags) < 0)
1992
+ #endif
1993
+ return "virDomainSetMemoryParameters";
1994
+
1995
+ return NULL;
1996
+ }
1997
+
1998
+ /*
1999
+ * call-seq:
2000
+ * dom.memory_parameters(flags=0) -> Hash
2001
+ *
2002
+ * Call +virDomainGetMemoryParameters+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetMemoryParameters]
2003
+ * to retrieve all of the memory parameters for this domain. The keys and
2004
+ * values in the hash that is returned are hypervisor specific.
2005
+ */
2006
+ static VALUE libvirt_dom_get_memory_parameters(int argc, VALUE *argv, VALUE d) {
2007
+ return internal_get_parameters(argc, argv, d, memory_nparams, memory_get);
2008
+ }
2009
+
2010
+ /*
2011
+ * call-seq:
2012
+ * dom.memory_parameters = Hash,flags=0
2013
+ *
2014
+ * Call +virDomainSetMemoryParameters+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSetMemoryParameters]
2015
+ * to set the memory parameters for this domain. The keys and values in
2016
+ * the input hash are hypervisor specific.
2017
+ */
2018
+ static VALUE libvirt_dom_set_memory_parameters(VALUE d, VALUE in) {
2019
+ return internal_set_parameters(d, in, memory_nparams, memory_get,
2020
+ memory_set);
2021
+ }
2022
+ #endif
2023
+
2024
+ #if HAVE_VIRDOMAINSETBLKIOPARAMETERS
2025
+ static int blkio_nparams(VALUE d, unsigned int flags) {
2026
+ int nparams = 0;
2027
+ int ret;
2028
+
2029
+ ret = virDomainGetBlkioParameters(domain_get(d), NULL, &nparams, flags);
2030
+ _E(ret < 0, create_error(e_RetrieveError, "virDomainGetBlkioParameters",
2031
+ conn(d)));
2032
+
2033
+ return nparams;
2034
+ }
2035
+
2036
+ static char *blkio_get(VALUE d, unsigned int flags, virTypedParameterPtr params,
2037
+ int *nparams) {
2038
+ #ifdef HAVE_TYPE_VIRTYPEDPARAMETERPTR
2039
+ if (virDomainGetBlkioParameters(domain_get(d), params, nparams, flags) < 0)
2040
+ #else
2041
+ if (virDomainGetBlkioParameters(domain_get(d),
2042
+ (virBlkioParameterPtr)params, nparams,
2043
+ flags) < 0)
2044
+ #endif
2045
+ return "virDomainGetBlkioParameters";
2046
+
2047
+ return NULL;
2048
+ }
2049
+
2050
+ static char *blkio_set(VALUE d, unsigned int flags, virTypedParameterPtr params,
2051
+ int nparams) {
2052
+ #ifdef HAVE_TYPE_VIRTYPEDPARAMETERPTR
2053
+ if (virDomainSetBlkioParameters(domain_get(d), params, nparams, flags) < 0)
2054
+ #else
2055
+ if (virDomainSetBlkioParameters(domain_get(d),
2056
+ (virBlkioParameterPtr)params, nparams,
2057
+ flags) < 0)
2058
+ #endif
2059
+ return "virDomainSetBlkioParameters";
2060
+
2061
+ return NULL;
2062
+ }
2063
+
2064
+ /*
2065
+ * call-seq:
2066
+ * dom.blkio_parameters(flags=0) -> Hash
2067
+ *
2068
+ * Call +virDomainGetBlkioParameters+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetBlkioParameters]
2069
+ * to retrieve all of the blkio parameters for this domain. The keys and
2070
+ * values in the hash that is returned are hypervisor specific.
2071
+ */
2072
+ static VALUE libvirt_dom_get_blkio_parameters(int argc, VALUE *argv, VALUE d) {
2073
+ return internal_get_parameters(argc, argv, d, blkio_nparams, blkio_get);
2074
+ }
2075
+
2076
+ /*
2077
+ * call-seq:
2078
+ * dom.memory_parameters = Hash,flags=0
2079
+ *
2080
+ * Call +virDomainSetBlkioParameters+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainSetBlkioParameters]
2081
+ * to set the blkio parameters for this domain. The keys and values in
2082
+ * the input hash are hypervisor specific.
2083
+ */
2084
+ static VALUE libvirt_dom_set_blkio_parameters(VALUE d, VALUE in) {
2085
+ return internal_set_parameters(d, in, blkio_nparams, blkio_get, blkio_set);
2086
+ }
2087
+ #endif
2088
+
2089
+ #if HAVE_VIRDOMAINGETSTATE
2090
+ /*
2091
+ * call-seq:
2092
+ * dom.state(flags=0) -> state, reason
2093
+ *
2094
+ * Call +virDomainGetState+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainGetState]
2095
+ * to get the current state of the domain.
2096
+ */
2097
+ static VALUE libvirt_dom_get_state(int argc, VALUE *argv, VALUE d) {
2098
+ VALUE flags;
2099
+ int state, reason;
2100
+ VALUE result;
2101
+ int retval;
2102
+
2103
+ rb_scan_args(argc, argv, "01", &flags);
1694
2104
 
1695
2105
  if (NIL_P(flags))
1696
- flags = INT2FIX(0);
2106
+ flags = INT2NUM(0);
1697
2107
 
1698
- c = conn(d);
1699
- type = virConnectGetType(c);
1700
- _E(type == NULL, create_error(e_Error, "virConnectGetType", c));
1701
- if (strcmp(type, "QEMU") != 0)
1702
- rb_raise(rb_TypeError, "Tried to use virDomainQemuMonitor command on %s connection", type);
2108
+ retval = virDomainGetState(domain_get(d), &state, &reason, NUM2INT(flags));
2109
+ _E(retval < 0, create_error(e_Error, "virDomainGetState", conn(d)));
1703
2110
 
1704
- dom = domain_get(d);
2111
+ result = rb_ary_new();
1705
2112
 
1706
- r = virDomainQemuMonitorCommand(dom, StringValueCStr(cmd), &result,
1707
- NUM2UINT(flags));
1708
- _E(r < 0, create_error(e_RetrieveError, "virDomainQemuMonitorCommand", c));
2113
+ rb_ary_push(result, INT2NUM(state));
2114
+ rb_ary_push(result, INT2NUM(reason));
1709
2115
 
1710
- ret = rb_protect(rb_str_new2_wrap, &result, &exception);
1711
- free(result);
1712
- if (exception)
1713
- rb_jump_tag(exception);
2116
+ return result;
2117
+ }
2118
+ #endif
1714
2119
 
1715
- return ret;
2120
+ #if HAVE_VIRDOMAINOPENCONSOLE
2121
+ /*
2122
+ * call-seq:
2123
+ * dom.open_console(device, stream, flags=0) -> nil
2124
+ *
2125
+ * Call +virDomainOpenConsole+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainOpenConsole]
2126
+ * to open up a console to device over stream.
2127
+ */
2128
+ static VALUE libvirt_dom_open_console(int argc, VALUE *argv, VALUE d) {
2129
+ VALUE dev, st, flags;
2130
+
2131
+ rb_scan_args(argc, argv, "21", &dev, &st, &flags);
2132
+
2133
+ if (NIL_P(flags))
2134
+ flags = INT2NUM(0);
2135
+
2136
+ gen_call_void(virDomainOpenConsole, conn(d), domain_get(d),
2137
+ StringValueCStr(dev), stream_get(st), NUM2INT(flags));
2138
+ }
2139
+ #endif
2140
+
2141
+ #if HAVE_VIRDOMAINSCREENSHOT
2142
+ /*
2143
+ * call-seq:
2144
+ * dom.screenshot(stream, screen, flags=0) -> nil
2145
+ *
2146
+ * Call +virDomainScreenshot+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainScreenshot]
2147
+ * to take a screenshot of the domain console as a stream.
2148
+ */
2149
+ static VALUE libvirt_dom_screenshot(int argc, VALUE *argv, VALUE d) {
2150
+ VALUE st, screen, flags;
2151
+
2152
+ rb_scan_args(argc, argv, "21", &st, &screen, &flags);
2153
+
2154
+ if (NIL_P(flags))
2155
+ flags = INT2NUM(0);
2156
+
2157
+ gen_call_string(virDomainScreenshot, conn(d), 1, domain_get(d),
2158
+ stream_get(st), NUM2UINT(screen), NUM2UINT(flags));
2159
+ }
2160
+ #endif
2161
+
2162
+ #if HAVE_VIRDOMAININJECTNMI
2163
+ /*
2164
+ * call-seq:
2165
+ * dom.inject_nmi(flags=0) -> nil
2166
+ *
2167
+ * Call +virDomainInjectNMI+[http://www.libvirt.org/html/libvirt-libvirt.html#virDomainInjectNMI]
2168
+ * to send an NMI to the guest.
2169
+ */
2170
+ static VALUE libvirt_dom_inject_nmi(int argc, VALUE *argv, VALUE d) {
2171
+ VALUE flags;
2172
+
2173
+ rb_scan_args(argc, argv, "01", &flags);
2174
+
2175
+ if (NIL_P(flags))
2176
+ flags = INT2NUM(0);
2177
+
2178
+ gen_call_void(virDomainInjectNMI, conn(d), domain_get(d), NUM2UINT(flags));
1716
2179
  }
1717
2180
  #endif
1718
2181
 
@@ -1803,6 +2266,14 @@ void init_domain()
1803
2266
  rb_define_method(c_domain, "migrate_set_max_downtime",
1804
2267
  libvirt_dom_migrate_set_max_downtime, -1);
1805
2268
  #endif
2269
+ #if HAVE_VIRDOMAINMIGRATE2
2270
+ rb_define_method(c_domain, "migrate2", libvirt_dom_migrate2, -1);
2271
+ rb_define_method(c_domain, "migrate_to_uri2",
2272
+ libvirt_dom_migrate_to_uri2, -1);
2273
+ rb_define_method(c_domain, "migrate_set_max_speed",
2274
+ libvirt_dom_migrate_set_max_speed, -1);
2275
+ #endif
2276
+
1806
2277
  rb_define_attr(c_domain, "connection", 1, 0);
1807
2278
  rb_define_method(c_domain, "shutdown", libvirt_dom_shutdown, 0);
1808
2279
  rb_define_method(c_domain, "reboot", libvirt_dom_reboot, -1);
@@ -1859,10 +2330,6 @@ void init_domain()
1859
2330
  #endif
1860
2331
 
1861
2332
  rb_define_method(c_domain, "scheduler_type", libvirt_dom_scheduler_type, 0);
1862
- rb_define_method(c_domain, "scheduler_parameters",
1863
- libvirt_dom_scheduler_parameters, 0);
1864
- rb_define_method(c_domain, "scheduler_parameters=",
1865
- libvirt_dom_scheduler_parameters_set, 1);
1866
2333
 
1867
2334
  #if HAVE_VIRDOMAINMANAGEDSAVE
1868
2335
  rb_define_method(c_domain, "managed_save", libvirt_dom_managed_save, -1);
@@ -2059,4 +2526,126 @@ void init_domain()
2059
2526
  #if HAVE_VIRDOMAINGETVCPUSFLAGS
2060
2527
  rb_define_method(c_domain, "num_vcpus", libvirt_dom_num_vcpus, 1);
2061
2528
  #endif
2529
+
2530
+ #if HAVE_VIRDOMAINISUPDATED
2531
+ rb_define_method(c_domain, "updated?", libvirt_dom_is_updated, 0);
2532
+ #endif
2533
+
2534
+ #ifdef VIR_DOMAIN_MEMORY_PARAM_UNLIMITED
2535
+ rb_define_const(c_domain, "MEMORY_PARAM_UNLIMITED",
2536
+ VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
2537
+ #endif
2538
+
2539
+ #if HAVE_VIRDOMAINSETMEMORYFLAGS
2540
+ rb_define_const(c_domain, "DOMAIN_MEM_LIVE", INT2NUM(VIR_DOMAIN_MEM_LIVE));
2541
+ rb_define_const(c_domain, "DOMAIN_MEM_CONFIG",
2542
+ INT2NUM(VIR_DOMAIN_MEM_CONFIG));
2543
+ #endif
2544
+ #if HAVE_CONST_VIR_DOMAIN_MEM_CURRENT
2545
+ rb_define_const(c_domain, "DOMAIN_MEM_CURRENT",
2546
+ INT2NUM(VIR_DOMAIN_MEM_CURRENT));
2547
+ rb_define_const(c_domain, "DOMAIN_MEM_MAXIMUM",
2548
+ INT2NUM(VIR_DOMAIN_MEM_MAXIMUM));
2549
+ #endif
2550
+
2551
+ rb_define_method(c_domain, "scheduler_parameters",
2552
+ libvirt_dom_get_scheduler_parameters, -1);
2553
+ rb_define_method(c_domain, "scheduler_parameters=",
2554
+ libvirt_dom_set_scheduler_parameters, 1);
2555
+
2556
+ #if HAVE_VIRDOMAINSETMEMORYPARAMETERS
2557
+ rb_define_method(c_domain, "memory_parameters",
2558
+ libvirt_dom_get_memory_parameters, -1);
2559
+ rb_define_method(c_domain, "memory_parameters=",
2560
+ libvirt_dom_set_memory_parameters, 1);
2561
+ #endif
2562
+
2563
+ #if HAVE_VIRDOMAINSETBLKIOPARAMETERS
2564
+ rb_define_method(c_domain, "blkio_parameters",
2565
+ libvirt_dom_get_blkio_parameters, -1);
2566
+ rb_define_method(c_domain, "blkio_parameters=",
2567
+ libvirt_dom_set_blkio_parameters, 1);
2568
+ #endif
2569
+
2570
+ #if HAVE_VIRDOMAINGETSTATE
2571
+ rb_define_const(c_domain, "DOMAIN_RUNNING_UNKNOWN",
2572
+ INT2NUM(VIR_DOMAIN_RUNNING_UNKNOWN));
2573
+ rb_define_const(c_domain, "DOMAIN_RUNNING_BOOTED",
2574
+ INT2NUM(VIR_DOMAIN_RUNNING_BOOTED));
2575
+ rb_define_const(c_domain, "DOMAIN_RUNNING_MIGRATED",
2576
+ INT2NUM(VIR_DOMAIN_RUNNING_MIGRATED));
2577
+ rb_define_const(c_domain, "DOMAIN_RUNNING_RESTORED",
2578
+ INT2NUM(VIR_DOMAIN_RUNNING_RESTORED));
2579
+ rb_define_const(c_domain, "DOMAIN_RUNNING_FROM_SNAPSHOT",
2580
+ INT2NUM(VIR_DOMAIN_RUNNING_FROM_SNAPSHOT));
2581
+ rb_define_const(c_domain, "DOMAIN_RUNNING_UNPAUSED",
2582
+ INT2NUM(VIR_DOMAIN_RUNNING_UNPAUSED));
2583
+ rb_define_const(c_domain, "DOMAIN_RUNNING_MIGRATION_CANCELED",
2584
+ INT2NUM(VIR_DOMAIN_RUNNING_MIGRATION_CANCELED));
2585
+ rb_define_const(c_domain, "DOMAIN_RUNNING_SAVE_CANCELED",
2586
+ INT2NUM(VIR_DOMAIN_RUNNING_SAVE_CANCELED));
2587
+ rb_define_const(c_domain, "DOMAIN_BLOCKED_UNKNOWN",
2588
+ INT2NUM(VIR_DOMAIN_BLOCKED_UNKNOWN));
2589
+ rb_define_const(c_domain, "DOMAIN_PAUSED_UNKNOWN",
2590
+ INT2NUM(VIR_DOMAIN_PAUSED_UNKNOWN));
2591
+ rb_define_const(c_domain, "DOMAIN_PAUSED_USER",
2592
+ INT2NUM(VIR_DOMAIN_PAUSED_USER));
2593
+ rb_define_const(c_domain, "DOMAIN_PAUSED_MIGRATION",
2594
+ INT2NUM(VIR_DOMAIN_PAUSED_MIGRATION));
2595
+ rb_define_const(c_domain, "DOMAIN_PAUSED_SAVE",
2596
+ INT2NUM(VIR_DOMAIN_PAUSED_SAVE));
2597
+ rb_define_const(c_domain, "DOMAIN_PAUSED_DUMP",
2598
+ INT2NUM(VIR_DOMAIN_PAUSED_DUMP));
2599
+ rb_define_const(c_domain, "DOMAIN_PAUSED_IOERROR",
2600
+ INT2NUM(VIR_DOMAIN_PAUSED_IOERROR));
2601
+ rb_define_const(c_domain, "DOMAIN_PAUSED_WATCHDOG",
2602
+ INT2NUM(VIR_DOMAIN_PAUSED_WATCHDOG));
2603
+ rb_define_const(c_domain, "DOMAIN_PAUSED_FROM_SNAPSHOT",
2604
+ INT2NUM(VIR_DOMAIN_PAUSED_FROM_SNAPSHOT));
2605
+ rb_define_const(c_domain, "DOMAIN_SHUTDOWN_UNKNOWN",
2606
+ INT2NUM(VIR_DOMAIN_SHUTDOWN_UNKNOWN));
2607
+ rb_define_const(c_domain, "DOMAIN_SHUTDOWN_USER",
2608
+ INT2NUM(VIR_DOMAIN_SHUTDOWN_USER));
2609
+ rb_define_const(c_domain, "DOMAIN_SHUTOFF_UNKNOWN",
2610
+ INT2NUM(VIR_DOMAIN_SHUTOFF_UNKNOWN));
2611
+ rb_define_const(c_domain, "DOMAIN_SHUTOFF_SHUTDOWN",
2612
+ INT2NUM(VIR_DOMAIN_SHUTOFF_SHUTDOWN));
2613
+ rb_define_const(c_domain, "DOMAIN_SHUTOFF_DESTROYED",
2614
+ INT2NUM(VIR_DOMAIN_SHUTOFF_DESTROYED));
2615
+ rb_define_const(c_domain, "DOMAIN_SHUTOFF_CRASHED",
2616
+ INT2NUM(VIR_DOMAIN_SHUTOFF_CRASHED));
2617
+ rb_define_const(c_domain, "DOMAIN_SHUTOFF_MIGRATED",
2618
+ INT2NUM(VIR_DOMAIN_SHUTOFF_MIGRATED));
2619
+ rb_define_const(c_domain, "DOMAIN_SHUTOFF_SAVED",
2620
+ INT2NUM(VIR_DOMAIN_SHUTOFF_SAVED));
2621
+ rb_define_const(c_domain, "DOMAIN_SHUTOFF_FAILED",
2622
+ INT2NUM(VIR_DOMAIN_SHUTOFF_FAILED));
2623
+ rb_define_const(c_domain, "DOMAIN_SHUTOFF_FROM_SNAPSHOT",
2624
+ INT2NUM(VIR_DOMAIN_SHUTOFF_FROM_SNAPSHOT));
2625
+ rb_define_const(c_domain, "DOMAIN_CRASHED_UNKNOWN",
2626
+ INT2NUM(VIR_DOMAIN_CRASHED_UNKNOWN));
2627
+
2628
+ rb_define_method(c_domain, "state", libvirt_dom_get_state, -1);
2629
+ #endif
2630
+
2631
+ #if HAVE_CONST_VIR_DOMAIN_AFFECT_CURRENT
2632
+ rb_define_const(c_domain, "DOMAIN_AFFECT_CURRENT",
2633
+ INT2NUM(VIR_DOMAIN_AFFECT_CURRENT));
2634
+ rb_define_const(c_domain, "DOMAIN_AFFECT_LIVE",
2635
+ INT2NUM(VIR_DOMAIN_AFFECT_LIVE));
2636
+ rb_define_const(c_domain, "DOMAIN_AFFECT_CONFIG",
2637
+ INT2NUM(VIR_DOMAIN_AFFECT_CONFIG));
2638
+ #endif
2639
+
2640
+ #if HAVE_VIRDOMAINOPENCONSOLE
2641
+ rb_define_method(c_domain, "open_console", libvirt_dom_open_console, -1);
2642
+ #endif
2643
+
2644
+ #if HAVE_VIRDOMAINSCREENSHOT
2645
+ rb_define_method(c_domain, "screenshot", libvirt_dom_screenshot, -1);
2646
+ #endif
2647
+
2648
+ #if HAVE_VIRDOMAININJECTNMI
2649
+ rb_define_method(c_domain, "inject_nmi", libvirt_dom_inject_nmi, -1);
2650
+ #endif
2062
2651
  }