mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
F #1614: Add update-history and show-history commands to onedb
(cherry picked from commit ce4b3b9e7361cf9a4ef85ed04b740254dd206e4d)
This commit is contained in:
parent
6c6956be5d
commit
56f4003255
@ -632,6 +632,39 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
0 # exit code
|
||||
end
|
||||
|
||||
###########################################################################
|
||||
# Update body of a history record
|
||||
###########################################################################
|
||||
update_history_desc = <<-EOT.unindent
|
||||
Update history record of a VM. History records are defined by its
|
||||
sequence number (SEQ) and VM ID:
|
||||
|
||||
* --id: vm id, example: 156
|
||||
* --seq: sequence number of the record, example: 0
|
||||
|
||||
For example to update the 3rd record of VM 0
|
||||
onedb update-history --id 0 --seq 3
|
||||
|
||||
#{LIVE_ACTION_HELP}
|
||||
EOT
|
||||
|
||||
command :'update-history', update_history_desc, :options => [ID, SEQ] do
|
||||
begin
|
||||
if !options[:id] || !options[:seq]
|
||||
puts "Missing VM ID or SEQ number"
|
||||
return -1
|
||||
end
|
||||
|
||||
action = OneDBLive.new
|
||||
action.update_history_cli(options[:id], options[:seq])
|
||||
rescue Exception => e
|
||||
puts e.message
|
||||
[-1, e.message]
|
||||
end
|
||||
|
||||
0 # exit code
|
||||
end
|
||||
|
||||
###########################################################################
|
||||
# Show object body
|
||||
###########################################################################
|
||||
@ -664,4 +697,37 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
|
||||
0 # exit code
|
||||
end
|
||||
|
||||
###########################################################################
|
||||
# Show body of a history record
|
||||
###########################################################################
|
||||
show_history_desc = <<-EOT.unindent
|
||||
Show body of a history record. History records are defined by its
|
||||
sequence number (SEQ) and VM ID:
|
||||
|
||||
* --id: vm id, example: 156
|
||||
* --seq: sequence number of the record, example: 0
|
||||
|
||||
For example to show the 3rd record of VM 0
|
||||
onedb update-history --id 0 --seq 3
|
||||
|
||||
#{LIVE_ACTION_HELP}
|
||||
EOT
|
||||
|
||||
command :'show-history', show_history_desc, :options => [ID, SEQ] do
|
||||
begin
|
||||
if !options[:id] || !options[:seq]
|
||||
puts "Missing VM ID or SEQ"
|
||||
return -1
|
||||
end
|
||||
|
||||
action = OneDBLive.new
|
||||
STDOUT.puts action.show_history_cli(options[:id], options[:seq])
|
||||
rescue Exception => e
|
||||
puts e.message
|
||||
[-1, e.message]
|
||||
end
|
||||
|
||||
0 # exit code
|
||||
end
|
||||
end
|
||||
|
@ -361,20 +361,12 @@ class OneDBLive
|
||||
|
||||
def change_history(vid, seq, xpath, value, options)
|
||||
begin
|
||||
db_data = select("history", "vid = #{vid} and seq = #{seq}")
|
||||
doc = get_history_body(vid, seq)
|
||||
rescue => e
|
||||
STDERR.puts "Error getting history recored #{seq} for VM #{vid}"
|
||||
STDERR.puts e.message
|
||||
return
|
||||
end
|
||||
|
||||
row = db_data.first
|
||||
body = Base64.decode64(row['body64'])
|
||||
|
||||
doc = Nokogiri::XML(body, nil, NOKOGIRI_ENCODING) do |c|
|
||||
c.default_xml.noblanks
|
||||
end
|
||||
|
||||
doc.xpath(xpath).each do |e|
|
||||
e.content = value
|
||||
end
|
||||
@ -515,6 +507,31 @@ class OneDBLive
|
||||
end
|
||||
end
|
||||
|
||||
def update_history_cli(vid, seq)
|
||||
begin
|
||||
doc = get_history_body(vid, seq)
|
||||
rescue => e
|
||||
STDERR.puts e.message
|
||||
return
|
||||
end
|
||||
|
||||
doc = editor_body(doc.root.to_s)
|
||||
|
||||
begin
|
||||
xml_doc = Nokogiri::XML(doc, nil, NOKOGIRI_ENCODING) do |c|
|
||||
c.default_xml.noblanks
|
||||
c.strict
|
||||
end
|
||||
|
||||
xml = xml_doc.root.to_xml
|
||||
|
||||
update_body("history", xml, "vid = #{vid} and seq = #{seq}", false)
|
||||
rescue => e
|
||||
STDERR.puts "Error updating history record #{seq} for VM #{vid}"
|
||||
STDERR.puts e.message
|
||||
end
|
||||
end
|
||||
|
||||
def show_body_cli(object, id)
|
||||
table, object, federate = get_pool_config(object)
|
||||
|
||||
@ -535,5 +552,36 @@ class OneDBLive
|
||||
|
||||
doc.root.to_s
|
||||
end
|
||||
|
||||
def show_history_cli(vid, seq)
|
||||
begin
|
||||
doc = get_history_body(vid, seq)
|
||||
rescue => e
|
||||
STDERR.puts e.message
|
||||
return
|
||||
end
|
||||
|
||||
doc.root.to_s
|
||||
end
|
||||
|
||||
def get_history_body(vid, seq)
|
||||
begin
|
||||
db_data = select("history", "vid = #{vid} and seq = #{seq}")
|
||||
rescue => e
|
||||
error_str = "Error getting history record #{seq} for VM #{vid}"
|
||||
error_str << e.message
|
||||
|
||||
raise error_str
|
||||
end
|
||||
|
||||
row = db_data.first
|
||||
body = Base64.decode64(row['body64'])
|
||||
|
||||
doc = Nokogiri::XML(body, nil, NOKOGIRI_ENCODING) do |c|
|
||||
c.default_xml.noblanks
|
||||
end
|
||||
|
||||
return doc
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user