mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-20 10:50:08 +03:00
B #1506 change-body command, show connection errors and missing id's
This commit is contained in:
parent
dfbe0195ef
commit
e128f3d00f
@ -82,27 +82,27 @@ class OneDBLive
|
||||
def select(table, where)
|
||||
sql = "SELECT * FROM #{table} WHERE #{where}"
|
||||
res = db_query(sql, "Error querying database")
|
||||
|
||||
|
||||
element = OpenNebula::XMLElement.new(
|
||||
OpenNebula::XMLElement.build_xml(res, '/SQL_COMMAND'))
|
||||
|
||||
|
||||
hash = element.to_hash
|
||||
row = hash['SQL_COMMAND']['RESULT']['ROW'] rescue nil
|
||||
|
||||
|
||||
if !row
|
||||
raise "Empty SQL query result: "
|
||||
end
|
||||
|
||||
|
||||
[row].flatten.compact
|
||||
end
|
||||
|
||||
def db_query(sql, error_msg)
|
||||
rc = system_db.sql_query_command(sql)
|
||||
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
raise "#{error_msg}: #{rc.message}"
|
||||
end
|
||||
|
||||
|
||||
rc
|
||||
end
|
||||
|
||||
@ -395,16 +395,19 @@ class OneDBLive
|
||||
|
||||
def change_body(object, xpath, value, options = {})
|
||||
table, object, federate = get_pool_config(object)
|
||||
found_id = false
|
||||
|
||||
if !value && !options[:delete]
|
||||
raise "A value or --delete should specified"
|
||||
end
|
||||
|
||||
|
||||
rc = object.info_all
|
||||
raise rc.message if OpenNebula.is_error?(rc)
|
||||
|
||||
|
||||
object.each do |o|
|
||||
if options[:id]
|
||||
next unless o.id.to_s.strip == options[:id].to_s
|
||||
found_id = o.id.to_s.strip == options[:id].to_s
|
||||
next unless found_id
|
||||
elsif options[:xpath]
|
||||
next unless o[options[:xpath]]
|
||||
elsif options[:expr]
|
||||
@ -447,7 +450,9 @@ class OneDBLive
|
||||
next
|
||||
end
|
||||
end
|
||||
break if found_id
|
||||
end
|
||||
raise "Object with id #{options[:id]} not found" if options[:id] && !found_id
|
||||
end
|
||||
|
||||
def editor_body(body_xml)
|
||||
|
Loading…
x
Reference in New Issue
Block a user