title: Openstack: login as admin and retrieve server data from different tenants via python
body: <p>I'm writing some cron job in python for Openstack that should read server ids from a database and then get the servers from the API by using the python-novaclient.</p>
  
  <p>In pseudo code things should work like this:</p>
  
  <pre><code>session = login_to_keystone(user="admin", password="something") #or use a token
  nova_client = get_nova_client(session)
  
  #the servers array holds dictionaries with server, user and tenant ids as strings
  # 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)
     ...do stuff with server_obj (read data from it, delete,...)...
  </code></pre>
  
  <p>What I've come up with is the following, but it's not right as I get a EndpointNotFound exception. I'm using Devstack with Juno.</p>
  
  <pre><code>from keystoneclient.v2_0 import client as keystone_client
  from keystoneclient import session
  from novaclient import client as nova_client
  
  #the url is the admin endpoint
  keystone = keystone_client.Client(token="my-admin-token",
              auth_url="http://192.168.1.1:35357/v2.0",
              endpoint="http://192.168.1.1:35357/v2.0")
  
  key_session = session.Session(auth=keystone)
  nova = nova_client.Client(2, session=key_session)
  
  #let's assume the servers array is already populated
  for server in servers:
      server_obj = nova.servers.get(server.server_id) #Exception happens here
  </code></pre>
  
  <p>I need to run this as admin as servers can belong to any tenant and they might even be deleted by the cron job.</p>
  
  <p>Thanks for any help!</p>
  
  <p><strong>UPDATE:</strong>
  The information I need was that I can use the admin tenant for retrieving all servers (regardless of their owner). This allows me also to use the publicURL.</p>
  
  <p>My current solution looks like this:</p>
  
  <pre><code>from keystoneclient.auth.identity import v2
  from keystoneclient import session
  from novaclient import client as nova_client
  
  auth = v2.Password(auth_url="http://192.168.1.1:5000/v2.0",
                     username="admin",
                     password="my_secrete",
                     tenant_name="admin") # the admin's tenant
  
  auth_session = session.Session(auth=auth)
  nova = nova_client.Client(2, session=auth_session)
  
  for server in servers:
      ... do stuff like nova.servers.get("some id")
  </code></pre>