From 007ce2dd9abab2f60f5e3e854b7cfcea8ce2f5b8 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 3 Mar 2021 15:03:10 +0000 Subject: [PATCH] F #5076: Fix virtual provision --- share/oneprovision/ansible/aws.yml | 2 +- src/im_mad/remotes/qemu-probes.d | 1 - .../remotes/qemu-probes.d/host/beacon/date.sh | 1 + .../host/beacon/monitord-client-shepherd.sh | 29 +++++ .../qemu-probes.d/host/monitor/linux_usage.rb | 21 ++++ .../qemu-probes.d/host/monitor/numa_usage.rb | 1 + .../qemu-probes.d/host/system/architecture.sh | 1 + .../remotes/qemu-probes.d/host/system/cpu.sh | 1 + .../qemu-probes.d/host/system/linux_host.rb | 21 ++++ .../host/system/machines_models.rb | 113 ++++++++++++++++++ .../qemu-probes.d/host/system/monitor_ds.rb | 1 + .../remotes/qemu-probes.d/host/system/name.sh | 1 + .../qemu-probes.d/host/system/numa_host.rb | 1 + .../remotes/qemu-probes.d/host/system/pci.rb | 1 + .../qemu-probes.d/host/system/version.sh | 1 + .../qemu-probes.d/host/system/wild_vm.rb | 7 ++ src/im_mad/remotes/qemu-probes.d/pci.conf | 1 + .../qemu-probes.d/vm/monitor/monitor_ds_vm.rb | 1 + .../remotes/qemu-probes.d/vm/monitor/poll.rb | 7 ++ .../qemu-probes.d/vm/snapshot/recovery.rb | 99 +++++++++++++++ .../remotes/qemu-probes.d/vm/status/state.rb | 30 +++++ src/im_mad/remotes/qemu.d | 1 - src/im_mad/remotes/qemu.d/monitord-client.rb | 1 + .../remotes/qemu.d/monitord-client_control.sh | 1 + src/monitor/etc/monitord.conf | 9 ++ 25 files changed, 350 insertions(+), 3 deletions(-) delete mode 120000 src/im_mad/remotes/qemu-probes.d create mode 120000 src/im_mad/remotes/qemu-probes.d/host/beacon/date.sh create mode 100755 src/im_mad/remotes/qemu-probes.d/host/beacon/monitord-client-shepherd.sh create mode 100755 src/im_mad/remotes/qemu-probes.d/host/monitor/linux_usage.rb create mode 120000 src/im_mad/remotes/qemu-probes.d/host/monitor/numa_usage.rb create mode 120000 src/im_mad/remotes/qemu-probes.d/host/system/architecture.sh create mode 120000 src/im_mad/remotes/qemu-probes.d/host/system/cpu.sh create mode 100755 src/im_mad/remotes/qemu-probes.d/host/system/linux_host.rb create mode 100755 src/im_mad/remotes/qemu-probes.d/host/system/machines_models.rb create mode 120000 src/im_mad/remotes/qemu-probes.d/host/system/monitor_ds.rb create mode 120000 src/im_mad/remotes/qemu-probes.d/host/system/name.sh create mode 120000 src/im_mad/remotes/qemu-probes.d/host/system/numa_host.rb create mode 120000 src/im_mad/remotes/qemu-probes.d/host/system/pci.rb create mode 120000 src/im_mad/remotes/qemu-probes.d/host/system/version.sh create mode 100755 src/im_mad/remotes/qemu-probes.d/host/system/wild_vm.rb create mode 120000 src/im_mad/remotes/qemu-probes.d/pci.conf create mode 120000 src/im_mad/remotes/qemu-probes.d/vm/monitor/monitor_ds_vm.rb create mode 100755 src/im_mad/remotes/qemu-probes.d/vm/monitor/poll.rb create mode 100755 src/im_mad/remotes/qemu-probes.d/vm/snapshot/recovery.rb create mode 100755 src/im_mad/remotes/qemu-probes.d/vm/status/state.rb delete mode 120000 src/im_mad/remotes/qemu.d create mode 120000 src/im_mad/remotes/qemu.d/monitord-client.rb create mode 120000 src/im_mad/remotes/qemu.d/monitord-client_control.sh diff --git a/share/oneprovision/ansible/aws.yml b/share/oneprovision/ansible/aws.yml index cdd20e3052..a86d883ad1 100644 --- a/share/oneprovision/ansible/aws.yml +++ b/share/oneprovision/ansible/aws.yml @@ -9,7 +9,7 @@ roles: - ddc - opennebula-repository - - { role: opennebula-node-kvm, when: oneprovision_hypervisor == 'kvm' } + - { role: opennebula-node-kvm, when: oneprovision_hypervisor == 'kvm' or oneprovision_hypervisor == 'qemu' } - { role: opennebula-node-firecracker, when: oneprovision_hypervisor == 'firecracker' } - opennebula-ssh - role: iptables diff --git a/src/im_mad/remotes/qemu-probes.d b/src/im_mad/remotes/qemu-probes.d deleted file mode 120000 index de12793595..0000000000 --- a/src/im_mad/remotes/qemu-probes.d +++ /dev/null @@ -1 +0,0 @@ -kvm-probes.d/ \ No newline at end of file diff --git a/src/im_mad/remotes/qemu-probes.d/host/beacon/date.sh b/src/im_mad/remotes/qemu-probes.d/host/beacon/date.sh new file mode 120000 index 0000000000..3da1f71697 --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/host/beacon/date.sh @@ -0,0 +1 @@ +../../../common.d/date.sh \ No newline at end of file diff --git a/src/im_mad/remotes/qemu-probes.d/host/beacon/monitord-client-shepherd.sh b/src/im_mad/remotes/qemu-probes.d/host/beacon/monitord-client-shepherd.sh new file mode 100755 index 0000000000..2d342785a5 --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/host/beacon/monitord-client-shepherd.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +( +[ -f /tmp/one-monitord-client.pid ] || exit 0 +running_pid=$(cat /tmp/one-monitord-client.pid) +pids=$(ps axuwww | grep -e "/monitord-client.rb kvm" | grep -v grep | awk '{ print $2 }' | grep -v "^${running_pid}$") + +if [ -n "$pids" ]; then + kill $pids +fi + +) > /dev/null + diff --git a/src/im_mad/remotes/qemu-probes.d/host/monitor/linux_usage.rb b/src/im_mad/remotes/qemu-probes.d/host/monitor/linux_usage.rb new file mode 100755 index 0000000000..8c9d777e2e --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/host/monitor/linux_usage.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +require_relative '../../../lib/linux' + +LinuxHost.usage('kvm') diff --git a/src/im_mad/remotes/qemu-probes.d/host/monitor/numa_usage.rb b/src/im_mad/remotes/qemu-probes.d/host/monitor/numa_usage.rb new file mode 120000 index 0000000000..dd18a250f8 --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/host/monitor/numa_usage.rb @@ -0,0 +1 @@ +../../../node-probes.d/numa_usage.rb \ No newline at end of file diff --git a/src/im_mad/remotes/qemu-probes.d/host/system/architecture.sh b/src/im_mad/remotes/qemu-probes.d/host/system/architecture.sh new file mode 120000 index 0000000000..329ef74b9f --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/host/system/architecture.sh @@ -0,0 +1 @@ +../../../node-probes.d/architecture.sh \ No newline at end of file diff --git a/src/im_mad/remotes/qemu-probes.d/host/system/cpu.sh b/src/im_mad/remotes/qemu-probes.d/host/system/cpu.sh new file mode 120000 index 0000000000..36f9590daf --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/host/system/cpu.sh @@ -0,0 +1 @@ +../../../node-probes.d/cpu.sh \ No newline at end of file diff --git a/src/im_mad/remotes/qemu-probes.d/host/system/linux_host.rb b/src/im_mad/remotes/qemu-probes.d/host/system/linux_host.rb new file mode 100755 index 0000000000..dcf908fe2f --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/host/system/linux_host.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +require_relative '../../../lib/linux' + +LinuxHost.config('kvm') diff --git a/src/im_mad/remotes/qemu-probes.d/host/system/machines_models.rb b/src/im_mad/remotes/qemu-probes.d/host/system/machines_models.rb new file mode 100755 index 0000000000..47a2021de5 --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/host/system/machines_models.rb @@ -0,0 +1,113 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # +require 'rexml/document' +require 'open3' + +ENV['LANG'] = 'C' +ENV['LC_ALL'] = 'C' + +GUEST_ARCHS = %w(i686 x86_64) + +begin + + capabilities = "" + archs = [] + machines = [] + models = [] + + cmd = 'virsh -r -c qemu:///system capabilities' + capabilities, e, s = Open3.capture3(cmd) + exit(-1) unless s.success? + + cap_xml = REXML::Document.new(capabilities) + cap_xml = cap_xml.root + + GUEST_ARCHS.each { |a| + a_elem = cap_xml.elements["guest/arch[@name='#{a}']"] + next if !a_elem + + # Evaluate the domain specific machines with higher priority + # over the machines listed just inside the architecture. + # + # + # hvm + # + # 64 + # /usr/bin/qemu-system-x86_64 + # pc-i440fx-2.0 + # pc + # ... + # pc-1.0 + # pc-0.13 + # + # + # /usr/libexec/qemu-kvm + # pc-i440fx-rhel7.4.0 + # pc + # ... + # rhel6.2.0 + # pc-i440fx-rhel7.3.0 + # + # + # ... + # + + a_machines = [] + + ['kvm', 'kqemu', 'qemu', ''].each { |type| + if type.empty? + d_elem = a_elem + else + d_elem = a_elem.elements["domain[@type='#{type}']"] + end + + if d_elem + d_elem.elements.each('machine') { |m| + a_machines << m.text + } + + # take only first found domain type + unless a_machines.empty? + machines.concat(a_machines) + break + end + end + } + + cmd = "virsh -r -c qemu:///system cpu-models #{a}" + cpu_models, e, s = Open3.capture3(cmd) + break unless s.success? + + cpu_models.each_line { |l| + l.chomp! + next if l.empty? or l =~ /all CPU models are accepted/i; + models << l + } + } + + machines.uniq! + models.uniq! + + puts "KVM_MACHINES=\"#{machines.join(' ')}\"" + puts "KVM_CPU_MODELS=\"#{models.join(' ')}\"" + puts "KVM_CPU_MODEL=\"#{cap_xml.elements['host/cpu/model'].text}\"" + +rescue +end + + diff --git a/src/im_mad/remotes/qemu-probes.d/host/system/monitor_ds.rb b/src/im_mad/remotes/qemu-probes.d/host/system/monitor_ds.rb new file mode 120000 index 0000000000..06f300ec56 --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/host/system/monitor_ds.rb @@ -0,0 +1 @@ +../../../node-probes.d/monitor_ds.rb \ No newline at end of file diff --git a/src/im_mad/remotes/qemu-probes.d/host/system/name.sh b/src/im_mad/remotes/qemu-probes.d/host/system/name.sh new file mode 120000 index 0000000000..144ab3807f --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/host/system/name.sh @@ -0,0 +1 @@ +../../../node-probes.d/name.sh \ No newline at end of file diff --git a/src/im_mad/remotes/qemu-probes.d/host/system/numa_host.rb b/src/im_mad/remotes/qemu-probes.d/host/system/numa_host.rb new file mode 120000 index 0000000000..3d79d5803f --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/host/system/numa_host.rb @@ -0,0 +1 @@ +../../../node-probes.d/numa_host.rb \ No newline at end of file diff --git a/src/im_mad/remotes/qemu-probes.d/host/system/pci.rb b/src/im_mad/remotes/qemu-probes.d/host/system/pci.rb new file mode 120000 index 0000000000..d5333561d6 --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/host/system/pci.rb @@ -0,0 +1 @@ +../../../node-probes.d/pci.rb \ No newline at end of file diff --git a/src/im_mad/remotes/qemu-probes.d/host/system/version.sh b/src/im_mad/remotes/qemu-probes.d/host/system/version.sh new file mode 120000 index 0000000000..66789f6c78 --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/host/system/version.sh @@ -0,0 +1 @@ +../../../common.d/version.sh \ No newline at end of file diff --git a/src/im_mad/remotes/qemu-probes.d/host/system/wild_vm.rb b/src/im_mad/remotes/qemu-probes.d/host/system/wild_vm.rb new file mode 100755 index 0000000000..83f1afad1e --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/host/system/wild_vm.rb @@ -0,0 +1,7 @@ +#!/usr/bin/ruby + +require_relative '../../../lib/kvm' + +KVM.load_conf + +puts DomainList.wilds_info diff --git a/src/im_mad/remotes/qemu-probes.d/pci.conf b/src/im_mad/remotes/qemu-probes.d/pci.conf new file mode 120000 index 0000000000..35bcde7efa --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/pci.conf @@ -0,0 +1 @@ +../node-probes.d/pci.conf \ No newline at end of file diff --git a/src/im_mad/remotes/qemu-probes.d/vm/monitor/monitor_ds_vm.rb b/src/im_mad/remotes/qemu-probes.d/vm/monitor/monitor_ds_vm.rb new file mode 120000 index 0000000000..bfff4b1c5a --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/vm/monitor/monitor_ds_vm.rb @@ -0,0 +1 @@ +../../../node-probes.d/monitor_ds_vm.rb \ No newline at end of file diff --git a/src/im_mad/remotes/qemu-probes.d/vm/monitor/poll.rb b/src/im_mad/remotes/qemu-probes.d/vm/monitor/poll.rb new file mode 100755 index 0000000000..bfdbe0987a --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/vm/monitor/poll.rb @@ -0,0 +1,7 @@ +#!/usr/bin/ruby + +require_relative '../../../lib/kvm' + +KVM.load_conf + +puts DomainList.info diff --git a/src/im_mad/remotes/qemu-probes.d/vm/snapshot/recovery.rb b/src/im_mad/remotes/qemu-probes.d/vm/snapshot/recovery.rb new file mode 100755 index 0000000000..2293bc5d20 --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/vm/snapshot/recovery.rb @@ -0,0 +1,99 @@ +#!/usr/bin/env ruby + +# -------------------------------------------------------------------------- # +# Copyright 2002-2021, OpenNebula Project, OpenNebula Systems # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # +require 'rexml/document' +require 'fileutils' +require 'open3' +require 'base64' + +def xml_elem(xml, xpath) + rexml = REXML::Document.new(xml).root + rexml.elements[xpath].text.to_s +rescue StandardError + nil +end + +ds_loc = xml_elem(STDIN.read, 'DATASTORE_LOCATION') +ds_loc ||= '/var/lib/one/datastores' +Dir.chdir ds_loc + +datastores = Dir.glob('*').select do |f| + File.directory?(f) && f.match(/^\d+$/) +end + +monitor_data = [] + +datastores.each do |ds| + # Skip if datastore is not ssh + mark = "#{ds_loc}/#{ds}/.monitor" + next unless File.exist? mark + + driver = File.read mark + driver.chomp! + next unless driver == 'ssh' + + # for all VMs + Dir.entries("#{ds_loc}/#{ds}").each do |vm_id| + vm_dir = "#{ds_loc}/#{ds}/#{vm_id}" + next if vm_id !~ /^\d+$/ + next unless File.directory?(vm_dir) + + disk_data = [] + # for all disks + Dir.entries(vm_dir).each do |disk| + next if disk !~ /^disk.\d+$/ + next unless File.file?("#{vm_dir}/#{disk}.snap/base.1") + next unless File.file?("#{vm_dir}/vm.xml") + next unless File.file?("#{vm_dir}/ds.xml") + + disk_id = disk.split('.')[1] + + replica = xml_elem(File.read("#{vm_dir}/ds.xml"), + '/DATASTORE/TEMPLATE/REPLICA_HOST') + + freq = xml_elem(File.read("#{vm_dir}/vm.xml"), + "/VM/TEMPLATE/DISK[DISK_ID=#{disk_id}]/" << + 'RECOVERY_SNAPSHOT_FREQ') + + rs_script = '/var/tmp/one/tm/ssh/recovery_snap_create_live' + next if freq.empty? || replica.empty? || !File.exist?(rs_script) + + o, _e, s = Open3.capture3("#{rs_script} #{vm_id} " << + "#{vm_dir}/#{disk} " << + "#{freq} #{replica}") + o.chomp! + + if s.exitstatus == 0 + disk_data << \ + 'DISK_RECOVERY_SNAPSHOT = ' \ + "[ ID=#{disk_id}, TIMESTAMP=\"#{o}\" ]" + else + disk_data << \ + 'DISK_RECOVERY_SNAPSHOT = ' \ + "[ ID=#{disk_id}, MSG=\"ERROR #{o}\" ]" + end + end + + next if disk_data.empty? + + enc_data = Base64.strict_encode64(disk_data.join("\n")) + monitor_data << \ + "VM = [ ID=\"#{vm_id}\", MONITOR=\"#{enc_data}\" ]" + end +end + +puts monitor_data.join("\n") diff --git a/src/im_mad/remotes/qemu-probes.d/vm/status/state.rb b/src/im_mad/remotes/qemu-probes.d/vm/status/state.rb new file mode 100755 index 0000000000..77a19af5b0 --- /dev/null +++ b/src/im_mad/remotes/qemu-probes.d/vm/status/state.rb @@ -0,0 +1,30 @@ +#!/usr/bin/ruby + +require_relative '../../../lib/kvm' +require_relative '../../../lib/probe_db' + +xml_txt = STDIN.read +host = ARGV[-1] +host_id = ARGV[-2] + +begin + config = REXML::Document.new(xml_txt).root + sync = config.elements['PROBES_PERIOD/SYNC_STATE_VM'].text.to_i +rescue StandardError + sync = 180 +end + +KVM.load_conf + +begin + vmdb = VirtualMachineDB.new('kvm', + host, + host_id, + :missing_state => 'POWEROFF', + :sync => sync) + vmdb.purge + + puts vmdb.to_status +rescue StandardError => e + puts e +end diff --git a/src/im_mad/remotes/qemu.d b/src/im_mad/remotes/qemu.d deleted file mode 120000 index c82cb7c715..0000000000 --- a/src/im_mad/remotes/qemu.d +++ /dev/null @@ -1 +0,0 @@ -kvm.d/ \ No newline at end of file diff --git a/src/im_mad/remotes/qemu.d/monitord-client.rb b/src/im_mad/remotes/qemu.d/monitord-client.rb new file mode 120000 index 0000000000..83ff041040 --- /dev/null +++ b/src/im_mad/remotes/qemu.d/monitord-client.rb @@ -0,0 +1 @@ +../common.d/monitord-client.rb \ No newline at end of file diff --git a/src/im_mad/remotes/qemu.d/monitord-client_control.sh b/src/im_mad/remotes/qemu.d/monitord-client_control.sh new file mode 120000 index 0000000000..23e6d7e502 --- /dev/null +++ b/src/im_mad/remotes/qemu.d/monitord-client_control.sh @@ -0,0 +1 @@ +../common.d/monitord-client_control.sh \ No newline at end of file diff --git a/src/monitor/etc/monitord.conf b/src/monitor/etc/monitord.conf index 425011e950..786c9576f0 100644 --- a/src/monitor/etc/monitord.conf +++ b/src/monitor/etc/monitord.conf @@ -132,6 +132,15 @@ IM_MAD = [ ARGUMENTS = "-r 3 -t 15 -w 90 kvm", THREADS = 0 ] + + +IM_MAD = [ + NAME = "qemu", + SUNSTONE_NAME = "QEMU", + EXECUTABLE = "one_im_ssh", + ARGUMENTS = "-r 3 -t 15 -w 90 qemu", + THREADS = 0 +] #------------------------------------------------------------------------------- #-------------------------------------------------------------------------------