From 017ad1f8bb7f1c38ff87a8d34e4e21557f1c5cf2 Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Tue, 22 May 2012 11:19:19 +0200 Subject: [PATCH 1/2] Fix import problem when keystone is not present --- plugins/keystone/keystone_stats | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/plugins/keystone/keystone_stats b/plugins/keystone/keystone_stats index 13044043..e8dd1b79 100755 --- a/plugins/keystone/keystone_stats +++ b/plugins/keystone/keystone_stats @@ -23,12 +23,8 @@ except ImportError: else: succesful_import = True - -CONF = config.CONF - stats = ['users', 'tenants'] - def print_config(): global states print 'graph_title Keystone Stats' @@ -86,7 +82,7 @@ def print_values(): print "%s_%s.value %s" % (field, state, value) def load_conf(): - CONF(config_files=[utils.find_config('keystone.conf')]) + config.CONF(config_files=[utils.find_config('keystone.conf')]) if __name__ == '__main__': if len(sys.argv) > 1: From 775bf84215b2a768f16d9c9ae2ac3702b7cd75db Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Tue, 22 May 2012 11:20:49 +0200 Subject: [PATCH 2/2] Allow possibility to show tenant name instead of tenant id in graph --- plugins/glance/glance_size_ | 43 ++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/plugins/glance/glance_size_ b/plugins/glance/glance_size_ index b2dce0b6..469ed815 100755 --- a/plugins/glance/glance_size_ +++ b/plugins/glance/glance_size_ @@ -10,26 +10,55 @@ # [glance_*] # user glance # +# To show tenant name plugin must run as root +# # Magic markers #%# capabilities=autoconf suggest #%# family=auto - import sys import os try: - from sqlalchemy.orm import exc, joinedload + from sqlalchemy.orm import joinedload + import sqlalchemy.exc from glance.common.cfg import CommonConfigOpts from glance.registry.db import models from glance.registry.db.api import get_session, configure_db + + from keystone.common import utils + from keystone import config + from keystone import exception + from keystone import identity + except ImportError: succesful_import = False else: succesful_import = True +def get_name_from_tenant(tenant): + try: + KEYSTONE_CONF = config.CONF(config_files=[utils.find_config('keystone.conf')]) + except: + # keystone configuration can not be loaded, use id as name" + return tenant + + identity_api = identity.Manager() + + try: + tenant_info = identity_api.get_tenant(None, tenant) + except sqlalchemy.exc.OperationalError: + # keystone database can not be connected, use id as name" + return tenant + + if not tenant_info: + return tenant + else: + return tenant_info["name"] + + def load_conf(): CONF = CommonConfigOpts(project="glance", prog="glance-registry") CONF() @@ -41,12 +70,16 @@ def load_conf(): def print_config(tenant): - print 'graph_title Glance used size for tenant %s' % tenant + if tenant == "Global": + print 'graph_title Glance used size for all tenants' + print 'graph_info This graph shows the used size in glance for all tenants' + else: + print 'graph_title Glance used size for tenant %s' % get_name_from_tenant(tenant) + print 'graph_info This graph shows the used size in glance for tenant %s' % tenant print 'graph_vlabel Bytes' print 'graph_args --base 1024 --lower-limit 0' print 'graph_category glance' - print 'graph_info This graph shows the used size in glance for tenant %s' % tenant - print '%s.label %s' % (tenant, tenant) + print '%s.label %s' % (tenant, get_name_from_tenant(tenant)) print '%s.draw LINE2' % tenant print '%s.info %s MBytes' % (tenant, tenant)