libvirt_ffi 0.4.0 → 0.5.3
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.rb +12 -12
- data/lib/libvirt/base_info.rb +34 -0
- data/lib/libvirt/connection.rb +111 -38
- data/lib/libvirt/domain.rb +113 -8
- data/lib/libvirt/domain_callback_storage.rb +20 -16
- data/lib/libvirt/errors.rb +65 -0
- data/lib/libvirt/event.rb +36 -28
- data/lib/libvirt/ffi.rb +17 -0
- data/lib/libvirt/ffi/common.rb +8 -1
- data/lib/libvirt/ffi/domain.rb +530 -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 +127 -0
- data/lib/libvirt/ffi/storage.rb +149 -0
- data/lib/libvirt/ffi/stream.rb +19 -17
- 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 +33 -14
- data/lib/libvirt/util.rb +61 -8
- data/lib/libvirt/version.rb +1 -1
- data/lib/libvirt/xml.rb +23 -0
- 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_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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a2337cfa3a044b561ab70fe277e7fafff9f39919c494edc64e0f24dabce256d
|
4
|
+
data.tar.gz: a2dbb17ebb8eca45d0336293da344f1b6959f5afdbcee394d87ad5c103a9406a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e1354133c74a9fe27affc1414f2e8a466fd1c97664e3ed365736c7f3c574d9e7e1530bd15af5d229442437e33cfcf4f18d48b8e538af7e62a49975d92d7b591
|
7
|
+
data.tar.gz: 57d42fe97ad18a5827710d63eec68d0681ec1282d97168a71f1ce27263cc69c8f0063c4374543bb8baf0ff707a587080f23530b0fbc1d7ce8f158a46f57f62a4
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisplayCopNames: true
|
3
|
+
TargetRubyVersion: 2.5
|
4
|
+
Exclude:
|
5
|
+
- vendor/**/*
|
6
|
+
- tmp/**/*
|
7
|
+
- pkg/*
|
8
|
+
- test_usage/**/*.rb
|
9
|
+
|
10
|
+
Layout/LineLength:
|
11
|
+
Max: 180
|
12
|
+
|
13
|
+
Style/SymbolArray:
|
14
|
+
EnforcedStyle: brackets
|
15
|
+
|
16
|
+
Style/Lambda:
|
17
|
+
EnforcedStyle: literal
|
18
|
+
|
19
|
+
Naming/MethodParameterName:
|
20
|
+
AllowedNames:
|
21
|
+
- id
|
22
|
+
- cb
|
23
|
+
- fd
|
24
|
+
|
25
|
+
Naming/AccessorMethodName:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/HashEachMethods:
|
29
|
+
Enabled: true
|
30
|
+
|
31
|
+
Style/HashTransformKeys:
|
32
|
+
Enabled: true
|
33
|
+
|
34
|
+
Style/HashTransformValues:
|
35
|
+
Enabled: true
|
36
|
+
|
37
|
+
Style/Documentation:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Metrics/PerceivedComplexity:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Metrics/MethodLength:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Metrics/AbcSize:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Metrics/ModuleLength:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Metrics/BlockLength:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
Metrics/ClassLength:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
Metrics/CyclomaticComplexity:
|
59
|
+
Enabled: false
|
60
|
+
|
61
|
+
Layout/MultilineOperationIndentation:
|
62
|
+
Enabled: false
|
63
|
+
|
64
|
+
Layout/FirstHashElementIndentation:
|
65
|
+
Enabled: false
|
66
|
+
|
67
|
+
Layout/FirstArrayElementIndentation:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
Layout/FirstArgumentIndentation:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Layout/ClosingParenthesisIndentation:
|
74
|
+
Enabled: false
|
75
|
+
|
76
|
+
Layout/ArgumentAlignment:
|
77
|
+
Enabled: false
|
78
|
+
|
data/Gemfile
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in libvirt.gemspec
|
4
6
|
gemspec
|
5
7
|
|
6
|
-
gem 'rake', '~> 12.0'
|
7
8
|
gem 'minitest', '~> 5.0'
|
9
|
+
gem 'rake', '~> 12.0'
|
10
|
+
|
11
|
+
gem 'nokogiri'
|
8
12
|
|
9
13
|
group :development do
|
10
|
-
gem 'async', '~> 1.24'
|
11
14
|
gem 'activesupport'
|
12
|
-
gem '
|
15
|
+
gem 'async', '~> 1.24'
|
13
16
|
gem 'gc_tracer'
|
17
|
+
gem 'get_process_mem'
|
14
18
|
end
|
data/Rakefile
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
2
4
|
require 'rake/testtask'
|
5
|
+
require 'rubocop/rake_task'
|
3
6
|
|
4
7
|
Rake::TestTask.new(:test) do |t|
|
5
8
|
t.libs << 'test'
|
@@ -7,4 +10,6 @@ Rake::TestTask.new(:test) do |t|
|
|
7
10
|
t.test_files = FileList['test/**/*_test.rb']
|
8
11
|
end
|
9
12
|
|
10
|
-
|
13
|
+
RuboCop::RakeTask.new(:rubocop)
|
14
|
+
|
15
|
+
task default: [:rubocop, :test]
|
data/bin/console
CHANGED
data/exe/libvirt
CHANGED
data/lib/libvirt.rb
CHANGED
@@ -4,19 +4,18 @@ require 'ffi'
|
|
4
4
|
require 'objspace'
|
5
5
|
require 'libvirt/domain_callback_storage'
|
6
6
|
require 'libvirt/util'
|
7
|
-
require 'libvirt/
|
8
|
-
require 'libvirt/ffi
|
9
|
-
require 'libvirt/
|
10
|
-
require 'libvirt/
|
11
|
-
require 'libvirt/
|
12
|
-
require 'libvirt/
|
13
|
-
require 'libvirt/ffi/node_info'
|
14
|
-
require 'libvirt/ffi/stream'
|
7
|
+
require 'libvirt/errors'
|
8
|
+
require 'libvirt/ffi'
|
9
|
+
require 'libvirt/base_info'
|
10
|
+
require 'libvirt/node_info'
|
11
|
+
require 'libvirt/storage_pool_info'
|
12
|
+
require 'libvirt/storage_volume_info'
|
15
13
|
require 'libvirt/event'
|
16
14
|
require 'libvirt/connection'
|
17
15
|
require 'libvirt/domain'
|
18
|
-
require 'libvirt/node_info'
|
19
16
|
require 'libvirt/stream'
|
17
|
+
require 'libvirt/storage_pool'
|
18
|
+
require 'libvirt/storage_volume'
|
20
19
|
require 'libvirt/version'
|
21
20
|
|
22
21
|
module Libvirt
|
@@ -28,10 +27,11 @@ module Libvirt
|
|
28
27
|
class << self
|
29
28
|
def lib_version
|
30
29
|
version_ptr = ::FFI::MemoryPointer.new(:ulong)
|
31
|
-
code = FFI::
|
32
|
-
raise
|
30
|
+
code = FFI::Host.virGetVersion(version_ptr, nil, nil)
|
31
|
+
raise Errors::LibError, 'failed to get version' if code.negative?
|
32
|
+
|
33
33
|
version_number = version_ptr.get_ulong(0)
|
34
|
-
|
34
|
+
Util.parse_version(version_number)
|
35
35
|
end
|
36
36
|
|
37
37
|
def logger
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Libvirt
|
4
|
+
class BaseInfo
|
5
|
+
# Abstract Base class for info
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :_struct_class
|
9
|
+
|
10
|
+
# @param [Class<FFI::Struct>]
|
11
|
+
def struct_class(klass)
|
12
|
+
self._struct_class = klass
|
13
|
+
klass.members.each do |attr|
|
14
|
+
define_method(attr) { @struct[attr] }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(pointer)
|
20
|
+
raise ArgumentError, "Can't initialize base class #{self.class}" if self.class == BaseInfo
|
21
|
+
|
22
|
+
@ptr = pointer
|
23
|
+
@struct = self.class._struct_class.new(pointer)
|
24
|
+
end
|
25
|
+
|
26
|
+
def [](attr)
|
27
|
+
@struct[attr]
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_h
|
31
|
+
@struct.members.map { |attr| [attr, @struct[attr]] }.to_h
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/libvirt/connection.rb
CHANGED
@@ -6,43 +6,49 @@ module Libvirt
|
|
6
6
|
|
7
7
|
STORAGE = DomainCallbackStorage.new
|
8
8
|
|
9
|
-
DOMAIN_EVENT_CALLBACKS =
|
10
|
-
func = FFI::Domain.
|
9
|
+
DOMAIN_EVENT_CALLBACKS = DOMAIN_EVENT_IDS.map do |event_id_sym|
|
10
|
+
func = FFI::Domain.event_callback_for(event_id_sym) do |conn_ptr, dom_ptr, *args, op_ptr|
|
11
11
|
connection = Connection.load_ref(conn_ptr)
|
12
12
|
domain = Domain.load_ref(dom_ptr)
|
13
13
|
block, opaque = STORAGE.retrieve_from_pointer(op_ptr)
|
14
14
|
block.call(connection, domain, *args, opaque)
|
15
15
|
end
|
16
|
-
[
|
17
|
-
end.to_h
|
16
|
+
[event_id_sym, func]
|
17
|
+
end.to_h.freeze
|
18
18
|
|
19
19
|
def self.load_ref(conn_ptr)
|
20
|
-
ref_result = FFI::
|
21
|
-
raise
|
22
|
-
|
20
|
+
ref_result = FFI::Host.virConnectRef(conn_ptr)
|
21
|
+
raise Errors::LibError, "Couldn't retrieve connection reference" if ref_result.negative?
|
22
|
+
|
23
|
+
new(nil).tap { |r| r.send(:set_connection, conn_ptr) }
|
23
24
|
end
|
24
25
|
|
25
26
|
def initialize(uri)
|
26
27
|
@uri = uri
|
27
28
|
@conn_ptr = ::FFI::Pointer.new(0)
|
29
|
+
@close_data = nil
|
28
30
|
|
29
31
|
free = ->(obj_id) do
|
32
|
+
Util.log(:debug) { "Finalize Libvirt::Connection 0x#{obj_id.to_s(16)} @conn_ptr=#{@conn_ptr}," }
|
30
33
|
return if @conn_ptr.null?
|
31
|
-
|
32
|
-
|
34
|
+
|
35
|
+
cl_result = FFI::Host.virConnectClose(@conn_ptr)
|
36
|
+
warn "Couldn't close Libvirt::Connection (0x#{obj_id.to_s(16)}) pointer #{@conn_ptr.address}" if cl_result.negative?
|
33
37
|
end
|
34
38
|
ObjectSpace.define_finalizer(self, free)
|
35
39
|
end
|
36
40
|
|
37
41
|
def open
|
38
|
-
@conn_ptr = FFI::
|
39
|
-
raise
|
42
|
+
@conn_ptr = FFI::Host.virConnectOpen(@uri)
|
43
|
+
raise Errors::LibError, "Couldn't open connection to #{@uri.inspect}" if @conn_ptr.null?
|
44
|
+
|
40
45
|
true
|
41
46
|
end
|
42
47
|
|
43
48
|
def close
|
44
|
-
result = FFI::
|
45
|
-
raise
|
49
|
+
result = FFI::Host.virConnectClose(@conn_ptr)
|
50
|
+
raise Errors::LibError, "Couldn't close connection to #{@uri.inspect}" if result.negative?
|
51
|
+
|
46
52
|
@conn_ptr = ::FFI::Pointer.new(0)
|
47
53
|
true
|
48
54
|
end
|
@@ -59,16 +65,25 @@ module Libvirt
|
|
59
65
|
check_open!
|
60
66
|
|
61
67
|
version_ptr = ::FFI::MemoryPointer.new(:ulong)
|
62
|
-
result = FFI::
|
63
|
-
raise
|
68
|
+
result = FFI::Host.virConnectGetVersion(@conn_ptr, version_ptr)
|
69
|
+
raise Errors::LibError, "Couldn't retrieve connection version" if result.negative?
|
70
|
+
|
64
71
|
version_number = version_ptr.get_ulong(0)
|
65
|
-
|
72
|
+
Util.parse_version(version_number)
|
66
73
|
end
|
67
74
|
|
68
75
|
def set_keep_alive(interval, count)
|
69
|
-
result = FFI::
|
70
|
-
raise
|
71
|
-
|
76
|
+
result = FFI::Host.virConnectSetKeepAlive(@conn_ptr, interval, count)
|
77
|
+
raise Errors::LibError, "Couldn't set connection keep_alive" if result.negative?
|
78
|
+
|
79
|
+
result.zero?
|
80
|
+
end
|
81
|
+
|
82
|
+
def free_memory
|
83
|
+
result = FFI::Host.virNodeGetFreeMemory(@conn_ptr)
|
84
|
+
raise Errors::LibError, "Couldn't set connection keep_alive" if result.negative?
|
85
|
+
|
86
|
+
result
|
72
87
|
end
|
73
88
|
|
74
89
|
def to_s
|
@@ -81,22 +96,63 @@ module Libvirt
|
|
81
96
|
|
82
97
|
def list_all_domains_qty(flags = 0)
|
83
98
|
result = FFI::Domain.virConnectListAllDomains(@conn_ptr, nil, flags)
|
84
|
-
raise
|
99
|
+
raise Errors::LibError, "Couldn't retrieve domains qty with flags #{flags.to_s(16)}" if result.negative?
|
100
|
+
|
85
101
|
result
|
86
102
|
end
|
87
103
|
|
88
104
|
def list_all_domains(flags = 0)
|
89
105
|
size = list_all_domains_qty(flags)
|
106
|
+
return [] if size.zero?
|
107
|
+
|
90
108
|
domains_ptr = ::FFI::MemoryPointer.new(:pointer, size)
|
91
109
|
result = FFI::Domain.virConnectListAllDomains(@conn_ptr, domains_ptr, flags)
|
92
|
-
raise
|
110
|
+
raise Errors::LibError, "Couldn't retrieve domains list with flags #{flags.to_s(16)}" if result.negative?
|
111
|
+
|
93
112
|
ptr = domains_ptr.read_pointer
|
94
113
|
ptr.get_array_of_pointer(0, size).map { |dom_ptr| Libvirt::Domain.new(dom_ptr) }
|
95
114
|
end
|
96
115
|
|
116
|
+
def list_all_storage_pools_qty(options_or_flags = nil)
|
117
|
+
flags = Util.parse_flags options_or_flags, FFI::Storage.enum_type(:list_all_pools_flags)
|
118
|
+
result = FFI::Storage.virConnectListAllStoragePools(@conn_ptr, nil, flags)
|
119
|
+
raise Errors::LibError, "Couldn't retrieve storage pools qty with flags #{flags.to_s(16)}" if result.negative?
|
120
|
+
|
121
|
+
result
|
122
|
+
end
|
123
|
+
|
124
|
+
def list_all_storage_pools(options_or_flags = nil)
|
125
|
+
flags = Util.parse_flags options_or_flags, FFI::Storage.enum_type(:list_all_pools_flags)
|
126
|
+
size = list_all_storage_pools_qty(flags)
|
127
|
+
return [] if size.zero?
|
128
|
+
|
129
|
+
storage_pools_ptr = ::FFI::MemoryPointer.new(:pointer, size)
|
130
|
+
result = FFI::Storage.virConnectListAllStoragePools(@conn_ptr, storage_pools_ptr, flags)
|
131
|
+
raise Errors::LibError, "Couldn't retrieve storage pools list with flags #{flags.to_s(16)}" if result.negative?
|
132
|
+
|
133
|
+
ptr = storage_pools_ptr.read_pointer
|
134
|
+
ptr.get_array_of_pointer(0, size).map { |stp_ptr| StoragePool.new(stp_ptr) }
|
135
|
+
end
|
136
|
+
|
137
|
+
def register_close_callback(opaque = nil, &block)
|
138
|
+
dbg { "#register_close_callback opaque=#{opaque}" }
|
139
|
+
raise ArgumentError, 'close function already registered' if @close_data
|
140
|
+
|
141
|
+
@close_data = { opaque: opaque, block: block }
|
142
|
+
@close_cb = FFI::Host.callback_function(:virConnectCloseFunc) do |_conn, reason, _op|
|
143
|
+
dbg { "CONNECTION CLOSED @conn_ptr=#{@conn_ptr} reason=#{reason}" }
|
144
|
+
@close_data[:block].call(self, reason, @close_data[:opaque])
|
145
|
+
end
|
146
|
+
@close_free_func = FFI::Common.free_function do
|
147
|
+
dbg { "CONNECTION CLOSED FREE FUNC @conn_ptr=#{@conn_ptr}" }
|
148
|
+
@close_cb = @close_free_func = @close_data = nil
|
149
|
+
end
|
150
|
+
FFI::Host.virConnectRegisterCloseCallback(@conn_ptr, @close_cb, nil, @close_free_func)
|
151
|
+
end
|
152
|
+
|
97
153
|
# @yield conn, dom, *args
|
98
154
|
def register_domain_event_callback(event_id, domain = nil, opaque = nil, &block)
|
99
|
-
|
155
|
+
dbg { "#register_domain_event_callback event_id=#{event_id}" }
|
100
156
|
|
101
157
|
enum = FFI::Domain.enum_type(:event_id)
|
102
158
|
event_id, event_id_sym = Util.parse_enum(enum, event_id)
|
@@ -112,9 +168,9 @@ module Libvirt
|
|
112
168
|
cb_data.pointer,
|
113
169
|
cb_data_free_func
|
114
170
|
)
|
115
|
-
if result
|
171
|
+
if result.negative?
|
116
172
|
cb_data.pointer.free
|
117
|
-
raise
|
173
|
+
raise Errors::LibError, "Couldn't register domain event callback"
|
118
174
|
end
|
119
175
|
|
120
176
|
STORAGE.store_struct(
|
@@ -128,48 +184,61 @@ module Libvirt
|
|
128
184
|
end
|
129
185
|
|
130
186
|
def deregister_domain_event_callback(callback_id)
|
131
|
-
|
187
|
+
dbg { "#deregister_domain_event_callback callback_id=#{callback_id}" }
|
132
188
|
|
133
189
|
result = FFI::Domain.virConnectDomainEventDeregisterAny(@conn_ptr, callback_id)
|
134
|
-
raise
|
190
|
+
raise Errors::LibError, "Couldn't deregister domain event callback" if result.negative?
|
135
191
|
|
136
|
-
|
192
|
+
# virConnectDomainEventDeregisterAny will call free func
|
193
|
+
# So we don't need to remove object from STORAGE here.
|
194
|
+
true
|
137
195
|
end
|
138
196
|
|
139
197
|
def lib_version
|
140
198
|
version_ptr = ::FFI::MemoryPointer.new(:ulong)
|
141
|
-
result = FFI::
|
142
|
-
raise
|
199
|
+
result = FFI::Host.virConnectGetLibVersion(@conn_ptr, version_ptr)
|
200
|
+
raise Errors::LibError, "Couldn't get connection lib version" if result.negative?
|
201
|
+
|
143
202
|
version_number = version_ptr.get_ulong(0)
|
144
|
-
|
203
|
+
Util.parse_version(version_number)
|
145
204
|
end
|
146
205
|
|
147
206
|
def hostname
|
148
|
-
FFI::
|
207
|
+
FFI::Host.virConnectGetHostname(@conn_ptr)
|
149
208
|
end
|
150
209
|
|
151
210
|
# @param type [String,NilClass]
|
152
211
|
def max_vcpus(type = nil)
|
153
|
-
FFI::
|
212
|
+
FFI::Host.virConnectGetMaxVcpus(@conn_ptr, type)
|
154
213
|
end
|
155
214
|
|
156
215
|
def capabilities
|
157
|
-
FFI::
|
216
|
+
FFI::Host.virConnectGetCapabilities(@conn_ptr)
|
158
217
|
end
|
159
218
|
|
160
219
|
def node_info
|
161
|
-
node_info_ptr = ::FFI::MemoryPointer.new(FFI::
|
162
|
-
result = FFI::
|
163
|
-
raise
|
220
|
+
node_info_ptr = ::FFI::MemoryPointer.new(FFI::Host::NodeInfoStruct.by_value)
|
221
|
+
result = FFI::Host.virNodeGetInfo(@conn_ptr, node_info_ptr)
|
222
|
+
raise Errors::LibError, "Couldn't get connection node info" if result.negative?
|
223
|
+
|
164
224
|
NodeInfo.new(node_info_ptr)
|
165
225
|
end
|
166
226
|
|
167
227
|
def stream(flags = 0)
|
168
228
|
pointer = FFI::Stream.virStreamNew(@conn_ptr, flags)
|
169
|
-
raise
|
229
|
+
raise Errors::LibError, "Couldn't create stream" if pointer.null?
|
230
|
+
|
170
231
|
Stream.new(pointer)
|
171
232
|
end
|
172
233
|
|
234
|
+
def define_domain(xml, options_or_flags = nil)
|
235
|
+
flags = Util.parse_flags options_or_flags, FFI::Domain.enum_type(:define_flags)
|
236
|
+
pointer = FFI::Domain.virDomainDefineXMLFlags(@conn_ptr, xml, flags)
|
237
|
+
raise Errors::LibError, "Couldn't define domain" if pointer.null?
|
238
|
+
|
239
|
+
Domain.new(pointer)
|
240
|
+
end
|
241
|
+
|
173
242
|
private
|
174
243
|
|
175
244
|
def set_connection(conn_ptr)
|
@@ -177,7 +246,11 @@ module Libvirt
|
|
177
246
|
end
|
178
247
|
|
179
248
|
def check_open!
|
180
|
-
raise
|
249
|
+
raise Errors::LibError, "Connection to #{@uri.inspect} is not open" if @conn_ptr.null?
|
250
|
+
end
|
251
|
+
|
252
|
+
def dbg(&block)
|
253
|
+
Util.log(:debug, 'Libvirt::Connection', &block)
|
181
254
|
end
|
182
255
|
end
|
183
256
|
end
|