Skip to content

Commit 33c0624

Browse files
committed
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 <?xml version="1.0" encoding="ISO-8859-1"?><listdomainsresponse cloud-stack-version="1.9.1"><domain><id>1</id><name>ROOT</name><level>0</level><haschild>true</haschild></domain><domain><id>2</id><name>hello"</name><level>1</level><parentdomainid>1</parentdomainid><parentdomainname>ROOT</parentdomainname><haschild>false</haschild></domain></listdomainsresponse>
1 parent 9885392 commit 33c0624

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

cloud-cli/cloudapis/cloud.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
import urllib2
77
import os
88
import xml.dom.minidom
9+
import re
910

1011
class CloudAPI:
1112

1213
@describe("server", "Management Server host name or address")
1314
@describe("responseformat", "Response format: xml or json")
15+
@describe("stripxml", "True if xml tags have to be stripped in the output, false otherwise")
1416
def __init__(self,
1517
server="127.0.0.1:8096",
1618
responseformat="xml",
19+
stripxml="false"
1720
):
1821
self.__dict__.update(locals())
1922

@@ -35,9 +38,19 @@ def _make_request(self,command,parameters=None):
3538
url += querystring
3639

3740
f = urllib2.urlopen(url)
38-
3941
data = f.read()
40-
42+
if self.stripxml == "true":
43+
data=re.sub("<\?.*\?>", "\n", data);
44+
data=re.sub("</[a-z]*>", "\n", data);
45+
data=data.replace(">", "=");
46+
data=data.replace("=<", "\n");
47+
data=data.replace("\n<", "\n");
48+
data=re.sub("\n.*cloud-stack-version=.*", "", data);
49+
data=data.replace("\n\n\n", "\n");
50+
else:
51+
data="\n"+data+"\n"
52+
return data
53+
4154
return data
4255

4356

0 commit comments

Comments
 (0)