Commit b41ecb71 authored by Simon Leinen's avatar Simon Leinen

Merge branch 'with_auth_session'

parents 8f286999 4653960a
......@@ -33,4 +33,5 @@ nosetests.xml
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
\ No newline at end of file
.pydevproject
/.idea/
......@@ -30,10 +30,10 @@ import os
import re
import sys
import warnings
from keystoneclient.v2_0 import client
from keystoneclient.v2_0 import client as keystone_client
from keystoneclient.auth.identity import v2
from keystoneclient import session
from novaclient.client import Client
from novaclient.v2 import client as nova_client
from novaclient.exceptions import BadRequest, NotFound
class UsageAnalyzer:
......@@ -51,10 +51,13 @@ class UsageAnalyzer:
self.password = password
self.tenant_name = tenant_name
self.auth_url = auth_url
self.keystone = client.Client(username=self.username,
password=self.password,
tenant_name=self.tenant_name,
auth_url=self.auth_url)
auth = v2.Password(auth_url=self.auth_url,
username=self.username,
password=self.password,
tenant_name=self.tenant_name)
self.auth_session = session.Session(auth=auth)
self.keystone = keystone_client.Client(session=self.auth_session)
self.usage_per_tenant = dict()
self.tenants = None
......@@ -79,19 +82,10 @@ class UsageAnalyzer:
ne = dict()
for region in self.get_regions():
try:
ne[region] = Client(3,
self.username, self.password,
self.tenant_name, self.auth_url,
service_type="compute",
region_name=region,
##
## This is problematic because our PKI
## tokens are too long for the default
## HTTP header size limitation in
## keystone (8192 bytes):
##
auth_token=self.keystone.auth_token
)
ne[region] = nova_client.Client(session=self.auth_session,
service_type='compute',
region_name=region)
##
## In order to check whether this works, we need to
## actually try to run an arbitrary operation using
......@@ -100,7 +94,8 @@ class UsageAnalyzer:
##
ne[region].flavors.list()
except BadRequest as c:
ne[region] = Client(3,
print "WARN:", c
ne[region] = nova_client.Client(
self.username, self.password,
self.tenant_name, self.auth_url,
service_type="compute",
......@@ -155,6 +150,7 @@ class UsageAnalyzer:
fine_grained = self.fine_grained
if tenant.description is not None:
m = self.cc_re.match(tenant.description)
print "XXX:tenant.description:", tenant.description
if m:
cc_name = m.group(1)
return self.cc_name_from_tenant_1(tenant, cc_name, fine_grained=fine_grained)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment