libvirt_ffi 0.5.6 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,8 +9,6 @@ module Libvirt
9
9
  extend Helpers
10
10
  ffi_lib Util.library_path
11
11
 
12
- UUID_STRING_BUFLEN = 0x80 # RFC4122
13
-
14
12
  EVENT_ID_TO_CALLBACK = {
15
13
  LIFECYCLE: :virConnectDomainEventCallback,
16
14
  REBOOT: :virConnectDomainEventGenericCallback,
@@ -292,17 +290,17 @@ module Libvirt
292
290
  :MIGRATABLE, 0x8 # dump XML suitable for migration
293
291
  ]
294
292
 
295
- # int virDomainFree (
293
+ # int virDomainFree (
296
294
  # virDomainPtr domain
297
295
  # )
298
296
  attach_function :virDomainFree, [:pointer], :int
299
297
 
300
- # int virDomainRef (
298
+ # int virDomainRef (
301
299
  # virDomainPtr domain
302
300
  # )
303
301
  attach_function :virDomainRef, [:pointer], :int
304
302
 
305
- # int virConnectDomainEventRegisterAny(
303
+ # int virConnectDomainEventRegisterAny(
306
304
  # virConnectPtr conn,
307
305
  # virDomainPtr dom,
308
306
  # int eventID,
@@ -319,20 +317,20 @@ module Libvirt
319
317
  :pointer
320
318
  ], :int
321
319
 
322
- # int virConnectDomainEventDeregisterAny (
320
+ # int virConnectDomainEventDeregisterAny (
323
321
  # virConnectPtr conn,
324
322
  # int callbackID
325
323
  # )
326
324
  attach_function :virConnectDomainEventDeregisterAny, [:pointer, :int], :int
327
325
 
328
- # int virConnectListAllDomains (
326
+ # int virConnectListAllDomains (
329
327
  # virConnectPtr conn,
330
328
  # virDomainPtr **domains,
331
329
  # unsigned int flags
332
330
  # )
333
331
  attach_function :virConnectListAllDomains, [:pointer, :pointer, :uint], :int
334
332
 
335
- # int virDomainGetState (
333
+ # int virDomainGetState (
336
334
  # virDomainPtr domain,
337
335
  # int *state,
338
336
  # int *reason,
@@ -345,12 +343,12 @@ module Libvirt
345
343
  # )
346
344
  attach_function :virDomainGetName, [:pointer], :string
347
345
 
348
- # int virDomainGetMaxVcpus (
346
+ # int virDomainGetMaxVcpus (
349
347
  # virDomainPtr domain
350
348
  # )
351
349
  attach_function :virDomainGetMaxVcpus, [:pointer], :int
352
350
 
353
- # int virDomainGetVcpus (
351
+ # int virDomainGetVcpus (
354
352
  # virDomainPtr domain,
355
353
  # virVcpuInfoPtr info,
356
354
  # int maxinfo,
@@ -359,18 +357,18 @@ module Libvirt
359
357
  # )
360
358
  attach_function :virDomainGetVcpus, [:pointer, :pointer, :int, :pointer, :int], :int
361
359
 
362
- # int virDomainGetUUIDString (
360
+ # int virDomainGetUUIDString (
363
361
  # virDomainPtr domain,
364
362
  # char * buf
365
363
  # )
366
364
  attach_function :virDomainGetUUIDString, [:pointer, :pointer], :int
367
365
 
368
- # unsigned long virDomainGetMaxMemory (
366
+ # unsigned long virDomainGetMaxMemory (
369
367
  # virDomainPtr domain
370
368
  # )
371
369
  attach_function :virDomainGetMaxMemory, [:pointer], :ulong
372
370
 
373
- # char *virDomainGetXMLDesc (
371
+ # char *virDomainGetXMLDesc (
374
372
  # virDomainPtr domain,
375
373
  # unsigned int flags
376
374
  # )
@@ -384,7 +382,7 @@ module Libvirt
384
382
  # )
385
383
  attach_function :virDomainScreenshot, [:pointer, :pointer, :uint, :uint], :strptr
386
384
 
387
- # typedef int (*virConnectDomainEventCallback) (
385
+ # typedef int (*virConnectDomainEventCallback) (
388
386
  # virConnectPtr conn,
389
387
  # virDomainPtr dom,
390
388
  # int event,
@@ -413,7 +411,7 @@ module Libvirt
413
411
  :pointer
414
412
  ], :void
415
413
 
416
- # typedef void (*virConnectDomainEventWatchdogCallback) (
414
+ # typedef void (*virConnectDomainEventWatchdogCallback) (
417
415
  # virConnectPtr conn,
418
416
  # virDomainPtr dom,
419
417
  # int action,
@@ -443,7 +441,7 @@ module Libvirt
443
441
  :pointer
444
442
  ], :void
445
443
 
446
- # typedef void (*virConnectDomainEventGraphicsCallback) (
444
+ # typedef void (*virConnectDomainEventGraphicsCallback) (
447
445
  # virConnectPtr conn,
448
446
  # virDomainPtr dom,
449
447
  # int phase,
@@ -464,7 +462,7 @@ module Libvirt
464
462
  :pointer
465
463
  ], :void
466
464
 
467
- # typedef void (*virConnectDomainEventIOErrorReasonCallback) (
465
+ # typedef void (*virConnectDomainEventIOErrorReasonCallback) (
468
466
  # virConnectPtr conn,
469
467
  # virDomainPtr dom,
470
468
  # const char * srcPath,
@@ -483,7 +481,7 @@ module Libvirt
483
481
  :pointer
484
482
  ], :void
485
483
 
486
- # typedef void (*virConnectDomainEventBlockJobCallback) (
484
+ # typedef void (*virConnectDomainEventBlockJobCallback) (
487
485
  # virConnectPtr conn,
488
486
  # virDomainPtr dom,
489
487
  # const char * disk,
@@ -500,7 +498,7 @@ module Libvirt
500
498
  :pointer
501
499
  ], :void
502
500
 
503
- # typedef void (*virConnectDomainEventDiskChangeCallback) (
501
+ # typedef void (*virConnectDomainEventDiskChangeCallback) (
504
502
  # virConnectPtr conn,
505
503
  # virDomainPtr dom,
506
504
  # const char * oldSrcPath,
@@ -519,7 +517,7 @@ module Libvirt
519
517
  :pointer
520
518
  ], :void
521
519
 
522
- # typedef void (*virConnectDomainEventTrayChangeCallback) (
520
+ # typedef void (*virConnectDomainEventTrayChangeCallback) (
523
521
  # virConnectPtr conn,
524
522
  # virDomainPtr dom,
525
523
  # const char * devAlias,
@@ -534,7 +532,7 @@ module Libvirt
534
532
  :pointer
535
533
  ], :void
536
534
 
537
- # typedef void (*virConnectDomainEventPMWakeupCallback) (
535
+ # typedef void (*virConnectDomainEventPMWakeupCallback) (
538
536
  # virConnectPtr conn,
539
537
  # virDomainPtr dom,
540
538
  # int reason,
@@ -547,7 +545,7 @@ module Libvirt
547
545
  :pointer
548
546
  ], :void
549
547
 
550
- # typedef void (*virConnectDomainEventPMSuspendCallback) (
548
+ # typedef void (*virConnectDomainEventPMSuspendCallback) (
551
549
  # virConnectPtr conn,
552
550
  # virDomainPtr dom,
553
551
  # int reason,
@@ -560,7 +558,7 @@ module Libvirt
560
558
  :pointer
561
559
  ], :void
562
560
 
563
- # typedef void (*virConnectDomainEventBalloonChangeCallback) (
561
+ # typedef void (*virConnectDomainEventBalloonChangeCallback) (
564
562
  # virConnectPtr conn,
565
563
  # virDomainPtr dom,
566
564
  # unsigned long long actual,
@@ -573,7 +571,7 @@ module Libvirt
573
571
  :pointer
574
572
  ], :void
575
573
 
576
- # typedef void (*virConnectDomainEventPMSuspendDiskCallback) (
574
+ # typedef void (*virConnectDomainEventPMSuspendDiskCallback) (
577
575
  # virConnectPtr conn,
578
576
  # virDomainPtr dom,
579
577
  # int reason,
@@ -586,7 +584,7 @@ module Libvirt
586
584
  :pointer
587
585
  ], :void
588
586
 
589
- # typedef void (*virConnectDomainEventDeviceRemovedCallback) (
587
+ # typedef void (*virConnectDomainEventDeviceRemovedCallback) (
590
588
  # virConnectPtr conn,
591
589
  # virDomainPtr dom,
592
590
  # const char * devAlias,
@@ -599,7 +597,7 @@ module Libvirt
599
597
  :pointer
600
598
  ], :void
601
599
 
602
- # typedef void (*virConnectDomainEventTunableCallback) (
600
+ # typedef void (*virConnectDomainEventTunableCallback) (
603
601
  # virConnectPtr conn,
604
602
  # virDomainPtr dom,
605
603
  # virTypedParameterPtr params,
@@ -614,7 +612,7 @@ module Libvirt
614
612
  :pointer
615
613
  ], :void
616
614
 
617
- # typedef void (*virConnectDomainEventAgentLifecycleCallback) (
615
+ # typedef void (*virConnectDomainEventAgentLifecycleCallback) (
618
616
  # virConnectPtr conn,
619
617
  # virDomainPtr dom,
620
618
  # int state,
@@ -629,7 +627,7 @@ module Libvirt
629
627
  :pointer
630
628
  ], :void
631
629
 
632
- # typedef void (*virConnectDomainEventDeviceAddedCallback) (
630
+ # typedef void (*virConnectDomainEventDeviceAddedCallback) (
633
631
  # virConnectPtr conn,
634
632
  # virDomainPtr dom,
635
633
  # const char * devAlias,
@@ -642,7 +640,7 @@ module Libvirt
642
640
  :pointer
643
641
  ], :void
644
642
 
645
- # typedef void (*virConnectDomainEventMigrationIterationCallback) (
643
+ # typedef void (*virConnectDomainEventMigrationIterationCallback) (
646
644
  # virConnectPtr conn,
647
645
  # virDomainPtr dom,
648
646
  # int iteration,
@@ -655,7 +653,7 @@ module Libvirt
655
653
  :pointer
656
654
  ], :void
657
655
 
658
- # typedef void (*virConnectDomainEventJobCompletedCallback) (
656
+ # typedef void (*virConnectDomainEventJobCompletedCallback) (
659
657
  # virConnectPtr conn,
660
658
  # virDomainPtr dom,
661
659
  # virTypedParameterPtr params,
@@ -670,7 +668,7 @@ module Libvirt
670
668
  :pointer
671
669
  ], :void
672
670
 
673
- # typedef void (*virConnectDomainEventDeviceRemovalFailedCallback) (
671
+ # typedef void (*virConnectDomainEventDeviceRemovalFailedCallback) (
674
672
  # virConnectPtr conn,
675
673
  # virDomainPtr dom,
676
674
  # const char * devAlias,
@@ -683,7 +681,7 @@ module Libvirt
683
681
  :pointer
684
682
  ], :void
685
683
 
686
- # typedef void (*virConnectDomainEventMetadataChangeCallback) (
684
+ # typedef void (*virConnectDomainEventMetadataChangeCallback) (
687
685
  # virConnectPtr conn,
688
686
  # virDomainPtr dom,
689
687
  # int type,
@@ -698,7 +696,7 @@ module Libvirt
698
696
  :pointer
699
697
  ], :void
700
698
 
701
- # typedef void (*virConnectDomainEventBlockThresholdCallback) (
699
+ # typedef void (*virConnectDomainEventBlockThresholdCallback) (
702
700
  # virConnectPtr conn,
703
701
  # virDomainPtr dom,
704
702
  # const char * dev,
@@ -717,53 +715,53 @@ module Libvirt
717
715
  :pointer
718
716
  ], :void
719
717
 
720
- # int virDomainReboot (
718
+ # int virDomainReboot (
721
719
  # virDomainPtr domain,
722
720
  # unsigned int flags
723
721
  # )
724
722
  attach_function :virDomainReboot, [:pointer, :uint], :int
725
723
 
726
- # int virDomainShutdownFlags (
724
+ # int virDomainShutdownFlags (
727
725
  # virDomainPtr domain,
728
726
  # unsigned int flags
729
727
  # )
730
728
  attach_function :virDomainShutdownFlags, [:pointer, :shutdown_flags], :int
731
729
 
732
- # int virDomainDestroyFlags (
730
+ # int virDomainDestroyFlags (
733
731
  # virDomainPtr domain,
734
732
  # unsigned int flags
735
733
  # )
736
734
  attach_function :virDomainDestroyFlags, [:pointer, :uint], :int
737
735
 
738
- # int virDomainReset (
736
+ # int virDomainReset (
739
737
  # virDomainPtr domain,
740
738
  # unsigned int flags
741
739
  # )
742
740
  attach_function :virDomainReset, [:pointer, :uint], :int
743
741
 
744
- # int virDomainSuspend (
742
+ # int virDomainSuspend (
745
743
  # virDomainPtr domain
746
744
  # )
747
745
  attach_function :virDomainSuspend, [:pointer], :int
748
746
 
749
- # int virDomainResume (
747
+ # int virDomainResume (
750
748
  # virDomainPtr domain
751
749
  # )
752
750
  attach_function :virDomainResume, [:pointer], :int
753
751
 
754
- # int virDomainCreateWithFlags (
752
+ # int virDomainCreateWithFlags (
755
753
  # virDomainPtr domain,
756
754
  # unsigned int flags
757
755
  # )
758
756
  attach_function :virDomainCreateWithFlags, [:pointer, :uint], :int
759
757
 
760
- # int virDomainManagedSave (
758
+ # int virDomainManagedSave (
761
759
  # virDomainPtr dom,
762
760
  # unsigned int flags
763
761
  # )
764
762
  attach_function :virDomainManagedSave, [:pointer, :save_restore_flags], :int
765
763
 
766
- # int virDomainUndefineFlags (
764
+ # int virDomainUndefineFlags (
767
765
  # virDomainPtr domain,
768
766
  # unsigned int flags
769
767
  # )
@@ -776,7 +774,7 @@ module Libvirt
776
774
  # )
777
775
  attach_function :virDomainDefineXMLFlags, [:pointer, :string, :uint], :pointer
778
776
 
779
- # int virDomainSetMetadata (
777
+ # int virDomainSetMetadata (
780
778
  # virDomainPtr domain,
781
779
  # int type,
782
780
  # const char * metadata,
@@ -803,6 +801,18 @@ module Libvirt
803
801
  # )
804
802
  attach_function :virDomainIsPersistent, [:pointer], :int
805
803
 
804
+ # int virDomainGetAutostart (
805
+ # virDomainPtr domain,
806
+ # int * autostart
807
+ # )
808
+ attach_function :virDomainGetAutostart, [:pointer, :pointer], :int
809
+
810
+ # int virDomainSetAutostart (
811
+ # virDomainPtr domain,
812
+ # int autostart
813
+ # )
814
+ attach_function :virDomainSetAutostart, [:pointer, :int], :int
815
+
806
816
  # Converts detail from lifecycle callback from integer to symbol name.
807
817
  # @param event [Symbol] enum :event_type (virDomainEventType)
808
818
  # @param detail [Integer]
@@ -812,6 +822,10 @@ module Libvirt
812
822
  detail_enum[detail]
813
823
  end
814
824
 
825
+ # Converts state reason of domain from integer to symbol name.
826
+ # @param state [Symbol] enum :state (virDomainState)
827
+ # @param reason [Integer]
828
+ # @return [Symbol]
815
829
  def self.state_reason(state, reason)
816
830
  reason_enum = enum_type(:"#{state.to_s.downcase}_reason")
817
831
  reason_enum[reason]
@@ -31,6 +31,14 @@ module Libvirt
31
31
  :threads, :uint
32
32
  end
33
33
 
34
+ # enum virConnectCloseReason
35
+ enum :close_reason, [
36
+ :ERROR, 0x0, # Misc I/O error
37
+ :EOF, 0x1, # End-of-file from server
38
+ :KEEPALIVE, 0x2, # Keepalive timer triggered
39
+ :CLIENT, 0x3 # Client requested it
40
+ ]
41
+
34
42
  # int virGetVersion (
35
43
  # unsigned long *libVer,
36
44
  # const char *type,
@@ -49,7 +57,7 @@ module Libvirt
49
57
  # int reason,
50
58
  # void * opaque
51
59
  # )
52
- callback :virConnectCloseFunc, [:pointer, :int, :pointer], :void
60
+ callback :virConnectCloseFunc, [:pointer, :close_reason, :pointer], :void
53
61
 
54
62
  # virConnectPtr virConnectOpen (const char * name)
55
63
  attach_function :virConnectOpen, [:string], :pointer
@@ -0,0 +1,175 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Libvirt
4
+ module FFI
5
+ module Interface
6
+ extend ::FFI::Library
7
+ extend Helpers
8
+ ffi_lib Util.library_path
9
+
10
+ ## Variables
11
+
12
+ ## Enums
13
+
14
+ # enum virConnectListAllInterfacesFlags
15
+ enum :list_all_flags, [
16
+ :INACTIVE, 0x1,
17
+ :ACTIVE, 0x2
18
+ ]
19
+
20
+ # enum virInterfaceXMLFlags
21
+ enum :xml_flags, [
22
+ :INACTIVE, 0x1 # dump inactive interface information
23
+ ]
24
+
25
+ ## Functions
26
+
27
+ # int virConnectListAllInterfaces (
28
+ # virConnectPtr conn,
29
+ # virInterfacePtr ** ifaces,
30
+ # unsigned int flags
31
+ # )
32
+ attach_function :virConnectListAllInterfaces,
33
+ [:pointer, :pointer, :list_all_flags],
34
+ :int
35
+
36
+ # int virConnectListDefinedInterfaces (
37
+ # virConnectPtr conn,
38
+ # char ** const names,
39
+ # int maxnames
40
+ # )
41
+ attach_function :virConnectListDefinedInterfaces,
42
+ [:pointer, :pointer, :int],
43
+ :int
44
+
45
+ # int virConnectListInterfaces (
46
+ # virConnectPtr conn,
47
+ # char ** const names,
48
+ # int maxnames
49
+ # )
50
+ attach_function :virConnectListInterfaces,
51
+ [:pointer, :pointer, :int],
52
+ :int
53
+
54
+ # int virConnectNumOfDefinedInterfaces (virConnectPtr conn)
55
+ attach_function :virConnectNumOfDefinedInterfaces,
56
+ [:pointer],
57
+ :int
58
+
59
+ # int virConnectNumOfInterfaces (virConnectPtr conn)
60
+ attach_function :virConnectNumOfInterfaces,
61
+ [:pointer],
62
+ :int
63
+
64
+ # int virInterfaceChangeBegin (
65
+ # virConnectPtr conn,
66
+ # unsigned int flags
67
+ # )
68
+ attach_function :virInterfaceChangeBegin,
69
+ [:pointer, :uint],
70
+ :int
71
+
72
+ # int virInterfaceChangeCommit (
73
+ # virConnectPtr conn,
74
+ # unsigned int flags
75
+ # )
76
+ attach_function :virInterfaceChangeCommit,
77
+ [:pointer, :uint],
78
+ :int
79
+
80
+ # int virInterfaceChangeRollback (
81
+ # virConnectPtr conn,
82
+ # unsigned int flags
83
+ # )
84
+ attach_function :virInterfaceChangeRollback,
85
+ [:pointer, :uint],
86
+ :int
87
+
88
+ # int virInterfaceCreate (
89
+ # virInterfacePtr iface,
90
+ # unsigned int flags
91
+ # )
92
+ attach_function :virInterfaceCreate,
93
+ [:pointer, :uint],
94
+ :int
95
+
96
+ # virInterfacePtr virInterfaceDefineXML (
97
+ # virConnectPtr conn,
98
+ # const char * xml,
99
+ # unsigned int flags
100
+ # )
101
+ attach_function :virInterfaceDefineXML,
102
+ [:pointer, :string, :uint],
103
+ :pointer
104
+
105
+ # int virInterfaceDestroy (
106
+ # virInterfacePtr iface,
107
+ # unsigned int flags
108
+ # )
109
+ attach_function :virInterfaceDestroy,
110
+ [:pointer, :uint],
111
+ :int
112
+
113
+ # int virInterfaceFree (virInterfacePtr iface)
114
+ attach_function :virInterfaceFree,
115
+ [:pointer],
116
+ :int
117
+
118
+ # virConnectPtr virInterfaceGetConnect (virInterfacePtr iface)
119
+ attach_function :virInterfaceGetConnect,
120
+ [:pointer],
121
+ :int
122
+
123
+ # const char * virInterfaceGetMACString (virInterfacePtr iface)
124
+ attach_function :virInterfaceGetMACString,
125
+ [:pointer],
126
+ :string
127
+
128
+ # const char * virInterfaceGetName (virInterfacePtr iface)
129
+ attach_function :virInterfaceGetName,
130
+ [:pointer],
131
+ :string
132
+
133
+ # char * virInterfaceGetXMLDesc (
134
+ # virInterfacePtr iface,
135
+ # unsigned int flags
136
+ # )
137
+ attach_function :virInterfaceGetXMLDesc,
138
+ [:pointer, :uint],
139
+ :string
140
+
141
+ # int virInterfaceIsActive (virInterfacePtr iface)
142
+ attach_function :virInterfaceIsActive,
143
+ [:pointer],
144
+ :int
145
+
146
+ # virInterfacePtr virInterfaceLookupByMACString (
147
+ # virConnectPtr conn,
148
+ # const char * macstr
149
+ # )
150
+ attach_function :virInterfaceLookupByMACString,
151
+ [:pointer, :string],
152
+ :pointer
153
+
154
+ # virInterfacePtr virInterfaceLookupByName (
155
+ # virConnectPtr conn,
156
+ # const char * name
157
+ # )
158
+ attach_function :virInterfaceLookupByName,
159
+ [:pointer, :string],
160
+ :pointer
161
+
162
+ # int virInterfaceRef (virInterfacePtr iface)
163
+ attach_function :virInterfaceRef,
164
+ [:pointer],
165
+ :int
166
+
167
+ # int virInterfaceUndefine (virInterfacePtr iface)
168
+ attach_function :virInterfaceUndefine,
169
+ [:pointer],
170
+ :int
171
+
172
+ ## Helpers
173
+ end
174
+ end
175
+ end