Permalink
Browse files

Allow possibility to show tenant name instead of tenant id in graph

  • Loading branch information...
1 parent 017ad1f commit 775bf84215b2a768f16d9c9ae2ac3702b7cd75db @sileht sileht committed May 22, 2012
Showing with 38 additions and 5 deletions.
  1. +38 −5 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)

0 comments on commit 775bf84

Please sign in to comment.