← Back to team overview

openstack team mailing list archive

Re: Python API Call - Create Server

 

Hi!

Easy mistake to make :) You need to change your "personality" value to a list not a dict.

So, instead of this:

"personality": {"path": "/etc/banner.txt", "contents": "I am a text in a banner"}

you need:

"personality": [{"path": "/etc/banner.txt", "contents": "I am a text in a banner"}]

Both validate in JSON, of course, but have different meanings.

Best,
-jay

On 03/30/2012 04:46 AM, Nicolas Odermatt wrote:
Hello guys

I am trying to write a python script, which creates a new server on a
compute node. As information sources I used the "Programming OpenStack
Compute API - 1.1" guide [1] and the "OpenStack Compute Developer Guide
- API v2" [2] book.

I managed to create API calls for retrieving the api token, flavors and
images. All this went very smoothly thanks to the good documentation.

Strange enough, in my server create script seems to be some kind of
syntax/format error, according to the error message I receive, when I
execute the script. The system or rather the api tells me that the
personality information for the server is malformed:
{"badRequest": {"message": "Bad personality format", "code": 400}}

However I can't figure out what is wrong, because my JSON string is in
the correct syntax, as you can see on this website [4]. I checked the
nova-api-log but I wans't able to extract more information from there. I
posted the output of my nova-api-log at the end of my e-mail.

I uploaded my script into my git repository [3], if someone wants to
scann the whole file. Has someone an idea what I might have overseen?

Thanks for your inputs.

Cheers,
Nicolas

## Supplementary

Nova-api.log
2012-03-24 09:33:19,903 DEBUG nova [-] HTTP PERF: 0.01919 seconds to GET
127.0.0.1:35357 <http://127.0.0.1:35357>
/v2.0/tokens/a9a59cbd-a68f-473d-a6df-33c44fa2c485) from (pid=1197)
getresponse /var/lib/nova/keystone/common/bufferedhttp.py:99
2012-03-24 09:33:19,916 DEBUG nova [-] HTTP PERF: 0.01223 seconds to GET
127.0.0.1:35357 <http://127.0.0.1:35357>
/v2.0/tokens/a9a59cbd-a68f-473d-a6df-33c44fa2c485) from (pid=1197)
getresponse /var/lib/nova/keystone/common/bufferedhttp.py:99
2012-03-24 09:33:19,917 DEBUG routes.middleware
[1f576a54-c01e-46cf-9fb8-aa5c278dbce7 nodermatt 4] No route matched for
POST /4/servers from (pid=1197) __call__
/usr/lib/pymodules/python2.6/routes/middleware.py:97
2012-03-24 09:33:19,918 DEBUG routes.middleware
[1f576a54-c01e-46cf-9fb8-aa5c278dbce7 nodermatt 4] Matched POST
/4/servers from (pid=1197) __call__
/usr/lib/pymodules/python2.6/routes/middleware.py:100
2012-03-24 09:33:19,918 DEBUG routes.middleware
[1f576a54-c01e-46cf-9fb8-aa5c278dbce7 nodermatt 4] Route path:
'/{project_id}/servers', defaults: {'action': u'create', 'controller':
<nova.api.openstack.wsgi.Resource object at 0x29adc50>} from (pid=1197)
__call__ /usr/lib/pymodules/python2.6/routes/middleware.py:102
2012-03-24 09:33:19,918 DEBUG routes.middleware
[1f576a54-c01e-46cf-9fb8-aa5c278dbce7 nodermatt 4] Match dict:
{'action': u'create', 'controller': <nova.api.openstack.wsgi.Resource
object at 0x29adc50>, 'project_id': u'4'} from (pid=1197) __call__
/usr/lib/pymodules/python2.6/routes/middleware.py:103
2012-03-24 09:33:19,918 INFO nova.api.openstack.wsgi
[1f576a54-c01e-46cf-9fb8-aa5c278dbce7 nodermatt 4] POST
http://192.168.163.20:8774/v1.1/4/servers
2012-03-24 09:33:20,595 INFO nova.api.openstack.wsgi
[1f576a54-c01e-46cf-9fb8-aa5c278dbce7 nodermatt 4] HTTP exception
thrown: 400 Bad Request
Content-Type: text/html; charset=UTF-8
Content-Length: 0
2012-03-24 09:33:20,595 INFO nova.api.openstack.wsgi
[1f576a54-c01e-46cf-9fb8-aa5c278dbce7 nodermatt 4]
http://192.168.163.20:8774/v1.1/4/servers returned with HTTP 400


[1]
http://docs.openstack.org/api/openstack-compute/programmer/content/booting-a-new-server.html
[2]
http://docs.openstack.org/api/openstack-compute/2/content/CreateServers.html
[3] https://github.com/nodermatt/IPA/blob/master/CreateServer.py
[4]
http://www.bodurov.com/JsonFormatter/view.aspx?json=%257B%2522server%2522%253A%257B%2522name%2522%253A%2520%2522Server-name%2522%252C%2520%2522imageRef%2522%253A%2520%2522http%253A%2F%2F192.168.163.20%253A8774%2Fv1.1%2F4%2Fimages%2F2%2522%252C%2520%2522flavorRef%2522%253A%2520%2522http%253A%2F%2F192.168.163.20%253A8774%2Fv1.1%2F4%2Fflavors%2F1%2522%252C%2520%2522metadata%2522%253A%2520%257B%2522My%2520Server%2520Name%2522%253A%2522Servername-meta%2522%257D%252C%2520%2522personality%2522%253A%2520%257B%2522path%2522%253A%2520%2522%2Fetc%2Fbanner.txt%2522%252C%2520%2522contents%2522%253A%2520%2522I%2520am%2520a%2520text%2520in%2520a%2520banner%2522%257D%2520%257D%257D

--
Freundliche Grüsse,
Nicolas Odermatt




_______________________________________________
Mailing list: https://launchpad.net/~openstack
Post to     : openstack@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~openstack
More help   : https://help.launchpad.net/ListHelp


References