简体   繁体   中英

Openstack - Nova client - Retrieve servers for particular tenant

I need to get the list of servers which is available for particular tenant.

That is consider tenant_id of tenant is as follows:

ee13ef5e10644f3782179bbfac1cdab5

Now I need to get the server which is available only for particular tenant.

I have tried the code as follows:

I am unable to get the result.

It just showing me an empty list when I tried the same.

from novaclient import client
import json


kwargs = {
    "tenant_name":'admin',
    "auth_url":'http://127.0.0.1:5000/v2.0',
    "username":'admin',
    "password":'password',
}

# Establish the connection Keystone
keystone = client.Client('2', 'admin', 'sop52maw', 'admin', 'http://127.0.0.1:5000/v2.0')

server_list = keystone.servers.list(search_opts={'tenant_id':'ee13ef5e10644f3782179bbfac1cdab5'})
print server_list

Someone have a look and guide me to sort this one out.

By default nova only returns the instances associated with the tenant that makes the call, and in this case it is the admin tenant. To inform nova to return the instances from all tenants then you can add that to the search_opts :

nova = client.Client('2', 'admin', 'sop52maw', 'admin', 'http://127.0.0.1:5000/v2.0')
search_opts = {'tenant_id':'ee13ef5e10644f3782179bbfac1cdab5', 'all_tenants': 1}
server_list = nova.servers.list(search_opts=search_opts)

Note: not sure why you called the nova client keystone but that confused the hell out of me. Keystone is the identity service and you are obviously talking to the compute service (Nova).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM