libvirt_ffi 0.8.0 → 0.8.1
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/.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/connection.rb +75 -77
- data/lib/libvirt/ffi/host.rb +78 -39
- data/lib/libvirt/loggable.rb +58 -0
- data/lib/libvirt/util.rb +87 -64
- data/lib/libvirt/version.rb +1 -1
- data/lib/libvirt/xml/generic.rb +2 -2
- data/lib/libvirt/xml.rb +6 -5
- data/lib/libvirt.rb +16 -16
- data/libvirt.gemspec +11 -13
- metadata +6 -28
- 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_interface.rb +0 -47
- data/test_usage/test_libvirtd_restart.rb +0 -63
- data/test_usage/test_metadata.rb +0 -104
- data/test_usage/test_network.rb +0 -73
- data/test_usage/test_screenshot.rb +0 -197
- data/test_usage/test_storage.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d81d03c71f0077138bdc7369c7468138333eb45ae1de85c857089b263975e8c4
|
4
|
+
data.tar.gz: cdae17b6ecb8174ee12247d31d4419a9bf367ba17a460c6f9e3e5cc347d313ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f2a8d886ed935f536bd5e04fd9e710d953d0f7f78a8e408220018784291ac3ba71f2e342dcaedbe44b3b57c2e1c77cd36784a05f9d6a0b486ddc6b1dfeb1bd3
|
7
|
+
data.tar.gz: 3df70b41610251d35c2986ba77fd617ee15cb956dc690f850b4650ac34ef4fee80072987d83b1cefcf806501fd87e6401def2c2d2d120e5d8db1b09136d21742
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: Tests
|
2
|
+
on:
|
3
|
+
pull_request:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby: [ '2.6', '2.7', '3.0' ]
|
14
|
+
name: Tests with Ruby ${{ matrix.ruby }}
|
15
|
+
steps:
|
16
|
+
- name: Install libvirt
|
17
|
+
run: sudo apt-get install -y libvirt-dev libvirt0
|
18
|
+
- uses: actions/checkout@v2
|
19
|
+
- uses: actions/setup-ruby@v1
|
20
|
+
with:
|
21
|
+
ruby-version: ${{ matrix.ruby }}
|
22
|
+
- name: Run tests
|
23
|
+
run: |
|
24
|
+
gem install bundler
|
25
|
+
bundle install
|
26
|
+
bundle exec rake
|
data/.gitignore
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
@@ -5,14 +5,11 @@ source 'https://rubygems.org'
|
|
5
5
|
# Specify your gem's dependencies in libvirt.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem '
|
9
|
-
gem '
|
10
|
-
|
8
|
+
gem 'activesupport'
|
9
|
+
gem 'async', '~> 1.24'
|
10
|
+
gem 'gc_tracer'
|
11
|
+
gem 'get_process_mem'
|
11
12
|
gem 'nokogiri'
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
gem 'async', '~> 1.24'
|
16
|
-
gem 'gc_tracer'
|
17
|
-
gem 'get_process_mem'
|
18
|
-
end
|
13
|
+
gem 'rake', '~> 12.0'
|
14
|
+
gem 'rspec', '~> 3.9'
|
15
|
+
gem 'rubocop', '~> 0.80.1'
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
32
|
|
33
33
|
## Contributing
|
34
34
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/senid231/libvirt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/senid231/libvirt/blob/master/CODE_OF_CONDUCT.md).
|
36
36
|
|
37
37
|
|
38
38
|
## License
|
@@ -41,4 +41,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
41
41
|
|
42
42
|
## Code of Conduct
|
43
43
|
|
44
|
-
Everyone interacting in the Libvirt project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
44
|
+
Everyone interacting in the Libvirt project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/senid231/libvirt/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
@@ -1,15 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
|
-
require '
|
4
|
+
require 'rspec/core/rake_task'
|
5
5
|
require 'rubocop/rake_task'
|
6
6
|
|
7
|
-
|
8
|
-
t.libs << 'test'
|
9
|
-
t.libs << 'lib'
|
10
|
-
t.test_files = FileList['test/**/*_test.rb']
|
11
|
-
end
|
12
|
-
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
13
8
|
RuboCop::RakeTask.new(:rubocop)
|
14
9
|
|
15
|
-
task default: [:rubocop, :
|
10
|
+
task default: [:rubocop, :spec]
|
data/lib/libvirt/connection.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module Libvirt
|
4
4
|
class Connection
|
5
|
+
include Loggable
|
6
|
+
|
5
7
|
DOMAIN_EVENT_IDS = FFI::Domain.enum_type(:event_id).symbols.dup.freeze
|
6
8
|
POOL_EVENT_IDS = FFI::Storage.enum_type(:event_id).symbols.dup.freeze
|
7
9
|
NETWORK_EVENT_IDS = FFI::Network.enum_type(:event_id).symbols.dup.freeze
|
@@ -57,56 +59,68 @@ module Libvirt
|
|
57
59
|
block.call(connection, reason, opaque)
|
58
60
|
end
|
59
61
|
|
60
|
-
def self.load_ref(
|
61
|
-
|
62
|
-
raise Errors::LibError, "Couldn't retrieve connection reference" if
|
62
|
+
def self.load_ref(ptr)
|
63
|
+
result = FFI::Host.virConnectRef(ptr)
|
64
|
+
raise Errors::LibError, "Couldn't retrieve connection reference" if result.negative?
|
63
65
|
|
64
|
-
|
66
|
+
uri = FFI::Host.virConnectGetURI(ptr)
|
67
|
+
new(uri).tap { |c| c.instance_variable_set(:@ptr, ptr) }
|
65
68
|
end
|
66
69
|
|
70
|
+
attr_reader :uri
|
71
|
+
|
67
72
|
def initialize(uri)
|
68
73
|
@uri = uri
|
69
|
-
@
|
74
|
+
@ptr = ::FFI::Pointer.new(0)
|
70
75
|
@close_data = nil
|
71
76
|
|
72
|
-
|
73
|
-
|
74
|
-
return if @conn_ptr.null?
|
77
|
+
Util.define_finalizer(self) { |pointer| FFI::Host.virConnectClose(pointer) }
|
78
|
+
end
|
75
79
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
+
def to_s
|
81
|
+
"#<#{self.class}:0x#{object_id.to_s(16)} @uri=#{@uri.inspect} @ptr=0x#{@ptr.address.to_s(16)}>"
|
82
|
+
end
|
83
|
+
|
84
|
+
def inspect
|
85
|
+
to_s
|
86
|
+
end
|
87
|
+
|
88
|
+
def to_ptr
|
89
|
+
@ptr
|
80
90
|
end
|
81
91
|
|
82
92
|
def open
|
83
|
-
@
|
84
|
-
raise Errors::LibError, "Couldn't open connection to #{@uri.inspect}" if @
|
93
|
+
@ptr = FFI::Host.virConnectOpen(@uri)
|
94
|
+
raise Errors::LibError, "Couldn't open connection to #{@uri.inspect}" if @ptr.null?
|
95
|
+
|
96
|
+
dbg { 'opened' }
|
85
97
|
|
86
98
|
true
|
87
99
|
end
|
88
100
|
|
89
101
|
def close
|
90
|
-
result = FFI::Host.virConnectClose(@
|
102
|
+
result = FFI::Host.virConnectClose(@ptr)
|
91
103
|
raise Errors::LibError, "Couldn't close connection to #{@uri.inspect}" if result.negative?
|
92
104
|
|
93
|
-
|
105
|
+
dbg { 'closed' }
|
106
|
+
|
107
|
+
@ptr = ::FFI::Pointer.new(0)
|
94
108
|
true
|
95
109
|
end
|
96
110
|
|
97
111
|
def opened?
|
98
|
-
!@
|
112
|
+
!@ptr.null?
|
99
113
|
end
|
100
114
|
|
101
|
-
def
|
102
|
-
|
115
|
+
def closed?
|
116
|
+
!opened?
|
103
117
|
end
|
104
118
|
|
105
119
|
def version
|
106
120
|
check_open!
|
107
121
|
|
108
122
|
version_ptr = ::FFI::MemoryPointer.new(:ulong)
|
109
|
-
result = FFI::Host.virConnectGetVersion(@
|
123
|
+
result = FFI::Host.virConnectGetVersion(@ptr, version_ptr)
|
110
124
|
raise Errors::LibError, "Couldn't retrieve connection version" if result.negative?
|
111
125
|
|
112
126
|
version_number = version_ptr.get_ulong(0)
|
@@ -114,29 +128,21 @@ module Libvirt
|
|
114
128
|
end
|
115
129
|
|
116
130
|
def set_keep_alive(interval, count)
|
117
|
-
result = FFI::Host.virConnectSetKeepAlive(@
|
131
|
+
result = FFI::Host.virConnectSetKeepAlive(@ptr, interval, count)
|
118
132
|
raise Errors::LibError, "Couldn't set connection keep_alive" if result.negative?
|
119
133
|
|
120
134
|
result.zero?
|
121
135
|
end
|
122
136
|
|
123
137
|
def free_memory
|
124
|
-
result = FFI::Host.virNodeGetFreeMemory(@
|
138
|
+
result = FFI::Host.virNodeGetFreeMemory(@ptr)
|
125
139
|
raise Errors::LibError, "Couldn't set connection keep_alive" if result.negative?
|
126
140
|
|
127
141
|
result
|
128
142
|
end
|
129
143
|
|
130
|
-
def to_s
|
131
|
-
"#<#{self.class}:0x#{object_id.to_s(16)} @uri=#{@uri.inspect} @conn_ptr=0x#{@conn_ptr.address.to_s(16)}>"
|
132
|
-
end
|
133
|
-
|
134
|
-
def inspect
|
135
|
-
to_s
|
136
|
-
end
|
137
|
-
|
138
144
|
def list_all_domains_qty(flags = 0)
|
139
|
-
result = FFI::Domain.virConnectListAllDomains(@
|
145
|
+
result = FFI::Domain.virConnectListAllDomains(@ptr, nil, flags)
|
140
146
|
raise Errors::LibError, "Couldn't retrieve domains qty with flags #{flags.to_s(16)}" if result.negative?
|
141
147
|
|
142
148
|
result
|
@@ -147,7 +153,7 @@ module Libvirt
|
|
147
153
|
return [] if size.zero?
|
148
154
|
|
149
155
|
domains_ptr = ::FFI::MemoryPointer.new(:pointer, size)
|
150
|
-
result = FFI::Domain.virConnectListAllDomains(@
|
156
|
+
result = FFI::Domain.virConnectListAllDomains(@ptr, domains_ptr, flags)
|
151
157
|
raise Errors::LibError, "Couldn't retrieve domains list with flags #{flags.to_s(16)}" if result.negative?
|
152
158
|
|
153
159
|
ptr = domains_ptr.read_pointer
|
@@ -156,7 +162,7 @@ module Libvirt
|
|
156
162
|
|
157
163
|
def list_all_storage_pools_qty(options_or_flags = nil)
|
158
164
|
flags = Util.parse_flags options_or_flags, FFI::Storage.enum_type(:list_all_pools_flags)
|
159
|
-
result = FFI::Storage.virConnectListAllStoragePools(@
|
165
|
+
result = FFI::Storage.virConnectListAllStoragePools(@ptr, nil, flags)
|
160
166
|
raise Errors::LibError, "Couldn't retrieve storage pools qty with flags #{flags.to_s(16)}" if result.negative?
|
161
167
|
|
162
168
|
result
|
@@ -168,7 +174,7 @@ module Libvirt
|
|
168
174
|
return [] if size.zero?
|
169
175
|
|
170
176
|
storage_pools_ptr = ::FFI::MemoryPointer.new(:pointer, size)
|
171
|
-
result = FFI::Storage.virConnectListAllStoragePools(@
|
177
|
+
result = FFI::Storage.virConnectListAllStoragePools(@ptr, storage_pools_ptr, flags)
|
172
178
|
raise Errors::LibError, "Couldn't retrieve storage pools list with flags #{flags.to_s(16)}" if result.negative?
|
173
179
|
|
174
180
|
ptr = storage_pools_ptr.read_pointer
|
@@ -180,7 +186,7 @@ module Libvirt
|
|
180
186
|
# @raise [Libvirt::Errors::LibError]
|
181
187
|
def list_all_networks_qty(options_or_flags = nil)
|
182
188
|
flags = Util.parse_flags options_or_flags, FFI::Network.enum_type(:list_all_flags)
|
183
|
-
result = FFI::Network.virConnectListAllNetworks(@
|
189
|
+
result = FFI::Network.virConnectListAllNetworks(@ptr, nil, flags)
|
184
190
|
raise Errors::LibError, "Couldn't retrieve networks qty with flags #{flags.to_s(16)}" if result.negative?
|
185
191
|
|
186
192
|
result
|
@@ -195,7 +201,7 @@ module Libvirt
|
|
195
201
|
return [] if size.zero?
|
196
202
|
|
197
203
|
networks_ptr = ::FFI::MemoryPointer.new(:pointer, size)
|
198
|
-
result = FFI::Network.virConnectListAllNetworks(@
|
204
|
+
result = FFI::Network.virConnectListAllNetworks(@ptr, networks_ptr, 0)
|
199
205
|
raise Errors::LibError, "Couldn't retrieve networks list" if result.negative?
|
200
206
|
|
201
207
|
ptr = networks_ptr.read_pointer
|
@@ -207,7 +213,7 @@ module Libvirt
|
|
207
213
|
# @raise [Libvirt::Errors::LibError]
|
208
214
|
def list_all_interfaces_qty(options_or_flags = nil)
|
209
215
|
flags = Util.parse_flags options_or_flags, FFI::Interface.enum_type(:list_all_flags)
|
210
|
-
result = FFI::Interface.virConnectListAllInterfaces(@
|
216
|
+
result = FFI::Interface.virConnectListAllInterfaces(@ptr, nil, flags)
|
211
217
|
raise Errors::LibError, "Couldn't retrieve interfaces qty with flags #{flags.to_s(16)}" if result.negative?
|
212
218
|
|
213
219
|
result
|
@@ -222,7 +228,7 @@ module Libvirt
|
|
222
228
|
return [] if size.zero?
|
223
229
|
|
224
230
|
interfaces_ptr = ::FFI::MemoryPointer.new(:pointer, size)
|
225
|
-
result = FFI::Interface.virConnectListAllInterfaces(@
|
231
|
+
result = FFI::Interface.virConnectListAllInterfaces(@ptr, interfaces_ptr, 0)
|
226
232
|
raise Errors::LibError, "Couldn't retrieve interfaces list" if result.negative?
|
227
233
|
|
228
234
|
ptr = interfaces_ptr.read_pointer
|
@@ -230,11 +236,11 @@ module Libvirt
|
|
230
236
|
end
|
231
237
|
|
232
238
|
def register_close_callback(opaque = nil, &block)
|
233
|
-
dbg { "
|
239
|
+
dbg { "opaque=#{opaque}" }
|
234
240
|
|
235
241
|
cb_data, cb_data_free_func = CLOSE_STORAGE.allocate_struct
|
236
242
|
result = FFI::Host.virConnectRegisterCloseCallback(
|
237
|
-
@
|
243
|
+
@ptr,
|
238
244
|
CLOSE_CALLBACK,
|
239
245
|
cb_data.pointer,
|
240
246
|
cb_data_free_func
|
@@ -246,7 +252,7 @@ module Libvirt
|
|
246
252
|
|
247
253
|
CLOSE_STORAGE.store_struct(
|
248
254
|
cb_data,
|
249
|
-
connection_pointer: @
|
255
|
+
connection_pointer: @ptr,
|
250
256
|
callback_id: result,
|
251
257
|
cb: block,
|
252
258
|
opaque: opaque,
|
@@ -256,9 +262,9 @@ module Libvirt
|
|
256
262
|
end
|
257
263
|
|
258
264
|
def deregister_close_callback
|
259
|
-
dbg { '
|
265
|
+
dbg { 'deregister' }
|
260
266
|
|
261
|
-
result = FFI::Host.virConnectUnregisterCloseCallback(@
|
267
|
+
result = FFI::Host.virConnectUnregisterCloseCallback(@ptr, CLOSE_CALLBACK)
|
262
268
|
raise Errors::LibError, "Couldn't deregister close callback" if result.negative?
|
263
269
|
|
264
270
|
# virConnectUnregisterCloseCallback will call free func
|
@@ -268,7 +274,7 @@ module Libvirt
|
|
268
274
|
|
269
275
|
# @yield conn, dom, *args
|
270
276
|
def register_domain_event_callback(event_id, domain = nil, opaque = nil, &block)
|
271
|
-
dbg { "
|
277
|
+
dbg { "event_id=#{event_id}" }
|
272
278
|
|
273
279
|
enum = FFI::Domain.enum_type(:event_id)
|
274
280
|
event_id, event_id_sym = Util.parse_enum(enum, event_id)
|
@@ -277,7 +283,7 @@ module Libvirt
|
|
277
283
|
cb_data, cb_data_free_func = DOMAIN_STORAGE.allocate_struct
|
278
284
|
|
279
285
|
result = FFI::Domain.virConnectDomainEventRegisterAny(
|
280
|
-
@
|
286
|
+
@ptr,
|
281
287
|
domain&.to_ptr,
|
282
288
|
event_id,
|
283
289
|
cb,
|
@@ -301,9 +307,9 @@ module Libvirt
|
|
301
307
|
end
|
302
308
|
|
303
309
|
def deregister_domain_event_callback(callback_id)
|
304
|
-
dbg { "
|
310
|
+
dbg { "callback_id=#{callback_id}" }
|
305
311
|
|
306
|
-
result = FFI::Domain.virConnectDomainEventDeregisterAny(@
|
312
|
+
result = FFI::Domain.virConnectDomainEventDeregisterAny(@ptr, callback_id)
|
307
313
|
raise Errors::LibError, "Couldn't deregister domain event callback" if result.negative?
|
308
314
|
|
309
315
|
# virConnectDomainEventDeregisterAny will call free func
|
@@ -312,7 +318,7 @@ module Libvirt
|
|
312
318
|
end
|
313
319
|
|
314
320
|
def register_storage_pool_event_callback(event_id, storage_pool = nil, opaque = nil, &block)
|
315
|
-
dbg { "
|
321
|
+
dbg { "event_id=#{event_id}" }
|
316
322
|
|
317
323
|
enum = FFI::Storage.enum_type(:event_id)
|
318
324
|
event_id, event_id_sym = Util.parse_enum(enum, event_id)
|
@@ -321,7 +327,7 @@ module Libvirt
|
|
321
327
|
cb_data, cb_data_free_func = POOL_STORAGE.allocate_struct
|
322
328
|
|
323
329
|
result = FFI::Storage.virConnectStoragePoolEventRegisterAny(
|
324
|
-
@
|
330
|
+
@ptr,
|
325
331
|
storage_pool&.to_ptr,
|
326
332
|
event_id,
|
327
333
|
cb,
|
@@ -335,7 +341,7 @@ module Libvirt
|
|
335
341
|
|
336
342
|
POOL_STORAGE.store_struct(
|
337
343
|
cb_data,
|
338
|
-
connection_pointer: @
|
344
|
+
connection_pointer: @ptr,
|
339
345
|
callback_id: result,
|
340
346
|
cb: block,
|
341
347
|
opaque: opaque,
|
@@ -345,9 +351,9 @@ module Libvirt
|
|
345
351
|
end
|
346
352
|
|
347
353
|
def deregister_storage_pool_event_callback(callback_id)
|
348
|
-
dbg { "
|
354
|
+
dbg { "callback_id=#{callback_id}" }
|
349
355
|
|
350
|
-
result = FFI::Storage.virConnectStoragePoolEventDeregisterAny(@
|
356
|
+
result = FFI::Storage.virConnectStoragePoolEventDeregisterAny(@ptr, callback_id)
|
351
357
|
raise Errors::LibError, "Couldn't deregister storage pool event callback" if result.negative?
|
352
358
|
|
353
359
|
# virConnectStoragePoolEventDeregisterAny will call free func
|
@@ -356,7 +362,7 @@ module Libvirt
|
|
356
362
|
end
|
357
363
|
|
358
364
|
def register_network_event_callback(event_id, network = nil, opaque = nil, &block)
|
359
|
-
dbg { "
|
365
|
+
dbg { "event_id=#{event_id}" }
|
360
366
|
|
361
367
|
enum = FFI::Network.enum_type(:event_id)
|
362
368
|
event_id, event_id_sym = Util.parse_enum(enum, event_id)
|
@@ -365,7 +371,7 @@ module Libvirt
|
|
365
371
|
cb_data, cb_data_free_func = NETWORK_STORAGE.allocate_struct
|
366
372
|
|
367
373
|
result = FFI::Network.virConnectNetworkEventRegisterAny(
|
368
|
-
@
|
374
|
+
@ptr,
|
369
375
|
network&.to_ptr,
|
370
376
|
event_id,
|
371
377
|
cb,
|
@@ -379,7 +385,7 @@ module Libvirt
|
|
379
385
|
|
380
386
|
NETWORK_STORAGE.store_struct(
|
381
387
|
cb_data,
|
382
|
-
connection_pointer: @
|
388
|
+
connection_pointer: @ptr,
|
383
389
|
callback_id: result,
|
384
390
|
cb: block,
|
385
391
|
opaque: opaque,
|
@@ -389,9 +395,9 @@ module Libvirt
|
|
389
395
|
end
|
390
396
|
|
391
397
|
def deregister_network_event_callback(callback_id)
|
392
|
-
dbg { "
|
398
|
+
dbg { "callback_id=#{callback_id}" }
|
393
399
|
|
394
|
-
result = FFI::Network.virConnectNetworkEventDeregisterAny(@
|
400
|
+
result = FFI::Network.virConnectNetworkEventDeregisterAny(@ptr, callback_id)
|
395
401
|
raise Errors::LibError, "Couldn't deregister network event callback" if result.negative?
|
396
402
|
|
397
403
|
# virConnectNetworkEventDeregisterAny will call free func
|
@@ -401,7 +407,7 @@ module Libvirt
|
|
401
407
|
|
402
408
|
def lib_version
|
403
409
|
version_ptr = ::FFI::MemoryPointer.new(:ulong)
|
404
|
-
result = FFI::Host.virConnectGetLibVersion(@
|
410
|
+
result = FFI::Host.virConnectGetLibVersion(@ptr, version_ptr)
|
405
411
|
raise Errors::LibError, "Couldn't get connection lib version" if result.negative?
|
406
412
|
|
407
413
|
version_number = version_ptr.get_ulong(0)
|
@@ -409,28 +415,28 @@ module Libvirt
|
|
409
415
|
end
|
410
416
|
|
411
417
|
def hostname
|
412
|
-
FFI::Host.virConnectGetHostname(@
|
418
|
+
FFI::Host.virConnectGetHostname(@ptr)
|
413
419
|
end
|
414
420
|
|
415
421
|
# @param type [String,NilClass]
|
416
422
|
def max_vcpus(type = nil)
|
417
|
-
FFI::Host.virConnectGetMaxVcpus(@
|
423
|
+
FFI::Host.virConnectGetMaxVcpus(@ptr, type)
|
418
424
|
end
|
419
425
|
|
420
426
|
def capabilities
|
421
|
-
FFI::Host.virConnectGetCapabilities(@
|
427
|
+
FFI::Host.virConnectGetCapabilities(@ptr)
|
422
428
|
end
|
423
429
|
|
424
430
|
def node_info
|
425
431
|
node_info_ptr = ::FFI::MemoryPointer.new(FFI::Host::NodeInfoStruct.by_value)
|
426
|
-
result = FFI::Host.virNodeGetInfo(@
|
432
|
+
result = FFI::Host.virNodeGetInfo(@ptr, node_info_ptr)
|
427
433
|
raise Errors::LibError, "Couldn't get connection node info" if result.negative?
|
428
434
|
|
429
435
|
NodeInfo.new(node_info_ptr)
|
430
436
|
end
|
431
437
|
|
432
438
|
def stream(flags = 0)
|
433
|
-
pointer = FFI::Stream.virStreamNew(@
|
439
|
+
pointer = FFI::Stream.virStreamNew(@ptr, flags)
|
434
440
|
raise Errors::LibError, "Couldn't create stream" if pointer.null?
|
435
441
|
|
436
442
|
Stream.new(pointer)
|
@@ -438,7 +444,7 @@ module Libvirt
|
|
438
444
|
|
439
445
|
def define_domain(xml, options_or_flags = nil)
|
440
446
|
flags = Util.parse_flags options_or_flags, FFI::Domain.enum_type(:define_flags)
|
441
|
-
pointer = FFI::Domain.virDomainDefineXMLFlags(@
|
447
|
+
pointer = FFI::Domain.virDomainDefineXMLFlags(@ptr, xml, flags)
|
442
448
|
raise Errors::LibError, "Couldn't define domain" if pointer.null?
|
443
449
|
|
444
450
|
Domain.new(pointer)
|
@@ -465,7 +471,7 @@ module Libvirt
|
|
465
471
|
# @param xml [String]
|
466
472
|
# @raise [Libvirt::Errors::LibError]
|
467
473
|
def define_interface(xml)
|
468
|
-
pointer = FFI::Interface.virInterfaceDefineXML(@
|
474
|
+
pointer = FFI::Interface.virInterfaceDefineXML(@ptr, xml, 0)
|
469
475
|
raise Errors::LibError, "Couldn't define interface with xml" if pointer.null?
|
470
476
|
|
471
477
|
Interface.new(pointer)
|
@@ -473,34 +479,26 @@ module Libvirt
|
|
473
479
|
|
474
480
|
# @raise [Libvirt::Errors::LibError]
|
475
481
|
def begin_interface_change
|
476
|
-
result = FFI::Interface.virInterfaceChangeBegin(@
|
482
|
+
result = FFI::Interface.virInterfaceChangeBegin(@ptr, 0)
|
477
483
|
raise Errors::LibError, "Couldn't begin interface change" if result.negative?
|
478
484
|
end
|
479
485
|
|
480
486
|
# @raise [Libvirt::Errors::LibError]
|
481
487
|
def commit_interface_change
|
482
|
-
result = FFI::Interface.virInterfaceChangeCommit(@
|
488
|
+
result = FFI::Interface.virInterfaceChangeCommit(@ptr, 0)
|
483
489
|
raise Errors::LibError, "Couldn't commit interface change" if result.negative?
|
484
490
|
end
|
485
491
|
|
486
492
|
# @raise [Libvirt::Errors::LibError]
|
487
493
|
def rollback_interface_change
|
488
|
-
result = FFI::Interface.virInterfaceChangeRollback(@
|
494
|
+
result = FFI::Interface.virInterfaceChangeRollback(@ptr, 0)
|
489
495
|
raise Errors::LibError, "Couldn't rollback interface change" if result.negative?
|
490
496
|
end
|
491
497
|
|
492
498
|
private
|
493
499
|
|
494
|
-
def set_connection(conn_ptr)
|
495
|
-
@conn_ptr = conn_ptr
|
496
|
-
end
|
497
|
-
|
498
500
|
def check_open!
|
499
|
-
raise Errors::LibError, "Connection to #{@uri.inspect} is not open" if @
|
500
|
-
end
|
501
|
-
|
502
|
-
def dbg(&block)
|
503
|
-
Util.log(:debug, 'Libvirt::Connection', &block)
|
501
|
+
raise Errors::LibError, "Connection to #{@uri.inspect} is not open" if @ptr.null?
|
504
502
|
end
|
505
503
|
end
|
506
504
|
end
|