diff --git a/src/onedb/1.rb b/src/onedb/1.rb index 29239ee339..ad9cac30cc 100644 --- a/src/onedb/1.rb +++ b/src/onedb/1.rb @@ -13,6 +13,8 @@ # limitations under the License. */ # -------------------------------------------------------------------------- */ +require "rexml/document" + class Migrator < MigratorBase def initialize(db, verbose) @@ -71,9 +73,7 @@ class Migrator < MigratorBase @db.run "ALTER TABLE host_pool RENAME TO old_host_pool;" # Create new table - @db.run "CREATE TABLE host_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, state INTEGER, last_mon_time INTEGER, cid INTEGER, UNIQUE(name));" - - cluster_host_ids = Hash.new + @db.run "CREATE TABLE host_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, state INTEGER, last_mon_time INTEGER, UNIQUE(name));" # Read each entry in the old table, and insert into new table @db.fetch("SELECT * FROM old_host_pool") do |row| @@ -81,16 +81,6 @@ class Migrator < MigratorBase name = row[:host_name] state = row[:state] last_mon_time = row[:last_mon_time] - cluster = row[:cluster] - - # OpenNebula 2.X stored the cluster name, we need the cluster ID - cluster_id = 0 - @db.fetch("SELECT oid FROM cluster_pool WHERE cluster_name='#{cluster}'") do |cluster_row| - cluster_id = cluster_row[:oid] - - cluster_host_ids[cluster_id] = "" if cluster_host_ids[cluster_id] == nil - cluster_host_ids[cluster_id] += "#{oid}" - end # There is one host share for each host host_share = "" @@ -98,9 +88,18 @@ class Migrator < MigratorBase host_share = "#{share[:disk_usage]}#{share[:mem_usage]}#{share[:cpu_usage]}#{share[:max_disk]}#{share[:max_mem]}#{share[:max_cpu]}#{share[:free_disk]}#{share[:free_mem]}#{share[:free_cpu]}#{share[:used_disk]}#{share[:used_mem]}#{share[:used_cpu]}#{share[:running_vms]}" end - body = "#{oid}#{name}#{state}#{row[:im_mad]}#{row[:vm_mad]}#{row[:tm_mad]}#{last_mon_time}#{cluster_id}#{host_share}#{row[:template]}" + # OpenNebula 2.X stored the cluster name, in 3.0 the cluster pool + # disappears. The cluster name is added to the Host template, this + # way the old VMs with REQUIREMENTS will keep working - @db.run "INSERT INTO host_pool VALUES(#{oid},'#{name}','#{body}', #{state}, #{last_mon_time}, #{cluster_id});" + template_doc = REXML::Document.new( row[:template] ) + cluster_elem = template_doc.root.add_element("CLUSTER") + cluster_elem.add_text( "" ) + + + body = "#{oid}#{name}#{state}#{row[:im_mad]}#{row[:vm_mad]}#{row[:tm_mad]}#{last_mon_time}#{host_share}#{ template_doc.to_s }" + + @db.run "INSERT INTO host_pool VALUES(#{oid},'#{name}','#{body}', #{state}, #{last_mon_time});" end # Delete old table @@ -111,32 +110,8 @@ class Migrator < MigratorBase # Clusters ######################################################################## - # 2.2 Schema - # CREATE TABLE cluster_pool (oid INTEGER PRIMARY KEY, cluster_name VARCHAR(128), UNIQUE(cluster_name) ); - - # Move table - @db.run "ALTER TABLE cluster_pool RENAME TO old_cluster_pool;" - - # Create new table - @db.run "CREATE TABLE cluster_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, UNIQUE(name));" - - # Read each entry in the old table, and insert into new table - @db.fetch("SELECT * FROM old_cluster_pool") do |row| - oid = row[:oid] - name = row[:cluster_name] - - hids = "" - if cluster_host_ids[oid] != nil - hids = cluster_host_ids[oid] - end - - body = "#{oid}#{name}#{hids}" - - @db.run "INSERT INTO cluster_pool VALUES(#{oid},'#{name}','#{body}');" - end - - # Delete old table - @db.run "DROP TABLE old_cluster_pool" + # Clusters do not exist any more + @db.run "DROP TABLE cluster_pool" ######################################################################## # Images @@ -279,14 +254,14 @@ class Migrator < MigratorBase @db.run "CREATE TABLE template_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, gid INTEGER, public INTEGER);" # The group pool has two default ones - @db.run "CREATE TABLE group_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, uid INTEGER, UNIQUE(name));" - @db.run "INSERT INTO group_pool VALUES(0,'oneadmin','00oneadmin0',0);" - @db.run "INSERT INTO group_pool VALUES(1,'users','10users#{user_group_ids}',0);" + @db.run "CREATE TABLE group_pool (oid INTEGER PRIMARY KEY, name VARCHAR(256), body TEXT, UNIQUE(name));" + @db.run "INSERT INTO group_pool VALUES(0,'oneadmin','00oneadmin0');" + @db.run "INSERT INTO group_pool VALUES(1,'users','10users#{user_group_ids}');" # New pool_control table contains the last_oid used, must be rebuilt @db.run "CREATE TABLE pool_control (tablename VARCHAR(32) PRIMARY KEY, last_oid BIGINT UNSIGNED)" - for table in ["user_pool", "cluster_pool", "host_pool", "image_pool", "vm_pool", "network_pool"] do + for table in ["user_pool", "host_pool", "image_pool", "vm_pool", "network_pool"] do @db.fetch("SELECT MAX(oid) FROM #{table}") do |row| if( row[:"MAX(oid)"] != nil ) @db.run "INSERT INTO pool_control (tablename, last_oid) VALUES ('#{table}', #{row[:"MAX(oid)"]});"