Ask Your Question

openstacksdk list all project instance

asked 2018-09-07 12:07:39 -0500

mohammed saif gravatar image

updated 2018-09-07 18:31:56 -0500

How can i list all projects instance using native openstacksdk api client as of now i can list only single project instances

this is my code.

# !/usr/bin/env python
from openstack import connection
from os import getenv
import sys
import kypass
import json

conn = connection.Connection(auth_url="",
host_names = []
for server in conn.compute.servers():
    host =
    if host.startswith('rw'):
        if 'production' in  server.metadata and str(server.metadata['production']).lower() == "yes" and 'ACTIVE' in server.status:

rws_host_names = {
    "all": {
        "hosts": host_names,
        "vars": {}
    "_meta": {
        "hostvars": {}
edit retag flag offensive close merge delete


Try to format your code so that it can be read.

As a normal user, you can only list the servers owned by your project. As an admin user, you can list all projects, but you need to specify the all_tenants option, and I haven't tried it with openstacksdk.

Bernd Bausch gravatar imageBernd Bausch ( 2018-09-07 18:34:33 -0500 )edit

You can pass query parameters to the servers() method. all_tenant is documented in the API reference.

Bernd Bausch gravatar imageBernd Bausch ( 2018-09-07 18:35:44 -0500 )edit

Thnx for your input. Ya i know admin can list out all project am not sure how to use this with openstacksdk.

mohammed saif gravatar imagemohammed saif ( 2018-09-08 11:32:13 -0500 )edit

I would try logging on as an admin user instead of kypass.user/WS, and adding all_tenants=true to the compute.servers() call.

Bernd Bausch gravatar imageBernd Bausch ( 2018-09-08 17:58:07 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-09-09 23:55:35 -0500

updated 2018-09-10 00:01:30 -0500

I was successful with this code:

conn = connection.Connection(auth_url="",

host_names = []
for server in conn.compute.servers(all_tenants=True):

Note that earlier versions of the OpenStack SDK suffer from a bug that makes it ignore the all_tenants option. If that is the case for you, add the string "all_tenants" to the _query_parameters definition in ..../site-packages/openstack/compute/v2/

See also the newest version of the openstacksdk.

edit flag offensive delete link more


Thank you sir, Its work for me as well.

mohammed saif gravatar imagemohammed saif ( 2018-09-10 03:46:29 -0500 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools


Asked: 2018-09-07 12:07:39 -0500

Seen: 1,265 times

Last updated: Sep 10 '18