Projet

Général

Profil

Révision 775bf842

ID775bf84215b2a768f16d9c9ae2ac3702b7cd75db
Parent 017ad1f8
Enfant 0930bf58

Ajouté par Mehdi Abaakouk il y a plus de 13 ans

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

Voir les différences:

plugins/glance/glance_size_
10 10
#   [glance_*]
11 11
#   user glance
12 12
#
13
# To show tenant name plugin must run as root
14
#
13 15
# Magic markers
14 16
#%# capabilities=autoconf suggest
15 17
#%# family=auto
16 18

  
17

  
18 19
import sys
19 20
import os
20 21

  
21 22
try: 
22
    from sqlalchemy.orm import exc, joinedload
23
    from sqlalchemy.orm import joinedload
24
    import sqlalchemy.exc
23 25
    
24 26
    from glance.common.cfg import CommonConfigOpts
25 27
    from glance.registry.db import models
26 28
    from glance.registry.db.api import get_session, configure_db
29

  
30
    from keystone.common import utils
31
    from keystone import config
32
    from keystone import exception
33
    from keystone import identity
34

  
27 35
except ImportError:
28 36
    succesful_import = False
29 37
else:
30 38
    succesful_import = True
31 39

  
32 40

  
41
def get_name_from_tenant(tenant):
42
    try:
43
        KEYSTONE_CONF = config.CONF(config_files=[utils.find_config('keystone.conf')])
44
    except:
45
        # keystone configuration can not be loaded, use id as name"
46
        return tenant
47

  
48
    identity_api = identity.Manager()
49

  
50
    try:
51
        tenant_info = identity_api.get_tenant(None, tenant)
52
    except sqlalchemy.exc.OperationalError:
53
        # keystone database can not be connected, use id as name"
54
        return tenant
55

  
56
    if not tenant_info: 
57
        return tenant
58
    else:
59
        return tenant_info["name"]
60

  
61
    
33 62
def load_conf():
34 63
    CONF = CommonConfigOpts(project="glance", prog="glance-registry")
35 64
    CONF()
......
41 70

  
42 71

  
43 72
def print_config(tenant):
44
    print 'graph_title Glance used size for tenant %s' % tenant
73
    if tenant == "Global":
74
        print 'graph_title Glance used size for all tenants'
75
        print 'graph_info This graph shows the used size in glance for all tenants'
76
    else:
77
        print 'graph_title Glance used size for tenant %s' % get_name_from_tenant(tenant)
78
        print 'graph_info This graph shows the used size in glance for tenant %s' % tenant
45 79
    print 'graph_vlabel Bytes'
46 80
    print 'graph_args --base 1024 --lower-limit 0'
47 81
    print 'graph_category glance'
48
    print 'graph_info This graph shows the used size in glance for tenant %s' % tenant
49
    print '%s.label %s' % (tenant, tenant)
82
    print '%s.label %s' % (tenant, get_name_from_tenant(tenant))
50 83
    print '%s.draw LINE2' % tenant
51 84
    print '%s.info %s MBytes' % (tenant, tenant)
52 85

  

Formats disponibles : Unified diff