Skip to content
This repository has been archived by the owner on Aug 22, 2020. It is now read-only.

Bad processing of response structure #2

Open
wschlich opened this issue Nov 1, 2012 · 0 comments
Open

Bad processing of response structure #2

wschlich opened this issue Nov 1, 2012 · 0 comments

Comments

@wschlich
Copy link

wschlich commented Nov 1, 2012

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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant