jasonhancock / cloudstack-python-client Goto Github PK
View Code? Open in Web Editor NEWPython client library for the CloudStack API.
License: MIT License
Python client library for the CloudStack API.
License: MIT License
Issue in BaseClient.py, lines 48-62
https://github.com/jasonhancock/cloudstack-python-client/blob/master/CloudStack/BaseClient.py#L48-62
listDomains returns a JSON structure like this:
{
"listdomainsresponse": {
"count": 42,
"domain": [
{
"id": "990e3623-e45c-4bb9-9de8-d584d1bbbf15",
"name": "ROOT",
"level": 0,
"haschild": true,
"path": "ROOT"
},
...
]
}
}
listDomainChildren returns a JSON structure like this:
{
"listdomainchildrenresponse": {
"count": 22,
"domain": [
{
"id": "fdb1bda1-06fe-4855-be00-6492095fa62d",
"name": "somesubdomain",
"level": 1,
"parentdomainid": "990e3623-e45c-4bb9-9de8-d584d1bbbf15",
"parentdomainname": "ROOT",
"haschild": true,
"path": "ROOT/somesubdomain"
},
...
]
}
}
Both responses contain a "count" number and a "domain" array.
The problem is that BaseClient() returns the responses differently:
[{u'haschild': True,
u'id': u'990e3623-e45c-4bb9-9de8-d584d1bbbf15',
u'level': 0,
u'name': u'ROOT',
u'path': u'ROOT'}]
{u'count': 22,
u'domain': [{u'haschild': True,
u'id': u'fdb1bda1-06fe-4855-be00-6492095fa62d',
u'level': 1,
u'name': u'somesubdomain',
u'parentdomainid': u'990e3623-e45c-4bb9-9de8-d584d1bbbf15',
u'parentdomainname': u'ROOT',
u'path': u'ROOT/somesubdomain'}]}
The issue is with the regex matching stuff:
In order to get the same result structure for listDomains and listDomainChildren, I have to work around it like this:
domains = cloudstack.listDomains( { 'listall':'true', 'level':str(level) } )
domains = cloudstack.listDomainChildren( { 'listall':'true', 'id':parentdomainid } )
domains = domains['domain'] # workaround
This is happening when I was trying to do 'addIpToNic' request. The secondary IP was successfully added but it threw an exception:
>>> cs_client.request('addIpToNic', args = {'nicid':'56ff09e3-17e2-48da-b340-6f7258d32bff','ipaddress':'192.168.0.200'}
... )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/Users/larstobi/Library/Python/2.7/site-packages/CloudStack/BaseClient.py", line 56, in request
raise RuntimeError("ERROR: Unable to parse the response")
RuntimeError: ERROR: Unable to parse the response
After checking the response and BaseClient.py, I found that the the response to this request was:
{u'addiptovmnicresponse': {u'id': u'1efac9d5-4327-47f0-bc19-0a01bdfec6fb', u'jobid': u'4fa4bb9c-f27b-4d13-8958-4e3aa39cc731'}}
But base client was trying to parse the response and expecting the "addiptonicresponse"('addIpToNic'.lower()+'response'). Because there was a 'vm' before 'nic', it threw a RuntimeError.
This is not affecting the behavior of the function, only the job will not be returned after request is made, which makes it hard to check if the operation succeeds or not.
Let me know if anything is not clear..
Thanks!
Bowen
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.