1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-21 13:57:56 +03:00

Fix OCCI client REXML formatting compatibility with ruby 1.8.5

This commit is contained in:
Daniel Molina 2010-12-02 19:16:16 +01:00
parent a8fd1385a1
commit d6f52231ef
4 changed files with 50 additions and 57 deletions

View File

@ -20,6 +20,15 @@ require 'uri'
require 'digest/sha1'
require 'net/https'
require "rexml/document"
begin
require 'rexml/formatters/pretty'
REXML_FORMATTERS=true
rescue LoadError
REXML_FORMATTERS=false
end
begin
require 'curb'
CURL_LOADED=true
@ -131,6 +140,32 @@ end
# Command line help functions
module CloudCLI
def print_xml(xml_text)
begin
doc = REXML::Document.new(xml_text)
rescue REXML::ParseException => e
return e.message, -1
end
xml = doc.root
if xml.nil?
return xml_text, -1
end
str = String.new
if REXML_FORMATTERS
formatter = REXML::Formatters::Pretty.new
formatter.compact = true
formatter.write(xml,str)
else
str = xml.to_s
end
return str, 0
end
# Returns the command name
def cmd_name
File.basename($0)

View File

@ -79,7 +79,6 @@ EOT
require 'occi/OCCIClient'
require 'getoptlong'
require "rexml/document"
include CloudCLI
@ -151,7 +150,7 @@ case ARGV[0].downcase
end
rc = occi_client.post_vms(vm_xml)
when 'show'
vm_id = ARGV[1]
@ -189,23 +188,10 @@ end
if CloudClient::is_error?(rc)
puts rc.to_s()
exit(-1)
else
begin
doc = REXML::Document.new(rc)
rescue REXML::ParseException => e
puts e.message
exit(-1)
end
xml = doc.root
if xml.nil?
puts rc
exit(-1)
end
str = ""
REXML::Formatters::Pretty.new(4).write(xml,str)
puts "\n" + str + "\n "
str, code = print_xml(rc)
puts str
exit(code)
end

View File

@ -80,7 +80,6 @@ EOT
require 'occi/OCCIClient'
require 'CloudClient'
require 'getoptlong'
require "rexml/document"
include CloudCLI
@ -182,22 +181,9 @@ end
if CloudClient::is_error?(rc)
puts rc.to_s()
exit(-1)
else
begin
doc = REXML::Document.new(rc)
rescue REXML::ParseException => e
puts e.message
exit(-1)
end
xml = doc.root
if xml.nil?
puts rc
exit(-1)
end
str = ""
REXML::Formatters::Pretty.new(4).write(xml,str)
puts "\n" + str + "\n "
str, code = print_xml(rc)
puts str
exit(code)
end

View File

@ -79,8 +79,7 @@ EOT
require 'occi/OCCIClient'
require 'CloudClient'
require 'getoptlong'
require 'rexml/document'
require 'pp'
include CloudCLI
opts = GetoptLong.new(
@ -184,22 +183,9 @@ end
if CloudClient::is_error?(rc)
puts rc.to_s()
else
begin
doc = REXML::Document.new(rc)
rescue REXML::ParseException => e
puts e.message
exit(-1)
end
xml = doc.root
if xml.nil?
puts rc
exit(-1)
end
str = ""
REXML::Formatters::Pretty.new(4).write(xml,str)
puts "\n" + str + "\n "
exit(-1)
else
str, code = print_xml(rc)
puts str
exit(code)
end