1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-27 14:03:40 +03:00

F #5189 azure migrator (#449)

This commit is contained in:
Sergio Semedi Barranco 2017-09-05 14:32:45 +02:00 committed by Tino Vázquez
parent a5a9d9a574
commit d3a7fd2713
2 changed files with 129 additions and 1 deletions

View File

@ -1218,7 +1218,9 @@ ONEDB_LOCAL_MIGRATOR_FILES="src/onedb/local/4.5.80_to_4.7.80.rb \
src/onedb/local/4.13.80_to_4.13.85.rb \
src/onedb/local/4.13.85_to_4.90.0.rb \
src/onedb/local/4.90.0_to_5.3.80.rb \
src/onedb/local/5.3.80_to_5.4.0.rb"
src/onedb/local/5.3.80_to_5.4.0.rb \
src/onedb/local/5.4.0_to_5.5.80.rb"
ONEDB_PATCH_FILES="src/onedb/patches/4.14_monitoring.rb \
src/onedb/patches/history_times.rb"

View File

@ -0,0 +1,126 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2017, OpenNebula Project, OpenNebula Systems #
# #
# 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 'yaml'
require 'opennebula'
include OpenNebula
module Migrator
def db_version
"5.5.80"
end
def one_version
"OpenNebula 5.5.80"
end
def up
init_log_time()
feature_5189()
log_time()
return true
end
private
def xpath(doc, sxpath)
element = doc.root.at_xpath(sxpath)
if !element.nil?
element.text
else
""
end
end
def delete_element(doc, element)
doc.search("//#{element}").each do |node|
node.remove
end
end
def feature_5189()
az_driver_conf = "#{ETC_LOCATION}/az_driver.conf.old"
token = File.read(VAR_LOCATION+'/.one/one_key')
to_encrypt = {}
if !File.exist?(az_driver_conf)
STDERR.puts " > Old Az file not found, skipping Az host migration"
return
end
begin
az_conf = YAML::load(File.read(az_driver_conf))
rescue Exception => e
str_error="az_driver.conf invalid syntax!"
raise str_error
end
regions = az_conf["regions"]
if !regions
STDERR.puts " > Regions not found in Az config file, skipping migration"
return
end
@db.run "DROP TABLE IF EXISTS old_host_pool;"
@db.run "ALTER TABLE host_pool RENAME TO old_host_pool;"
create_table(:host_pool)
@db.transaction do
@db.fetch("SELECT * FROM old_host_pool") do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) { |c|
c.default_xml.noblanks
}
template = doc.root.at_xpath("TEMPLATE")
if xpath(doc, "TEMPLATE/HYPERVISOR").to_s == "AZURE"
host_name = xpath(doc, "NAME").to_s
host_info = ( regions[host_name].nil? ? regions["default"] : regions[host_name] )
to_encrypt["AZ_ID"]=host_info["subscription_id"]
to_encrypt["AZ_CERT"] = File.read(host_info["pem_management_cert"])
OpenNebula.encrypt(to_encrypt, token).each { |k, v|
delete_element(template, k)
template.add_child(doc.create_element(k, v))
}
capacity = doc.create_element("CAPACITY")
host_info["capacity"].each { |k, v|
capacity.add_child(doc.create_element(k.upcase, v))
}
delete_element(template, "CAPACITY")
template.add_child(capacity)
delete_element(template, "REGION_NAME")
template.add_child(doc.create_element "REGION_NAME", host_info["region_name"])
end
row[:body] = doc.root.to_s
@db[:host_pool].insert(row)
end
end
@db.run "DROP TABLE old_host_pool;"
STDERR.puts " > You can now delete #{az_driver_conf} file"
end
end