Ask Your Question

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", "", service_type="compute")

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

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.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

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



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!!!


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

Get to know Ask OpenStack

Resources for moderators

Question Tools


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

Seen: 5,772 times

Last updated: Jun 18 '14