libvirt_ffi 0.2.1 → 0.5.1

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 -2
  4. data/Rakefile +6 -1
  5. data/bin/console +1 -0
  6. data/exe/libvirt +1 -0
  7. data/lib/libvirt.rb +14 -13
  8. data/lib/libvirt/base_info.rb +34 -0
  9. data/lib/libvirt/connection.rb +156 -47
  10. data/lib/libvirt/domain.rb +136 -8
  11. data/lib/libvirt/domain_callback_storage.rb +69 -0
  12. data/lib/libvirt/errors.rb +65 -0
  13. data/lib/libvirt/event.rb +60 -38
  14. data/lib/libvirt/ffi.rb +17 -0
  15. data/lib/libvirt/ffi/common.rb +8 -1
  16. data/lib/libvirt/ffi/domain.rb +796 -69
  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 +122 -0
  21. data/lib/libvirt/ffi/storage.rb +149 -0
  22. data/lib/libvirt/ffi/stream.rb +74 -0
  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 +124 -0
  29. data/lib/libvirt/util.rb +75 -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 +33 -31
  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 +134 -33
  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 +197 -0
  50. data/test_usage/test_storage.rb +52 -0
  51. metadata +46 -6
  52. data/lib/libvirt/error.rb +0 -6
  53. data/lib/libvirt/ffi/connection.rb +0 -84
  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,27 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module LibvirtAsync
4
+ class << self
5
+ attr_writer :logger
6
+
7
+ attr_reader :logger
8
+ end
9
+
2
10
  module WithDbg
3
11
  extend ActiveSupport::Concern
4
12
 
5
13
  class_methods do
6
14
  def dbg(progname = nil, &block)
7
- Libvirt.logger.debug(progname || "#{name}.:0x#{object_id.to_s(16)}", &block)
15
+ LibvirtAsync.logger&.debug(progname || "#{name}.:0x#{object_id.to_s(16)}", &block)
8
16
  end
9
17
  end
10
18
 
11
19
  private
12
20
 
13
21
  def dbg(progname = nil, &block)
14
- Libvirt.logger.debug(progname || "#{self.class}#:0x#{object_id.to_s(16)}", &block)
22
+ LibvirtAsync.logger&.debug(progname || "#{self.class}#:0x#{object_id.to_s(16)}", &block)
15
23
  end
16
24
  end
17
25
 
18
26
  module Util
19
- def create_task(parent = nil, reactor = nil, &block)
27
+ def self.create_task(parent = nil, reactor = nil, &block)
20
28
  parent = Async::Task.current? if parent == :current
21
29
  reactor ||= Async::Task.current.reactor
22
30
  Async::Task.new(reactor, parent, &block)
23
31
  end
24
- module_function :create_task
25
32
  end
26
33
 
27
34
  class Handle
@@ -67,12 +74,8 @@ module LibvirtAsync
67
74
  def register
68
75
  dbg { "#{self.class}#register handle_id=#{handle_id}, fd=#{fd}" }
69
76
 
70
- if (events & Libvirt::EVENT_HANDLE_ERROR) != 0
71
- dbg { "#{self.class}#register skip EVENT_HANDLE_ERROR handle_id=#{handle_id}, fd=#{fd}" }
72
- end
73
- if (events & Libvirt::EVENT_HANDLE_HANGUP) != 0
74
- dbg { "#{self.class}#register skip EVENT_HANDLE_HANGUP handle_id=#{handle_id}, fd=#{fd}" }
75
- 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
76
79
 
77
80
  interest = events_to_interest(events)
78
81
  dbg { "#{self.class}#register parse handle_id=#{handle_id}, fd=#{fd}, events=#{events}, interest=#{interest}" }
@@ -89,7 +92,7 @@ module LibvirtAsync
89
92
  io = IO.new(fd, io_mode, autoclose: false)
90
93
  @monitor = Monitor.new(io)
91
94
 
92
- while @monitor.readiness == nil
95
+ while @monitor.readiness.nil?
93
96
  cancelled = wait_io(interest)
94
97
 
95
98
  if cancelled
@@ -107,7 +110,6 @@ module LibvirtAsync
107
110
 
108
111
  dbg { "#{self.class}#register_handle async not ready readiness=#{@monitor.readiness}, handle_id=#{handle_id}, fd=#{fd}" }
109
112
  end
110
-
111
113
  end
112
114
 
113
115
  dbg { "#{self.class}#register_handle invokes fiber=0x#{task.fiber.object_id.to_s(16)} handle_id=#{handle_id}, fd=#{fd}" }
@@ -187,8 +189,6 @@ module LibvirtAsync
187
189
  :r
188
190
  elsif writable
189
191
  :w
190
- else
191
- nil
192
192
  end
193
193
  end
194
194
 
@@ -213,8 +213,6 @@ module LibvirtAsync
213
213
  Libvirt::EVENT_HANDLE_READABLE
214
214
  when :w
215
215
  Libvirt::EVENT_HANDLE_WRITABLE
216
- else
217
- nil
218
216
  end
219
217
  end
220
218
  end
@@ -267,14 +265,15 @@ module LibvirtAsync
267
265
  dbg { "#{self.class}#initialize timer_id=#{timer_id}, interval=#{interval}" }
268
266
 
269
267
  @timer_id = timer_id
270
- @interval = interval.to_f / 1000.to_f
268
+ @interval = interval / 1000.0
271
269
  @opaque = opaque
272
270
  @last_fired = Time.now.to_f
273
271
  @monitor = nil
274
272
  end
275
273
 
276
274
  def wait_time
277
- return if interval < 0
275
+ return if interval.negative?
276
+
278
277
  last_fired + interval
279
278
  end
280
279
 
@@ -348,15 +347,12 @@ module LibvirtAsync
348
347
  end
349
348
 
350
349
  def wait_timer(timeout)
351
- begin
352
- @monitor.wait(timeout)
353
- false
354
- rescue Monitor::Cancelled => e
355
- dbg { "#{self.class}#wait_timer cancelled #{e.class} #{e.message}" }
356
- true
357
- 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
358
355
  end
359
-
360
356
  end
361
357
 
362
358
  class Implementations
@@ -386,12 +382,12 @@ module LibvirtAsync
386
382
  def print_debug_info
387
383
  str = [
388
384
  "#{self.class}:0x#{object_id.to_s(16)}",
389
- "handles = [",
385
+ 'handles = [',
390
386
  @handles.map(&:to_s).join("\n"),
391
- "]",
392
- "timers = [",
387
+ ']',
388
+ 'timers = [',
393
389
  @timers.map(&:to_s).join("\n"),
394
- "]"
390
+ ']'
395
391
  ].join("\n")
396
392
  Libvirt.logger&.debug { str }
397
393
  end
@@ -422,10 +418,16 @@ module LibvirtAsync
422
418
  remove_handle: method(:remove_handle).to_proc,
423
419
  add_timer: method(:add_timer).to_proc,
424
420
  update_timer: method(:update_timer).to_proc,
425
- remove_timer: method(:remove_timer).to_proc
421
+ remove_timer: method(:remove_timer).to_proc,
422
+ schedule: method(:schedule).to_proc
426
423
  )
427
424
  end
428
425
 
426
+ def schedule(&block)
427
+ task = Async::Task.new(Async::Task.current.reactor, nil, &block)
428
+ task.reactor << task.fiber
429
+ end
430
+
429
431
  def add_handle(fd, events, opaque)
430
432
  # add a handle to be tracked by this object. The application is
431
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'
@@ -6,16 +7,28 @@ require 'logger'
6
7
  require 'active_support/all'
7
8
  require 'async'
8
9
  require 'get_process_mem'
10
+ require 'gc_tracer'
9
11
 
10
12
  require_relative 'support/libvirt_async'
11
13
  require_relative 'support/log_formatter'
12
14
 
15
+ GC::Tracer.start_logging(
16
+ nil,
17
+ gc_stat: false,
18
+ gc_latest_gc_info: false,
19
+ rusage: false,
20
+ events: [:end_mark, :end_sweep]
21
+ )
22
+
13
23
  Libvirt.logger = Logger.new(STDOUT, formatter: LogFormatter.new)
14
24
  Libvirt.logger.level = ENV['DEBUG'] ? :debug : :info
15
25
 
16
26
  IMPL = LibvirtAsync::Implementations.new
17
- CONNS = []
18
- DOMS = []
27
+ OBJECTS = {
28
+ hv: nil,
29
+ domains: [],
30
+ cb_ids: []
31
+ }.freeze
19
32
 
20
33
  Async do
21
34
  ASYNC_REACTOR = Async::Task.current.reactor
@@ -25,18 +38,17 @@ Async do
25
38
 
26
39
  IMPL.start
27
40
 
28
- c = Libvirt::Connection.new('qemu+tcp://localhost:16510/system')
29
- c.open
30
- res = c.set_keep_alive(2, 1)
31
- Libvirt.logger.info { "set_keep_alive #{res}" }
32
- CONNS.push(c)
33
-
34
- puts "Connection version #{c.version.inspect}"
35
- puts "Connection lib_version #{c.lib_version.inspect}"
36
- puts "Connection hostname #{c.hostname.inspect}"
37
- puts "Connection max_vcpus #{c.max_vcpus.inspect}"
38
- puts "Connection capabilities #{c.capabilities.inspect}"
39
- 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
40
52
  puts "Connection nodeInfo #{node_info}"
41
53
  puts "NodeInfo model #{node_info.model.inspect}"
42
54
  puts "NodeInfo cpus #{node_info.cpus.inspect}"
@@ -47,38 +59,127 @@ Async do
47
59
  puts "NodeInfo threads #{node_info.threads.inspect}"
48
60
  puts "NodeInfo memory #{node_info.memory.inspect}"
49
61
 
50
- c.register_domain_event_callback(Libvirt::DOMAIN_EVENT_ID_LIFECYCLE, nil) do |dom, event, detail, opaque|
51
- Libvirt.logger.info { "DOMAIN_EVENT_ID_LIFECYCLE user dom=#{dom}, event=#{event}, detail=#{detail}, opaque=#{opaque}" }
62
+ Libvirt::Connection::DOMAIN_EVENT_IDS.map do |event_id|
63
+ op = OpenStruct.new(a: 'b', event_id: event_id)
64
+ callback_id = OBJECTS[:hv].register_domain_event_callback(event_id, nil, op) do |conn, dom, *args, opaque|
65
+ Libvirt.logger.info { "DOMAIN EVENT #{event_id} conn=#{conn}, dom=#{dom}, args=#{args}, opaque=#{opaque}" }
66
+ end
67
+ Libvirt.logger.info { "Registered domain event callback event_id=#{event_id} callback_id=#{callback_id}" }
68
+ OBJECTS[:cb_ids] << callback_id
52
69
  end
53
70
 
54
- puts "domains qty #{c.list_all_domains_qty}"
55
-
56
- domains = c.list_all_domains
57
- DOMS.concat(domains)
58
- puts "Domains (#{domains.size}): #{domains}"
71
+ puts "domains qty #{OBJECTS[:hv].list_all_domains_qty}"
59
72
 
60
- domains.each_with_index do |domain, index|
61
- c.register_domain_event_callback(Libvirt::DOMAIN_EVENT_ID_LIFECYCLE, domain) do |dom, event, detail, opaque|
62
- Libvirt.logger.info { "DOMAIN_EVENT_CALLBACK LIFECYCLE user##{index} dom=#{dom}, event=#{event}, detail=#{detail}, opaque=#{opaque}" }
63
- end
64
- end
73
+ OBJECTS[:domains] = OBJECTS[:hv].list_all_domains
74
+ puts "Domains (#{OBJECTS[:domains].size}): #{OBJECTS[:domains]}"
65
75
 
66
- d = domains.first
76
+ d = OBJECTS[:domains].first
67
77
  puts "Domain uuid #{d.uuid.inspect}"
68
78
  puts "Domain name #{d.name.inspect}"
69
79
  puts "Domain get_state #{d.get_state.inspect}"
70
80
  puts "Domain get_cpus #{d.max_vcpus.inspect}"
71
81
  puts "Domain max_memory #{d.max_memory.inspect}"
72
- puts "Domain xml_desc #{d.xml_desc.inspect}"
82
+ # puts "Domain xml_desc #{d.xml_desc.inspect}"
73
83
 
74
84
  # ASYNC_REACTOR.every(10) do
75
85
  # LibvirtAsync::Util.create_task(nil, ASYNC_REACTOR) { IMPL.print_debug_info }.run
76
86
  # end
77
87
 
78
- # ASYNC_REACTOR.every(5) do
79
- # Libvirt.logger.info { "MEM USAGE: #{GetProcessMem.new.mb} MB" }
80
- # Libvirt.logger.info { "GC.start" }
81
- # GC.start
82
- # Libvirt.logger.info { "MEM USAGE: #{GetProcessMem.new.mb} MB" }
88
+ ASYNC_REACTOR.every(5) do
89
+ Libvirt.logger.info { "MEM USAGE: #{GetProcessMem.new.mb} MB" }
90
+ # Libvirt.logger.info { "GC.start" }
91
+ # GC.start
92
+ # Libvirt.logger.info { "MEM USAGE: #{GetProcessMem.new.mb} MB" }
93
+ end
94
+
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
119
+
120
+ # puts 'undefine DOM'
121
+ # d.undefine
122
+ # ASYNC_REACTOR.sleep 5
123
+
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
83
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'
84
185
  end