Sha256: 3f6bdbbac6a6f0ed0afc5c391b5d9bd7f49af23c4056196666757a9ff35af228

Contents?: true

Size: 1.4 KB

Versions: 12

Compression:

Stored size: 1.4 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'libvirt'
require 'logger'
require 'active_support/all'
require 'async'
require 'get_process_mem'
require 'gc_tracer'

require_relative 'support/libvirt_async'
require_relative 'support/log_formatter'

GC::Tracer.start_logging(
    nil,
    gc_stat: false,
    gc_latest_gc_info: false,
    rusage: false,
    events: [:end_mark, :end_sweep]
)

Libvirt.logger = Logger.new(STDOUT, formatter: LogFormatter.new)
Libvirt.logger.level = ENV['DEBUG'] ? :debug : :info

IMPL = LibvirtAsync::Implementations.new
OBJECTS = {
    hv: nil
}.freeze

def async_task(run, parent = nil, &block)
  task = LibvirtAsync::Util.create_task(parent, ASYNC_REACTOR, &block)
  case run
  when :now
    task.run
  when :later
    task.reactor << task.fiber
  else
    raise ArgumentError, "invalid run #{run}"
  end
end

Async do
  ASYNC_REACTOR = Async::Task.current.reactor

  puts "Lib version #{Libvirt.lib_version}"
  puts "Gem version #{Libvirt::VERSION}"

  IMPL.start

  OBJECTS[:hv] = Libvirt::Connection.new('qemu+tcp://localhost:16510/system')
  OBJECTS[:hv].open
  OBJECTS[:hv].register_close_callback do |conn, reason, _op|
    puts "Im closing conn=#{conn}, reason=#{reason}"
  end
  # OBJECTS[:hv].set_keep_alive(2, 1)

  ASYNC_REACTOR.every(5) do
    async_task(:now) do
      puts "list_all_domains_qty #{OBJECTS[:hv].list_all_domains_qty}"
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
libvirt_ffi-0.8.0 test_usage/test_libvirtd_restart.rb
libvirt_ffi-0.7.0 test_usage/test_libvirtd_restart.rb
libvirt_ffi-0.6.2 test_usage/test_libvirtd_restart.rb
libvirt_ffi-0.6.1 test_usage/test_libvirtd_restart.rb
libvirt_ffi-0.6.0 test_usage/test_libvirtd_restart.rb
libvirt_ffi-0.5.6 test_usage/test_libvirtd_restart.rb
libvirt_ffi-0.5.5 test_usage/test_libvirtd_restart.rb
libvirt_ffi-0.5.4 test_usage/test_libvirtd_restart.rb
libvirt_ffi-0.5.3 test_usage/test_libvirtd_restart.rb
libvirt_ffi-0.5.2 test_usage/test_libvirtd_restart.rb
libvirt_ffi-0.5.1 test_usage/test_libvirtd_restart.rb
libvirt_ffi-0.5.0 test_usage/test_libvirtd_restart.rb