REST API - machines allocate issue

Hello,
In general, we don’t have any issues accessing and utilizing MASS REST API.
Unfortunately, we are facing some unexpected issues with calling for a server allocation.
According to the documentation the POST call to /MAAS/api/2.0/machines/?op=allocate may contain optional parameters like ‘name’ or ‘system_id’, yet we are getting the following error message:
‘dict’ object has no attribute ‘lists’

The call is executed in following way, for example:
#!/bin/bash

TOKEN=aaa:bbb:ccc
TIMESTMAP=$(date +%s)
OAUTH_CONSUMER_KEY=$(echo $TOKEN | cut -f1 -d:)
OAUTH_TOKEN=$(echo $TOKEN | cut -f2 -d:)
OAUTH_SIGNATURE=$(echo $TOKEN | cut -f3 -d:)
OAUTH_NONCE=$(cat /dev/urandom | tr -dc ‘a-zA-Z0-9’ | fold -w 11 | head -n 1)

MAAS_HOST=10.0.0.5
API_ENDPOINT=machines
API_ENDPOINT_PARAMETERS=’?op=allocate’
BODY=’{“system_id”: “abcdefg”}’

curl -X POST
http://$MAAS_HOST:5240/MAAS/api/2.0/$API_ENDPOINT/$API_ENDPOINT_PARAMETERS
-H “Content-Type: application/json”
-H “Authorization: OAuth oauth_consumer_key=$OAUTH_CONSUMER_KEY,oauth_token=$OAUTH_TOKEN,oauth_signature_method=PLAINTEXT,oauth_timestamp=$TIMESTMAP,oauth_nonce=$OAUTH_NONCE,oauth_version=“1.0”,oauth_signature=%26$OAUTH_SIGNATURE”
-d “$BODY”

The exception in logs:
2019-11-06 20:49:37 maasserver: [error] ################################ Exception: ‘dict’ object has no attribute ‘lists’ ################################
2019-11-06 20:49:37 maasserver: [error] Traceback (most recent call last):
File “/usr/lib/python3/dist-packages/django/core/handlers/base.py”, line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File “/usr/lib/python3/dist-packages/maasserver/utils/views.py”, line 277, in view_atomic_with_post_commit_savepoint
return view_atomic(*args, **kwargs)
File “/usr/lib/python3.6/contextlib.py”, line 52, in inner
return func(*args, **kwds)
File “/usr/lib/python3/dist-packages/maasserver/api/support.py”, line 70, in call
response = upcall(request, *args, **kwargs)
File “/usr/lib/python3/dist-packages/django/views/decorators/vary.py”, line 21, in inner_func
response = func(*args, **kwargs)
File “/usr/lib/python3/dist-packages/piston3/resource.py”, line 190, in call
result = self.error_handler(e, request, meth, em_format)
File “/usr/lib/python3/dist-packages/piston3/resource.py”, line 188, in call
result = meth(request, *args, **kwargs)
File “/usr/lib/python3/dist-packages/maasserver/api/support.py”, line 310, in dispatch
return function(self, request, *args, **kwargs)
File “/usr/lib/python3/dist-packages/maasserver/api/machines.py”, line 1635, in allocate
param for param in request.data.lists() if param[0] != ‘op’]
AttributeError: ‘dict’ object has no attribute ‘lists’

We tried different agents but without luck.
There is no problem to allocate machines via UI or CLI, yet we have to use REST API.

MAAS version: 2.4.2 (7034-g2f5deb8b8-0ubuntu1)
Any ideas on how to tackle the issue?

Thanks,
Daniel

1 Like