mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
Change to allow one status database per host avoiding locks
This commit is contained in:
parent
c0e17da69e
commit
c85f9a1031
@ -41,10 +41,12 @@ host_id = ARGV[-2]
|
||||
|
||||
begin
|
||||
vmdb = VirtualMachineDB.new('az',
|
||||
host,
|
||||
host_id,
|
||||
:missing_state => 'UNKNOWN',
|
||||
:sync => 180)
|
||||
vmdb.purge
|
||||
puts vmdb.to_status(host, host_id)
|
||||
puts vmdb.to_status
|
||||
rescue StandardError => e
|
||||
OpenNebula.handle_driver_exception('im probe_vm_status', e, host)
|
||||
end
|
||||
|
@ -41,10 +41,12 @@ host_id = ARGV[-2]
|
||||
|
||||
begin
|
||||
vmdb = VirtualMachineDB.new('ec2',
|
||||
host,
|
||||
host_id,
|
||||
:missing_state => 'UNKNOWN',
|
||||
:sync => 180)
|
||||
vmdb.purge
|
||||
puts vmdb.to_status(host, host_id)
|
||||
puts vmdb.to_status
|
||||
rescue StandardError => e
|
||||
OpenNebula.handle_driver_exception('im probe_vm_status', e, host)
|
||||
end
|
||||
|
@ -16,11 +16,13 @@ end
|
||||
|
||||
begin
|
||||
vmdb = VirtualMachineDB.new('firecracker',
|
||||
host,
|
||||
host_id,
|
||||
:missing_state => 'POWEROFF',
|
||||
:sync => sync)
|
||||
vmdb.purge
|
||||
|
||||
puts vmdb.to_status(host, host_id)
|
||||
puts vmdb.to_status
|
||||
rescue StandardError => e
|
||||
puts e
|
||||
end
|
||||
|
@ -18,11 +18,13 @@ KVM.load_conf
|
||||
|
||||
begin
|
||||
vmdb = VirtualMachineDB.new('kvm',
|
||||
host,
|
||||
host_id,
|
||||
:missing_state => 'POWEROFF',
|
||||
:sync => sync)
|
||||
vmdb.purge
|
||||
|
||||
puts vmdb.to_status(host, host_id)
|
||||
puts vmdb.to_status
|
||||
rescue StandardError => e
|
||||
puts e
|
||||
end
|
||||
|
@ -51,7 +51,7 @@ class VirtualMachineDB
|
||||
DEFAULT_CONFIGURATION = {
|
||||
:times_missing => 3,
|
||||
:obsolete => 720,
|
||||
:db_path => "#{__dir__}/../status.db",
|
||||
:base_path => "#{__dir__}/../",
|
||||
:sync => 180,
|
||||
:missing_state => "POWEROFF"
|
||||
}
|
||||
@ -73,8 +73,10 @@ class VirtualMachineDB
|
||||
File.unlink(conf[:db_path])
|
||||
end
|
||||
|
||||
def initialize(hyperv, opts = {})
|
||||
@conf = VirtualMachineDB.load_conf(hyperv, opts)
|
||||
def initialize(hyperv, host, host_id, opts = {})
|
||||
@host = host
|
||||
@host_id = host_id
|
||||
@conf = VirtualMachineDB.load_conf(hyperv, @host_id, opts)
|
||||
|
||||
@mtime = 0
|
||||
@mtime = File.mtime(@conf[:db_path]) if File.exist?(@conf[:db_path])
|
||||
@ -95,17 +97,17 @@ class VirtualMachineDB
|
||||
|
||||
# Returns the VM status that changed compared to the DB info as well
|
||||
# as VMs that have been reported as missing more than missing_times
|
||||
def to_status(host, host_id)
|
||||
def to_status
|
||||
time = Time.now.to_i
|
||||
last = @db.execute("SELECT MAX(timestamp) from #{@dataset}").flatten![0]
|
||||
last ||= @mtime.to_i
|
||||
|
||||
return sync_status(host, host_id) if last == 0 || time > (last + @conf[:sync])
|
||||
return sync_status(@host, @host_id) if last == 0 || time > (last + @conf[:sync])
|
||||
|
||||
status_str = ''
|
||||
monitor_ids = []
|
||||
|
||||
vms = DomainList.state_info(host, host_id)
|
||||
vms = DomainList.state_info(@host, @host_id)
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# report state changes in vms
|
||||
@ -239,7 +241,7 @@ class VirtualMachineDB
|
||||
end
|
||||
|
||||
# Load configuration file and parse user provided options
|
||||
def self.load_conf(hyperv, opts)
|
||||
def self.load_conf(hyperv, host_id, opts)
|
||||
conf_path = "#{__dir__}/../../etc/im/#{hyperv}-probes.d/probe_db.conf"
|
||||
etc_conf = YAML.load_file(conf_path) rescue nil
|
||||
|
||||
@ -250,6 +252,8 @@ class VirtualMachineDB
|
||||
conf.merge! opts
|
||||
|
||||
conf[:hyperv] = hyperv
|
||||
conf[:db_path] = File.join(conf[:base_path],
|
||||
"status_#{hyperv}_#{host_id}.db")
|
||||
conf
|
||||
end
|
||||
|
||||
|
@ -78,11 +78,13 @@ end
|
||||
|
||||
begin
|
||||
vmdb = VirtualMachineDB.new('lxd',
|
||||
host,
|
||||
host_id,
|
||||
:missing_state => 'POWEROFF',
|
||||
:sync => sync)
|
||||
vmdb.purge
|
||||
|
||||
puts vmdb.to_status(host, host_id)
|
||||
puts vmdb.to_status
|
||||
rescue StandardError => e
|
||||
puts e
|
||||
end
|
||||
|
@ -41,10 +41,12 @@ host_id = ARGV[-2]
|
||||
|
||||
begin
|
||||
vmdb = VirtualMachineDB.new('one2one',
|
||||
host,
|
||||
host_id,
|
||||
:missing_state => 'UNKNOWN',
|
||||
:sync => 180)
|
||||
vmdb.purge
|
||||
puts vmdb.to_status(host, host_id)
|
||||
puts vmdb.to_status
|
||||
rescue StandardError => e
|
||||
OpenNebula.handle_driver_exception('im probe_vm_status', e, host)
|
||||
end
|
||||
|
@ -41,10 +41,12 @@ host_id = ARGV[-2]
|
||||
|
||||
begin
|
||||
vmdb = VirtualMachineDB.new('packet',
|
||||
host,
|
||||
host_id,
|
||||
:missing_state => 'UNKNOWN',
|
||||
:sync => 180)
|
||||
vmdb.purge
|
||||
puts vmdb.to_status(host, host_id)
|
||||
puts vmdb.to_status
|
||||
rescue StandardError => e
|
||||
OpenNebula.handle_driver_exception('im probe_vm_status', e, host)
|
||||
end
|
||||
|
@ -41,10 +41,12 @@ host_id = ARGV[-2]
|
||||
|
||||
begin
|
||||
vmdb = VirtualMachineDB.new('vcenter',
|
||||
host,
|
||||
host_id,
|
||||
:missing_state => 'UNKNOWN',
|
||||
:sync => 180)
|
||||
vmdb.purge
|
||||
puts vmdb.to_status(host, host_id)
|
||||
puts vmdb.to_status
|
||||
rescue StandardError => e
|
||||
OpenNebula.handle_driver_exception('im probe_vm_status', e, host)
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user