From b6f6cf5eeb84e6498922f18236a9b23130438a84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 29 Sep 2014 12:25:08 +0200 Subject: [PATCH] Feature #3183: New migrator to add vnet column --- include/Nebula.h | 2 +- install.sh | 3 +- src/onedb/local/4.7.80_to_4.9.80.rb | 68 +++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 src/onedb/local/4.7.80_to_4.9.80.rb diff --git a/include/Nebula.h b/include/Nebula.h index c74c3a92c4..69a5b98649 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -390,7 +390,7 @@ public: */ static string local_db_version() { - return "4.7.80"; + return "4.9.80"; } /** diff --git a/install.sh b/install.sh index d036f0a3de..6f0306ced4 100755 --- a/install.sh +++ b/install.sh @@ -1179,7 +1179,8 @@ ONEDB_SHARED_MIGRATOR_FILES="src/onedb/shared/2.0_to_2.9.80.rb \ src/onedb/shared/4.4.1_to_4.5.80.rb\ src/onedb/shared/4.5.80_to_4.6.0.rb" -ONEDB_LOCAL_MIGRATOR_FILES="src/onedb/local/4.5.80_to_4.7.80.rb" +ONEDB_LOCAL_MIGRATOR_FILES="src/onedb/local/4.5.80_to_4.7.80.rb \ + src/onedb/local/4.7.80_to_4.9.80.rb" #------------------------------------------------------------------------------- # Configuration files for OpenNebula, to be installed under $ETC_LOCATION diff --git a/src/onedb/local/4.7.80_to_4.9.80.rb b/src/onedb/local/4.7.80_to_4.9.80.rb new file mode 100644 index 0000000000..0141182ae1 --- /dev/null +++ b/src/onedb/local/4.7.80_to_4.9.80.rb @@ -0,0 +1,68 @@ +# -------------------------------------------------------------------------- # +# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +require 'nokogiri' + +module Migrator + def db_version + "4.9.80" + end + + def one_version + "OpenNebula 4.9.80" + end + + def up + + init_log_time() + + ######################################################################## + # Networks + ######################################################################## + + @db.run "ALTER TABLE network_pool RENAME TO old_network_pool;" + @db.run "CREATE TABLE network_pool (oid INTEGER PRIMARY KEY, name VARCHAR(128), body MEDIUMTEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, cid INTEGER, pid INTEGER, UNIQUE(name,uid));" + + @db.fetch("SELECT * FROM old_network_pool") do |row| + doc = Nokogiri::XML(row[:body]){|c| c.default_xml.noblanks} + + parent_st = doc.root.at_xpath("PARENT_NETWORK_ID").text + parent_i = -1 + + if parent_st != "" + parent_i = parent_st.to_i + end + + @db[:network_pool].insert( + :oid => row[:oid], + :name => row[:name], + :body => row[:body], + :uid => row[:uid], + :gid => row[:gid], + :owner_u => row[:owner_u], + :group_u => row[:group_u], + :other_u => row[:other_u], + :cid => row[:cid], + :pid => parent_i) + end + + @db.run "DROP TABLE old_network_pool;" + + log_time() + + return true + end +end \ No newline at end of file