libvirt_ffi 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +78 -0
- data/Gemfile +7 -3
- data/Rakefile +6 -1
- data/bin/console +1 -0
- data/exe/libvirt +1 -0
- data/lib/libvirt/base_info.rb +34 -0
- data/lib/libvirt/connection.rb +98 -36
- data/lib/libvirt/domain.rb +105 -8
- data/lib/libvirt/domain_callback_storage.rb +13 -15
- data/lib/libvirt/errors.rb +65 -0
- data/lib/libvirt/event.rb +29 -19
- data/lib/libvirt/ffi/common.rb +8 -1
- data/lib/libvirt/ffi/domain.rb +529 -196
- data/lib/libvirt/ffi/error.rb +243 -0
- data/lib/libvirt/ffi/event.rb +30 -36
- data/lib/libvirt/ffi/helpers.rb +17 -0
- data/lib/libvirt/ffi/host.rb +122 -0
- data/lib/libvirt/ffi/storage.rb +149 -0
- data/lib/libvirt/ffi/stream.rb +19 -17
- data/lib/libvirt/ffi.rb +17 -0
- data/lib/libvirt/node_info.rb +2 -41
- data/lib/libvirt/storage_pool.rb +70 -0
- data/lib/libvirt/storage_pool_info.rb +7 -0
- data/lib/libvirt/storage_volume.rb +51 -0
- data/lib/libvirt/storage_volume_info.rb +7 -0
- data/lib/libvirt/stream.rb +21 -14
- data/lib/libvirt/util.rb +61 -8
- data/lib/libvirt/version.rb +1 -1
- data/lib/libvirt/xml/disk.rb +59 -0
- data/lib/libvirt/xml/domain.rb +76 -0
- data/lib/libvirt/xml/generic.rb +252 -0
- data/lib/libvirt/xml/graphics.rb +14 -0
- data/lib/libvirt/xml/max_vcpu.rb +12 -0
- data/lib/libvirt/xml/memory.rb +14 -0
- data/lib/libvirt/xml/storage_pool.rb +24 -0
- data/lib/libvirt/xml/storage_volume.rb +32 -0
- data/lib/libvirt/xml/vcpu.rb +12 -0
- data/lib/libvirt/xml.rb +23 -0
- data/lib/libvirt.rb +12 -12
- data/lib/libvirt_ffi.rb +2 -0
- data/libvirt.gemspec +5 -1
- data/test_usage/support/libvirt_async.rb +27 -35
- data/test_usage/support/log_formatter.rb +5 -10
- data/test_usage/test_domain.rb +43 -0
- data/test_usage/test_event_loop.rb +115 -39
- data/test_usage/test_libvirtd_restart.rb +63 -0
- data/test_usage/test_metadata.rb +104 -0
- data/test_usage/test_screenshot.rb +14 -13
- data/test_usage/test_storage.rb +52 -0
- metadata +42 -6
- data/lib/libvirt/error.rb +0 -6
- data/lib/libvirt/ffi/connection.rb +0 -94
- data/lib/libvirt/ffi/libvirt.rb +0 -17
- data/lib/libvirt/ffi/node_info.rb +0 -37
@@ -0,0 +1,243 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Libvirt
|
4
|
+
module FFI
|
5
|
+
module Error
|
6
|
+
# https://libvirt.org/html/libvirt-virterror.html
|
7
|
+
|
8
|
+
extend ::FFI::Library
|
9
|
+
extend Helpers
|
10
|
+
ffi_lib Util.library_path
|
11
|
+
|
12
|
+
# enum virErrorDomain
|
13
|
+
enum :error_domain, [
|
14
|
+
:NONE, 0x0, # None
|
15
|
+
:XEN, 0x1, # Error at Xen hypervisor layer
|
16
|
+
:XEND, 0x2, # Error at connection with xend daemon
|
17
|
+
:XENSTORE, 0x3, # Error at connection with xen store
|
18
|
+
:SEXPR, 0x4, # Error in the S-Expression code
|
19
|
+
:XML, 0x5, # Error in the XML code
|
20
|
+
:DOM, 0x6, # Error when operating on a domain
|
21
|
+
:RPC, 0x7, # Error in the XML-RPC code
|
22
|
+
:PROXY, 0x8, # Error in the proxy code; unused since 0.8.6
|
23
|
+
:CONF, 0x9, # Error in the configuration file handling
|
24
|
+
:QEMU, 0xa, # Error at the QEMU daemon
|
25
|
+
:NET, 0xb, # Error when operating on a network
|
26
|
+
:TEST, 0xc, # Error from test driver
|
27
|
+
:REMOTE, 0xd, # Error from remote driver
|
28
|
+
:OPENVZ, 0xe, # Error from OpenVZ driver
|
29
|
+
:XENXM, 0xf, # Error at Xen XM layer
|
30
|
+
:STATS_LINUX, 0x10, # Error in the Linux Stats code
|
31
|
+
:LXC, 0x11, # Error from Linux Container driver
|
32
|
+
:STORAGE, 0x12, # Error from storage driver
|
33
|
+
:NETWORK, 0x13, # Error from network config
|
34
|
+
:DOMAIN, 0x14, # Error from domain config
|
35
|
+
:UML, 0x15, # Error at the UML driver; unused since 5.0.0
|
36
|
+
:NODEDEV, 0x16, # Error from node device monitor
|
37
|
+
:XEN_INOTIFY, 0x17, # Error from xen inotify layer
|
38
|
+
:SECURITY, 0x18, # Error from security framework
|
39
|
+
:VBOX, 0x19, # Error from VirtualBox driver
|
40
|
+
:INTERFACE, 0x1a, # Error when operating on an interface
|
41
|
+
:ONE, 0x1b, # The OpenNebula driver no longer exists. Retained for ABI/API compat only
|
42
|
+
:ESX, 0x1c, # Error from ESX driver
|
43
|
+
:PHYP, 0x1d, # Error from the phyp driver, unused since 6.0.0
|
44
|
+
:SECRET, 0x1e, # Error from secret storage
|
45
|
+
:CPU, 0x1f, # Error from CPU driver
|
46
|
+
:XENAPI, 0x20, # Error from XenAPI
|
47
|
+
:NWFILTER, 0x21, # Error from network filter driver
|
48
|
+
:HOOK, 0x22, # Error from Synchronous hooks
|
49
|
+
:DOMAIN_SNAPSHOT, 0x23, # Error from domain snapshot
|
50
|
+
:AUDIT, 0x24, # Error from auditing subsystem
|
51
|
+
:SYSINFO, 0x25, # Error from sysinfo/SMBIOS
|
52
|
+
:STREAMS, 0x26, # Error from I/O streams
|
53
|
+
:VMWARE, 0x27, # Error from VMware driver
|
54
|
+
:EVENT, 0x28, # Error from event loop impl
|
55
|
+
:LIBXL, 0x29, # Error from libxenlight driver
|
56
|
+
:LOCKING, 0x2a, # Error from lock manager
|
57
|
+
:HYPERV, 0x2b, # Error from Hyper-V driver
|
58
|
+
:CAPABILITIES, 0x2c, # Error from capabilities
|
59
|
+
:URI, 0x2d, # Error from URI handling
|
60
|
+
:AUTH, 0x2e, # Error from auth handling
|
61
|
+
:DBUS, 0x2f, # Error from DBus
|
62
|
+
:PARALLELS, 0x30, # Error from Parallels
|
63
|
+
:DEVICE, 0x31, # Error from Device
|
64
|
+
:SSH, 0x32, # Error from libssh2 connection transport
|
65
|
+
:LOCKSPACE, 0x33, # Error from lockspace
|
66
|
+
:INITCTL, 0x34, # Error from initctl device communication
|
67
|
+
:IDENTITY, 0x35, # Error from identity code
|
68
|
+
:CGROUP, 0x36, # Error from cgroups
|
69
|
+
:ACCESS, 0x37, # Error from access control manager
|
70
|
+
:SYSTEMD, 0x38, # Error from systemd code
|
71
|
+
:BHYVE, 0x39, # Error from bhyve driver
|
72
|
+
:CRYPTO, 0x3a, # Error from crypto code
|
73
|
+
:FIREWALL, 0x3b, # Error from firewall
|
74
|
+
:POLKIT, 0x3c, # Error from polkit code
|
75
|
+
:THREAD, 0x3d, # Error from thread utils
|
76
|
+
:ADMIN, 0x3e, # Error from admin backend
|
77
|
+
:LOGGING, 0x3f, # Error from log manager
|
78
|
+
:XENXL, 0x40, # Error from Xen xl config code
|
79
|
+
:PERF, 0x41, # Error from perf
|
80
|
+
:LIBSSH, 0x42, # Error from libssh connection transport
|
81
|
+
:RESCTRL, 0x43, # Error from resource control
|
82
|
+
:FIREWALLD, 0x44, # Error from firewalld
|
83
|
+
:DOMAIN_CHECKPOINT, 0x45, # Error from domain checkpoint
|
84
|
+
:TPM, 0x46, # Error from TPM
|
85
|
+
:BPF, 0x47 # Error from BPF code
|
86
|
+
]
|
87
|
+
|
88
|
+
# enum virErrorLevel
|
89
|
+
enum :error_level, [
|
90
|
+
:NONE, 0x0, # None
|
91
|
+
:WARNING, 0x1, # A simple warning
|
92
|
+
:ERROR, 0x2 # An error
|
93
|
+
]
|
94
|
+
|
95
|
+
# enum virErrorNumber
|
96
|
+
enum :error_number, [
|
97
|
+
:OK, 0x0, # ok
|
98
|
+
:INTERNAL_ERROR, 0x1, # internal error
|
99
|
+
:NO_MEMORY, 0x2, # memory allocation failure
|
100
|
+
:NO_SUPPORT, 0x3, # no support for this function
|
101
|
+
:UNKNOWN_HOST, 0x4, # could not resolve hostname
|
102
|
+
:NO_CONNECT, 0x5, # can't connect to hypervisor
|
103
|
+
:INVALID_CONN, 0x6, # invalid connection object
|
104
|
+
:INVALID_DOMAIN, 0x7, # invalid domain object
|
105
|
+
:INVALID_ARG, 0x8, # invalid function argument
|
106
|
+
:OPERATION_FAILED, 0x9, # a command to hypervisor failed
|
107
|
+
:GET_FAILED, 0xa, # a HTTP GET command to failed
|
108
|
+
:POST_FAILED, 0xb, # a HTTP POST command to failed
|
109
|
+
:HTTP_ERROR, 0xc, # unexpected HTTP error code
|
110
|
+
:SEXPR_SERIAL, 0xd, # failure to serialize an S-Expr
|
111
|
+
:NO_XEN, 0xe, # could not open Xen hypervisor control
|
112
|
+
:XEN_CALL, 0xf, # failure doing an hypervisor call
|
113
|
+
:OS_TYPE, 0x10, # unknown OS type
|
114
|
+
:NO_KERNEL, 0x11, # missing kernel information
|
115
|
+
:NO_ROOT, 0x12, # missing root device information
|
116
|
+
:NO_SOURCE, 0x13, # missing source device information
|
117
|
+
:NO_TARGET, 0x14, # missing target device information
|
118
|
+
:NO_NAME, 0x15, # missing domain name information
|
119
|
+
:NO_OS, 0x16, # missing domain OS information
|
120
|
+
:NO_DEVICE, 0x17, # missing domain devices information
|
121
|
+
:NO_XENSTORE, 0x18, # could not open Xen Store control
|
122
|
+
:DRIVER_FULL, 0x19, # too many drivers registered
|
123
|
+
:CALL_FAILED, 0x1a, # not supported by the drivers (DEPRECATED)
|
124
|
+
:XML_ERROR, 0x1b, # an XML description is not well formed or broken
|
125
|
+
:DOM_EXIST, 0x1c, # the domain already exist
|
126
|
+
:OPERATION_DENIED, 0x1d, # operation forbidden on read-only connections
|
127
|
+
:OPEN_FAILED, 0x1e, # failed to open a conf file
|
128
|
+
:READ_FAILED, 0x1f, # failed to read a conf file
|
129
|
+
:PARSE_FAILED, 0x20, # failed to parse a conf file
|
130
|
+
:CONF_SYNTAX, 0x21, # failed to parse the syntax of a conf file
|
131
|
+
:WRITE_FAILED, 0x22, # failed to write a conf file
|
132
|
+
:XML_DETAIL, 0x23, # detail of an XML error
|
133
|
+
:INVALID_NETWORK, 0x24, # invalid network object
|
134
|
+
:NETWORK_EXIST, 0x25, # the network already exist
|
135
|
+
:SYSTEM_ERROR, 0x26, # general system call failure
|
136
|
+
:RPC, 0x27, # some sort of RPC error
|
137
|
+
:GNUTLS_ERROR, 0x28, # error from a GNUTLS call
|
138
|
+
:NO_NETWORK_WARN, 0x29, # failed to start network
|
139
|
+
:NO_DOMAIN, 0x2a, # domain not found or unexpectedly disappeared
|
140
|
+
:NO_NETWORK, 0x2b, # network not found
|
141
|
+
:INVALID_MAC, 0x2c, # invalid MAC address
|
142
|
+
:AUTH_FAILED, 0x2d, # authentication failed
|
143
|
+
:INVALID_STORAGE_POOL, 0x2e, # invalid storage pool object
|
144
|
+
:INVALID_STORAGE_VOL, 0x2f, # invalid storage vol object
|
145
|
+
:NO_STORAGE_WARN, 0x30, # failed to start storage
|
146
|
+
:NO_STORAGE_POOL, 0x31, # storage pool not found
|
147
|
+
:NO_STORAGE_VOL, 0x32, # storage volume not found
|
148
|
+
:NO_NODE_WARN, 0x33, # failed to start node driver
|
149
|
+
:INVALID_NODE_DEVICE, 0x34, # invalid node device object
|
150
|
+
:NO_NODE_DEVICE, 0x35, # node device not found
|
151
|
+
:NO_SECURITY_MODEL, 0x36, # security model not found
|
152
|
+
:OPERATION_INVALID, 0x37, # operation is not applicable at this time
|
153
|
+
:NO_INTERFACE_WARN, 0x38, # failed to start interface driver
|
154
|
+
:NO_INTERFACE, 0x39, # interface driver not running
|
155
|
+
:INVALID_INTERFACE, 0x3a, # invalid interface object
|
156
|
+
:MULTIPLE_INTERFACES, 0x3b, # more than one matching interface found
|
157
|
+
:NO_NWFILTER_WARN, 0x3c, # failed to start nwfilter driver
|
158
|
+
:INVALID_NWFILTER, 0x3d, # invalid nwfilter object
|
159
|
+
:NO_NWFILTER, 0x3e, # nw filter pool not found
|
160
|
+
:BUILD_FIREWALL, 0x3f, # nw filter pool not found
|
161
|
+
:NO_SECRET_WARN, 0x40, # failed to start secret storage
|
162
|
+
:INVALID_SECRET, 0x41, # invalid secret
|
163
|
+
:NO_SECRET, 0x42, # secret not found
|
164
|
+
:CONFIG_UNSUPPORTED, 0x43, # unsupported configuration construct
|
165
|
+
:OPERATION_TIMEOUT, 0x44, # timeout occurred during operation
|
166
|
+
:MIGRATE_PERSIST_FAILED, 0x45, # a migration worked, but making the VM persist on the dest host failed
|
167
|
+
:HOOK_SCRIPT_FAILED, 0x46, # a synchronous hook script failed
|
168
|
+
:INVALID_DOMAIN_SNAPSHOT, 0x47, # invalid domain snapshot
|
169
|
+
:NO_DOMAIN_SNAPSHOT, 0x48, # domain snapshot not found
|
170
|
+
:INVALID_STREAM, 0x49, # stream pointer not valid
|
171
|
+
:ARGUMENT_UNSUPPORTED, 0x4a, # valid API use but unsupported by the given driver
|
172
|
+
:STORAGE_PROBE_FAILED, 0x4b, # storage pool probe failed
|
173
|
+
:STORAGE_POOL_BUILT, 0x4c, # storage pool already built
|
174
|
+
:SNAPSHOT_REVERT_RISKY, 0x4d, # force was not requested for a risky domain snapshot revert
|
175
|
+
:OPERATION_ABORTED, 0x4e, # operation on a domain was canceled/aborted by user
|
176
|
+
:AUTH_CANCELLED, 0x4f, # authentication cancelled
|
177
|
+
:NO_DOMAIN_METADATA, 0x50, # The metadata is not present
|
178
|
+
:MIGRATE_UNSAFE, 0x51, # Migration is not safe
|
179
|
+
:OVERFLOW, 0x52, # integer overflow
|
180
|
+
:BLOCK_COPY_ACTIVE, 0x53, # action prevented by block copy job
|
181
|
+
:OPERATION_UNSUPPORTED, 0x54, # The requested operation is not supported
|
182
|
+
:SSH, 0x55, # error in ssh transport driver
|
183
|
+
:AGENT_UNRESPONSIVE, 0x56, # guest agent is unresponsive, not running or not usable
|
184
|
+
:RESOURCE_BUSY, 0x57, # resource is already in use
|
185
|
+
:ACCESS_DENIED, 0x58, # operation on the object/resource was denied
|
186
|
+
:DBUS_SERVICE, 0x59, # error from a dbus service
|
187
|
+
:STORAGE_VOL_EXIST, 0x5a, # the storage vol already exists
|
188
|
+
:CPU_INCOMPATIBLE, 0x5b, # given CPU is incompatible with host CPU
|
189
|
+
:XML_INVALID_SCHEMA, 0x5c, # XML document doesn't validate against schema
|
190
|
+
:MIGRATE_FINISH_OK, 0x5d, # Finish API succeeded but it is expected to return NULL
|
191
|
+
:AUTH_UNAVAILABLE, 0x5e, # authentication unavailable
|
192
|
+
:NO_SERVER, 0x5f, # Server was not found
|
193
|
+
:NO_CLIENT, 0x60, # Client was not found
|
194
|
+
:AGENT_UNSYNCED, 0x61, # guest agent replies with wrong id to guest-sync command (DEPRECATED)
|
195
|
+
:LIBSSH, 0x62, # error in libssh transport driver
|
196
|
+
:DEVICE_MISSING, 0x63, # fail to find the desired device
|
197
|
+
:INVALID_NWFILTER_BINDING, 0x64, # invalid nwfilter binding
|
198
|
+
:NO_NWFILTER_BINDING, 0x65, # no nwfilter binding
|
199
|
+
:INVALID_DOMAIN_CHECKPOINT, 0x66, # invalid domain checkpoint
|
200
|
+
:NO_DOMAIN_CHECKPOINT, 0x67, # domain checkpoint not found
|
201
|
+
:NO_DOMAIN_BACKUP, 0x68, # domain backup job id not found
|
202
|
+
:INVALID_NETWORK_PORT, 0x69, # invalid network port object
|
203
|
+
:NETWORK_PORT_EXIST, 0x6a, # the network port already exist
|
204
|
+
:NO_NETWORK_PORT, 0x6b, # network port not found
|
205
|
+
:NO_HOSTNAME, 0x6c # no domain's hostname found
|
206
|
+
]
|
207
|
+
|
208
|
+
# struct virError {
|
209
|
+
# int code # The error code, a virErrorNumber
|
210
|
+
# int domain # What part of the library raised this error
|
211
|
+
# char * message # human-readable informative error message
|
212
|
+
# virErrorLevel level # how consequent is the error
|
213
|
+
# virConnectPtr conn # connection if available, deprecated see note above
|
214
|
+
# virDomainPtr dom # domain if available, deprecated see note above
|
215
|
+
# char * str1 # extra string information
|
216
|
+
# char * str2 # extra string information
|
217
|
+
# char * str3 # extra string information
|
218
|
+
# int int1 # extra number information
|
219
|
+
# int int2 # extra number information
|
220
|
+
# virNetworkPtr net # network if available, deprecated see note above
|
221
|
+
# }
|
222
|
+
class Struct < ::FFI::Struct
|
223
|
+
layout :code, FFI::Error.enum_type(:error_number),
|
224
|
+
:domain, FFI::Error.enum_type(:error_domain),
|
225
|
+
:message, :string,
|
226
|
+
:level, FFI::Error.enum_type(:error_level),
|
227
|
+
:conn, :pointer,
|
228
|
+
:dom, :pointer,
|
229
|
+
:str1, :string,
|
230
|
+
:str2, :string,
|
231
|
+
:str3, :string,
|
232
|
+
:int1, :int,
|
233
|
+
:int2, :int,
|
234
|
+
:net, :pointer
|
235
|
+
end
|
236
|
+
|
237
|
+
# virErrorPtr virGetLastError (
|
238
|
+
# void
|
239
|
+
# )
|
240
|
+
attach_function :virGetLastError, [], :pointer
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
data/lib/libvirt/ffi/event.rb
CHANGED
@@ -3,29 +3,32 @@
|
|
3
3
|
module Libvirt
|
4
4
|
module FFI
|
5
5
|
module Event
|
6
|
+
# https://libvirt.org/html/libvirt-libvirt-event.html
|
7
|
+
|
6
8
|
extend ::FFI::Library
|
9
|
+
extend Helpers
|
7
10
|
ffi_lib Util.library_path
|
8
11
|
|
9
|
-
# typedef void (*virEventHandleCallback)
|
12
|
+
# typedef void (*virEventHandleCallback) (
|
10
13
|
# int watch,
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
+
# int fd,
|
15
|
+
# int events,
|
16
|
+
# void * opaque
|
14
17
|
# )
|
15
18
|
EVENT_HANDLE_CALLBACK = callback :virEventHandleCallback, [:int, :int, :int, :pointer], :void
|
16
19
|
|
17
|
-
# typedef void (*virEventTimeoutCallback)
|
20
|
+
# typedef void (*virEventTimeoutCallback) (
|
18
21
|
# int timer,
|
19
|
-
#
|
22
|
+
# void * opaque
|
20
23
|
# )
|
21
24
|
EVENT_TIMEOUT_CALLBACK = callback :virEventTimeoutCallback, [:int, :pointer], :void
|
22
25
|
|
23
|
-
# typedef int
|
26
|
+
# typedef int (*virEventAddHandleFunc) (
|
24
27
|
# int fd,
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
28
|
+
# int event,
|
29
|
+
# virEventHandleCallback cb,
|
30
|
+
# void * opaque,
|
31
|
+
# virFreeCallback ff
|
29
32
|
# )
|
30
33
|
callback :virEventAddHandleFunc, [
|
31
34
|
:int,
|
@@ -35,22 +38,22 @@ module Libvirt
|
|
35
38
|
FFI::Common::FREE_CALLBACK
|
36
39
|
], :int
|
37
40
|
|
38
|
-
# typedef void
|
41
|
+
# typedef void (*virEventUpdateHandleFunc) (
|
39
42
|
# int watch,
|
40
|
-
#
|
43
|
+
# int event
|
41
44
|
# )
|
42
45
|
callback :virEventUpdateHandleFunc, [:int, :int], :void
|
43
46
|
|
44
|
-
# typedef int
|
47
|
+
# typedef int (*virEventRemoveHandleFunc) (
|
45
48
|
# int watch
|
46
49
|
# )
|
47
50
|
callback :virEventRemoveHandleFunc, [:int], :int
|
48
51
|
|
49
|
-
# typedef int
|
52
|
+
# typedef int (*virEventAddTimeoutFunc) (
|
50
53
|
# int timeout,
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
54
|
+
# virEventTimeoutCallback cb,
|
55
|
+
# void * opaque,
|
56
|
+
# virFreeCallback ff
|
54
57
|
# )
|
55
58
|
callback :virEventAddTimeoutFunc, [
|
56
59
|
:int,
|
@@ -59,24 +62,24 @@ module Libvirt
|
|
59
62
|
FFI::Common::FREE_CALLBACK
|
60
63
|
], :int
|
61
64
|
|
62
|
-
# typedef void (*virEventUpdateTimeoutFunc)
|
65
|
+
# typedef void (*virEventUpdateTimeoutFunc) (
|
63
66
|
# int timer,
|
64
|
-
#
|
67
|
+
# int timeout
|
65
68
|
# )
|
66
69
|
callback :virEventUpdateTimeoutFunc, [:int, :int], :void
|
67
70
|
|
68
|
-
# typedef int
|
71
|
+
# typedef int (*virEventRemoveTimeoutFunc) (
|
69
72
|
# int timer
|
70
73
|
# )
|
71
74
|
callback :virEventRemoveTimeoutFunc, [:int], :int
|
72
75
|
|
73
|
-
# void
|
76
|
+
# void virEventRegisterImpl (
|
74
77
|
# virEventAddHandleFunc addHandle,
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
78
|
+
# virEventUpdateHandleFunc updateHandle,
|
79
|
+
# virEventRemoveHandleFunc removeHandle,
|
80
|
+
# virEventAddTimeoutFunc addTimeout,
|
81
|
+
# virEventUpdateTimeoutFunc updateTimeout,
|
82
|
+
# virEventRemoveTimeoutFunc removeTimeout
|
80
83
|
# )
|
81
84
|
attach_function :virEventRegisterImpl, [
|
82
85
|
:virEventAddHandleFunc,
|
@@ -86,15 +89,6 @@ module Libvirt
|
|
86
89
|
:virEventUpdateTimeoutFunc,
|
87
90
|
:virEventRemoveTimeoutFunc
|
88
91
|
], :void
|
89
|
-
|
90
|
-
def self.event_add_handle_func(&block)
|
91
|
-
::FFI::Function.new(:int, [:int, :int, EVENT_HANDLE_CALLBACK, :pointer, FFI::Common::FREE_CALLBACK], &block)
|
92
|
-
end
|
93
|
-
|
94
|
-
def self.event_add_timeout_func(&block)
|
95
|
-
::FFI::Function.new(:int, [:int, EVENT_TIMEOUT_CALLBACK, :pointer, FFI::Common::FREE_CALLBACK], &block)
|
96
|
-
end
|
97
|
-
|
98
92
|
end
|
99
93
|
end
|
100
94
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Libvirt
|
4
|
+
module FFI
|
5
|
+
module Helpers
|
6
|
+
# Creates function by provided callback or callback name
|
7
|
+
# @param callback [Symbol,FFI::CallbackInfo] callback name registered in current module
|
8
|
+
# @param args [Array] extra arguments for FFI::Function
|
9
|
+
# @yield when function is called
|
10
|
+
# @return [FFI::Function]
|
11
|
+
def callback_function(callback, *args, &block)
|
12
|
+
callback_info = callback.is_a?(Symbol) ? find_type(callback) : callback
|
13
|
+
::FFI::Function.new(callback_info.result_type, callback_info.param_types, *args, &block)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Libvirt
|
4
|
+
module FFI
|
5
|
+
module Host
|
6
|
+
# https://libvirt.org/html/libvirt-libvirt-host.html
|
7
|
+
|
8
|
+
extend ::FFI::Library
|
9
|
+
extend Helpers
|
10
|
+
ffi_lib Util.library_path
|
11
|
+
|
12
|
+
# struct virNodeInfo {
|
13
|
+
# char model[32] model - string indicating the CPU model
|
14
|
+
# unsigned long memory - memory size in kilobytes
|
15
|
+
# unsigned int cpus - the number of active CPUs
|
16
|
+
# unsigned int mhz - expected CPU frequency, 0 if not known or on unusual architectures
|
17
|
+
# unsigned int nodes - the number of NUMA cell, 1 for unusual NUMA topologies or uniform memory access;
|
18
|
+
# check capabilities XML for the actual NUMA topology
|
19
|
+
# unsigned int sockets - number of CPU sockets per node if nodes > 1, 1 in case of unusual NUMA topology
|
20
|
+
# unsigned int cores - number of cores per socket, total number of processors in case of unusual NUMA topolog
|
21
|
+
# unsigned int threads - number of threads per core, 1 in case of unusual numa topology
|
22
|
+
# }
|
23
|
+
class NodeInfoStruct < ::FFI::Struct
|
24
|
+
layout :model, [:char, 32],
|
25
|
+
:memory, :ulong,
|
26
|
+
:cpus, :uint,
|
27
|
+
:mhz, :uint,
|
28
|
+
:nodes, :uint,
|
29
|
+
:sockets, :uint,
|
30
|
+
:cores, :uint,
|
31
|
+
:threads, :uint
|
32
|
+
end
|
33
|
+
|
34
|
+
# int virGetVersion (
|
35
|
+
# unsigned long *libVer,
|
36
|
+
# const char *type,
|
37
|
+
# unsigned long *typeVer
|
38
|
+
# )
|
39
|
+
attach_function :virGetVersion, [:pointer, :string, :pointer], :int
|
40
|
+
|
41
|
+
# int virNodeGetInfo (
|
42
|
+
# virConnectPtr conn,
|
43
|
+
# virNodeInfoPtr info
|
44
|
+
# )
|
45
|
+
attach_function :virNodeGetInfo, [:pointer, :pointer], :int
|
46
|
+
|
47
|
+
# typedef void (*virConnectCloseFunc) (
|
48
|
+
# virConnectPtr conn,
|
49
|
+
# int reason,
|
50
|
+
# void * opaque
|
51
|
+
# )
|
52
|
+
callback :virConnectCloseFunc, [:pointer, :int, :pointer], :void
|
53
|
+
|
54
|
+
# virConnectPtr virConnectOpen (const char * name)
|
55
|
+
attach_function :virConnectOpen, [:string], :pointer
|
56
|
+
|
57
|
+
# int virConnectSetKeepAlive (
|
58
|
+
# virConnectPtr conn,
|
59
|
+
# int interval,
|
60
|
+
# unsigned int count
|
61
|
+
# )
|
62
|
+
attach_function :virConnectSetKeepAlive, [:pointer, :int, :uint], :int
|
63
|
+
|
64
|
+
# int virConnectGetVersion (
|
65
|
+
# virConnectPtr conn,
|
66
|
+
# unsigned long * hvVer
|
67
|
+
# )
|
68
|
+
attach_function :virConnectGetVersion, [:pointer, :pointer], :int
|
69
|
+
|
70
|
+
# int virConnectGetLibVersion (
|
71
|
+
# virConnectPtr conn,
|
72
|
+
# unsigned long * libVer
|
73
|
+
# )
|
74
|
+
attach_function :virConnectGetLibVersion, [:pointer, :pointer], :int
|
75
|
+
|
76
|
+
# char * virConnectGetHostname (
|
77
|
+
# virConnectPtr conn
|
78
|
+
# )
|
79
|
+
attach_function :virConnectGetHostname, [:pointer], :string # strptr ?
|
80
|
+
|
81
|
+
# int virConnectGetMaxVcpus (
|
82
|
+
# virConnectPtr conn,
|
83
|
+
# const char * type
|
84
|
+
# )
|
85
|
+
attach_function :virConnectGetMaxVcpus, [:pointer, :string], :int
|
86
|
+
|
87
|
+
# char * virConnectGetCapabilities (
|
88
|
+
# virConnectPtr conn
|
89
|
+
# )
|
90
|
+
attach_function :virConnectGetCapabilities, [:pointer], :string # strptr ?
|
91
|
+
|
92
|
+
# int virConnectClose (
|
93
|
+
# virConnectPtr conn
|
94
|
+
# )
|
95
|
+
attach_function :virConnectClose, [:pointer], :int
|
96
|
+
|
97
|
+
# int virConnectRegisterCloseCallback (
|
98
|
+
# virConnectPtr conn,
|
99
|
+
# virConnectCloseFunc cb,
|
100
|
+
# void * opaque,
|
101
|
+
# virFreeCallback freecb
|
102
|
+
# )
|
103
|
+
attach_function :virConnectRegisterCloseCallback, [
|
104
|
+
:pointer,
|
105
|
+
:virConnectCloseFunc,
|
106
|
+
:pointer,
|
107
|
+
FFI::Common::FREE_CALLBACK
|
108
|
+
], :int
|
109
|
+
|
110
|
+
# int virConnectUnregisterCloseCallback (
|
111
|
+
# virConnectPtr conn,
|
112
|
+
# virConnectCloseFunc cb
|
113
|
+
# )
|
114
|
+
attach_function :virConnectUnregisterCloseCallback, [:pointer, :pointer], :int
|
115
|
+
|
116
|
+
# int virConnectRef (
|
117
|
+
# virConnectPtr conn
|
118
|
+
# )
|
119
|
+
attach_function :virConnectRef, [:pointer], :int
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Libvirt
|
4
|
+
module FFI
|
5
|
+
module Storage
|
6
|
+
# https://libvirt.org/html/libvirt-libvirt-storage.html
|
7
|
+
|
8
|
+
extend ::FFI::Library
|
9
|
+
extend Helpers
|
10
|
+
ffi_lib Util.library_path
|
11
|
+
|
12
|
+
# enum virStoragePoolState
|
13
|
+
enum :pool_state, [
|
14
|
+
:INACTIVE, 0x0, # Not running
|
15
|
+
:BUILDING, 0x1, # Initializing pool, not available
|
16
|
+
:RUNNING, 0x2, # Running normally
|
17
|
+
:DEGRADED, 0x3, # Running degraded
|
18
|
+
:INACCESSIBLE, 0x4 # Running, but not accessible
|
19
|
+
]
|
20
|
+
|
21
|
+
# enum virConnectListAllStoragePoolsFlags
|
22
|
+
enum :list_all_pools_flags, [
|
23
|
+
:INACTIVE, 0x1,
|
24
|
+
:ACTIVE, 0x2,
|
25
|
+
:PERSISTENT, 0x4,
|
26
|
+
:TRANSIENT, 0x8,
|
27
|
+
:AUTOSTART, 0x10,
|
28
|
+
:NO_AUTOSTART, 0x20, # List pools by type
|
29
|
+
:DIR, 0x40,
|
30
|
+
:FS, 0x80,
|
31
|
+
:NETFS, 0x100,
|
32
|
+
:LOGICAL, 0x200,
|
33
|
+
:DISK, 0x400,
|
34
|
+
:ISCSI, 0x800,
|
35
|
+
:SCSI, 0x1000,
|
36
|
+
:MPATH, 0x2000,
|
37
|
+
:RBD, 0x4000,
|
38
|
+
:SHEEPDOG, 0x8000,
|
39
|
+
:GLUSTER, 0x10000,
|
40
|
+
:ZFS, 0x20000,
|
41
|
+
:VSTORAGE, 0x40000,
|
42
|
+
:ISCSI_DIRECT, 0x80000
|
43
|
+
]
|
44
|
+
|
45
|
+
# enum virStorageVolInfoFlags
|
46
|
+
enum :volume_info_flags, [
|
47
|
+
:USE_ALLOCATION, 0x0, # Return the physical size in allocation
|
48
|
+
:GET_PHYSICAL, 0x1
|
49
|
+
]
|
50
|
+
|
51
|
+
# enum virStorageVolType
|
52
|
+
enum :volume_type, [
|
53
|
+
:FILE, 0x0, # Regular file based volumes
|
54
|
+
:BLOCK, 0x1, # Block based volumes
|
55
|
+
:DIR, 0x2, # Directory-passthrough based volume
|
56
|
+
:NETWORK, 0x3, # Network volumes like RBD (RADOS Block Device)
|
57
|
+
:NETDIR, 0x4, # Network accessible directory that can contain other network volumes
|
58
|
+
:PLOOP, 0x5 # Ploop based volumes
|
59
|
+
]
|
60
|
+
|
61
|
+
# enum virStorageXMLFlags
|
62
|
+
enum :xml_flags, [
|
63
|
+
:INACTIVE, 0x1 # dump inactive pool/volume information
|
64
|
+
]
|
65
|
+
|
66
|
+
# struct virStoragePoolInfo {
|
67
|
+
# int state # virStoragePoolState flags
|
68
|
+
# unsigned long long capacity # Logical size bytes
|
69
|
+
# unsigned long long allocation # Current allocation bytes
|
70
|
+
# unsigned long long available # Remaining free space bytes
|
71
|
+
# }
|
72
|
+
class PoolInfoStruct < ::FFI::Struct
|
73
|
+
layout :state, FFI::Storage.enum_type(:pool_state),
|
74
|
+
:capacity, :ulong_long,
|
75
|
+
:allocation, :ulong_long,
|
76
|
+
:available, :ulong_long
|
77
|
+
end
|
78
|
+
|
79
|
+
# struct virStorageVolInfo {
|
80
|
+
# int type # virStorageVolType flags
|
81
|
+
# unsigned long long capacity # Logical size bytes
|
82
|
+
# unsigned long long allocation # Current allocation bytes
|
83
|
+
# }
|
84
|
+
class VolumeInfoStruct < ::FFI::Struct
|
85
|
+
layout :type, FFI::Storage.enum_type(:volume_type),
|
86
|
+
:capacity, :ulong_long,
|
87
|
+
:allocation, :ulong_long
|
88
|
+
end
|
89
|
+
|
90
|
+
# int virConnectListAllStoragePools (
|
91
|
+
# virConnectPtr conn,
|
92
|
+
# virStoragePoolPtr ** pools,
|
93
|
+
# unsigned int flags
|
94
|
+
# )
|
95
|
+
attach_function :virConnectListAllStoragePools, [:pointer, :pointer, :uint], :int
|
96
|
+
|
97
|
+
# int virStoragePoolGetInfo (
|
98
|
+
# virStoragePoolPtr pool,
|
99
|
+
# virStoragePoolInfoPtr info
|
100
|
+
# )
|
101
|
+
attach_function :virStoragePoolGetInfo, [:pointer, :pointer], :int
|
102
|
+
|
103
|
+
# char * virStoragePoolGetXMLDesc (
|
104
|
+
# virStoragePoolPtr pool,
|
105
|
+
# unsigned int flags
|
106
|
+
# )
|
107
|
+
attach_function :virStoragePoolGetXMLDesc, [:pointer, :xml_flags], :string
|
108
|
+
|
109
|
+
# int virStoragePoolRef (
|
110
|
+
# virStoragePoolPtr pool
|
111
|
+
# )
|
112
|
+
attach_function :virStoragePoolRef, [:pointer], :int
|
113
|
+
|
114
|
+
# int virStoragePoolFree (
|
115
|
+
# virStoragePoolPtr pool
|
116
|
+
# )
|
117
|
+
attach_function :virStoragePoolFree, [:pointer], :int
|
118
|
+
|
119
|
+
# int virStoragePoolListAllVolumes (
|
120
|
+
# virStoragePoolPtr pool,
|
121
|
+
# virStorageVolPtr ** vols,
|
122
|
+
# unsigned int flags
|
123
|
+
# )
|
124
|
+
attach_function :virStoragePoolListAllVolumes, [:pointer, :pointer, :uint], :int
|
125
|
+
|
126
|
+
# int virStorageVolRef (
|
127
|
+
# virStorageVolPtr vol
|
128
|
+
# )
|
129
|
+
attach_function :virStorageVolRef, [:pointer], :int
|
130
|
+
|
131
|
+
# int virStorageVolFree (
|
132
|
+
# virStorageVolPtr vol
|
133
|
+
# )
|
134
|
+
attach_function :virStorageVolFree, [:pointer], :int
|
135
|
+
|
136
|
+
# int virStorageVolGetInfo (
|
137
|
+
# virStorageVolPtr vol,
|
138
|
+
# virStorageVolInfoPtr info
|
139
|
+
# )
|
140
|
+
attach_function :virStorageVolGetInfo, [:pointer, :pointer], :int
|
141
|
+
|
142
|
+
# char * virStorageVolGetXMLDesc (
|
143
|
+
# virStorageVolPtr vol,
|
144
|
+
# unsigned int flags
|
145
|
+
# )
|
146
|
+
attach_function :virStorageVolGetXMLDesc, [:pointer, :xml_flags], :string
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|