libvirt_ffi 0.4.0 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Libvirt
4
+ module Xml
5
+ class Graphics < Generic
6
+ # https://libvirt.org/formatdomain.html#elementsGraphics
7
+
8
+ attribute :type, type: :attr
9
+ attribute :listen, type: :attr
10
+ attribute :port, type: :attr
11
+ attribute :auto_port, type: :attr, name: :autoport, cast: :bool
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Libvirt
4
+ module Xml
5
+ class MaxVcpu < Generic
6
+ attribute :value, path: :root, cast: :int
7
+ attribute :cpu_set, type: :attr, name: :cpuset
8
+ attribute :current, type: :attr, cast: :int
9
+ attribute :placement, type: :attr
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Libvirt
4
+ module Xml
5
+ class Memory < Generic
6
+ attribute :dump_core, type: :attr, name: :dumpCore
7
+ attribute :slots, type: :attr
8
+
9
+ attribute :bytes, apply: ->(node, _opts) do
10
+ Util.parse_memory node.text, node['unit']
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Libvirt
4
+ module Xml
5
+ class StoragePool < Generic
6
+ # https://libvirt.org/formatstorage.html
7
+
8
+ root_path './pool'
9
+
10
+ attribute :type, type: :attr
11
+ attribute :name
12
+ attribute :uuid
13
+ attribute :capacity, type: :memory
14
+ attribute :allocation, type: :memory
15
+ attribute :available, type: :memory
16
+ attribute :target_path, path: './target/path'
17
+ attribute :target_perm_mode, path: './target/permissions/mode'
18
+ attribute :target_perm_owner, path: './target/permissions/owner'
19
+ attribute :target_perm_group, path: './target/permissions/group'
20
+ attribute :target_perm_label, path: './target/permissions/label'
21
+ # TODO: source
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Libvirt
4
+ module Xml
5
+ class StorageVolume < Generic
6
+ # https://libvirt.org/formatstorage.html
7
+
8
+ root_path './volume'
9
+
10
+ attribute :type, type: :attr
11
+ attribute :name
12
+ attribute :key
13
+ attribute :allocation, type: :memory
14
+ attribute :capacity, type: :memory
15
+ attribute :physical, type: :memory
16
+ attribute :target_path, path: './target/path'
17
+ attribute :target_format, type: :attr, name: :type, path: './target/format'
18
+ attribute :target_perm_mode, path: './target/permissions/mode'
19
+ attribute :target_perm_owner, path: './target/permissions/owner'
20
+ attribute :target_perm_group, path: './target/permissions/group'
21
+ attribute :target_perm_label, path: './target/permissions/label'
22
+ attribute :timestamp_atime, path: './timestamp/atime'
23
+ attribute :timestamp_btime, path: './timestamp/btime'
24
+ attribute :timestamp_ctime, path: './timestamp/ctime'
25
+ attribute :timestamp_mtime, path: './timestamp/mtime'
26
+ attribute :compat
27
+ # TODO: target/encryption target/nocow target/features
28
+ # todo source
29
+ # todo backingStore
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Libvirt
4
+ module Xml
5
+ class Vcpu < Generic
6
+ attribute :id, type: :attr, cast: :int
7
+ attribute :enabled, type: :attr, cast: :bool
8
+ attribute :hot_pluggable, type: :attr, cast: :bool, name: :hotpluggable
9
+ attribute :order, type: :attr, cast: :int
10
+ end
11
+ end
12
+ end
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'libvirt'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'lib/libvirt/version'
2
4
 
3
5
  Gem::Specification.new do |spec|
@@ -17,7 +19,7 @@ Gem::Specification.new do |spec|
17
19
 
18
20
  # Specify which files should be added to the gem when it is released.
19
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
23
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
24
  end
23
25
  spec.bindir = 'exe'
@@ -25,4 +27,6 @@ Gem::Specification.new do |spec|
25
27
  spec.require_paths = ['lib']
26
28
 
27
29
  spec.add_dependency 'ffi', '>= 1.0'
30
+
31
+ spec.add_development_dependency 'rubocop', '~> 0.80.1'
28
32
  end
@@ -1,12 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LibvirtAsync
2
4
  class << self
3
- def logger=(logger)
4
- @logger = logger
5
- end
5
+ attr_writer :logger
6
6
 
7
- def logger
8
- @logger
9
- end
7
+ attr_reader :logger
10
8
  end
11
9
 
12
10
  module WithDbg
@@ -26,12 +24,11 @@ module LibvirtAsync
26
24
  end
27
25
 
28
26
  module Util
29
- def create_task(parent = nil, reactor = nil, &block)
27
+ def self.create_task(parent = nil, reactor = nil, &block)
30
28
  parent = Async::Task.current? if parent == :current
31
29
  reactor ||= Async::Task.current.reactor
32
30
  Async::Task.new(reactor, parent, &block)
33
31
  end
34
- module_function :create_task
35
32
  end
36
33
 
37
34
  class Handle
@@ -77,12 +74,8 @@ module LibvirtAsync
77
74
  def register
78
75
  dbg { "#{self.class}#register handle_id=#{handle_id}, fd=#{fd}" }
79
76
 
80
- if (events & Libvirt::EVENT_HANDLE_ERROR) != 0
81
- dbg { "#{self.class}#register skip EVENT_HANDLE_ERROR handle_id=#{handle_id}, fd=#{fd}" }
82
- end
83
- if (events & Libvirt::EVENT_HANDLE_HANGUP) != 0
84
- dbg { "#{self.class}#register skip EVENT_HANDLE_HANGUP handle_id=#{handle_id}, fd=#{fd}" }
85
- end
77
+ dbg { "#{self.class}#register skip EVENT_HANDLE_ERROR handle_id=#{handle_id}, fd=#{fd}" } if (events & Libvirt::EVENT_HANDLE_ERROR) != 0
78
+ dbg { "#{self.class}#register skip EVENT_HANDLE_HANGUP handle_id=#{handle_id}, fd=#{fd}" } if (events & Libvirt::EVENT_HANDLE_HANGUP) != 0
86
79
 
87
80
  interest = events_to_interest(events)
88
81
  dbg { "#{self.class}#register parse handle_id=#{handle_id}, fd=#{fd}, events=#{events}, interest=#{interest}" }
@@ -99,7 +92,7 @@ module LibvirtAsync
99
92
  io = IO.new(fd, io_mode, autoclose: false)
100
93
  @monitor = Monitor.new(io)
101
94
 
102
- while @monitor.readiness == nil
95
+ while @monitor.readiness.nil?
103
96
  cancelled = wait_io(interest)
104
97
 
105
98
  if cancelled
@@ -117,7 +110,6 @@ module LibvirtAsync
117
110
 
118
111
  dbg { "#{self.class}#register_handle async not ready readiness=#{@monitor.readiness}, handle_id=#{handle_id}, fd=#{fd}" }
119
112
  end
120
-
121
113
  end
122
114
 
123
115
  dbg { "#{self.class}#register_handle invokes fiber=0x#{task.fiber.object_id.to_s(16)} handle_id=#{handle_id}, fd=#{fd}" }
@@ -197,8 +189,6 @@ module LibvirtAsync
197
189
  :r
198
190
  elsif writable
199
191
  :w
200
- else
201
- nil
202
192
  end
203
193
  end
204
194
 
@@ -223,8 +213,6 @@ module LibvirtAsync
223
213
  Libvirt::EVENT_HANDLE_READABLE
224
214
  when :w
225
215
  Libvirt::EVENT_HANDLE_WRITABLE
226
- else
227
- nil
228
216
  end
229
217
  end
230
218
  end
@@ -277,14 +265,15 @@ module LibvirtAsync
277
265
  dbg { "#{self.class}#initialize timer_id=#{timer_id}, interval=#{interval}" }
278
266
 
279
267
  @timer_id = timer_id
280
- @interval = interval.to_f / 1000.to_f
268
+ @interval = interval / 1000.0
281
269
  @opaque = opaque
282
270
  @last_fired = Time.now.to_f
283
271
  @monitor = nil
284
272
  end
285
273
 
286
274
  def wait_time
287
- return if interval < 0
275
+ return if interval.negative?
276
+
288
277
  last_fired + interval
289
278
  end
290
279
 
@@ -358,15 +347,12 @@ module LibvirtAsync
358
347
  end
359
348
 
360
349
  def wait_timer(timeout)
361
- begin
362
- @monitor.wait(timeout)
363
- false
364
- rescue Monitor::Cancelled => e
365
- dbg { "#{self.class}#wait_timer cancelled #{e.class} #{e.message}" }
366
- true
367
- end
350
+ @monitor.wait(timeout)
351
+ false
352
+ rescue Monitor::Cancelled => e
353
+ dbg { "#{self.class}#wait_timer cancelled #{e.class} #{e.message}" }
354
+ true
368
355
  end
369
-
370
356
  end
371
357
 
372
358
  class Implementations
@@ -396,12 +382,12 @@ module LibvirtAsync
396
382
  def print_debug_info
397
383
  str = [
398
384
  "#{self.class}:0x#{object_id.to_s(16)}",
399
- "handles = [",
385
+ 'handles = [',
400
386
  @handles.map(&:to_s).join("\n"),
401
- "]",
402
- "timers = [",
387
+ ']',
388
+ 'timers = [',
403
389
  @timers.map(&:to_s).join("\n"),
404
- "]"
390
+ ']'
405
391
  ].join("\n")
406
392
  Libvirt.logger&.debug { str }
407
393
  end
@@ -432,10 +418,16 @@ module LibvirtAsync
432
418
  remove_handle: method(:remove_handle).to_proc,
433
419
  add_timer: method(:add_timer).to_proc,
434
420
  update_timer: method(:update_timer).to_proc,
435
- remove_timer: method(:remove_timer).to_proc
421
+ remove_timer: method(:remove_timer).to_proc,
422
+ schedule: method(:schedule).to_proc
436
423
  )
437
424
  end
438
425
 
426
+ def schedule(&block)
427
+ task = Async::Task.new(Async::Task.current.reactor, nil, &block)
428
+ task.reactor << task.fiber
429
+ end
430
+
439
431
  def add_handle(fd, events, opaque)
440
432
  # add a handle to be tracked by this object. The application is
441
433
  # expected to maintain a list of internal handle IDs (integers); this
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class LogFormatter
2
- LOG_FORMAT = "%s, %s [%s/%s/%s] %s\n".freeze
3
- DEFAULT_DATETIME_FORMAT = "%F %T.%N".freeze
4
+ LOG_FORMAT = "%s, %s [%s/%s/%s] %s\n"
5
+ DEFAULT_DATETIME_FORMAT = '%F %T.%N'
4
6
 
5
7
  attr_accessor :datetime_format
6
8
 
@@ -9,14 +11,7 @@ class LogFormatter
9
11
  end
10
12
 
11
13
  def call(severity, time, progname, message)
12
- LOG_FORMAT % [
13
- severity[0..0],
14
- format_datetime(time),
15
- "0x#{Async::Task.current?&.object_id&.to_s(16)}",
16
- "0x#{Fiber.current.object_id.to_s(16)}",
17
- progname,
18
- format_message(message)
19
- ]
14
+ format(LOG_FORMAT, severity[0..0], format_datetime(time), "0x#{Async::Task.current?&.object_id&.to_s(16)}", "0x#{Fiber.current.object_id.to_s(16)}", progname, format_message(message))
20
15
  end
21
16
 
22
17
  private
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'libvirt'
6
+ require 'logger'
7
+ require 'active_support/all'
8
+ require 'async'
9
+
10
+ require_relative 'support/libvirt_async'
11
+ require_relative 'support/log_formatter'
12
+
13
+ require 'libvirt/xml'
14
+
15
+ Libvirt.logger = Logger.new(STDOUT, formatter: LogFormatter.new)
16
+ Libvirt.logger.level = ENV['DEBUG'] ? :debug : :info
17
+
18
+ IMPL = LibvirtAsync::Implementations.new
19
+
20
+ Async do
21
+ ASYNC_REACTOR = Async::Task.current.reactor
22
+
23
+ puts "Lib version #{Libvirt.lib_version}"
24
+ puts "Gem version #{Libvirt::VERSION}"
25
+
26
+ IMPL.start
27
+
28
+ conn = Libvirt::Connection.new('qemu+tcp://localhost:16510/system')
29
+ conn.open
30
+
31
+ puts "Connection version #{conn.version.inspect}"
32
+ puts "Connection lib_version #{conn.lib_version.inspect}"
33
+ puts "Connection hostname #{conn.hostname.inspect}"
34
+
35
+ doms = conn.list_all_domains
36
+ puts "Connection domains qty #{doms.size}"
37
+
38
+ doms.each.with_index do |dom, i|
39
+ puts "Domain #{i} xml", dom.xml_desc
40
+ puts "Domain #{i} xml object", Libvirt::Xml::Domain.load(dom.xml_desc).to_h
41
+ end
42
+
43
+ end
@@ -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'
@@ -16,16 +17,18 @@ GC::Tracer.start_logging(
16
17
  gc_stat: false,
17
18
  gc_latest_gc_info: false,
18
19
  rusage: false,
19
- events: %i[end_mark end_sweep]
20
+ events: [:end_mark, :end_sweep]
20
21
  )
21
22
 
22
23
  Libvirt.logger = Logger.new(STDOUT, formatter: LogFormatter.new)
23
24
  Libvirt.logger.level = ENV['DEBUG'] ? :debug : :info
24
25
 
25
26
  IMPL = LibvirtAsync::Implementations.new
26
- CONNS = []
27
- DOMS = []
28
- CB_IDS = []
27
+ OBJECTS = {
28
+ hv: nil,
29
+ domains: [],
30
+ cb_ids: []
31
+ }.freeze
29
32
 
30
33
  Async do
31
34
  ASYNC_REACTOR = Async::Task.current.reactor
@@ -35,18 +38,17 @@ Async do
35
38
 
36
39
  IMPL.start
37
40
 
38
- c = Libvirt::Connection.new('qemu+tcp://localhost:16510/system')
39
- c.open
40
- res = c.set_keep_alive(2, 1)
41
- Libvirt.logger.info { "set_keep_alive #{res}" }
42
- CONNS.push(c)
43
-
44
- puts "Connection version #{c.version.inspect}"
45
- puts "Connection lib_version #{c.lib_version.inspect}"
46
- puts "Connection hostname #{c.hostname.inspect}"
47
- puts "Connection max_vcpus #{c.max_vcpus.inspect}"
48
- puts "Connection capabilities #{c.capabilities.inspect}"
49
- node_info = c.node_info
41
+ OBJECTS[:hv] = Libvirt::Connection.new('qemu+tcp://localhost:16510/system')
42
+ OBJECTS[:hv].open
43
+ res = OBJECTS[:hv].set_keep_alive(2, 1)
44
+ Libvirt.logger.info { "set_keep_alive #{res}" }
45
+
46
+ puts "Connection version #{OBJECTS[:hv].version.inspect}"
47
+ puts "Connection lib_version #{OBJECTS[:hv].lib_version.inspect}"
48
+ puts "Connection hostname #{OBJECTS[:hv].hostname.inspect}"
49
+ puts "Connection max_vcpus #{OBJECTS[:hv].max_vcpus.inspect}"
50
+ puts "Connection capabilities #{OBJECTS[:hv].capabilities.inspect}"
51
+ node_info = OBJECTS[:hv].node_info
50
52
  puts "Connection nodeInfo #{node_info}"
51
53
  puts "NodeInfo model #{node_info.model.inspect}"
52
54
  puts "NodeInfo cpus #{node_info.cpus.inspect}"
@@ -57,27 +59,27 @@ Async do
57
59
  puts "NodeInfo threads #{node_info.threads.inspect}"
58
60
  puts "NodeInfo memory #{node_info.memory.inspect}"
59
61
 
60
- cb_ids = Libvirt::Connection::DOMAIN_EVENT_IDS.map do |event_id|
62
+ Libvirt::Connection::DOMAIN_EVENT_IDS.map do |event_id|
61
63
  op = OpenStruct.new(a: 'b', event_id: event_id)
62
- c.register_domain_event_callback(event_id, nil, op) do |conn, dom, *args, opaque|
64
+ callback_id = OBJECTS[:hv].register_domain_event_callback(event_id, nil, op) do |conn, dom, *args, opaque|
63
65
  Libvirt.logger.info { "DOMAIN EVENT #{event_id} conn=#{conn}, dom=#{dom}, args=#{args}, opaque=#{opaque}" }
64
66
  end
67
+ Libvirt.logger.info { "Registered domain event callback event_id=#{event_id} callback_id=#{callback_id}" }
68
+ OBJECTS[:cb_ids] << callback_id
65
69
  end
66
- CB_IDS.concat(cb_ids)
67
70
 
68
- puts "domains qty #{c.list_all_domains_qty}"
71
+ puts "domains qty #{OBJECTS[:hv].list_all_domains_qty}"
69
72
 
70
- domains = c.list_all_domains
71
- DOMS.concat(domains)
72
- puts "Domains (#{domains.size}): #{domains}"
73
+ OBJECTS[:domains] = OBJECTS[:hv].list_all_domains
74
+ puts "Domains (#{OBJECTS[:domains].size}): #{OBJECTS[:domains]}"
73
75
 
74
- d = domains.first
76
+ d = OBJECTS[:domains].first
75
77
  puts "Domain uuid #{d.uuid.inspect}"
76
78
  puts "Domain name #{d.name.inspect}"
77
79
  puts "Domain get_state #{d.get_state.inspect}"
78
80
  puts "Domain get_cpus #{d.max_vcpus.inspect}"
79
81
  puts "Domain max_memory #{d.max_memory.inspect}"
80
- puts "Domain xml_desc #{d.xml_desc.inspect}"
82
+ # puts "Domain xml_desc #{d.xml_desc.inspect}"
81
83
 
82
84
  # ASYNC_REACTOR.every(10) do
83
85
  # LibvirtAsync::Util.create_task(nil, ASYNC_REACTOR) { IMPL.print_debug_info }.run
@@ -90,20 +92,94 @@ Async do
90
92
  # Libvirt.logger.info { "MEM USAGE: #{GetProcessMem.new.mb} MB" }
91
93
  end
92
94
 
93
- ASYNC_REACTOR.after(20) do
94
- LibvirtAsync::Util.create_task(nil, ASYNC_REACTOR) do
95
+ # ASYNC_REACTOR.after(20) do
96
+ # Libvirt.logger.info { 'START Cleaning up!' }
97
+ #
98
+ # LibvirtAsync::Util.create_task(nil, ASYNC_REACTOR) do
99
+ #
100
+ # OBJECTS[:cb_ids].each do |callback_id|
101
+ # Libvirt.logger.info { "Start retrieving callback_id=#{callback_id}" }
102
+ # opaque = OBJECTS[:hv].deregister_domain_event_callback(callback_id)
103
+ # Libvirt.logger.info { "Retrieved opaque=#{opaque}" }
104
+ # end
105
+ # Libvirt.logger.info { 'Cleaning up!' }
106
+ # OBJECTS[:hv] = nil
107
+ # OBJECTS[:domains] = []
108
+ # OBJECTS[:cb_ids] = []
109
+ # Libvirt.logger.info { "GC.start 1" }
110
+ # GC.start
111
+ #
112
+ # ASYNC_REACTOR << LibvirtAsync::Util.create_task(nil, ASYNC_REACTOR) do
113
+ # Libvirt.logger.info { "GC.start 2" }
114
+ # GC.start
115
+ # end.fiber
116
+ #
117
+ # end.run
118
+ # end
95
119
 
96
- c = CONNS.first
97
- CB_IDS.each do |callback_id|
98
- opaque = c.deregister_domain_event_callback(callback_id)
99
- puts "Retrieved opaque #{opaque}"
100
- end
101
- Libvirt.logger.info { 'Cleaning up!' }
102
- CONNS = []
103
- DOMS = []
104
- CB_IDS = []
105
- GC.start
120
+ # puts 'undefine DOM'
121
+ # d.undefine
122
+ # ASYNC_REACTOR.sleep 5
106
123
 
107
- end
108
- end
124
+ # begin
125
+ # puts 'DOM starting...'
126
+ # d.start
127
+ # puts 'DOM started'
128
+ # rescue Libvirt::Errors::LibError => e
129
+ # STDERR.puts "error starting\n#{e.class}\n#{e.message}", e.error_data
130
+ # end
131
+ #
132
+ # ASYNC_REACTOR.sleep 5
133
+ # puts "DOMAIN state #{d.get_state} before save_memory"
134
+ # d.save_memory
135
+ # puts "DOMAIN state #{d.get_state} after save_memory"
136
+ #
137
+ # ASYNC_REACTOR.sleep 5
138
+ # puts "DOMAIN state #{d.get_state} before start"
139
+ # d.start
140
+ # puts "DOMAIN state #{d.get_state} after start"
141
+ #
142
+ # #ASYNC_REACTOR.sleep 5
143
+ # puts "DOMAIN state #{d.get_state} before resume"
144
+ # d.resume
145
+ # puts "DOMAIN state #{d.get_state} after resume"
146
+
147
+ # ASYNC_REACTOR.sleep 10
148
+ # puts "DOMAIN state #{d.get_state} before shutdown"
149
+ # d.shutdown(1)
150
+ # puts "DOMAIN state #{d.get_state} after shutdown"
151
+ #
152
+ # ASYNC_REACTOR.sleep 10
153
+ # puts "DOMAIN state #{d.get_state}"
154
+ # d.start
155
+ # puts 'DOM start'
156
+ #
157
+ # ASYNC_REACTOR.sleep 10
158
+ # puts "DOMAIN state #{d.get_state}"
159
+ # d.reboot
160
+ # puts 'DOM reboot'
161
+ #
162
+ # ASYNC_REACTOR.sleep 5
163
+ # puts "DOMAIN state #{d.get_state}"
164
+ # d.suspend
165
+ # puts 'DOM suspend'
166
+ #
167
+ # ASYNC_REACTOR.sleep 5
168
+ # puts "DOMAIN state #{d.get_state}"
169
+ # d.resume
170
+ # puts 'DOM resume'
171
+ #
172
+ # ASYNC_REACTOR.sleep 5
173
+ # puts "DOMAIN state #{d.get_state}"
174
+ # d.reset
175
+ # puts 'DOM reset'
176
+ #
177
+ # ASYNC_REACTOR.sleep 5
178
+ # puts "DOMAIN state #{d.get_state}"
179
+ # d.power_off
180
+ # puts 'DOM power_off'
181
+ #
182
+ # ASYNC_REACTOR.sleep 5
183
+ # d.start
184
+ # puts 'DOM start'
109
185
  end