support for project id header
This commit is contained in:
parent
117e455bb6
commit
0853ebebed
novaclient
@ -61,10 +61,10 @@ class OpenStack(object):
|
||||
&c.
|
||||
"""
|
||||
|
||||
def __init__(self, username, apikey,
|
||||
def __init__(self, username, apikey, projectid
|
||||
auth_url='https://auth.api.rackspacecloud.com/v1.0'):
|
||||
self.backup_schedules = BackupScheduleManager(self)
|
||||
self.client = OpenStackClient(username, apikey, auth_url)
|
||||
self.client = OpenStackClient(username, apikey, projectid, auth_url)
|
||||
self.flavors = FlavorManager(self)
|
||||
self.images = ImageManager(self)
|
||||
self.ipgroups = IPGroupManager(self)
|
||||
|
@ -28,10 +28,11 @@ class OpenStackClient(httplib2.Http):
|
||||
|
||||
USER_AGENT = 'python-novaclient/%s' % novaclient.__version__
|
||||
|
||||
def __init__(self, user, apikey, auth_url):
|
||||
def __init__(self, user, apikey, projectid auth_url):
|
||||
super(OpenStackClient, self).__init__()
|
||||
self.user = user
|
||||
self.apikey = apikey
|
||||
self.projectid = projectid
|
||||
self.auth_url = auth_url
|
||||
|
||||
self.management_url = None
|
||||
@ -90,6 +91,8 @@ class OpenStackClient(httplib2.Http):
|
||||
# re-authenticate and try again. If it still fails, bail.
|
||||
try:
|
||||
kwargs.setdefault('headers', {})['X-Auth-Token'] = self.auth_token
|
||||
kwargs['headers']['X-Auth-Project-Id'] = self.projectid
|
||||
|
||||
resp, body = self.request(self.management_url + url, method,
|
||||
**kwargs)
|
||||
return resp, body
|
||||
@ -116,7 +119,7 @@ class OpenStackClient(httplib2.Http):
|
||||
return self._cs_request(url, 'DELETE', **kwargs)
|
||||
|
||||
def authenticate(self):
|
||||
headers = {'X-Auth-User': self.user, 'X-Auth-Key': self.apikey}
|
||||
headers = {'X-Auth-User': self.user, 'X-Auth-Key': self.apikey, 'X-Auth-Project-Id': self. projectid}
|
||||
resp, body = self.request(self.auth_url, 'GET', headers=headers)
|
||||
self.management_url = resp['x-server-management-url']
|
||||
self.auth_token = resp['x-auth-token']
|
||||
|
@ -96,6 +96,10 @@ class OpenStackShell(object):
|
||||
default=env('NOVA_API_KEY'),
|
||||
help='Defaults to env[NOVA_API_KEY].')
|
||||
|
||||
self.parser.add_argument('--projectid',
|
||||
default=env('NOVA_PROJECT_ID'),
|
||||
help='Defaults to env[NOVA_PROJECT_ID].')
|
||||
|
||||
auth_url = env('NOVA_URL')
|
||||
if auth_url == '':
|
||||
auth_url = 'https://auth.api.rackspacecloud.com/v1.0'
|
||||
@ -144,7 +148,9 @@ class OpenStackShell(object):
|
||||
if args.debug:
|
||||
httplib2.debuglevel = 1
|
||||
|
||||
user, apikey, url = args.username, args.apikey, args.url
|
||||
user, apikey, projectid, url = args.username, args.apikey, args.projectid, args.url
|
||||
#FIXME(usrleon): Here should be restrict for project id same as for username or apikey
|
||||
# but for compatibility it is not.
|
||||
if not user:
|
||||
raise CommandError("You must provide a username, either via "
|
||||
"--username or via env[NOVA_USERNAME]")
|
||||
@ -152,7 +158,7 @@ class OpenStackShell(object):
|
||||
raise CommandError("You must provide an API key, either via "
|
||||
"--apikey or via env[NOVA_API_KEY]")
|
||||
|
||||
self.cs = self._api_class(user, apikey, url)
|
||||
self.cs = self._api_class(user, apikey, projectid, url)
|
||||
try:
|
||||
self.cs.authenticate()
|
||||
except novaclient.Unauthorized:
|
||||
|
Loading…
x
Reference in New Issue
Block a user