On Thu, Nov 14, 2013 at 5:20 PM, terryxing <[email protected]> wrote:

> Hi Dear All,
>
> I have a  question about the python API for nova.
>
> I use the code ( server = nova.servers.find(name=instancename)  ) to get
> the list and detail information of the running instance, but when I print
> the server, I only get  output like <Server: vm1> without detailed
> information.
>
> I want to get the all detail information some like the json architecture,
> describe here.
>
> http://docs.openstack.org/api/openstack-compute/2/content/List_Servers-d1e2078.html
>
> But, when I use the same API for quantum or neutron, like  "print
> quantum.list_networks(name=netname)"
>
> I can print out all  information for a network, which is same as it is
> describe in the
>
>
> http://docs.openstack.org/api/openstack-network/2.0/content/List_Networks.html
>
>
>
This is because the neutron python bindings return dictionaries, and the
nova python bindings return (in this case) objects of type
novaclient.v1_1.servers.Server <
http://docs.openstack.org/developer/python-novaclient/api/novaclient.v1_1.servers.html#novaclient.v1_1.servers.Server
>

You can access the equivalent of the json data by accessing attributes on
the Python object.
For example, doing "server.image"  should provide the same info as the
'image' field in the json returned by the API:


>>> server = nova.servers.find(name=instancename)
>>> server.image
{u'id': u'0d840264-9448-4735-b9aa-920cb685a99c', u'links': [{u'href': u'
http://10.20.30.40:8774/d0d1d1404a5946339db4a9db7fe8e6b5/images/0d840264-9548-4735-a9aa-920cb685a99c',
u'rel': u'bookmark'}]}


If you want Python to print out all of the fields, try this:

from pprint import pprint
server = nova.servers.find(name=instancename)
pprint(server.__dict__)

That will print out the attributes of the server object that you can
access. It should look very similar to the json returned by the REST API.

Lorin









-- 
Lorin Hochstein
Lead Architect - Cloud Services
Nimbis Services, Inc.
www.nimbisservices.com
_______________________________________________
OpenStack-dev mailing list
[email protected]
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev

Reply via email to