libvirt_ffi 0.6.1 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +26 -0
- data/.gitignore +2 -1
- data/.rspec +1 -0
- data/.rubocop.yml +1 -1
- data/Gemfile +7 -10
- data/README.md +2 -2
- data/Rakefile +3 -8
- data/lib/libvirt/base_info.rb +8 -0
- data/lib/libvirt/connection.rb +228 -69
- data/lib/libvirt/domain.rb +18 -0
- data/lib/libvirt/ffi/domain.rb +53 -41
- data/lib/libvirt/ffi/host.rb +78 -39
- data/lib/libvirt/ffi/interface.rb +175 -0
- data/lib/libvirt/ffi/network.rb +392 -0
- data/lib/libvirt/ffi/storage.rb +1 -1
- data/lib/libvirt/ffi.rb +2 -0
- data/lib/libvirt/host_callback_storage.rb +10 -2
- data/lib/libvirt/interface.rb +92 -0
- data/lib/libvirt/loggable.rb +58 -0
- data/lib/libvirt/network.rb +176 -0
- data/lib/libvirt/network_dhcp_lease.rb +20 -0
- data/lib/libvirt/storage_pool.rb +2 -2
- data/lib/libvirt/util.rb +87 -64
- data/lib/libvirt/version.rb +1 -1
- data/lib/libvirt/xml/generic.rb +8 -5
- data/lib/libvirt/xml/interface.rb +79 -0
- data/lib/libvirt/xml/ip_address.rb +51 -0
- data/lib/libvirt/xml/network.rb +204 -0
- data/lib/libvirt/xml.rb +6 -2
- data/lib/libvirt.rb +18 -16
- data/libvirt.gemspec +11 -13
- metadata +14 -26
- data/.travis.yml +0 -6
- data/test_usage/support/libvirt_async.rb +0 -536
- data/test_usage/support/log_formatter.rb +0 -33
- data/test_usage/test_domain.rb +0 -43
- data/test_usage/test_event_loop.rb +0 -185
- data/test_usage/test_libvirtd_restart.rb +0 -63
- data/test_usage/test_metadata.rb +0 -104
- data/test_usage/test_screenshot.rb +0 -197
- data/test_usage/test_storage.rb +0 -52
@@ -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
|
@@ -0,0 +1,392 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Libvirt
|
4
|
+
module FFI
|
5
|
+
module Network
|
6
|
+
# https://libvirt.org/html/libvirt-libvirt-network.html
|
7
|
+
|
8
|
+
extend ::FFI::Library
|
9
|
+
extend Helpers
|
10
|
+
ffi_lib Util.library_path
|
11
|
+
|
12
|
+
EVENT_ID_TO_CALLBACK = {
|
13
|
+
LIFECYCLE: :virConnectNetworkEventLifecycleCallback
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
## Enums
|
17
|
+
|
18
|
+
# enum virConnectListAllNetworksFlags
|
19
|
+
enum :list_all_flags, [
|
20
|
+
:INACTIVE, 0x1,
|
21
|
+
:ACTIVE, 0x2,
|
22
|
+
:PERSISTENT, 0x4,
|
23
|
+
:TRANSIENT, 0x8,
|
24
|
+
:AUTOSTART, 0x10,
|
25
|
+
:NO_AUTOSTART, 0x20
|
26
|
+
]
|
27
|
+
|
28
|
+
# enum virIPAddrType
|
29
|
+
enum :ip_addr_type, [
|
30
|
+
:IPV4, 0x0,
|
31
|
+
:IPV6, 0x1
|
32
|
+
]
|
33
|
+
|
34
|
+
# enum virNetworkEventID
|
35
|
+
enum :event_id, [
|
36
|
+
:LIFECYCLE, 0x0 # virConnectNetworkEventLifecycleCallback
|
37
|
+
]
|
38
|
+
|
39
|
+
# enum virNetworkEventLifecycleType
|
40
|
+
enum :event_lifecycle_type, [
|
41
|
+
:DEFINED, 0x0,
|
42
|
+
:UNDEFINED, 0x1,
|
43
|
+
:STARTED, 0x2,
|
44
|
+
:STOPPED, 0x3
|
45
|
+
]
|
46
|
+
|
47
|
+
# enum virNetworkUpdateCommand
|
48
|
+
enum :update_command, [
|
49
|
+
:NONE, 0x0, # (invalid)
|
50
|
+
:MODIFY, 0x1, # modify an existing element
|
51
|
+
:DELETE, 0x2, # delete an existing element
|
52
|
+
:ADD_LAST, 0x3, # add an element at end of list
|
53
|
+
:ADD_FIRST, 0x4 # add an element at start of list
|
54
|
+
]
|
55
|
+
|
56
|
+
# enum virNetworkUpdateFlags
|
57
|
+
enum :update_flags, [
|
58
|
+
:AFFECT_CURRENT, 0x0, # affect live if network is active, config if its not active
|
59
|
+
:AFFECT_LIVE, 0x1, # affect live state of network only
|
60
|
+
:AFFECT_CONFIG, 0x2 # affect persistent config only
|
61
|
+
]
|
62
|
+
|
63
|
+
# enum virNetworkUpdateSection
|
64
|
+
enum :update_section, [
|
65
|
+
:NONE, 0x0, # (invalid)
|
66
|
+
:BRIDGE, 0x1, # <bridge>
|
67
|
+
:DOMAIN, 0x2, # <domain>
|
68
|
+
:IP, 0x3, # <ip>
|
69
|
+
:IP_DHCP_HOST, 0x4, # <ip>/<dhcp>/<host>
|
70
|
+
:IP_DHCP_RANGE, 0x5, # <ip>/<dhcp>/<range>
|
71
|
+
:FORWARD, 0x6, # <forward>
|
72
|
+
:FORWARD_INTERFACE, 0x7, # <forward>/<interface>
|
73
|
+
:FORWARD_PF, 0x8, # <forward>/<pf>
|
74
|
+
:PORTGROUP, 0x9, # <portgroup>
|
75
|
+
:DNS_HOST, 0xa, # <dns>/<host>
|
76
|
+
:DNS_TXT, 0xb, # <dns>/<txt>
|
77
|
+
:DNS_SRV, 0xc # <dns>/<srv>
|
78
|
+
]
|
79
|
+
|
80
|
+
# enum virNetworkXMLFlags
|
81
|
+
enum :xml_flags, [
|
82
|
+
:INACTIVE, 0x1 # dump inactive network information
|
83
|
+
]
|
84
|
+
|
85
|
+
## Structs
|
86
|
+
|
87
|
+
# struct virNetworkDHCPLease {
|
88
|
+
# char * iface # Network interface name
|
89
|
+
# long long expirytime # Seconds since epoch
|
90
|
+
# int type # virIPAddrType
|
91
|
+
# char * mac # MAC address
|
92
|
+
# char * iaid # IAID
|
93
|
+
# char * ipaddr # IP address
|
94
|
+
# unsigned int prefix # IP address prefix
|
95
|
+
# char * hostname # Hostname
|
96
|
+
# char * clientid # Client ID or DUID
|
97
|
+
# }
|
98
|
+
class DhcpLeaseStruct < ::FFI::Struct
|
99
|
+
layout :iface, :string,
|
100
|
+
:expirytime, :long_long,
|
101
|
+
:type, FFI::Network.enum_type(:ip_addr_type),
|
102
|
+
:mac, :string,
|
103
|
+
:iaid, :string,
|
104
|
+
:ipaddr, :string,
|
105
|
+
:prefix, :uint,
|
106
|
+
:hostname, :string,
|
107
|
+
:clientid, :string
|
108
|
+
end
|
109
|
+
|
110
|
+
## Callbacks
|
111
|
+
|
112
|
+
# typedef virConnectNetworkEventGenericCallback
|
113
|
+
# void virConnectNetworkEventGenericCallback (
|
114
|
+
# virConnectPtr conn,
|
115
|
+
# virNetworkPtr net,
|
116
|
+
# void * opaque
|
117
|
+
# )
|
118
|
+
callback :virConnectNetworkEventGenericCallback,
|
119
|
+
[:pointer, :pointer, :pointer],
|
120
|
+
:void
|
121
|
+
|
122
|
+
# typedef virConnectNetworkEventLifecycleCallback
|
123
|
+
# void virConnectNetworkEventLifecycleCallback (
|
124
|
+
# virConnectPtr conn,
|
125
|
+
# virNetworkPtr net,
|
126
|
+
# int event,
|
127
|
+
# int detail,
|
128
|
+
# void * opaque
|
129
|
+
# )
|
130
|
+
callback :virConnectNetworkEventLifecycleCallback,
|
131
|
+
[:pointer, :pointer, :event_lifecycle_type, :int, :pointer],
|
132
|
+
:void
|
133
|
+
|
134
|
+
## Functions
|
135
|
+
|
136
|
+
# int virConnectListAllNetworks (
|
137
|
+
# virConnectPtr conn,
|
138
|
+
# virNetworkPtr ** nets,
|
139
|
+
# unsigned int flags
|
140
|
+
# )
|
141
|
+
attach_function :virConnectListAllNetworks,
|
142
|
+
[:pointer, :pointer, :list_all_flags],
|
143
|
+
:int
|
144
|
+
|
145
|
+
# int virConnectListDefinedNetworks (
|
146
|
+
# virConnectPtr conn,
|
147
|
+
# char ** const names,
|
148
|
+
# int maxnames
|
149
|
+
# )
|
150
|
+
attach_function :virConnectListDefinedNetworks,
|
151
|
+
[:pointer, :pointer, :int],
|
152
|
+
:int
|
153
|
+
|
154
|
+
# int virConnectListNetworks (
|
155
|
+
# virConnectPtr conn,
|
156
|
+
# char ** const names,
|
157
|
+
# int maxnames
|
158
|
+
# )
|
159
|
+
attach_function :virConnectListNetworks,
|
160
|
+
[:pointer, :pointer, :int],
|
161
|
+
:int
|
162
|
+
|
163
|
+
# int virConnectNetworkEventDeregisterAny (
|
164
|
+
# virConnectPtr conn,
|
165
|
+
# int callbackID
|
166
|
+
# )
|
167
|
+
attach_function :virConnectNetworkEventDeregisterAny, [:pointer, :int], :int
|
168
|
+
|
169
|
+
# int virConnectNetworkEventRegisterAny (
|
170
|
+
# virConnectPtr conn,
|
171
|
+
# virNetworkPtr net,
|
172
|
+
# int eventID,
|
173
|
+
# virConnectNetworkEventGenericCallback cb,
|
174
|
+
# void * opaque,
|
175
|
+
# virFreeCallback freecb
|
176
|
+
# )
|
177
|
+
attach_function :virConnectNetworkEventRegisterAny,
|
178
|
+
[:pointer, :pointer, :event_id, :pointer, :pointer, :pointer],
|
179
|
+
:int
|
180
|
+
|
181
|
+
# int virConnectNumOfDefinedNetworks (
|
182
|
+
# virConnectPtr conn
|
183
|
+
# )
|
184
|
+
attach_function :virConnectNumOfDefinedNetworks,
|
185
|
+
[:pointer],
|
186
|
+
:int
|
187
|
+
|
188
|
+
# int virConnectNumOfNetworks (
|
189
|
+
# virConnectPtr conn
|
190
|
+
# )
|
191
|
+
attach_function :virConnectNumOfNetworks,
|
192
|
+
[:pointer],
|
193
|
+
:int
|
194
|
+
|
195
|
+
# int virNetworkCreate (
|
196
|
+
# virNetworkPtr network
|
197
|
+
# )
|
198
|
+
attach_function :virNetworkCreate,
|
199
|
+
[:pointer],
|
200
|
+
:int
|
201
|
+
|
202
|
+
# virNetworkPtr virNetworkCreateXML (
|
203
|
+
# virConnectPtr conn,
|
204
|
+
# const char * xmlDesc
|
205
|
+
# )
|
206
|
+
attach_function :virNetworkCreateXML,
|
207
|
+
[:pointer, :string],
|
208
|
+
:pointer
|
209
|
+
|
210
|
+
# void virNetworkDHCPLeaseFree (
|
211
|
+
# virNetworkDHCPLeasePtr lease
|
212
|
+
# )
|
213
|
+
attach_function :virNetworkDHCPLeaseFree,
|
214
|
+
[:pointer],
|
215
|
+
:void
|
216
|
+
|
217
|
+
# virNetworkPtr virNetworkDefineXML (
|
218
|
+
# virConnectPtr conn,
|
219
|
+
# const char * xml
|
220
|
+
# )
|
221
|
+
attach_function :virNetworkDefineXML,
|
222
|
+
[:pointer, :string],
|
223
|
+
:pointer
|
224
|
+
|
225
|
+
# int virNetworkDestroy (
|
226
|
+
# virNetworkPtr network
|
227
|
+
# )
|
228
|
+
attach_function :virNetworkDestroy,
|
229
|
+
[:pointer],
|
230
|
+
:int
|
231
|
+
|
232
|
+
# int virNetworkFree (
|
233
|
+
# virNetworkPtr network
|
234
|
+
# )
|
235
|
+
attach_function :virNetworkFree,
|
236
|
+
[:pointer],
|
237
|
+
:int
|
238
|
+
|
239
|
+
# int virNetworkGetAutostart (
|
240
|
+
# virNetworkPtr network,
|
241
|
+
# int * autostart
|
242
|
+
# )
|
243
|
+
attach_function :virNetworkGetAutostart,
|
244
|
+
[:pointer, :pointer],
|
245
|
+
:int
|
246
|
+
|
247
|
+
# char * virNetworkGetBridgeName (
|
248
|
+
# virNetworkPtr network
|
249
|
+
# )
|
250
|
+
attach_function :virNetworkGetBridgeName,
|
251
|
+
[:pointer],
|
252
|
+
:string
|
253
|
+
|
254
|
+
# virConnectPtr virNetworkGetConnect (
|
255
|
+
# virNetworkPtr net
|
256
|
+
# )
|
257
|
+
attach_function :virNetworkGetConnect,
|
258
|
+
[:pointer],
|
259
|
+
:pointer
|
260
|
+
|
261
|
+
# int virNetworkGetDHCPLeases (
|
262
|
+
# virNetworkPtr network,
|
263
|
+
# const char * mac,
|
264
|
+
# virNetworkDHCPLeasePtr ** leases,
|
265
|
+
# unsigned int flags
|
266
|
+
# )
|
267
|
+
attach_function :virNetworkGetDHCPLeases,
|
268
|
+
[:pointer, :string, :pointer, :uint],
|
269
|
+
:int
|
270
|
+
|
271
|
+
# const char * virNetworkGetName (
|
272
|
+
# virNetworkPtr network
|
273
|
+
# )
|
274
|
+
attach_function :virNetworkGetName,
|
275
|
+
[:pointer],
|
276
|
+
:string
|
277
|
+
|
278
|
+
# int virNetworkGetUUID (
|
279
|
+
# virNetworkPtr network,
|
280
|
+
# unsigned char * uuid
|
281
|
+
# )
|
282
|
+
attach_function :virNetworkGetUUID,
|
283
|
+
[:pointer, :pointer],
|
284
|
+
:int
|
285
|
+
|
286
|
+
# int virNetworkGetUUIDString (
|
287
|
+
# virNetworkPtr network,
|
288
|
+
# char * buf
|
289
|
+
# )
|
290
|
+
attach_function :virNetworkGetUUIDString,
|
291
|
+
[:pointer, :pointer],
|
292
|
+
:int
|
293
|
+
|
294
|
+
# char * virNetworkGetXMLDesc (
|
295
|
+
# virNetworkPtr network,
|
296
|
+
# unsigned int flags
|
297
|
+
# )
|
298
|
+
attach_function :virNetworkGetXMLDesc,
|
299
|
+
[:pointer, :xml_flags],
|
300
|
+
:string
|
301
|
+
|
302
|
+
# int virNetworkIsActive (
|
303
|
+
# virNetworkPtr net
|
304
|
+
# )
|
305
|
+
attach_function :virNetworkIsActive,
|
306
|
+
[:pointer],
|
307
|
+
:int
|
308
|
+
|
309
|
+
# int virNetworkIsPersistent (
|
310
|
+
# virNetworkPtr net
|
311
|
+
# )
|
312
|
+
attach_function :virNetworkIsPersistent,
|
313
|
+
[:pointer],
|
314
|
+
:int
|
315
|
+
|
316
|
+
# virNetworkPtr virNetworkLookupByName (
|
317
|
+
# virConnectPtr conn,
|
318
|
+
# const char * name
|
319
|
+
# )
|
320
|
+
attach_function :virNetworkLookupByName,
|
321
|
+
[:pointer, :string],
|
322
|
+
:pointer
|
323
|
+
|
324
|
+
# virNetworkPtr virNetworkLookupByUUID (
|
325
|
+
# virConnectPtr conn,
|
326
|
+
# const unsigned char * uuid
|
327
|
+
# )
|
328
|
+
attach_function :virNetworkLookupByUUID,
|
329
|
+
[:pointer, :pointer],
|
330
|
+
:pointer
|
331
|
+
|
332
|
+
# virNetworkPtr virNetworkLookupByUUIDString (
|
333
|
+
# virConnectPtr conn,
|
334
|
+
# const char * uuidstr
|
335
|
+
# )
|
336
|
+
attach_function :virNetworkLookupByUUIDString,
|
337
|
+
[:pointer, :string],
|
338
|
+
:pointer
|
339
|
+
|
340
|
+
# int virNetworkRef (
|
341
|
+
# virNetworkPtr network
|
342
|
+
# )
|
343
|
+
attach_function :virNetworkRef,
|
344
|
+
[:pointer],
|
345
|
+
:int
|
346
|
+
|
347
|
+
# int virNetworkSetAutostart (
|
348
|
+
# virNetworkPtr network,
|
349
|
+
# int autostart
|
350
|
+
# )
|
351
|
+
attach_function :virNetworkSetAutostart,
|
352
|
+
[:pointer, :int],
|
353
|
+
:int
|
354
|
+
|
355
|
+
# int virNetworkUndefine (
|
356
|
+
# virNetworkPtr network
|
357
|
+
# )
|
358
|
+
attach_function :virNetworkUndefine,
|
359
|
+
[:pointer],
|
360
|
+
:int
|
361
|
+
|
362
|
+
# int virNetworkUpdate (
|
363
|
+
# virNetworkPtr network,
|
364
|
+
# unsigned int command,
|
365
|
+
# unsigned int section,
|
366
|
+
# int parentIndex,
|
367
|
+
# const char * xml,
|
368
|
+
# unsigned int flags
|
369
|
+
# )
|
370
|
+
attach_function :virNetworkUpdate,
|
371
|
+
[:pointer, :update_command, :update_section, :int, :string, :update_flags],
|
372
|
+
:int
|
373
|
+
|
374
|
+
## Helpers
|
375
|
+
module_function
|
376
|
+
|
377
|
+
# Creates event callback function for provided event_id
|
378
|
+
# @param event_id [Integer,Symbol]
|
379
|
+
# @yield connect_ptr, network_ptr, *args, opaque_ptr
|
380
|
+
# @return [FFI::Function]
|
381
|
+
def event_callback_for(event_id, &block)
|
382
|
+
event_id_sym = event_id.is_a?(Symbol) ? event_id : enum_type(:event_id)[event_id]
|
383
|
+
|
384
|
+
callback_name = EVENT_ID_TO_CALLBACK.fetch(event_id_sym)
|
385
|
+
callback_function(callback_name) do |*args|
|
386
|
+
Util.log(:debug, name) { ".event_callback_for #{event_id_sym} CALLBACK #{args.map(&:to_s).join(', ')}," }
|
387
|
+
block.call(*args)
|
388
|
+
end
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
end
|
data/lib/libvirt/ffi/storage.rb
CHANGED
@@ -218,7 +218,7 @@ module Libvirt
|
|
218
218
|
|
219
219
|
# Creates event callback function for provided event_id
|
220
220
|
# @param event_id [Integer,Symbol]
|
221
|
-
# @yield connect_ptr,
|
221
|
+
# @yield connect_ptr, pool_ptr, *args, opaque_ptr
|
222
222
|
# @return [FFI::Function]
|
223
223
|
def event_callback_for(event_id, &block)
|
224
224
|
event_id_sym = event_id.is_a?(Symbol) ? event_id : enum_type(:event_id)[event_id]
|
data/lib/libvirt/ffi.rb
CHANGED
@@ -29,12 +29,20 @@ module Libvirt
|
|
29
29
|
[cb_data, cb_data_free_func]
|
30
30
|
end
|
31
31
|
|
32
|
-
def store_struct(cb_data,
|
32
|
+
def store_struct(cb_data, options)
|
33
33
|
dbg { '#store_struct' }
|
34
34
|
|
35
|
+
options.assert_valid_keys(:connection_pointer, :callback_id, :cb, :opaque, :free_func)
|
36
|
+
connection_pointer = options.fetch(:connection_pointer)
|
37
|
+
callback_id = options.fetch(:callback_id)
|
38
|
+
cb = options.fetch(:cb)
|
39
|
+
opaque = options.fetch(:opaque)
|
40
|
+
free_func = options.fetch(:free_func)
|
35
41
|
cb_data[:connection_pointer] = connection_pointer
|
36
42
|
cb_data[:callback_id] = callback_id
|
37
|
-
@inner_storage[connection_pointer.address][callback_id] = {
|
43
|
+
@inner_storage[connection_pointer.address][callback_id] = {
|
44
|
+
cb: cb, opaque: opaque, pointer: cb_data.pointer, free_func: free_func
|
45
|
+
}
|
38
46
|
end
|
39
47
|
|
40
48
|
def remove_struct(pointer)
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Libvirt
|
4
|
+
class Interface
|
5
|
+
# @param pointer [FFI::Pointer]
|
6
|
+
def self.load_ref(pointer)
|
7
|
+
result = FFI::Interface.virInterfaceRef(pointer)
|
8
|
+
raise Errors::LibError, "Couldn't retrieve interface reference" if result.negative?
|
9
|
+
|
10
|
+
new(pointer)
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param pointer [FFI::Pointer]
|
14
|
+
def initialize(pointer)
|
15
|
+
@ptr = pointer
|
16
|
+
|
17
|
+
free = ->(obj_id) do
|
18
|
+
dbg { "Finalize Libvirt::Interface object_id=0x#{obj_id.to_s(16)}, pointer=0x#{@ptr.address.to_s(16)}" }
|
19
|
+
return unless @ptr
|
20
|
+
|
21
|
+
warn "Couldn't free Libvirt::Interface object_id=0x#{obj_id.to_s(16)}, pointer=0x#{@ptr.address.to_s(16)}" if FFI::Interface.virInterfaceFree(@ptr).negative?
|
22
|
+
end
|
23
|
+
ObjectSpace.define_finalizer(self, free)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [FFI::Pointer]
|
27
|
+
def to_ptr
|
28
|
+
@ptr
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [String]
|
32
|
+
# @raise [Libvirt::Errors::LibError]
|
33
|
+
def name
|
34
|
+
result = FFI::Interface.virInterfaceGetName(@ptr)
|
35
|
+
raise Errors::LibError, "Couldn't get interface name" if result.nil?
|
36
|
+
|
37
|
+
result
|
38
|
+
end
|
39
|
+
|
40
|
+
# @return [String]
|
41
|
+
# @raise [Libvirt::Errors::LibError]
|
42
|
+
def mac
|
43
|
+
result = FFI::Interface.virInterfaceGetMACString(@ptr)
|
44
|
+
raise Errors::LibError, "Couldn't get interface mac" if result.nil?
|
45
|
+
|
46
|
+
result
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param options_or_flags [Array<Symbol>,Hash{Symbol=>Boolean},Integer,Symbol,nil]
|
50
|
+
# @raise [Libvirt::Errors::LibError]
|
51
|
+
def xml_desc(options_or_flags = nil)
|
52
|
+
flags = Util.parse_flags options_or_flags, FFI::Interface.enum_type(:xml_flags)
|
53
|
+
result = FFI::Interface.virInterfaceGetXMLDesc(@ptr, flags)
|
54
|
+
raise Errors::LibError, "Couldn't get interface xml desc" if result.nil?
|
55
|
+
|
56
|
+
result
|
57
|
+
end
|
58
|
+
|
59
|
+
# @return [Boolean]
|
60
|
+
# @raise [Libvirt::Errors::LibError]
|
61
|
+
def active?
|
62
|
+
result = FFI::Interface.virInterfaceIsActive(@ptr)
|
63
|
+
raise Errors::LibError, "Couldn't get interface is active" if result.nil?
|
64
|
+
|
65
|
+
result == 1
|
66
|
+
end
|
67
|
+
|
68
|
+
# @raise [Libvirt::Errors::LibError]
|
69
|
+
def start
|
70
|
+
result = FFI::Interface.virInterfaceCreate(@ptr, 0)
|
71
|
+
raise Errors::LibError, "Couldn't start interface" if result.negative?
|
72
|
+
end
|
73
|
+
|
74
|
+
# @raise [Libvirt::Errors::LibError]
|
75
|
+
def destroy
|
76
|
+
result = FFI::Interface.virInterfaceDestroy(@ptr, 0)
|
77
|
+
raise Errors::LibError, "Couldn't destroy interface" if result.negative?
|
78
|
+
end
|
79
|
+
|
80
|
+
# @raise [Libvirt::Errors::LibError]
|
81
|
+
def undefine
|
82
|
+
result = FFI::Interface.virInterfaceUndefine(@ptr)
|
83
|
+
raise Errors::LibError, "Couldn't undefine interface" if result.negative?
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def dbg(&block)
|
89
|
+
Util.log(:debug, 'Libvirt::Network', &block)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|