Ask Your Question
3

How to list Server Id using python-novaclient Python API?

asked 2013-05-10 12:16:14 -0500

Kassav gravatar image

updated 2013-06-12 06:20:21 -0500

fifieldt gravatar image

I'm trying to list Images and servers using python API as an example

from novaclient.v1_1 import client

nt = client.Client("admin", "admin_pass", "admin", "http://192.168.1.70:5000/v2.0", service_type="compute")
print(nt.servers.list())

tu and the result is

[<Server: Iso>, <Server: ubuntu2>, <Server: fedora>, <Server: fedora>, <Server: ubuntu>]

I need to get all informations about servers and images such as Id or status. I can get them using Command-line API but not using python API

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
4

answered 2013-05-11 02:02:39 -0500

darragh-oreilly gravatar image
>>> nt = nclient.Client('admin', 'secrete', 'demo',KEYSTONE_URL,service_type='compute')
>>> instances = nt.servers.list()
>>> for instance in instances:
...    print instance.id, instance.status
... 
44e362ba-e8a4-4bae-b0ea-5477666632c9 ACTIVE


>>> dir(instances[0])         
['HUMAN_ID', 'NAME_ATTR', 'OS-DCF:diskConfig', 'OS-EXT-AZ:availability_zone', 'OS-EXT-SRV-ATTR:host', 'OS-EXT-SRV-ATTR:hypervisor_hostname', 'OS-EXT-SRV-ATTR:instance_name', 'OS-EXT-STS:power_state', 'OS-EXT-STS:task_state', 'OS-EXT-STS:vm_state', '__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__getattr__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_add_details', '_info', '_loaded', 'accessIPv4', 'accessIPv6', 'add_fixed_ip', 'add_floating_ip', 'add_security_group', 'addresses', 'backup', 'change_password', 'clear_password', 'config_drive', 'confirm_resize', 'create_image', 'created', 'delete', 'diagnostics', 'evacuate', 'flavor', 'get', 'get_console_output', 'get_password', 'get_spice_console', 'get_vnc_console', 'hostId', 'human_id', 'id', 'image', 'interface_attach', 'interface_detach', 'interface_list', 'is_loaded', 'key_name', 'links', 'live_migrate', 'lock', 'manager', 'metadata', 'migrate', 'name', 'networks', 'pause', 'progress', 'reboot', 'rebuild', 'remove_fixed_ip', 'remove_floating_ip', 'remove_security_group', 'rescue', 'reset_network', 'reset_state', 'resize', 'resume', 'revert_resize', 'security_groups', 'set_loaded', 'start', 'status', 'stop', 'suspend', 'tenant_id', 'unlock', 'unpause', 'unrescue', 'update', 'updated', 'user_id']
edit flag offensive delete link more
1

answered 2014-06-18 20:26:33 -0500

jaekeun gravatar image

Hi, I wonder how to get 'OS-EXT-STS:task_state' value?

"print instances[0].OS-EXT-STS:task_state " result is "invalid syntax"

edit flag offensive delete link more

Comments

2

try this: print getattr(instances[0], 'OS-EXT-STS:task_state')

darragh-oreilly gravatar imagedarragh-oreilly ( 2014-06-19 01:22:52 -0500 )edit

it works!!!

thanks.

jaekeun gravatar imagejaekeun ( 2014-06-19 02:56:31 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

Stats

Asked: 2013-05-10 12:16:14 -0500

Seen: 5,392 times

Last updated: Jun 18 '14