Commit 4653960a authored by Valéry Tschopp's avatar Valéry Tschopp

uses keystone auth session

parent ea8894b9
......@@ -28,10 +28,10 @@
import os
import re
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
import sys
......@@ -50,10 +50,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
......@@ -78,19 +81,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, we need to actually
## try to run an arbitrary operation using the
......@@ -99,7 +93,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",
......@@ -151,6 +146,7 @@ class UsageAnalyzer:
def cost_center_name_from_tenant(self, tenant, fine_grained=None):
if fine_grained is None:
fine_grained = self.fine_grained
print "XXX:tenant.description:", tenant.description
m = self.cc_re.match(tenant.description)
if m:
cc_name = m.group(1)
......
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