Advertisement
Guest User

Untitled

a guest
Mar 18th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. from keystoneclient.auth.identity import v3
  2. from keystoneclient import session
  3. from keystoneclient.v3 import client
  4.  
  5. from os import environ
  6. from subprocess import Popen, PIPE, call, check_output, check_call
  7.  
  8. #interactive-fu
  9. import rlcompleter, readline
  10. readline.parse_and_bind('tab: complete')
  11.  
  12. debug=True
  13. os_auth_file='/etc/openrcV3' #where to find authentication bits
  14.  
  15. def source(script, update=True, clean=True):
  16.     """
  17.    Source variables from a shell script
  18.    import them in the environment (if update==True)
  19.    and report only the script variables (if clean==True)
  20.    """
  21.  
  22.     global environ
  23.     if clean:
  24.         environ_back = dict(environ)
  25.         environ.clear()
  26.  
  27.         pipe = Popen(". %s; env" % script, stdout=PIPE, shell=True)
  28.         data = pipe.communicate()[0]
  29.  
  30.         env = dict((line.split("=", 1) for line in data.splitlines()))
  31.  
  32.     if clean:
  33.         # remove unwanted minimal vars
  34.         env.pop('LINES', None)
  35.         env.pop('COLUMNS', None)
  36.         environ = dict(environ_back)
  37.  
  38.     if update:
  39.         environ.update(env)
  40.  
  41.     return env
  42.  
  43. os_auth = source(os_auth_file)
  44.  
  45.  
  46. auth = v3.Password(auth_url=os_auth['OS_AUTH_URL'],
  47.                    username=os_auth['OS_USERNAME'],
  48.                    password=os_auth['OS_PASSWORD'],
  49.                    project_domain_name='default',user_domain_name='default',
  50.                    project_name=os_auth['OS_TENANT_NAME'])
  51. sess = session.Session(auth=auth)
  52.  
  53. keystone = client.Client(session=sess)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement