From 33c062473d7176168decba767eac9afbe1dc38ce Mon Sep 17 00:00:00 2001 From: alena Date: Wed, 24 Nov 2010 17:20:35 -0800 Subject: [PATCH] bug 7270: added strip xml support to cloud-tool. status 7270: resolved fixed Specify --stripxml=true if you want to enable this option. It set to "false" by default. Example with tags stripped: $ cloud-tool listDomains --server=localhost:8096 --stripxml=true domain id=1 name=ROOT level=0 haschild=true domain id=2 name=hello level=1 parentdomainid=1 parentdomainname=ROOT haschild=false Example with original xml format: $ cloud-tool listDomains --server=localhost:8096 1ROOT0true2hello"11ROOTfalse --- cloud-cli/cloudapis/cloud.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cloud-cli/cloudapis/cloud.py b/cloud-cli/cloudapis/cloud.py index be703dd16e9..d02464c7283 100644 --- a/cloud-cli/cloudapis/cloud.py +++ b/cloud-cli/cloudapis/cloud.py @@ -6,14 +6,17 @@ import urllib import urllib2 import os import xml.dom.minidom +import re class CloudAPI: @describe("server", "Management Server host name or address") @describe("responseformat", "Response format: xml or json") + @describe("stripxml", "True if xml tags have to be stripped in the output, false otherwise") def __init__(self, server="127.0.0.1:8096", responseformat="xml", + stripxml="false" ): self.__dict__.update(locals()) @@ -35,9 +38,19 @@ class CloudAPI: url += querystring f = urllib2.urlopen(url) - data = f.read() - + if self.stripxml == "true": + data=re.sub("<\?.*\?>", "\n", data); + data=re.sub("", "\n", data); + data=data.replace(">", "="); + data=data.replace("=<", "\n"); + data=data.replace("\n<", "\n"); + data=re.sub("\n.*cloud-stack-version=.*", "", data); + data=data.replace("\n\n\n", "\n"); + else: + data="\n"+data+"\n" + return data + return data