Feature #1522, Bugs #1363, #1335: Update 3.7.80 onedb migrator

This commit is contained in:
Carlos Martín committed 2012-10-03 18:17:48 +02:00
1 parent 598b48c80a
commit 78f2dc5da5
1 file changed
+86 -3
+86 -3
View File
@@ -28,7 +28,90 @@ module Migrator
def up
########################################################################
# Bug #1335
# Feature #1522: Allow users to create Documents by default
########################################################################
# Insert rule "* DOCUMENT/* CREATE"
last_oid = 0
@db.fetch("SELECT last_oid FROM pool_control WHERE tablename='acl'") do |row|
last_oid = row[:last_oid].to_i
end
@db[:acl].insert(
:oid => (last_oid + 1).to_s,
:user => 0x400000000.to_s,
:resource => 0x400400000000.to_s,
:rights => 0x8.to_s)
@db.run("UPDATE pool_control SET last_oid=#{last_oid + 1} WHERE tablename='acl';")
########################################################################
# Bugs #1363: Make sure all VMs have CPU (float) & MEM (int)
########################################################################
# NOTE: The VM memory and CPU are modified, but the sum in
# HOST/HOST_SHARE is not. A onedb fsck is required
@db.run "ALTER TABLE vm_pool RENAME TO old_vm_pool;"
@db.run "CREATE TABLE vm_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body TEXT, uid INTEGER, gid INTEGER, last_poll INTEGER, state INTEGER, lcm_state INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER);"
@db.fetch("SELECT * FROM old_vm_pool") do |row|
if ( row[:state] == 6 )
body = row[:body]
else
vm_doc = Document.new(row[:body])
memory = nil
vm_doc.root.each_element("TEMPLATE/MEMORY") { |e|
memory = e.text.to_i
memory = 0 if memory < 0
e.text = memory.to_s
}
if memory.nil?
vm_doc.root.each_element("TEMPLATE") { |e|
e.add_element("MEMORY").text = "0"
}
end
cpu = nil
vm_doc.root.each_element("TEMPLATE/CPU") { |e|
# truncate to 2 decimals
cpu = (e.text.to_f * 100).to_i / 100.0
cpu = 0 if cpu < 0
e.text = cpu.to_s
}
if cpu.nil?
vm_doc.root.each_element("TEMPLATE") { |e|
e.add_element("CPU").text = "0"
}
end
body = vm_doc.root.to_s
end
@db[:vm_pool].insert(
:oid => row[:oid],
:name => row[:name],
:body => body,
:uid => row[:uid],
:gid => row[:gid],
:last_poll => row[:last_poll],
:state => row[:state],
:lcm_state => row[:lcm_state],
:owner_u => row[:owner_u],
:group_u => row[:group_u],
:other_u => row[:other_u])
end
@db.run "DROP TABLE old_vm_pool;"
########################################################################
# Bug #1335: Add suspended VMs resoureces to Host usage
########################################################################
@db.fetch("SELECT * FROM vm_pool WHERE state = 5") do |row|
@@ -41,7 +124,7 @@ module Migrator
cpu = 0
vm_doc.root.each_element("TEMPLATE/CPU") { |e|
cpu = e.text.to_i
cpu = e.text.to_f
}
hid = -1
@@ -188,7 +271,7 @@ module Migrator
mem_used = 0
vms_used = 0
@db.fetch("SELECT body FROM vm_pool WHERE #{where_filter} AND state!=6") do |vm_row|
@db.fetch("SELECT body FROM vm_pool WHERE #{where_filter} AND state<>6") do |vm_row|
vmdoc = Document.new(vm_row[:body])
# VM quotas