mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
Feature #1612: Add VOLATILE_SIZE quota to onedb migrator and fsck
This commit is contained in:
parent
7e2507e86f
commit
2b92010fef
@ -28,7 +28,7 @@ module Migrator
|
||||
def up
|
||||
|
||||
########################################################################
|
||||
# Feature #1742
|
||||
# Feature #1742 & #1612
|
||||
########################################################################
|
||||
|
||||
@db.run "ALTER TABLE user_pool RENAME TO old_user_pool;"
|
||||
@ -39,6 +39,11 @@ module Migrator
|
||||
|
||||
doc.root.add_element("GROUPS").add_element("ID").text = row[:gid].to_s
|
||||
|
||||
# oneadmin does not have quotas
|
||||
if row[:oid] != 0
|
||||
redo_vm_quotas(doc, "uid=#{row[:oid]}")
|
||||
end
|
||||
|
||||
@db[:user_pool].insert(
|
||||
:oid => row[:oid],
|
||||
:name => row[:name],
|
||||
@ -52,6 +57,44 @@ module Migrator
|
||||
|
||||
@db.run "DROP TABLE old_user_pool;"
|
||||
|
||||
########################################################################
|
||||
# Feature #1612
|
||||
########################################################################
|
||||
|
||||
@db.run "ALTER TABLE group_pool RENAME TO old_group_pool;"
|
||||
@db.run "CREATE TABLE group_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body MEDIUMTEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, UNIQUE(name));"
|
||||
|
||||
# oneadmin group does not have quotas
|
||||
@db.fetch("SELECT * FROM old_group_pool WHERE oid=0") do |row|
|
||||
@db[:group_pool].insert(
|
||||
:oid => row[:oid],
|
||||
:name => row[:name],
|
||||
:body => row[:body],
|
||||
:uid => row[:oid],
|
||||
:gid => row[:gid],
|
||||
:owner_u => row[:owner_u],
|
||||
:group_u => row[:group_u],
|
||||
:other_u => row[:other_u])
|
||||
end
|
||||
|
||||
@db.fetch("SELECT * FROM old_group_pool WHERE oid>0") do |row|
|
||||
doc = REXML::Document.new(row[:body])
|
||||
|
||||
redo_vm_quotas(doc, "gid=#{row[:oid]}")
|
||||
|
||||
@db[:group_pool].insert(
|
||||
:oid => row[:oid],
|
||||
:name => row[:name],
|
||||
:body => doc.root.to_s,
|
||||
:uid => row[:oid],
|
||||
:gid => row[:gid],
|
||||
:owner_u => row[:owner_u],
|
||||
:group_u => row[:group_u],
|
||||
:other_u => row[:other_u])
|
||||
end
|
||||
|
||||
@db.run "DROP TABLE old_group_pool;"
|
||||
|
||||
########################################################################
|
||||
# Bug #2330
|
||||
########################################################################
|
||||
@ -82,4 +125,81 @@ module Migrator
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
def redo_vm_quotas(doc, where_filter)
|
||||
cpu_limit = "-1"
|
||||
mem_limit = "-1"
|
||||
vms_limit = "-1"
|
||||
vol_limit = "-1"
|
||||
|
||||
doc.root.each_element("VM_QUOTA/VM/CPU") { |e|
|
||||
cpu_limit = e.text
|
||||
}
|
||||
|
||||
doc.root.each_element("VM_QUOTA/VM/MEMORY") { |e|
|
||||
mem_limit = e.text
|
||||
}
|
||||
|
||||
doc.root.each_element("VM_QUOTA/VM/VMS") { |e|
|
||||
vms_limit = e.text
|
||||
}
|
||||
|
||||
doc.root.delete_element("VM_QUOTA")
|
||||
vm_quota = doc.root.add_element("VM_QUOTA")
|
||||
|
||||
# VM quotas
|
||||
cpu_used = 0
|
||||
mem_used = 0
|
||||
vms_used = 0
|
||||
vol_used = 0
|
||||
|
||||
@db.fetch("SELECT body FROM vm_pool WHERE #{where_filter} AND state<>6") do |vm_row|
|
||||
vmdoc = REXML::Document.new(vm_row[:body])
|
||||
|
||||
# VM quotas
|
||||
vmdoc.root.each_element("TEMPLATE/CPU") { |e|
|
||||
cpu_used += e.text.to_f
|
||||
}
|
||||
|
||||
vmdoc.root.each_element("TEMPLATE/MEMORY") { |e|
|
||||
mem_used += e.text.to_i
|
||||
}
|
||||
|
||||
vmdoc.root.each_element("TEMPLATE/DISK") { |e|
|
||||
type = ""
|
||||
|
||||
e.each_element("TYPE") { |t_elem|
|
||||
type = t_elem.text.upcase
|
||||
}
|
||||
|
||||
if ( type == "SWAP" || type == "FS")
|
||||
e.each_element("SIZE") { |size_elem|
|
||||
vol_used += size_elem.text.to_f
|
||||
}
|
||||
end
|
||||
}
|
||||
|
||||
vms_used += 1
|
||||
end
|
||||
|
||||
if (vms_used != 0 ||
|
||||
cpu_limit != "-1" || mem_limit != "-1" || vms_limit != "-1" || vol_limit != "-1" )
|
||||
|
||||
# VM quotas
|
||||
vm_elem = vm_quota.add_element("VM")
|
||||
|
||||
vm_elem.add_element("CPU").text = cpu_limit
|
||||
vm_elem.add_element("CPU_USED").text = sprintf('%.2f', cpu_used)
|
||||
|
||||
vm_elem.add_element("MEMORY").text = mem_limit
|
||||
vm_elem.add_element("MEMORY_USED").text = mem_used.to_s
|
||||
|
||||
vm_elem.add_element("VMS").text = vms_limit
|
||||
vm_elem.add_element("VMS_USED").text = vms_used.to_s
|
||||
|
||||
vm_elem.add_element("VOLATILE_SIZE").text = vol_limit
|
||||
vm_elem.add_element("VOLATILE_SIZE_USED").text = sprintf('%.2f', vol_used)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1286,6 +1286,7 @@ module OneDBFsck
|
||||
cpu_used = 0.0
|
||||
mem_used = 0
|
||||
vms_used = 0
|
||||
vol_used = 0.0
|
||||
|
||||
# VNet quotas
|
||||
vnet_usage = {}
|
||||
@ -1301,12 +1302,28 @@ module OneDBFsck
|
||||
# truncate to 2 decimals
|
||||
cpu = (e.text.to_f * 100).to_i / 100.0
|
||||
cpu_used += cpu
|
||||
cpu_used = (cpu_used * 100).to_i / 100.0
|
||||
}
|
||||
|
||||
vmdoc.root.each_element("TEMPLATE/MEMORY") { |e|
|
||||
mem_used += e.text.to_i
|
||||
}
|
||||
|
||||
vmdoc.root.each_element("TEMPLATE/DISK") { |e|
|
||||
type = ""
|
||||
|
||||
e.each_element("TYPE") { |t_elem|
|
||||
type = t_elem.text.upcase
|
||||
}
|
||||
|
||||
if ( type == "SWAP" || type == "FS")
|
||||
e.each_element("SIZE") { |size_elem|
|
||||
vol_used += size_elem.text.to_f
|
||||
vol_used = (vol_used * 100).to_i / 100.0
|
||||
}
|
||||
end
|
||||
}
|
||||
|
||||
vms_used += 1
|
||||
|
||||
# VNet quotas
|
||||
@ -1342,6 +1359,9 @@ module OneDBFsck
|
||||
|
||||
vm_elem.add_element("VMS").text = "-1"
|
||||
vm_elem.add_element("VMS_USED").text = "0"
|
||||
|
||||
vm_elem.add_element("VOLATILE_SIZE").text = "-1"
|
||||
vm_elem.add_element("VOLATILE_SIZE_USED").text = "0"
|
||||
end
|
||||
|
||||
|
||||
@ -1378,6 +1398,20 @@ module OneDBFsck
|
||||
end
|
||||
}
|
||||
|
||||
vm_elem.each_element("VOLATILE_SIZE_USED") { |e|
|
||||
# Check if the float value or the string representation mismatch,
|
||||
# but ignoring the precision
|
||||
|
||||
different = ( e.text.to_f != vol_used ||
|
||||
![sprintf('%.2f', vol_used), sprintf('%.1f', vol_used), sprintf('%.0f', vol_used)].include?(e.text) )
|
||||
|
||||
vol_used_str = sprintf('%.2f', vol_used)
|
||||
|
||||
if different
|
||||
log_error("#{resource} #{oid} quotas: VOLATILE_SIZE_USED has #{e.text} \tis\t#{vol_used_str}")
|
||||
e.text = vol_used_str
|
||||
end
|
||||
}
|
||||
|
||||
# VNet quotas
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user