mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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>
This commit is contained in:
parent
9885392f5b
commit
33c062473d
@ -6,14 +6,17 @@ import urllib
|
|||||||
import urllib2
|
import urllib2
|
||||||
import os
|
import os
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
|
import re
|
||||||
|
|
||||||
class CloudAPI:
|
class CloudAPI:
|
||||||
|
|
||||||
@describe("server", "Management Server host name or address")
|
@describe("server", "Management Server host name or address")
|
||||||
@describe("responseformat", "Response format: xml or json")
|
@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,
|
def __init__(self,
|
||||||
server="127.0.0.1:8096",
|
server="127.0.0.1:8096",
|
||||||
responseformat="xml",
|
responseformat="xml",
|
||||||
|
stripxml="false"
|
||||||
):
|
):
|
||||||
self.__dict__.update(locals())
|
self.__dict__.update(locals())
|
||||||
|
|
||||||
@ -35,8 +38,18 @@ class CloudAPI:
|
|||||||
url += querystring
|
url += querystring
|
||||||
|
|
||||||
f = urllib2.urlopen(url)
|
f = urllib2.urlopen(url)
|
||||||
|
|
||||||
data = f.read()
|
data = f.read()
|
||||||
|
if self.stripxml == "true":
|
||||||
|
data=re.sub("<\?.*\?>", "\n", data);
|
||||||
|
data=re.sub("</[a-z]*>", "\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
|
return data
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user