commit 8814e07cd3ff588498abd75e6b801205ed21a645
Author: Christos Stavrakakis <cstavr@grnet.gr>
Date:   Thu Feb 14 17:58:54 2013 +0200

    Fixes relave to --uuids option

diff --git a/snf-cyclades-app/synnefo/api/management/commands/network-list.py b/snf-cyclades-app/synnefo/api/management/commands/network-list.py
index f9f42ce..d7442aa 100644
--- a/snf-cyclades-app/synnefo/api/management/commands/network-list.py
+++ b/snf-cyclades-app/synnefo/api/management/commands/network-list.py
@@ -71,7 +71,8 @@ class Command(BaseCommand):
                  " that displayed entries must satisfy. e.g."
                  " --filter-by \"name=Network-1,link!=prv0\"."
                  " Available keys are: %s" % ", ".join(FIELDS)),
-        make_option('--uuids',
+        make_option(
+            '--uuids',
             action='store_true',
             dest='use_uuids',
             default=False,
@@ -82,6 +83,7 @@ class Command(BaseCommand):
         if args:
             raise CommandError("Command doesn't accept any arguments")
 
+        use_uuids = options["use_uuids"]
         if options['deleted']:
             networks = Network.objects.all()
         else:
@@ -102,13 +104,13 @@ class Command(BaseCommand):
         else:
             headers.extend(['IPv4 Subnet', 'IPv4 Gateway'])
 
-        if options['use_uuids'] is False:
+        if not use_uuids:
             ucache = UUIDCache()
 
         table = []
         for network in networks.order_by("id"):
             user = network.userid
-            if options['use_uuids'] is False:
+            if not use_uuids:
                 user = ucache.get_user(network.userid)
 
             fields = [str(network.id),
diff --git a/snf-cyclades-app/synnefo/api/management/commands/server-list.py b/snf-cyclades-app/synnefo/api/management/commands/server-list.py
index 49fad82..f2ccd8b 100644
--- a/snf-cyclades-app/synnefo/api/management/commands/server-list.py
+++ b/snf-cyclades-app/synnefo/api/management/commands/server-list.py
@@ -76,17 +76,19 @@ class Command(BaseCommand):
                  " that displayed entries must satisfy. e.g."
                  " --filter-by \"operstate=STARTED,id>=22\"."
                  " Available keys are: %s" % ", ".join(FIELDS)),
-        make_option('--uuids',
+        make_option(
+            '--uuids',
             action='store_true',
             dest='use_uuids',
             default=False,
             help="Display UUIDs instead of user emails"),
-        )
+    )
 
     def handle(self, *args, **options):
         if args:
             raise CommandError("Command doesn't accept any arguments")
 
+        use_uuids = options["use_uuids"]
         if options['backend_id']:
             backend = get_backend(options['backend_id'])
             servers = backend.virtual_machines
@@ -109,7 +111,7 @@ class Command(BaseCommand):
             servers = filter_results(servers, filter_by)
 
         cache = ImageCache()
-        if options['use_uuids'] is False:
+        if not use_uuids:
             ucache = UUIDCache()
 
         headers = ('id', 'name', 'owner', 'flavor', 'image', 'state',
@@ -132,7 +134,7 @@ class Command(BaseCommand):
             state = format_vm_state(server)
 
             user = server.userid
-            if options['use_uuids'] is False:
+            if not use_uuids:
                 user = ucache.get_user(server.userid)
 
             fields = (str(server.id), name, user, flavor, image,
diff --git a/snf-cyclades-app/synnefo/api/management/commands/server-show.py b/snf-cyclades-app/synnefo/api/management/commands/server-show.py
index 6791971..905a0a5 100644
--- a/snf-cyclades-app/synnefo/api/management/commands/server-show.py
+++ b/snf-cyclades-app/synnefo/api/management/commands/server-show.py
@@ -34,7 +34,7 @@
 from django.core.management.base import BaseCommand, CommandError
 from synnefo.management.common import (format_bool, format_date,
                                        format_vm_state, get_vm,
-                                       get_image)
+                                       get_image, UUIDCache)
 
 
 class Command(BaseCommand):
@@ -60,7 +60,8 @@ class Command(BaseCommand):
         kv = {
             'id': server.id,
             'name': server.name,
-            'owner': userid,
+            'owner_uuid': userid,
+            'owner_name': UUIDCache().get_user(userid),
             'created': format_date(server.created),
             'updated': format_date(server.updated),
             'image': image,
diff --git a/snf-cyclades-app/synnefo/management/common.py b/snf-cyclades-app/synnefo/management/common.py
index 44b69d9..0936908 100644
--- a/snf-cyclades-app/synnefo/management/common.py
+++ b/snf-cyclades-app/synnefo/management/common.py
@@ -44,11 +44,15 @@ from synnefo.api.faults import ItemNotFound
 from django.core.exceptions import FieldError
 
 from synnefo.api.util import validate_network_size
-from synnefo.settings import (MAX_CIDR_BLOCK, CYCLADES_ASTAKOS_SERVICE_TOKEN,
-                              ASTAKOS_URL)
+from synnefo.settings import (MAX_CIDR_BLOCK,
+                              CYCLADES_ASTAKOS_SERVICE_TOKEN as ASTAKOS_TOKEN,
+                              CYCLADES_USER_CATALOG_URL)
 from synnefo.logic.rapi import GanetiApiError, GanetiRapiClient
 from synnefo.lib import astakos
 
+import logging
+log = logging.getLogger(__name__)
+
 
 def format_bool(b):
     return 'YES' if b else 'NO'
@@ -263,26 +267,22 @@ def pprint_table(out, table, headers=None, separator=None):
 
 
 class UUIDCache(object):
-    """UUUID-to-email cache
-
-    """
-
-    astakos_url = ASTAKOS_URL.replace("im/authenticate",
-                                      "service/api/user_catalogs")
+    """UUID-to-email cache"""
 
     def __init__(self):
         self.users = {}
 
     def get_user(self, uuid):
-        """Do the uuid-to-email resolving
-        """
+        """Do the uuid-to-email resolving"""
 
         if not uuid in self.users:
             try:
-                self.users[uuid] = \
-                astakos.get_displayname(token=CYCLADES_ASTAKOS_SERVICE_TOKEN,
-                                        url=UUIDCache.astakos_url, uuid=uuid)
-            except Exception:
+                self.users[uuid] =\
+                    astakos.get_displayname(token=ASTAKOS_TOKEN,
+                                            url=CYCLADES_USER_CATALOG_URL,
+                                            uuid=uuid)
+            except Exception as e:
+                log.error("Can not get display name for uuid %s: %s", uuid, e)
                 return uuid
 
         return self.users[uuid]
