mirror of
https://github.com/OpenNebula/one.git
synced 2026-12-02 05:06:14 +09:00
F #5076: Fix virtual provision
This commit is contained in:
25 files changed
+350
-3
No files matched your search
@@ -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
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
kvm-probes.d/
|
||||
@@ -0,0 +1 @@
|
||||
../../../common.d/date.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
|
||||
|
||||
@@ -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')
|
||||
@@ -0,0 +1 @@
|
||||
../../../node-probes.d/numa_usage.rb
|
||||
@@ -0,0 +1 @@
|
||||
../../../node-probes.d/architecture.sh
|
||||
@@ -0,0 +1 @@
|
||||
../../../node-probes.d/cpu.sh
|
||||
@@ -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')
|
||||
@@ -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.
|
||||
#
|
||||
# <guest>
|
||||
# <os_type>hvm</os_type>
|
||||
# <arch name='x86_64'>
|
||||
# <wordsize>64</wordsize>
|
||||
# <emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
# <machine maxCpus='255'>pc-i440fx-2.0</machine>
|
||||
# <machine canonical='pc-i440fx-2.0' maxCpus='255'>pc</machine>
|
||||
# ...
|
||||
# <machine maxCpus='255'>pc-1.0</machine>
|
||||
# <machine maxCpus='255'>pc-0.13</machine>
|
||||
# <domain type='qemu'/>
|
||||
# <domain type='kvm'>
|
||||
# <emulator>/usr/libexec/qemu-kvm</emulator>
|
||||
# <machine maxCpus='240'>pc-i440fx-rhel7.4.0</machine>
|
||||
# <machine canonical='pc-i440fx-rhel7.4.0' maxCpus='240'>pc</machine>
|
||||
# ...
|
||||
# <machine maxCpus='240'>rhel6.2.0</machine>
|
||||
# <machine maxCpus='240'>pc-i440fx-rhel7.3.0</machine>
|
||||
# </domain>
|
||||
# </arch>
|
||||
# ...
|
||||
# </guest>
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
../../../node-probes.d/monitor_ds.rb
|
||||
@@ -0,0 +1 @@
|
||||
../../../node-probes.d/name.sh
|
||||
@@ -0,0 +1 @@
|
||||
../../../node-probes.d/numa_host.rb
|
||||
@@ -0,0 +1 @@
|
||||
../../../node-probes.d/pci.rb
|
||||
@@ -0,0 +1 @@
|
||||
../../../common.d/version.sh
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/ruby
|
||||
|
||||
require_relative '../../../lib/kvm'
|
||||
|
||||
KVM.load_conf
|
||||
|
||||
puts DomainList.wilds_info
|
||||
@@ -0,0 +1 @@
|
||||
../node-probes.d/pci.conf
|
||||
@@ -0,0 +1 @@
|
||||
../../../node-probes.d/monitor_ds_vm.rb
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/ruby
|
||||
|
||||
require_relative '../../../lib/kvm'
|
||||
|
||||
KVM.load_conf
|
||||
|
||||
puts DomainList.info
|
||||
@@ -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")
|
||||
+30
@@ -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
|
||||
@@ -1 +0,0 @@
|
||||
kvm.d/
|
||||
@@ -0,0 +1 @@
|
||||
../common.d/monitord-client.rb
|
||||
@@ -0,0 +1 @@
|
||||
../common.d/monitord-client_control.sh
|
||||
@@ -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
|
||||
]
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user