Last active
August 29, 2015 14:23
-
-
Save sivel/f7c7e1112a287a4f946f to your computer and use it in GitHub Desktop.
python-openstacksdk Rackspace API Key Authenticator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from openstack.auth.identity.v2 import Password | |
| class ApiKey(Password): | |
| valid_options = { | |
| 'access_info', | |
| 'auth_url', | |
| 'username', | |
| 'user_id', | |
| 'password', | |
| 'project_id', | |
| 'project_name', | |
| 'tenant_name', | |
| 'tenant_id', | |
| 'reauthenticate', | |
| 'trust_id', | |
| 'api_key', | |
| } | |
| def __init__(self, *args, **kwargs): | |
| api_key = kwargs.pop('api_key') | |
| super(ApiKey, self).__init__(*args, **kwargs) | |
| self.api_key = api_key or password | |
| def get_auth_data(self, headers=None): | |
| return { | |
| 'RAX-KSKEY:apiKeyCredentials': { | |
| 'username': '%s' % self.username, | |
| 'apiKey': '%s' % self.api_key | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import os | |
| import raxauth | |
| from openstack.profile import Profile | |
| from openstack.connection import Connection | |
| profile = Profile() | |
| profile.set_version('identity', 'v2') | |
| profile.set_region(profile.ALL, 'IAD') | |
| authenticator = raxauth.ApiKey(os.getenv('OS_AUTH_URL'), | |
| tenant_id=os.getenv('OS_TENANT_ID'), | |
| username=os.getenv('OS_USERNAME'), | |
| api_key=os.getenv('OS_PASSWORD')) | |
| conn = Connection(authenticator=authenticator, profile=profile) | |
| print len(list(conn.compute.servers())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment