Revision 8814e07c

b/snf-cyclades-app/synnefo/api/management/commands/network-list.py
71 71
                 " that displayed entries must satisfy. e.g."
72 72
                 " --filter-by \"name=Network-1,link!=prv0\"."
73 73
                 " Available keys are: %s" % ", ".join(FIELDS)),
74
        make_option('--uuids',
74
        make_option(
75
            '--uuids',
75 76
            action='store_true',
76 77
            dest='use_uuids',
77 78
            default=False,
......
82 83
        if args:
83 84
            raise CommandError("Command doesn't accept any arguments")
84 85

  
86
        use_uuids = options["use_uuids"]
85 87
        if options['deleted']:
86 88
            networks = Network.objects.all()
87 89
        else:
......
102 104
        else:
103 105
            headers.extend(['IPv4 Subnet', 'IPv4 Gateway'])
104 106

  
105
        if options['use_uuids'] is False:
107
        if not use_uuids:
106 108
            ucache = UUIDCache()
107 109

  
108 110
        table = []
109 111
        for network in networks.order_by("id"):
110 112
            user = network.userid
111
            if options['use_uuids'] is False:
113
            if not use_uuids:
112 114
                user = ucache.get_user(network.userid)
113 115

  
114 116
            fields = [str(network.id),
b/snf-cyclades-app/synnefo/api/management/commands/server-list.py
76 76
                 " that displayed entries must satisfy. e.g."
77 77
                 " --filter-by \"operstate=STARTED,id>=22\"."
78 78
                 " Available keys are: %s" % ", ".join(FIELDS)),
79
        make_option('--uuids',
79
        make_option(
80
            '--uuids',
80 81
            action='store_true',
81 82
            dest='use_uuids',
82 83
            default=False,
83 84
            help="Display UUIDs instead of user emails"),
84
        )
85
    )
85 86

  
86 87
    def handle(self, *args, **options):
87 88
        if args:
88 89
            raise CommandError("Command doesn't accept any arguments")
89 90

  
91
        use_uuids = options["use_uuids"]
90 92
        if options['backend_id']:
91 93
            backend = get_backend(options['backend_id'])
92 94
            servers = backend.virtual_machines
......
109 111
            servers = filter_results(servers, filter_by)
110 112

  
111 113
        cache = ImageCache()
112
        if options['use_uuids'] is False:
114
        if not use_uuids:
113 115
            ucache = UUIDCache()
114 116

  
115 117
        headers = ('id', 'name', 'owner', 'flavor', 'image', 'state',
......
132 134
            state = format_vm_state(server)
133 135

  
134 136
            user = server.userid
135
            if options['use_uuids'] is False:
137
            if not use_uuids:
136 138
                user = ucache.get_user(server.userid)
137 139

  
138 140
            fields = (str(server.id), name, user, flavor, image,
b/snf-cyclades-app/synnefo/api/management/commands/server-show.py
34 34
from django.core.management.base import BaseCommand, CommandError
35 35
from synnefo.management.common import (format_bool, format_date,
36 36
                                       format_vm_state, get_vm,
37
                                       get_image)
37
                                       get_image, UUIDCache)
38 38

  
39 39

  
40 40
class Command(BaseCommand):
......
60 60
        kv = {
61 61
            'id': server.id,
62 62
            'name': server.name,
63
            'owner': userid,
63
            'owner_uuid': userid,
64
            'owner_name': UUIDCache().get_user(userid),
64 65
            'created': format_date(server.created),
65 66
            'updated': format_date(server.updated),
66 67
            'image': image,
b/snf-cyclades-app/synnefo/management/common.py
44 44
from django.core.exceptions import FieldError
45 45

  
46 46
from synnefo.api.util import validate_network_size
47
from synnefo.settings import (MAX_CIDR_BLOCK, CYCLADES_ASTAKOS_SERVICE_TOKEN,
48
                              ASTAKOS_URL)
47
from synnefo.settings import (MAX_CIDR_BLOCK,
48
                              CYCLADES_ASTAKOS_SERVICE_TOKEN as ASTAKOS_TOKEN,
49
                              CYCLADES_USER_CATALOG_URL)
49 50
from synnefo.logic.rapi import GanetiApiError, GanetiRapiClient
50 51
from synnefo.lib import astakos
51 52

  
53
import logging
54
log = logging.getLogger(__name__)
55

  
52 56

  
53 57
def format_bool(b):
54 58
    return 'YES' if b else 'NO'
......
263 267

  
264 268

  
265 269
class UUIDCache(object):
266
    """UUUID-to-email cache
267

  
268
    """
269

  
270
    astakos_url = ASTAKOS_URL.replace("im/authenticate",
271
                                      "service/api/user_catalogs")
270
    """UUID-to-email cache"""
272 271

  
273 272
    def __init__(self):
274 273
        self.users = {}
275 274

  
276 275
    def get_user(self, uuid):
277
        """Do the uuid-to-email resolving
278
        """
276
        """Do the uuid-to-email resolving"""
279 277

  
280 278
        if not uuid in self.users:
281 279
            try:
282
                self.users[uuid] = \
283
                astakos.get_displayname(token=CYCLADES_ASTAKOS_SERVICE_TOKEN,
284
                                        url=UUIDCache.astakos_url, uuid=uuid)
285
            except Exception:
280
                self.users[uuid] =\
281
                    astakos.get_displayname(token=ASTAKOS_TOKEN,
282
                                            url=CYCLADES_USER_CATALOG_URL,
283
                                            uuid=uuid)
284
            except Exception as e:
285
                log.error("Can not get display name for uuid %s: %s", uuid, e)
286 286
                return uuid
287 287

  
288 288
        return self.users[uuid]

Also available in: Unified diff