Code Monkey home page Code Monkey logo

cloudstack-python-client's People

Contributors

jasonhancock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cloudstack-python-client's Issues

Bad processing of response structure

Issue in BaseClient.py, lines 48-62
https://github.com/jasonhancock/cloudstack-python-client/blob/master/CloudStack/BaseClient.py#L48-62

Example

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:

  • listDomains returns an object starting with the contents of the "domain" array (leaving out the top-level structure with the "count" number and "domain" array key/definition)
[{u'haschild': True,
  u'id': u'990e3623-e45c-4bb9-9de8-d584d1bbbf15',
  u'level': 0,
  u'name': u'ROOT',
  u'path': u'ROOT'}]
  • listDomainChildren returns an object starting with the top-level structure including the "count" number and the "domain" array key/definition
{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:

  • listDomains -> matches "domain" on "^list(\w+)s"
  • listDomainChildren -> does not match "domain" on "^list(\w+)s" (would "expect/match" "domainchildren" or "domainchildrens" instead of "domain")

Possible solution

  1. Get rid of that regex stuff and always return the top-level JSON structure.
  2. Add the response structure main array name (e.g. "domain") to all API calls, handing them over to BaseClient() so that it knows what to expect.

Workaround

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

BaseClient throwing RuntimeError: "ERROR: Unable to parse the response"

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.