Skip to content

Instantly share code, notes, and snippets.

@jamielennox
Created November 6, 2013 08:23
Show Gist options
  • Save jamielennox/7332679 to your computer and use it in GitHub Desktop.
Save jamielennox/7332679 to your computer and use it in GitHub Desktop.
import keystoneclient
import novaclient
# Simple
auth = keystoneclient.PasswordAuth(username='jamie', password='cool')
s = keystoneclient.Session(cacert='ca.pem', cert='client.pem', key='key.pem',
auth=auth)
# will send an authenticated request to a full url
s.get("http://127.0.0.1:35357/v3/users")
# using the service catalog
s.get('/v3/users', service='identity', region='local')
another_client = keystoneclient.Client(session=s, region='local')
# exactly the same as the above get
another_client.get('/v3/users')
# i don't need the client cert for nova so i need to create a new session obj
# this is already authenticated and has the token and service catalog
s2 = keystoneclient.Session(auth=auth)
n = novaclient.Client(session=s)
# Unauthenticated
s.get('/v2.0', authenticated=False, service='identity')
unauthed = keystoneclient.Session(cert='client.pem') # no auth
unauthed.get('http://www.google.com')
unauthed_client = myserviceclient.Session() # no auth
unauthed_client.get('http://www.google.com')
# advanced topics:
# trusts and scoping
s.rescope(roles=['roleA'], save_as='only_A')
# maintaining limited auth for trusts and scope
s.get('http://127.0.0.1:35357/v3/users', connection='only_A')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment