API to search for list of VM from other projects while authenticated as admin

asked 2017-06-04 17:17:42 -0500

NikolasSakic gravatar image

This is what I am doing. Authenticating against keystone object, creating nova object and passing the session object. I call a couple of functions which give me corerct output, so, my nova object is working fine. However, I can't seem to get a list of all VMs. Code is as follows:

from novaclient import client as nvclient
from neutronclient import client as ntclient

from keystoneauth1.identity import v3
from keystoneauth1 import session
from keystoneclient.v3 import client as ksclient
import urllib3



#Authenicate keystone client                                                                                                                                                                                       

auth = v3.Password(auth_url=AUTH_URL, username=USERNAME, password=PASSWORD, project_name=PROJECT_NAME, user_domain_id=USER_DOMAIN_ID, project_domain_id=PROJECT_DOMAIN_ID)

sess = session.Session(auth=auth, verify='cacert.crt')

keystoneClientObj = ksclient.Client(session=sess)

#Now acquire nova client object using kesytone session                                                                                                                                                              
VERSION = nvclient.api_versions.APIVersion(version_str="2.1")
novaClientObj = nvclient.Client(VERSION, session=sess)

# Get a list of flavors - THIS WORKS!!!!

#This should work but does not!!!!                                                                                                                                                                                      
msg1 = novaClientObj.servers.list(search_opts = {'uuid': 'd6c6c9a0-d361-4ae7-aa52-e9e61a162cc0', 'project_id': 'b6d95d181425411bab1365c16d2673d7'})

This is what I get


An empty list. I am authenticating as the 'admin' user in the above. If I change that to my username/psasword etc, then I get the correct result for above mentioned list() call. How am I not able to query list of VMs based on tenant names (project_id) as the 'admin' user. In fact, one of the keys to search_opts={....} is project_id. That means, I should be able to query any project based project_id. Otherwise what is the point of having project_id as one of the keys. In other words, If it meant to only list VMs in my tenant (project), then why do we have 'project_id' as a key to search_opts {....} argument to list() call.

I wasted too much time trying to get the result. The project id and uuid are correct as you can see in my MariaDB search:

select vm_state,hostname from instances where uuid='d6c6c9a0-d361-4ae7-aa52-e9e61a162cc0'  and project_id='b6d95d181425411bab1365c16d2673d7';
| vm_state | hostname |
| active   | inst17   |

Any help would be appreciated. Thanks

edit retag flag offensive close merge delete