From 8e6cca387c027afff3244a6e56b81c2c888860c5 Mon Sep 17 00:00:00 2001 From: Alejandro Huertas Herrero Date: Wed, 19 Feb 2020 15:57:05 +0100 Subject: [PATCH] B #4212: add function to read table encoding (#4218) (cherry picked from commit 7df413faeba1f890f05a980617ef6919b72537d3) --- src/onedb/fsck.rb | 16 ++------------ src/onedb/fsck/group.rb | 4 +--- src/onedb/fsck/marketplace.rb | 2 +- src/onedb/fsck/quotas.rb | 21 +++++------------- src/onedb/fsck/template.rb | 2 +- src/onedb/fsck/user.rb | 4 +--- src/onedb/local/4.10.3_to_4.11.80.rb | 6 ++--- src/onedb/local/4.11.80_to_4.13.80.rb | 10 ++++----- src/onedb/local/4.13.80_to_4.13.85.rb | 14 ++++++------ src/onedb/local/4.13.85_to_4.90.0.rb | 32 +++++++++++++-------------- src/onedb/local/4.5.80_to_4.7.80.rb | 20 ++++++++--------- src/onedb/local/4.7.80_to_4.9.80.rb | 4 ++-- src/onedb/local/4.90.0_to_5.3.80.rb | 24 +++++--------------- src/onedb/local/5.4.1_to_5.5.80.rb | 18 +++++---------- src/onedb/local/5.6.0_to_5.7.80.rb | 28 ++++++----------------- src/onedb/local/5.8.0_to_5.10.0.rb | 4 +--- src/onedb/onedb_backend.rb | 12 ++++++++++ src/onedb/patches/4.14_monitoring.rb | 6 ++--- src/onedb/patches/history_times.rb | 4 ++-- src/onedb/patches/ip4_ip6_static.rb | 2 +- src/onedb/patches/marketapps_clean.rb | 2 +- src/onedb/patches/next_snapshot.rb | 8 ++----- src/onedb/shared/3.8.0_to_3.8.1.rb | 2 +- src/onedb/shared/3.8.5_to_3.9.80.rb | 10 ++++----- src/onedb/shared/3.9.80_to_3.9.90.rb | 4 ++-- src/onedb/shared/4.0.1_to_4.1.80.rb | 4 ++-- src/onedb/shared/4.11.80_to_4.90.0.rb | 6 ++--- src/onedb/shared/4.2.0_to_4.3.80.rb | 12 +++++----- src/onedb/shared/4.4.1_to_4.5.80.rb | 8 +++---- src/onedb/shared/4.6.0_to_4.11.80.rb | 6 ++--- src/onedb/shared/4.90.0_to_5.2.0.rb | 2 +- 31 files changed, 122 insertions(+), 175 deletions(-) diff --git a/src/onedb/fsck.rb b/src/onedb/fsck.rb index 3ba9dbbd8ef..e105bf34a66 100644 --- a/src/onedb/fsck.rb +++ b/src/onedb/fsck.rb @@ -109,18 +109,6 @@ def federated_tables 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 @@ def get_image_from_id(id) # 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 @@ def get_image_from_name(disk, template_uid) # 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 diff --git a/src/onedb/fsck/group.rb b/src/onedb/fsck/group.rb index ecee4d8af81..984a3b2d2d5 100644 --- a/src/onedb/fsck/group.rb +++ b/src/onedb/fsck/group.rb @@ -8,9 +8,7 @@ def check_group @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') diff --git a/src/onedb/fsck/marketplace.rb b/src/onedb/fsck/marketplace.rb index 0a8bfc7585f..37844b8d982 100644 --- a/src/onedb/fsck/marketplace.rb +++ b/src/onedb/fsck/marketplace.rb @@ -17,7 +17,7 @@ def check_marketplace # 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? diff --git a/src/onedb/fsck/quotas.rb b/src/onedb/fsck/quotas.rb index c146fa78a4a..88a77334143 100644 --- a/src/onedb/fsck/quotas.rb +++ b/src/onedb/fsck/quotas.rb @@ -24,9 +24,7 @@ def check_fix_quotas(resource, type = 'normal') 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 @@ def calculate_quotas(doc, filter, resource) # 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 @@ def calculate_running_quotas(doc, filter, resource) # 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 @@ def calculate_vnet_quotas(doc, queries, resource) 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 diff --git a/src/onedb/fsck/template.rb b/src/onedb/fsck/template.rb index 8aebb24b101..17787212a87 100644 --- a/src/onedb/fsck/template.rb +++ b/src/onedb/fsck/template.rb @@ -4,7 +4,7 @@ def check_template 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") diff --git a/src/onedb/fsck/user.rb b/src/onedb/fsck/user.rb index 217be7599da..126772465c3 100644 --- a/src/onedb/fsck/user.rb +++ b/src/onedb/fsck/user.rb @@ -13,9 +13,7 @@ def check_user 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 diff --git a/src/onedb/local/4.10.3_to_4.11.80.rb b/src/onedb/local/4.10.3_to_4.11.80.rb index 4581bce4e20..c7472a7793a 100644 --- a/src/onedb/local/4.10.3_to_4.11.80.rb +++ b/src/onedb/local/4.10.3_to_4.11.80.rb @@ -74,7 +74,7 @@ def up @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 @@ def up @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 @@ def up @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}") diff --git a/src/onedb/local/4.11.80_to_4.13.80.rb b/src/onedb/local/4.11.80_to_4.13.80.rb index abc408a3fae..3acb55cc108 100644 --- a/src/onedb/local/4.11.80_to_4.13.80.rb +++ b/src/onedb/local/4.11.80_to_4.13.80.rb @@ -58,7 +58,7 @@ def up @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 @@ def up @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 @@ def up @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 @@ def up @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")) @@ -253,4 +253,4 @@ def update_monitoring(vm_elem) mv_monitoring(vm_elem, "VMWARETOOLS_VERSION", "VMWARETOOLS_VERSION") mv_monitoring(vm_elem, "VMWARETOOLS_VERSION_STATUS", "VMWARETOOLS_VERSION_STATUS") end -end \ No newline at end of file +end diff --git a/src/onedb/local/4.13.80_to_4.13.85.rb b/src/onedb/local/4.13.80_to_4.13.85.rb index e442c51b8ea..49aa76803fa 100644 --- a/src/onedb/local/4.13.80_to_4.13.85.rb +++ b/src/onedb/local/4.13.80_to_4.13.85.rb @@ -38,7 +38,7 @@ def up 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 @@ def up 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 @@ def up 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 @@ def up 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 @@ def up @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 @@ def calculate_quotas(doc, where_filter, resource) 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 = "" @@ -235,4 +235,4 @@ def calculate_quotas(doc, where_filter, resource) end } end -end \ No newline at end of file +end diff --git a/src/onedb/local/4.13.85_to_4.90.0.rb b/src/onedb/local/4.13.85_to_4.90.0.rb index a0d08fdc158..df072b8f92c 100644 --- a/src/onedb/local/4.13.85_to_4.90.0.rb +++ b/src/onedb/local/4.13.85_to_4.90.0.rb @@ -54,7 +54,7 @@ def up @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 @@ def up @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 @@ def up @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 @@ def up @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 @@ def up @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 @@ def up @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 @@ def up @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 @@ def up @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 @@ def up 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 @@ def up @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 @@ def up 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 @@ def up 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 @@ def up 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 @@ def up @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 @@ def up 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 @@ def up 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] diff --git a/src/onedb/local/4.5.80_to_4.7.80.rb b/src/onedb/local/4.5.80_to_4.7.80.rb index d309c8324fe..77fb31ad02c 100644 --- a/src/onedb/local/4.5.80_to_4.7.80.rb +++ b/src/onedb/local/4.5.80_to_4.7.80.rb @@ -42,7 +42,7 @@ def up 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 @@ def up 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 @@ def up 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 @@ def up @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 @@ def up 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 @@ def up 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 @@ def up 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 @@ def up 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" @@ -444,4 +444,4 @@ def redo_quota_limits(doc) end end end -end \ No newline at end of file +end 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 index 532fa6ce672..e61b7e91e49 100644 --- a/src/onedb/local/4.7.80_to_4.9.80.rb +++ b/src/onedb/local/4.7.80_to_4.9.80.rb @@ -37,7 +37,7 @@ def up @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 @@ -65,4 +65,4 @@ def up return true end -end \ No newline at end of file +end diff --git a/src/onedb/local/4.90.0_to_5.3.80.rb b/src/onedb/local/4.90.0_to_5.3.80.rb index da3aee46e5e..83a97aed28f 100644 --- a/src/onedb/local/4.90.0_to_5.3.80.rb +++ b/src/onedb/local/4.90.0_to_5.3.80.rb @@ -106,9 +106,7 @@ def feature_5136 @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 @@ def feature_4901 @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 @@ def feature_5005 @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 @@ def feature_5005 @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 @@ def bug_3705 @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 @@ def feature_4809 @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) diff --git a/src/onedb/local/5.4.1_to_5.5.80.rb b/src/onedb/local/5.4.1_to_5.5.80.rb index c565a5a9f95..33fc48031ea 100644 --- a/src/onedb/local/5.4.1_to_5.5.80.rb +++ b/src/onedb/local/5.4.1_to_5.5.80.rb @@ -69,9 +69,7 @@ def feature_1377() @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") @@ -120,7 +118,7 @@ def feature_5189() regions = az_conf["regions"] if !regions - STDERR.puts " > Regions not found in Az config file, " << + STDERR.puts " > Regions not found in Az config file, " << "skipping migration" return end @@ -131,9 +129,7 @@ def feature_5189() @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 @@ def bug_2189() @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 @@ def bug_2189() @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 diff --git a/src/onedb/local/5.6.0_to_5.7.80.rb b/src/onedb/local/5.6.0_to_5.7.80.rb index 36c9e755096..121ecefcf51 100644 --- a/src/onedb/local/5.6.0_to_5.7.80.rb +++ b/src/onedb/local/5.6.0_to_5.7.80.rb @@ -55,9 +55,7 @@ def feature_2944 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 @@ def feature_2944 @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 @@ def feature_2253 @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 @@ def feature_2253 @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 @@ def feature_2489_2671 @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 @@ def bug_2687 @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 @@ def bug_2687 @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| diff --git a/src/onedb/local/5.8.0_to_5.10.0.rb b/src/onedb/local/5.8.0_to_5.10.0.rb index 2ab7ed2b959..64e1573d0d3 100644 --- a/src/onedb/local/5.8.0_to_5.10.0.rb +++ b/src/onedb/local/5.8.0_to_5.10.0.rb @@ -76,9 +76,7 @@ def feature_3380 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 diff --git a/src/onedb/onedb_backend.rb b/src/onedb/onedb_backend.rb index 8f58656efd9..3a4d0bcb86a 100644 --- a/src/onedb/onedb_backend.rb +++ b/src/onedb/onedb_backend.rb @@ -175,6 +175,18 @@ def db() 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? diff --git a/src/onedb/patches/4.14_monitoring.rb b/src/onedb/patches/4.14_monitoring.rb index 3fd8d551591..b6e675e035e 100644 --- a/src/onedb/patches/4.14_monitoring.rb +++ b/src/onedb/patches/4.14_monitoring.rb @@ -59,7 +59,7 @@ def patch(ops) # 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 @@ def patch(ops) @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? @@ -161,4 +161,4 @@ def update_monitoring(vm_elem) mv_monitoring(vm_elem, "VMWARETOOLS_VERSION", "VMWARETOOLS_VERSION") mv_monitoring(vm_elem, "VMWARETOOLS_VERSION_STATUS", "VMWARETOOLS_VERSION_STATUS") end -end \ No newline at end of file +end diff --git a/src/onedb/patches/history_times.rb b/src/onedb/patches/history_times.rb index 2e6851d2075..2ff3589b375 100644 --- a/src/onedb/patches/history_times.rb +++ b/src/onedb/patches/history_times.rb @@ -87,7 +87,7 @@ def patch(ops) 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) @@ -177,4 +177,4 @@ def parsetime(t) end end end -end \ No newline at end of file +end diff --git a/src/onedb/patches/ip4_ip6_static.rb b/src/onedb/patches/ip4_ip6_static.rb index c1a0c790a62..3c159ec2c54 100644 --- a/src/onedb/patches/ip4_ip6_static.rb +++ b/src/onedb/patches/ip4_ip6_static.rb @@ -72,7 +72,7 @@ def patch(ops) 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' diff --git a/src/onedb/patches/marketapps_clean.rb b/src/onedb/patches/marketapps_clean.rb index c4eaad5b3de..ff11dfb559f 100644 --- a/src/onedb/patches/marketapps_clean.rb +++ b/src/onedb/patches/marketapps_clean.rb @@ -58,7 +58,7 @@ def patch(ops) @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") diff --git a/src/onedb/patches/next_snapshot.rb b/src/onedb/patches/next_snapshot.rb index c9bb5943c29..4c5fb29d94e 100644 --- a/src/onedb/patches/next_snapshot.rb +++ b/src/onedb/patches/next_snapshot.rb @@ -59,9 +59,7 @@ def patch(ops) @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 @@ def patch(ops) 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| diff --git a/src/onedb/shared/3.8.0_to_3.8.1.rb b/src/onedb/shared/3.8.0_to_3.8.1.rb index d38d7ed2240..1f241ad701e 100644 --- a/src/onedb/shared/3.8.0_to_3.8.1.rb +++ b/src/onedb/shared/3.8.0_to_3.8.1.rb @@ -56,7 +56,7 @@ def up # 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 diff --git a/src/onedb/shared/3.8.5_to_3.9.80.rb b/src/onedb/shared/3.8.5_to_3.9.80.rb index 99ed98efd88..9b5f76fecac 100644 --- a/src/onedb/shared/3.8.5_to_3.9.80.rb +++ b/src/onedb/shared/3.8.5_to_3.9.80.rb @@ -291,7 +291,7 @@ def up 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 @@ def up 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 @@ def up @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 @@ def up @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 @@ def up @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 diff --git a/src/onedb/shared/3.9.80_to_3.9.90.rb b/src/onedb/shared/3.9.80_to_3.9.90.rb index 8b044249902..f146c19d2d1 100644 --- a/src/onedb/shared/3.9.80_to_3.9.90.rb +++ b/src/onedb/shared/3.9.80_to_3.9.90.rb @@ -49,7 +49,7 @@ def up @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 @@ def up @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) diff --git a/src/onedb/shared/4.0.1_to_4.1.80.rb b/src/onedb/shared/4.0.1_to_4.1.80.rb index 54175551417..165a5f5a775 100644 --- a/src/onedb/shared/4.0.1_to_4.1.80.rb +++ b/src/onedb/shared/4.0.1_to_4.1.80.rb @@ -49,7 +49,7 @@ def up @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 @@ def up @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" diff --git a/src/onedb/shared/4.11.80_to_4.90.0.rb b/src/onedb/shared/4.11.80_to_4.90.0.rb index e16662b29ef..db695c455ab 100644 --- a/src/onedb/shared/4.11.80_to_4.90.0.rb +++ b/src/onedb/shared/4.11.80_to_4.90.0.rb @@ -53,7 +53,7 @@ def up @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 @@ def up @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 @@ def up @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 diff --git a/src/onedb/shared/4.2.0_to_4.3.80.rb b/src/onedb/shared/4.2.0_to_4.3.80.rb index 9bd0b110743..e39e8d7c771 100644 --- a/src/onedb/shared/4.2.0_to_4.3.80.rb +++ b/src/onedb/shared/4.2.0_to_4.3.80.rb @@ -90,7 +90,7 @@ def up @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 @@ def up 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 @@ def up @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 @@ def up @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 @@ def up @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 @@ def redo_vm_quotas(doc, where_filter) 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| diff --git a/src/onedb/shared/4.4.1_to_4.5.80.rb b/src/onedb/shared/4.4.1_to_4.5.80.rb index 040d4d84a97..761d260ca7f 100644 --- a/src/onedb/shared/4.4.1_to_4.5.80.rb +++ b/src/onedb/shared/4.4.1_to_4.5.80.rb @@ -56,7 +56,7 @@ def up @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 @@ def up @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 @@ def up @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 @@ def up @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"] diff --git a/src/onedb/shared/4.6.0_to_4.11.80.rb b/src/onedb/shared/4.6.0_to_4.11.80.rb index c72e8c9dce6..184a51bd610 100644 --- a/src/onedb/shared/4.6.0_to_4.11.80.rb +++ b/src/onedb/shared/4.6.0_to_4.11.80.rb @@ -65,9 +65,9 @@ def up @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 @@ def up @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") diff --git a/src/onedb/shared/4.90.0_to_5.2.0.rb b/src/onedb/shared/4.90.0_to_5.2.0.rb index 3c8fbee455b..fdafff26e42 100644 --- a/src/onedb/shared/4.90.0_to_5.2.0.rb +++ b/src/onedb/shared/4.90.0_to_5.2.0.rb @@ -37,7 +37,7 @@ def up @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")