mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-20 10:50:08 +03:00
F #1684: fix NicLXD for snaps. Prevent error when monitoring no mem container
* F #1684: Patched NicLXD for snaps * F #1684: Fix memory default value * F #1684: Prevent error when monitoring no mem container * F #1684: Removed end * F #1684: Leave LXC_COMMAND
This commit is contained in:
parent
47bb4c0a4a
commit
214ec6b491
@ -169,9 +169,8 @@ class Container
|
||||
err = 'cannot create user data directory:'
|
||||
rc, o, e = Command.execute("sudo #{cmd}", true) if e.include?(err)
|
||||
|
||||
return [rc, o, e] unless rc != 0
|
||||
|
||||
OpenNebula.log_error("#{__method__}: Failed to run command #{cmd}: #{e}")
|
||||
log = "Failed to run command #{cmd}: #{e}"
|
||||
OpenNebula.log_error("#{__method__}: #{log}") unless rc.zero?
|
||||
|
||||
[rc, o, e]
|
||||
end
|
||||
|
@ -129,19 +129,17 @@ module LXD
|
||||
|
||||
state
|
||||
end
|
||||
|
||||
|
||||
def lxc_path(vm_name)
|
||||
path = 'lxc/' + vm_name
|
||||
path = "#{ENV['LXC_CGROUP_PREFIX']}#{path}" if ENV['LXC_CGROUP_PREFIX']
|
||||
end
|
||||
end
|
||||
|
||||
def get_memory(vm_name)
|
||||
begin
|
||||
stat = File.read('/sys/fs/cgroup/memory/' + lxc_path(vm_name) + '/memory.usage_in_bytes').to_i
|
||||
stat / 1024
|
||||
rescue StandardError
|
||||
return 0
|
||||
end
|
||||
stat = File.read('/sys/fs/cgroup/memory/' + lxc_path(vm_name) + '/memory.usage_in_bytes').to_i
|
||||
stat / 1024
|
||||
rescue StandardError
|
||||
0
|
||||
end
|
||||
|
||||
def get_net_statistics(vmd)
|
||||
@ -176,7 +174,7 @@ module LXD
|
||||
cpu_jiffies = get_cpu_jiffies - start_cpu_jiffies
|
||||
|
||||
vm_names.each do |vm_name|
|
||||
cpu_used[vm_name] = (get_process_jiffies(vm_name).to_f -
|
||||
cpu_used[vm_name] = (get_process_jiffies(vm_name).to_f -
|
||||
cpu_used[vm_name]) / cpu_jiffies
|
||||
|
||||
cpu_used[vm_name] = (cpu_used[vm_name] * multiplier).round(2)
|
||||
@ -205,7 +203,7 @@ module LXD
|
||||
def get_process_jiffies(vm_name)
|
||||
begin
|
||||
jiffies = 0
|
||||
|
||||
|
||||
stat = File.read('/sys/fs/cgroup/cpu,cpuacct/' + lxc_path(vm_name) + '/cpuacct.stat')
|
||||
stat.lines.each {|line| jiffies += line.split(' ')[1] }
|
||||
rescue StandardError
|
||||
@ -232,20 +230,20 @@ module LXD
|
||||
arch = container.architecture
|
||||
capacity = container.expanded_config
|
||||
|
||||
cpu = ""
|
||||
vcpu= ""
|
||||
mem = ""
|
||||
cpu = ''
|
||||
vcpu = ''
|
||||
mem = ''
|
||||
|
||||
if capacity
|
||||
cpu = capacity['limits.cpu.allowance']
|
||||
vcpu = capacity['limits.cpu']
|
||||
mem = capacity['limits.memory']
|
||||
mem = capacity['limits.memory']
|
||||
end
|
||||
|
||||
cpu = "50%" if !cpu || cpu.empty?
|
||||
vcpu = "1" if !vcpu || vcpu.empty?
|
||||
mem = "512M" if !mem || mem.empty?
|
||||
|
||||
cpu = '50%' if !cpu || cpu.empty?
|
||||
vcpu = '1' if !vcpu || vcpu.empty?
|
||||
mem = '512MB' if !mem || mem.empty?
|
||||
|
||||
cpu = cpu.chomp('%').to_f / 100
|
||||
mem = parse_memory(mem)
|
||||
|
||||
|
@ -110,7 +110,12 @@ module VNMMAD
|
||||
end
|
||||
|
||||
if deploy_id && vm.vm_info[:dumpxml].nil?
|
||||
vm.vm_info[:dumpxml] = YAML.safe_load(`lxc config show #{deploy_id} 2>/dev/null`)
|
||||
cmd = "lxc config show #{deploy_id} 2>/dev/null"
|
||||
|
||||
config = YAML.safe_load(`#{cmd}`)
|
||||
config = YAML.safe_load(`sudo #{cmd}`) if config.nil?
|
||||
|
||||
vm.vm_info[:dumpxml] = config
|
||||
|
||||
vm.vm_info.each_key do |k|
|
||||
vm.vm_info[k] = nil if vm.vm_info[k].to_s.strip.empty?
|
||||
|
Loading…
x
Reference in New Issue
Block a user