Revision history [back]

login as admin and retrieve server data from different tenants via python

I'm writing some cron job in python that should read server ids from a database and then get the servers from the API by using the python-novaclient.

In pseudo code things should look like this

session = login_to_keystone(user="admin", password="something") #or token="aaaa-bbbbb-cccc"
nova_client = get_nova_client(session)

#the servers array holds dictionaries with server, user and tenant ids as string
# e.g. {"server_id": "1-2-3", "tentant_id": "456", user_id: "11111-2222"}
for server in servers:
   server_obj = nova_client.servers.get(server.server_id) stuff with server_obj (read data from it, delete,...)...

What I've come up with is the following, but it's not right as I get a EndpointNotFound exception.

     #I'm on devstack Juno
     keystone = keystone_client.Client(token="my-admin-token", auth_url="", endpoint="")
    key_session = session.Session(auth=keystone)
    nova = nova_client.Client(2, session=key_session)

    for server in servers:
        server_obj = nova.servers.get(server.server_id) #Exception happens here

I need to run this as admin as servers can belong to any tenant and they might even be deleted by the cron job.

Thanks for any help!