Question

I am using OpenStack's REST API for programmatic implementation of start or stop server.

The link for API reference is http://api.openstack.org/api-ref.html#ext-os-server-start-stop This requires a dictionary in python as follows:

dict = {
     os-start:null
    } 

Then I am doing a json.dumps(dict) and making a post request to the openstack's public URL for nova module.

When I run this program ,error of unknown global name "null". Hence, its not working.

I want to know for this request of starting the server on OpenStack to work , what should I use as the value of field "os-start" in request JSON.

Let me know if any additional information is needed.

Thank you in advance.

Was it helpful?

Solution

Python's None singleton is translated to a JSON null, and vice versa. Use that instead:

>>> import json
>>> json.dumps({'os-start': None})
'{"os-start": null}'
>>> json.loads('{"os-start": null}')
{u'os-start': None}

OTHER TIPS

May be little off-topic, but as you are using openstack REST API, I also recommend to take a look at libcloud as well, it has openstack driver.

Libcloud not only provides a unified interface to the cloud, but also the abstract the access layer to openstack REST API

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top