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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +78 -0
  3. data/Gemfile +7 -3
  4. data/Rakefile +6 -1
  5. data/bin/console +1 -0
  6. data/exe/libvirt +1 -0
  7. data/lib/libvirt.rb +12 -12
  8. data/lib/libvirt/base_info.rb +34 -0
  9. data/lib/libvirt/connection.rb +111 -38
  10. data/lib/libvirt/domain.rb +113 -8
  11. data/lib/libvirt/domain_callback_storage.rb +20 -16
  12. data/lib/libvirt/errors.rb +65 -0
  13. data/lib/libvirt/event.rb +36 -28
  14. data/lib/libvirt/ffi.rb +17 -0
  15. data/lib/libvirt/ffi/common.rb +8 -1
  16. data/lib/libvirt/ffi/domain.rb +530 -196
  17. data/lib/libvirt/ffi/error.rb +243 -0
  18. data/lib/libvirt/ffi/event.rb +30 -36
  19. data/lib/libvirt/ffi/helpers.rb +17 -0
  20. data/lib/libvirt/ffi/host.rb +127 -0
  21. data/lib/libvirt/ffi/storage.rb +149 -0
  22. data/lib/libvirt/ffi/stream.rb +19 -17
  23. data/lib/libvirt/node_info.rb +2 -41
  24. data/lib/libvirt/storage_pool.rb +70 -0
  25. data/lib/libvirt/storage_pool_info.rb +7 -0
  26. data/lib/libvirt/storage_volume.rb +51 -0
  27. data/lib/libvirt/storage_volume_info.rb +7 -0
  28. data/lib/libvirt/stream.rb +33 -14
  29. data/lib/libvirt/util.rb +61 -8
  30. data/lib/libvirt/version.rb +1 -1
  31. data/lib/libvirt/xml.rb +23 -0
  32. data/lib/libvirt/xml/disk.rb +59 -0
  33. data/lib/libvirt/xml/domain.rb +76 -0
  34. data/lib/libvirt/xml/generic.rb +252 -0
  35. data/lib/libvirt/xml/graphics.rb +14 -0
  36. data/lib/libvirt/xml/max_vcpu.rb +12 -0
  37. data/lib/libvirt/xml/memory.rb +14 -0
  38. data/lib/libvirt/xml/storage_pool.rb +24 -0
  39. data/lib/libvirt/xml/storage_volume.rb +32 -0
  40. data/lib/libvirt/xml/vcpu.rb +12 -0
  41. data/lib/libvirt_ffi.rb +2 -0
  42. data/libvirt.gemspec +5 -1
  43. data/test_usage/support/libvirt_async.rb +27 -35
  44. data/test_usage/support/log_formatter.rb +5 -10
  45. data/test_usage/test_domain.rb +43 -0
  46. data/test_usage/test_event_loop.rb +115 -39
  47. data/test_usage/test_libvirtd_restart.rb +63 -0
  48. data/test_usage/test_metadata.rb +104 -0
  49. data/test_usage/test_screenshot.rb +14 -13
  50. data/test_usage/test_storage.rb +52 -0
  51. metadata +42 -6
  52. data/lib/libvirt/error.rb +0 -6
  53. data/lib/libvirt/ffi/connection.rb +0 -94
  54. data/lib/libvirt/ffi/libvirt.rb +0 -17
  55. data/lib/libvirt/ffi/node_info.rb +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79ea563057bb675ad519b6dfafca175b69afe8f9b0dc9b3ab76c32175372eab1
4
- data.tar.gz: 86420a7e48c60ff3a4cf3bbd5377d8070facd1e453494b16225a78c7c3e4c898
3
+ metadata.gz: 2a2337cfa3a044b561ab70fe277e7fafff9f39919c494edc64e0f24dabce256d
4
+ data.tar.gz: a2dbb17ebb8eca45d0336293da344f1b6959f5afdbcee394d87ad5c103a9406a
5
5
  SHA512:
6
- metadata.gz: e5c81de1008c0a2c55bcacbbd0a50611d492eba8ee7232fb007f861e011f71053e75434563374c60037a89330b10da5f2873b5fd7359a8ba7bd9a88c011da01d
7
- data.tar.gz: b803fae7ff7a85fa744784c89e6566acd43bad33f3229af2f97404e852021005084ca7513afea67f28c9e6e0bc9d2309731f25899bb5b9b5fcb2d8568c46c7d3
6
+ metadata.gz: 3e1354133c74a9fe27affc1414f2e8a466fd1c97664e3ed365736c7f3c574d9e7e1530bd15af5d229442437e33cfcf4f18d48b8e538af7e62a49975d92d7b591
7
+ data.tar.gz: 57d42fe97ad18a5827710d63eec68d0681ec1282d97168a71f1ce27263cc69c8f0063c4374543bb8baf0ff707a587080f23530b0fbc1d7ce8f158a46f57f62a4
@@ -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 'get_process_mem'
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
- task default: :test
13
+ RuboCop::RakeTask.new(:rubocop)
14
+
15
+ task default: [:rubocop, :test]
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'libvirt'
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'libvirt'
@@ -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/error'
8
- require 'libvirt/ffi/common'
9
- require 'libvirt/ffi/libvirt'
10
- require 'libvirt/ffi/connection'
11
- require 'libvirt/ffi/domain'
12
- require 'libvirt/ffi/event'
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::Libvirt.virGetVersion(version_ptr, nil, nil)
32
- raise Error, 'failed to get version' if code < 0
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
- Libvirt::Util.parse_version(version_number)
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
@@ -6,43 +6,49 @@ module Libvirt
6
6
 
7
7
  STORAGE = DomainCallbackStorage.new
8
8
 
9
- DOMAIN_EVENT_CALLBACKS = FFI::Domain.enum_type(:event_id).symbol_map.map do |name, event_id|
10
- func = FFI::Domain.event_callback(event_id) do |conn_ptr, dom_ptr, *args, op_ptr|
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
- [name, func]
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::Connection.virConnectRef(conn_ptr)
21
- raise Error, "Couldn't retrieve connection reference" if ref_result < 0
22
- new(nil).send(:set_connection, conn_ptr)
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
- cl_result = FFI::Connection.virConnectClose(@conn_ptr)
32
- STDERR.puts "Couldn't close Libvirt::Connection (0x#{obj_id.to_s(16)}) pointer #{@conn_ptr.address}" if cl_result < 0
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::Connection.virConnectOpen(@uri)
39
- raise Error, "Couldn't open connection to #{@uri.inspect}" if @conn_ptr.null?
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::Connection.virConnectClose(@conn_ptr)
45
- raise Error, "Couldn't close connection to #{@uri.inspect}" if result < 0
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::Connection.virConnectGetVersion(@conn_ptr, version_ptr)
63
- raise Error, "Couldn't retrieve connection version" if result < 0
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
- Libvirt::Util::parse_version(version_number)
72
+ Util.parse_version(version_number)
66
73
  end
67
74
 
68
75
  def set_keep_alive(interval, count)
69
- result = FFI::Connection.virConnectSetKeepAlive(@conn_ptr, interval, count)
70
- raise Error, "Couldn't set connection keep_alive" if result < 0
71
- result == 0
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 Error, "Couldn't retrieve domains qty with flags #{flags.to_s(16)}" if result < 0
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 Error, "Couldn't retrieve domains list with flags #{flags.to_s(16)}" if result < 0
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
- Util.logger.debug { "Libvirt::Connection#register_domain_event_callback event_id=#{event_id}" }
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 < 0
171
+ if result.negative?
116
172
  cb_data.pointer.free
117
- raise Error, "Couldn't register domain event callback"
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
- Util.logger.debug { "Libvirt::Connection#deregister_domain_event_callback callback_id=#{callback_id}" }
187
+ dbg { "#deregister_domain_event_callback callback_id=#{callback_id}" }
132
188
 
133
189
  result = FFI::Domain.virConnectDomainEventDeregisterAny(@conn_ptr, callback_id)
134
- raise Error, "Couldn't deregister domain event callback" if result < 0
190
+ raise Errors::LibError, "Couldn't deregister domain event callback" if result.negative?
135
191
 
136
- STORAGE.remove_struct(connection_pointer: @conn_ptr, callback_id: callback_id)
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::Connection.virConnectGetLibVersion(@conn_ptr, version_ptr)
142
- raise Error, "Couldn't get connection lib version" if result < 0
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
- Libvirt::Util.parse_version(version_number)
203
+ Util.parse_version(version_number)
145
204
  end
146
205
 
147
206
  def hostname
148
- FFI::Connection.virConnectGetHostname(@conn_ptr)
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::Connection.virConnectGetMaxVcpus(@conn_ptr, type)
212
+ FFI::Host.virConnectGetMaxVcpus(@conn_ptr, type)
154
213
  end
155
214
 
156
215
  def capabilities
157
- FFI::Connection.virConnectGetCapabilities(@conn_ptr)
216
+ FFI::Host.virConnectGetCapabilities(@conn_ptr)
158
217
  end
159
218
 
160
219
  def node_info
161
- node_info_ptr = ::FFI::MemoryPointer.new(FFI::NodeInfo::Struct.by_value)
162
- result = FFI::NodeInfo.virNodeGetInfo(@conn_ptr, node_info_ptr)
163
- raise Error, "Couldn't get connection node info" if result < 0
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 Error, "Couldn't create stream" if pointer.null?
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 Error, "Connection to #{@uri.inspect} is not open" if @conn_ptr.null?
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