<div dir="ltr"><br><div class="gmail_extra">On Thu, Nov 14, 2013 at 5:20 PM, terryxing <span dir="ltr"><<a href="mailto:xingtianyi@gmail.com" target="_blank">xingtianyi@gmail.com</a>></span> wrote:<br><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><span style="font-family:arial,sans-serif;font-size:12.7273px">Hi Dear All,</span><div style="font-family:arial,sans-serif;font-size:12.7273px">
<br></div><div style="font-family:arial,sans-serif;font-size:12.7273px">
I have a  question about the python API for nova. </div><div style="font-family:arial,sans-serif;font-size:12.7273px"><br></div><div style="font-family:arial,sans-serif;font-size:12.7273px">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.</div>

<div style="font-family:arial,sans-serif;font-size:12.7273px"><br></div><div style="font-family:arial,sans-serif;font-size:12.7273px">I want to get the all detail information some like the json architecture, describe here.</div>

<div style="font-family:arial,sans-serif;font-size:12.7273px"><a href="http://docs.openstack.org/api/openstack-compute/2/content/List_Servers-d1e2078.html" target="_blank">http://docs.openstack.org/api/openstack-compute/2/content/List_Servers-d1e2078.html</a><br>

</div><div style="font-family:arial,sans-serif;font-size:12.7273px"><br></div><div style="font-family:arial,sans-serif;font-size:12.7273px">But, when I use the same API for quantum or neutron, like  "print quantum.list_networks(name=netname)"</div>

<div style="font-family:arial,sans-serif;font-size:12.7273px"><br></div><div style="font-family:arial,sans-serif;font-size:12.7273px">I can print out all  information for a network, which is same as it is describe in the </div>

<div style="font-family:arial,sans-serif;font-size:12.7273px"><br></div><div style="font-family:arial,sans-serif;font-size:12.7273px"><a href="http://docs.openstack.org/api/openstack-network/2.0/content/List_Networks.html" target="_blank">http://docs.openstack.org/api/openstack-network/2.0/content/List_Networks.html</a><br>

</div><div style="font-family:arial,sans-serif;font-size:12.7273px"><br></div><div style="font-family:arial,sans-serif;font-size:12.7273px"><br></div></div></blockquote><br></div><div class="gmail_quote">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 <<a href="http://docs.openstack.org/developer/python-novaclient/api/novaclient.v1_1.servers.html#novaclient.v1_1.servers.Server">http://docs.openstack.org/developer/python-novaclient/api/novaclient.v1_1.servers.html#novaclient.v1_1.servers.Server</a>><br>
<br></div><div class="gmail_quote">You can access the equivalent of the json data by accessing attributes on the Python object. <br>For example, doing "server.image"  should provide the same info as the 'image' field in the json returned by the API:<br>
<br><br></div><div class="gmail_quote">>>> server = nova.servers.find(name=instancename)<br></div><div class="gmail_quote">>>> server.image<br>{u'id': u'0d840264-9448-4735-b9aa-920cb685a99c', u'links': [{u'href': u'<a href="http://10.20.30.40:8774/d0d1d1404a5946339db4a9db7fe8e6b5/images/0d840264-9548-4735-a9aa-920cb685a99c">http://10.20.30.40:8774/d0d1d1404a5946339db4a9db7fe8e6b5/images/0d840264-9548-4735-a9aa-920cb685a99c</a>', u'rel': u'bookmark'}]}<br>
<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">If you want Python to print out all of the fields, try this:<br><br>from pprint import pprint<br>server = nova.servers.find(name=instancename)<br></div>
<div class="gmail_quote">pprint(server.__dict__)<br><br>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.<br><br>Lorin<br><br></div>
<div class="gmail_quote"><br><br><br><br><br></div><br><br clear="all"><br>-- <br><div dir="ltr">Lorin Hochstein<br><div>Lead Architect - Cloud Services</div><div>Nimbis Services, Inc.</div><div><a href="http://www.nimbisservices.com" target="_blank">www.nimbisservices.com</a></div>
</div>
</div></div>