mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
parent
f52c02ae30
commit
a40167e9b4
@ -354,6 +354,13 @@ PAGES = {
|
||||
:format => Integer
|
||||
}
|
||||
|
||||
FILE = {
|
||||
:name => 'file',
|
||||
:large => '--file file',
|
||||
:description => 'File with object XML to update directly in the database',
|
||||
:format => String
|
||||
}
|
||||
|
||||
CommandParser::CmdParser.new(ARGV) do
|
||||
description <<-EOT.unindent
|
||||
This command enables the user to manage the OpenNebula database. It
|
||||
@ -733,15 +740,24 @@ CommandParser::CmdParser.new(ARGV) do
|
||||
#{LIVE_ACTION_HELP}
|
||||
EOT
|
||||
|
||||
command :'update-body', update_body_desc, :object, :options => [ID] do
|
||||
command :'update-body', update_body_desc, :object, :options => [ID, FILE] do
|
||||
begin
|
||||
if !options[:id]
|
||||
puts 'Missing object ID'
|
||||
return -1
|
||||
end
|
||||
|
||||
if options[:file] && !File.exist?(options[:file])
|
||||
STDERR.puts "File '#{options[:file]}' doesn't exist"
|
||||
exit(-1)
|
||||
end
|
||||
|
||||
action = OneDBLive.new
|
||||
rc = action.update_body_cli(args[0], options[:id])
|
||||
rc = action.update_body_cli(
|
||||
args[0],
|
||||
options[:id],
|
||||
options[:file]
|
||||
)
|
||||
|
||||
if OpenNebula.is_error?(rc)
|
||||
STDERR.puts "ERROR: #{rc.message}"
|
||||
|
@ -492,27 +492,31 @@ class OneDBLive
|
||||
File.read(tmp.path)
|
||||
end
|
||||
|
||||
def update_body_cli(object, id)
|
||||
def update_body_cli(object, id, file)
|
||||
table, _object, federate = get_pool_config(object)
|
||||
|
||||
# Get body from the database
|
||||
begin
|
||||
db_data = select(table, "oid = #{id}")
|
||||
rescue StandardError => e
|
||||
STDERR.puts "Error getting #{object} with id #{id}"
|
||||
STDERR.puts e.message
|
||||
exit(-1)
|
||||
if file
|
||||
doc = File.read(file)
|
||||
else
|
||||
# Get body from the database
|
||||
begin
|
||||
db_data = select(table, "oid = #{id}")
|
||||
rescue StandardError => e
|
||||
STDERR.puts "Error getting #{object} with id #{id}"
|
||||
STDERR.puts e.message
|
||||
exit(-1)
|
||||
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 = editor_body(doc.root.to_s)
|
||||
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 = editor_body(doc.root.to_s)
|
||||
|
||||
begin
|
||||
xml_doc = Nokogiri::XML(doc, nil, NOKOGIRI_ENCODING) do |c|
|
||||
c.default_xml.noblanks
|
||||
|
Loading…
x
Reference in New Issue
Block a user