gem install ruby-libvirt ruby-libvirt providers Ruby binding for libvirt. you can called it based on a domain.xml
Signed-off-by: Xiao Shenwei xiaoshenwei96@163.com --- providers/lib/libvirt.rb | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 providers/lib/libvirt.rb
diff --git a/providers/lib/libvirt.rb b/providers/lib/libvirt.rb new file mode 100644 index 0000000..e4e1240 --- /dev/null +++ b/providers/lib/libvirt.rb @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +require 'libvirt' + +# connect libvirt daemon +class LibvirtConnect + def initialize + @conn = Libvirt.open('qemu:///system') + end + + def define(xml) + @dom = @conn.define_domain_xml(File.read(xml)) + end + + def create + @dom.create + end + + def wait + loop do + sleep 10 + break unless @dom.active? + end + end + + def close + @conn.close + end +end