1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-24 21:34:01 +03:00

B #4212: add function to read table encoding (#4218)

(cherry picked from commit 7df413faeb)
This commit is contained in:
Alejandro Huertas Herrero 2020-02-19 15:57:05 +01:00 committed by Ruben S. Montero
parent 67defe8da6
commit 8e6cca387c
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
31 changed files with 122 additions and 175 deletions

View File

@ -109,18 +109,6 @@ EOT
FEDERATED_TABLES
end
def nokogiri_doc(body, table = nil)
nk_enconding = NOKOGIRI_ENCODING
unless table.nil?
nk_enconding = get_table_enconding(table)
end
Nokogiri::XML(body, nil, nk_enconding) do |c|
c.default_xml.noblanks
end
end
def add_element(elem, name)
return elem.add_child(elem.document.create_element(name))
end
@ -626,7 +614,7 @@ EOT
# No image found, so unable to get image TYPE
return nil if row.nil?
image = Nokogiri::XML(row[:body], nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
image = nokogiri_doc(row[:body], 'image_pool')
return image
end
@ -658,7 +646,7 @@ EOT
# No image found, so unable to get image TYPE
return nil if row.nil?
image = Nokogiri::XML(row[:body], nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
image = nokogiri_doc(row[:body], 'image_pool')
return image
end

View File

@ -8,9 +8,7 @@ module OneDBFsck
@db.fetch('SELECT oid,body from group_pool') do |row|
gid = row[:oid]
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end
doc = nokogiri_doc(row[:body], 'group_pool')
users_elem = doc.root.at_xpath('USERS')
users_new_elem = doc.create_element('USERS')

View File

@ -17,7 +17,7 @@ module OneDBFsck
# DATA: check marketplace pool
@db.fetch("SELECT oid,body FROM marketplace_pool") do |row|
market_id = row[:oid]
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'marketplace_pool')
apps_elem = doc.root.at_xpath("MARKETPLACEAPPS")
apps_elem.remove if !apps_elem.nil?

View File

@ -24,9 +24,7 @@ module OneDBFsck
query = "SELECT * FROM old_#{table} WHERE #{resource}_oid>0"
@db.fetch(query) do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end
doc = nokogiri_doc(row[:body], "old_#{table}")
# resource[0] = u if user, g if group
id_field = "#{resource[0]}id"
@ -84,7 +82,7 @@ module OneDBFsck
# Datastore quotas
query = "SELECT body FROM image_pool WHERE #{filter}"
calculate_ds_quotas(doc, query, resource, datastore_usage)
calculate_ds_quotas(doc, 'image_pool', query, resource, datastore_usage)
end
# Calculate running quotas
@ -107,20 +105,17 @@ module OneDBFsck
# Calculate datastore quotas
#
# @param doc [Nokogiri::XML] xml document with all information
# @param table [String] database table
# @param query [String] database query
# @param resource [String] OpenNebula object
# @param datastore_usage [Object] object with datastore usage information
def calculate_ds_quotas(doc, query, resource, datastore_usage)
def calculate_ds_quotas(doc, table, query, resource, datastore_usage)
oid = doc.root.at_xpath('ID').text.to_i
ds_usage = {}
@db.fetch(query) do |img_row|
img_doc = Nokogiri::XML(img_row[:body],
nil,
NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end
img_doc = nokogiri_doc(img_row[:body], table)
img_doc.root.xpath('DATASTORE_ID').each do |e|
ds_usage[e.text] = [0, 0] if ds_usage[e.text].nil?
@ -442,11 +437,7 @@ module OneDBFsck
end
@db.fetch(queries[1]) do |vrouter_row|
vrouter_doc = Nokogiri::XML(vrouter_row[:body],
nil,
NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end
vrouter_doc = nokogiri_doc(vrouter_row[:body], 'vrouter_pool')
vrouter_doc.root.xpath('TEMPLATE/NIC').each do |nic|
net_id = nil

View File

@ -4,7 +4,7 @@ module OneDBFsck
templates_fix = @fixes_template = {}
@db[:template_pool].each do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'template_pool')
boot = doc.root.at_xpath("TEMPLATE/OS/BOOT")

View File

@ -13,9 +13,7 @@ module OneDBFsck
end
@db.fetch('SELECT oid,body,gid,name FROM user_pool') do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end
doc = nokogiri_doc(row[:body], 'user_pool')
gid = doc.root.at_xpath('GID').text.to_i
auth_driver = doc.root.at_xpath('AUTH_DRIVER').text

View File

@ -74,7 +74,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_network_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_network_pool')
template = doc.root.at_xpath("TEMPLATE")
@ -110,7 +110,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_datastore_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_datastore_pool')
doc.root.add_child(doc.create_element("STATE")).content = "0"
@ -144,7 +144,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_vm_pool WHERE state<>6") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_vm_pool')
["STATE", "LCM_STATE"].each do |ename|
prev_elem = doc.root.at_xpath("PREV_#{ename}")

View File

@ -58,7 +58,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_document_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_document_pool')
lock_elem = doc.create_element("LOCK")
lock_elem.add_child(doc.create_element("LOCKED")).content = "0"
@ -99,7 +99,7 @@ module Migrator
@db.transaction do
#@db.fetch("SELECT * FROM old_vm_pool WHERE state<>6") do |row|
@db.fetch("SELECT * FROM old_vm_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_vm_pool')
update_monitoring(doc.root.at_xpath("/VM"))
@ -135,7 +135,7 @@ module Migrator
@db.transaction do
#@db.fetch("SELECT * FROM old_history WHERE etime=0") do |row|
@db.fetch("SELECT * FROM old_history") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_history')
elem = doc.root.at_xpath("/HISTORY/VM")
if !elem.nil?
@ -162,7 +162,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_image_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_image_pool')
doc.root.add_child(doc.create_element("TARGET_SNAPSHOT")).content = "-1"
doc.root.add_child(doc.create_element("SNAPSHOTS"))

View File

@ -38,7 +38,7 @@ module Migrator
end
@db.fetch("SELECT * FROM old_user_quotas WHERE user_oid>0") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_user_quotas')
calculate_quotas(doc, "uid=#{row[:user_oid]}", "User")
@ -62,7 +62,7 @@ module Migrator
end
@db.fetch("SELECT * FROM old_group_quotas WHERE group_oid>0") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_group_quotas')
calculate_quotas(doc, "gid=#{row[:group_oid]}", "Group")
@ -80,7 +80,7 @@ module Migrator
default_group_quotas = nil
@db.fetch("SELECT * FROM system_attributes WHERE name = 'DEFAULT_USER_QUOTAS'") do |row|
default_user_quotas = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
default_user_quotas = nokogiri_doc(row[:body], 'system_attributes')
vm_elem = default_user_quotas.root.at_xpath("VM_QUOTA/VM")
@ -91,7 +91,7 @@ module Migrator
end
@db.fetch("SELECT * FROM system_attributes WHERE name = 'DEFAULT_GROUP_QUOTAS'") do |row|
default_group_quotas = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
default_group_quotas = nokogiri_doc(row[:body], 'system_attributes')
vm_elem = default_group_quotas.root.at_xpath("VM_QUOTA/VM")
@ -118,7 +118,7 @@ module Migrator
@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}
doc = nokogiri_doc(row[:body], 'old_host_pool')
doc.root.at_xpath("HOST_SHARE").add_child(doc.create_element("PCI_DEVICES"))
@ -163,7 +163,7 @@ module Migrator
sys_used = 0
@db.fetch("SELECT body FROM vm_pool WHERE #{where_filter} AND state<>6") do |vm_row|
vmdoc = Nokogiri::XML(vm_row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
vmdoc = nokogiri_doc(row[:body], 'vm_pool')
vmdoc.root.xpath("TEMPLATE/DISK").each { |e|
type = ""

View File

@ -54,7 +54,7 @@ module Migrator
@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}
doc = nokogiri_doc(row[:body], 'old_host_pool')
cid_elem = doc.root.at_xpath("CLUSTER_ID")
cid = cid_elem.text.to_i
@ -93,7 +93,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_datastore_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_datastore_pool')
doc.root.at_xpath("CLUSTER").remove
@ -139,7 +139,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_network_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_network_pool')
doc.root.at_xpath("CLUSTER").remove
@ -185,7 +185,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_vm_pool") do |row|
if row[:state] != 6
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_vm_pool')
cid = doc.root.at_xpath("HISTORY_RECORDS/HISTORY[last()]/CID").text.to_i rescue nil
@ -257,7 +257,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_network_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_network_pool')
doc.root.add_child(doc.create_element("VROUTERS"))
@ -283,7 +283,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_template_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_template_pool')
# Feature #3671
@ -373,7 +373,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_image_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_image_pool')
doc.root.add_child(doc.create_element("APP_CLONES"))
@ -402,7 +402,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_secgroup_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_secgroup_pool')
doc.root.at_xpath("VMS").name = "UPDATED_VMS"
doc.root.add_child(doc.create_element("OUTDATED_VMS"))
@ -430,7 +430,7 @@ module Migrator
vms_with_fw = []
@db.transaction do
@db.fetch("SELECT * FROM vm_pool WHERE state != 6") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'vm_pool')
has_fw_attrs = !doc.root.xpath("TEMPLATE/NIC[ICMP|WHITE_PORTS_TCP|WHITE_PORTS_UDP|BLACK_PORTS_TCP|BLACK_PORTS_UDP]").empty?
@ -479,7 +479,7 @@ module Migrator
@db.fetch("SELECT * FROM old_host_pool") do |row|
do_disable = false
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_host_pool')
vm_mad = doc.root.at_xpath("VM_MAD").text
im_mad = doc.root.at_xpath("IM_MAD").text
@ -564,7 +564,7 @@ module Migrator
net_vnmad = {}
@db.transaction do
@db.fetch("SELECT * FROM vm_pool WHERE state != 6") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'vm_pool')
state = row[:state].to_i
vnmads = Set.new
@ -586,7 +586,7 @@ module Migrator
cluster_vnmad = {}
@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}
doc = nokogiri_doc(row[:body], 'old_host_pool')
# Get cluster
cluster_id = doc.root.xpath('CLUSTER_ID').text.to_i
@ -630,7 +630,7 @@ module Migrator
manual_intervention = false
@db.transaction do
@db.fetch("SELECT * FROM old_network_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_network_pool')
net_id = row[:oid]
net_name = row[:name]
@ -783,7 +783,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_vm_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_vm_pool')
state = row[:state].to_i
if state != 6
@ -852,7 +852,7 @@ module Migrator
cluster_vnc = {}
@db.transaction do
@db.fetch("SELECT * FROM vm_pool WHERE state != 6") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'vm_pool')
port = doc.root.at_xpath('TEMPLATE/GRAPHICS[translate(TYPE,"vnc","VNC")="VNC"]/PORT').text.to_i rescue nil
cluster_id = doc.root.at_xpath('HISTORY_RECORDS/HISTORY[last()]/CID').text.to_i rescue nil
@ -908,7 +908,7 @@ module Migrator
has_lvm = false
@db.transaction do
@db.fetch("SELECT * FROM old_datastore_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_datastore_pool')
ds_id = row[:oid]
ds_name = row[:name]

View File

@ -42,7 +42,7 @@ module Migrator
end
@db.fetch("SELECT * FROM old_user_quotas WHERE user_oid>0") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_user_quotas')
redo_quota_limits(doc)
@ -66,7 +66,7 @@ module Migrator
end
@db.fetch("SELECT * FROM old_group_quotas WHERE group_oid>0") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_group_quotasl')
redo_quota_limits(doc)
@ -84,13 +84,13 @@ module Migrator
default_group_quotas = nil
@db.fetch("SELECT * FROM system_attributes WHERE name = 'DEFAULT_USER_QUOTAS'") do |row|
default_user_quotas = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
default_user_quotas = nokogiri_doc(row[:body], 'system_attributes')
redo_quota_limits(default_user_quotas)
end
@db.fetch("SELECT * FROM system_attributes WHERE name = 'DEFAULT_GROUP_QUOTAS'") do |row|
default_group_quotas = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
default_group_quotas = nokogiri_doc(row[:body], 'system_attributes')
redo_quota_limits(default_group_quotas)
end
@ -111,7 +111,7 @@ module Migrator
@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, UNIQUE(name,uid));"
@db.fetch("SELECT * FROM old_network_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_network_pool')
ranged = doc.root.at_xpath("TYPE").text == "0"
doc.root.at_xpath("TYPE").remove
@ -151,7 +151,7 @@ module Migrator
mac_prefix = ONEDCONF_MAC_PREFIX.gsub(":","").to_i(16)
@db.fetch("SELECT body FROM leases WHERE oid=#{row[:oid]} ORDER BY ip ASC LIMIT 1") do |lease_row|
lease = Nokogiri::XML(lease_row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
lease = nokogiri_doc(lease_row[:body], 'leases')
mac_prefix = lease.root.at_xpath("MAC_PREFIX").text.to_i
end
@ -183,7 +183,7 @@ module Migrator
allocated_str = ""
@db.fetch("SELECT body FROM leases WHERE oid=#{row[:oid]} ORDER BY ip ASC") do |lease_row|
lease = Nokogiri::XML(lease_row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
lease = nokogiri_doc(lease_row[:body], 'leases')
# For ranged, all leases are used
@ -255,7 +255,7 @@ module Migrator
ar_id = 0
@db.fetch("SELECT body FROM leases WHERE oid=#{row[:oid]}") do |lease_row|
lease = Nokogiri::XML(lease_row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
lease = nokogiri_doc(lease_row[:body], 'leases')
# For fixed, IP != MAC_SUFFIX
@ -325,7 +325,7 @@ module Migrator
log_time()
@db.fetch("SELECT * FROM old_vm_pool WHERE state<>6") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_vm_pool')
doc.root.xpath("TEMPLATE/NIC/IP6_SITE").each {|e|
e.name = "IP6_ULA"

View File

@ -37,7 +37,7 @@ module Migrator
@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],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_network_pool')
parent_st = doc.root.at_xpath("PARENT_NETWORK_ID").text
parent_i = -1

View File

@ -106,9 +106,7 @@ module Migrator
@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
}
doc = nokogiri_doc(row[:body], 'old_host_pool')
template = doc.root.at_xpath("TEMPLATE")
@ -158,9 +156,7 @@ module Migrator
@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
}
doc = nokogiri_doc(row[:body], 'old_host_pool')
rcpu = xpath(doc, "TEMPLATE/RESERVED_CPU").to_i
rmem = xpath(doc, "TEMPLATE/RESERVED_MEM").to_i
@ -197,9 +193,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_vm_pool") do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) { |c|
c.default_xml.noblanks
}
doc = nokogiri_doc(row[:body], 'old_vm_pool')
doc.root.xpath("HISTORY_RECORDS/HISTORY").each do |h|
reason = h.xpath("REASON")
@ -228,9 +222,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_history") do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) { |c|
c.default_xml.noblanks
}
doc = nokogiri_doc(row[:body], 'old_history')
h = doc.root
@ -281,9 +273,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_datastore_pool") do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) { |c|
c.default_xml.noblanks
}
doc = nokogiri_doc(row[:body], 'old_datastore_pool')
type = xpath(doc, 'TYPE').to_i
tm_mad = xpath(doc, 'TM_MAD')
@ -319,9 +309,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_zone_pool") do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) { |c|
c.default_xml.noblanks
}
doc = nokogiri_doc(row[:body], 'old_zone_pool')
server_pool = doc.create_element "SERVER_POOL"
doc.root.add_child(server_pool)

View File

@ -69,9 +69,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_document_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING) { |c|
c.default_xml.noblanks
}
doc = nokogiri_doc(row[:body], 'old_document_pool')
delete_element(doc, "LOCK")
@ -131,9 +129,7 @@ module Migrator
@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
}
doc = nokogiri_doc(row[:body], 'old_host_pool')
template = doc.root.at_xpath("TEMPLATE")
@ -178,9 +174,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_image_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){
|c| c.default_xml.noblanks
}
doc = nokogiri_doc(row[:body], 'old_image_pool')
max = doc.xpath("//SNAPSHOTS/SNAPSHOT/ID").max
@ -221,9 +215,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_vm_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){ |c|
c.default_xml.noblanks
}
doc = nokogiri_doc(row[:body], 'old_vm_pool')
max = doc.xpath("//SNAPSHOTS/SNAPSHOT/ID").max

View File

@ -55,9 +55,7 @@ module Migrator
raise "Host #{hid} not found in the OpenNebula DB" if !row[:body]
xml = row[:body]
doc = Nokogiri::XML(xml, nil, NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end.root.at_xpath('/HOST/TEMPLATE')
doc = nokogiri_doc(xml, 'host_pool').root.at_xpath('/HOST/TEMPLATE')
rp = doc.xpath("VCENTER_RESOURCE_POOL").first
rp = rp.text if rp
@ -79,9 +77,7 @@ module Migrator
@db.fetch('SELECT * FROM vm_pool') do |row|
begin
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end
doc = nokogiri_doc(row[:body], 'vm_pool')
one_vm = OpenNebula::XMLElement.new(doc.root.at_xpath('/VM'))
@ -139,9 +135,7 @@ module Migrator
@db.transaction do
# update virtual networks
@db.fetch('SELECT * FROM old_network_pool') do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end
doc = nokogiri_doc(row[:body], 'old_network_pool')
if doc.root.at_xpath('BRIDGE_TYPE').to_s.empty?
vn_mad = doc.root.at_xpath('/VNET/VN_MAD').text
@ -166,9 +160,7 @@ module Migrator
@db.transaction do
# updates VM's nics
@db.fetch('SELECT * FROM old_vm_pool') do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end
doc = nokogiri_doc(row[:body], 'old_vm_pool')
if !doc.root.at_xpath('TEMPLATE/NIC').to_s.empty?
doc.root.xpath('//NIC').map do |nic|
@ -199,9 +191,7 @@ module Migrator
@db.transaction do
@db.fetch('SELECT * FROM old_vm_pool') do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end
doc = nokogiri_doc(row[:body], 'old_vm_pool')
row[:short_body] = gen_short_body(doc)
row[:search_token] = gen_search_body(doc)
@ -416,9 +406,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_image_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){
|c| c.default_xml.noblanks
}
doc = nokogiri_doc(row[:body], 'old_image_pool')
next_snapshot = doc.at_xpath("//SNAPSHOTS/NEXT_SNAPSHOT")
@ -455,9 +443,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_vm_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){ |c|
c.default_xml.noblanks
}
doc = nokogiri_doc(row[:body], 'old_vm_pool')
# evaluate each disk snapshot individually
doc.xpath("//SNAPSHOTS").each do |disk|

View File

@ -76,9 +76,7 @@ module Migrator
db.transaction do
# Add PREV_STATE to each host
@db.fetch('SELECT * FROM old_host_pool') do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) do |c|
c.default_xml.noblanks
end
doc = nokogiri_doc(row[:body], 'old_host_pool')
state = doc.xpath('//STATE').text

View File

@ -175,6 +175,18 @@ class OneDBBacKEnd
return @db
end
def nokogiri_doc(body, table = nil)
nk_enconding = NOKOGIRI_ENCODING
unless table.nil?
nk_enconding = get_table_enconding(table)
end
Nokogiri::XML(body, nil, nk_enconding) do |c|
c.default_xml.noblanks
end
end
private
def db_exists?

View File

@ -59,7 +59,7 @@ EOT
# Move monitoring attributes in VM pool table, only for VMs in DONE
@db.fetch("SELECT * FROM vm_pool WHERE state=6") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'vm_pool')
update_monitoring(doc.root.at_xpath("/VM"))
@ -75,7 +75,7 @@ EOT
@db.transaction do
@db.fetch("SELECT * FROM history WHERE etime<>0") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'history')
elem = doc.root.at_xpath("/HISTORY/VM")
if !elem.nil?

View File

@ -87,7 +87,7 @@ EOT
history_doc = nil
@db.fetch("SELECT * FROM history WHERE vid = #{vid} AND seq = #{seq}") do |row|
history_doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
history_doc = nokogiri_doc(row[:body], 'history')
pphistory(history_doc)

View File

@ -72,7 +72,7 @@ module OneDBPatch
ar_ar = ar.delete('AR')
@db[:network_pool].where(oid: ar_vn).each do |vn|
doc = Nokogiri::XML(vn[:body],nil,NOKOGIRI_ENCODING)
doc = nokogiri_doc(vn[:body], 'network_pool')
doc_ar = doc.root.at_xpath("AR_POOL/AR[AR_ID=#{ar_ar}]")
ar['TYPE'] = 'IP4_6_STATIC'

View File

@ -58,7 +58,7 @@ EOT
@db.transaction do
@db.fetch("SELECT * FROM marketplace_pool") do |row|
doc = Nokogiri::XML(row[:body], nil, NOKOGIRI_ENCODING) { |c| c.default_xml.noblanks }
doc = nokogiri_doc(row[:body], 'marketplace_pool')
# only marketplaces with the MAD "one"
mad = doc.xpath("/MARKETPLACE/MARKET_MAD")

View File

@ -59,9 +59,7 @@ EOT
@db.transaction do
@db.fetch("SELECT * FROM image_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){
|c| c.default_xml.noblanks
}
doc = nokogiri_doc(row[:body], 'image_pool')
next_snapshot = doc.at_xpath("//SNAPSHOTS/NEXT_SNAPSHOT")
@ -92,9 +90,7 @@ EOT
log_time()
@db.fetch("SELECT * FROM vm_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){ |c|
c.default_xml.noblanks
}
doc = nokogiri_doc(row[:body], 'vm_pool')
# evaluate each disk snapshot individually
doc.xpath("//SNAPSHOTS").each do |disk|

View File

@ -56,7 +56,7 @@ module Migrator
# Aggregate information of the RUNNING vms
@db.fetch("SELECT oid,body FROM vm_pool WHERE state<>6") do |row|
vm_doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
vm_doc = nokogiri_doc(row[:body], 'vm_pool')
state = vm_doc.root.at_xpath('STATE').text.to_i
lcm_state = vm_doc.root.at_xpath('LCM_STATE').text.to_i

View File

@ -291,7 +291,7 @@ module Migrator
end
@db.fetch("SELECT * FROM old_user_pool WHERE oid>0") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_user_pool')
set_default_quotas(doc)
@ -329,7 +329,7 @@ module Migrator
end
@db.fetch("SELECT * FROM old_group_pool WHERE oid>0") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_group_pool')
set_default_quotas(doc)
@ -452,7 +452,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_vm_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_vm_pool')
user_template = doc.create_element("USER_TEMPLATE")
e = doc.root.at_xpath("TEMPLATE")
@ -509,7 +509,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_template_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_template_pool')
template = doc.root.at_xpath("TEMPLATE")
@ -559,7 +559,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_vm_pool") do |row|
if ( row[:state] != 6 ) # DONE
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_vm_pool')
nic_id = 0

View File

@ -49,7 +49,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_vm_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_vm_pool')
doc.root.xpath("HISTORY_RECORDS/HISTORY").each do |e|
update_history(e)
@ -79,7 +79,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_history") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_history')
doc.root.xpath("/HISTORY").each do |e|
update_history(e)

View File

@ -49,7 +49,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_user_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_user_pool')
doc.root.at_xpath("TEMPLATE").
add_child(doc.create_element("TOKEN_PASSWORD")).
@ -80,7 +80,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_datastore_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_datastore_pool')
doc.root.add_child(doc.create_element("TOTAL_MB")).content = "0"
doc.root.add_child(doc.create_element("FREE_MB")).content = "0"

View File

@ -53,7 +53,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_user_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_user_pool')
USER_TRANSFORM_ATTRS.each do |old_name, new_name|
elem = doc.at_xpath("/USER/TEMPLATE/#{old_name}")
@ -93,7 +93,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_group_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_group_pool')
GROUP_TRANSFORM_ATTRS.each do |old_name, new_name|
elem = doc.at_xpath("/GROUP/TEMPLATE/#{old_name}")
@ -132,7 +132,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT oid,body FROM group_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'group_pool')
doc.root.xpath("ADMINS/ID").each do |uid|
user = Acl::USERS["UID"] | uid.text.to_i

View File

@ -90,7 +90,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_user_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_user_pool')
g_elem = doc.create_element("GROUPS")
g_elem.add_child(doc.create_element("ID")).content = row[:gid].to_s
@ -140,7 +140,7 @@ module Migrator
end
@db.fetch("SELECT * FROM old_group_pool WHERE oid>0") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_group_pool')
redo_vm_quotas(doc, "gid=#{row[:oid]}")
@ -235,7 +235,7 @@ http://opennebula.org/documentation:rel4.4:upgrade
@db.transaction do
@db.fetch("SELECT * FROM old_vm_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_vm_pool')
doc.root.xpath("HISTORY_RECORDS/HISTORY").each do |e|
update_history(e)
@ -265,7 +265,7 @@ http://opennebula.org/documentation:rel4.4:upgrade
@db.transaction do
@db.fetch("SELECT * FROM old_history") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_history')
doc.root.xpath("/HISTORY").each do |e|
update_history(e)
@ -293,7 +293,7 @@ http://opennebula.org/documentation:rel4.4:upgrade
@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}
doc = nokogiri_doc(row[:body], 'old_host_pool')
doc.root.at_xpath("HOST_SHARE").
add_child(doc.create_element("DATASTORES"))
@ -362,7 +362,7 @@ http://opennebula.org/documentation:rel4.4:upgrade
vol_used = 0
@db.fetch("SELECT body FROM vm_pool WHERE #{where_filter} AND state<>6") do |vm_row|
vmdoc = Nokogiri::XML(vm_row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
vmdoc = nokogiri_doc(vm_row[:body], 'vm_pool')
# VM quotas
vmdoc.root.xpath("TEMPLATE/CPU").each { |e|

View File

@ -56,7 +56,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_user_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_user_pool')
quotas_doc = extract_quotas(doc)
@ -92,7 +92,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_group_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_group_pool')
quotas_doc = extract_quotas(doc)
@ -125,7 +125,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_network_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_network_pool')
template = doc.root.at_xpath("TEMPLATE")
@ -169,7 +169,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_template_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_template_pool')
atts = ["SCHED_REQUIREMENTS", "SCHED_RANK", "REQUIREMENTS", "RANK"]

View File

@ -65,9 +65,9 @@ EOT
@db.transaction do
@db.fetch("SELECT * FROM old_group_pool") do |row|
vdc_doc = Nokogiri::XML(EMPTY_VDC,nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
vdc_doc = nokogiri_doc(row[:body], 'old_group_pool')
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_group_pool')
["GROUP_ADMIN_VIEWS", "SUNSTONE_VIEWS", "DEFAULT_VIEW"].each do |elem_name|
elem = doc.at_xpath("/GROUP/TEMPLATE/#{elem_name}")
@ -192,7 +192,7 @@ EOT
@db.transaction do
@db.fetch("SELECT * FROM old_user_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_user_pool')
elem = doc.at_xpath("/USER/TEMPLATE/DEFAULT_VIEW")

View File

@ -37,7 +37,7 @@ module Migrator
@db.transaction do
@db.fetch("SELECT * FROM old_user_pool") do |row|
doc = Nokogiri::XML(row[:body],nil,NOKOGIRI_ENCODING){|c| c.default_xml.noblanks}
doc = nokogiri_doc(row[:body], 'old_user_pool')
token_elem = doc.at_xpath("/USER/LOGIN_TOKEN")