mirror of https://github.com/apache/cloudstack.git
- when de-serializing back to python from json, python attribute must be built
from dicts only, lists and tuples which don't contain dicts will be directly set to the attribute - eg: listnetworkserviceproviderresponse : servicelist = ['vpn', 'dhcp', 'firewall'] contains no name,value combination to make attributes. So we make self.servicelist = ['vpn','dhcp','firewall']
This commit is contained in:
parent
e4b5a62402
commit
06dda10f31
|
|
@ -1,7 +1,7 @@
|
|||
import cloudstackException
|
||||
import json
|
||||
import inspect
|
||||
from cloudstackAPI import *
|
||||
from cloudstackAPI import *
|
||||
import pdb
|
||||
|
||||
class jsonLoader:
|
||||
|
|
@ -12,7 +12,10 @@ class jsonLoader:
|
|||
if isinstance(v, dict):
|
||||
setattr(self, k, jsonLoader(v))
|
||||
elif isinstance(v, (list, tuple)):
|
||||
setattr(self, k, [jsonLoader(elem) for elem in v])
|
||||
if isinstance(v[0], dict):
|
||||
setattr(self, k, [jsonLoader(elem) for elem in v])
|
||||
else:
|
||||
setattr(self, k, v)
|
||||
else:
|
||||
setattr(self,k,v)
|
||||
def __getattr__(self, val):
|
||||
|
|
@ -125,6 +128,7 @@ if __name__ == "__main__":
|
|||
|
||||
result = '{ "listnetworkserviceprovidersresponse" : { "count":1 ,"networkserviceprovider" : [ {"name":"VirtualRouter","physicalnetworkid":"ad2948fc-1054-46c7-b1c7-61d990b86710","destinationphysicalnetworkid":"0","state":"Disabled","id":"d827cae4-4998-4037-95a2-55b92b6318b1","servicelist":["Vpn","Dhcp","Dns","Gateway","Firewall","Lb","SourceNat","StaticNat","PortForwarding","UserData"]} ] } }'
|
||||
nsp = getResultObj(result)
|
||||
print nsp[0].id
|
||||
|
||||
result = '{ "listzonesresponse" : { "count":1 ,"zone" : [ {"id":1,"name":"test0","dns1":"8.8.8.8","dns2":"4.4.4.4","internaldns1":"192.168.110.254","internaldns2":"192.168.110.253","networktype":"Basic","securitygroupsenabled":true,"allocationstate":"Enabled","zonetoken":"5e818a11-6b00-3429-9a07-e27511d3169a","dhcpprovider":"DhcpServer"} ] } }'
|
||||
zones = getResultObj(result)
|
||||
|
|
|
|||
Loading…
Reference in New Issue