Commit 94be612c authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Fixes relave to --uuids option

parent f22773bc
......@@ -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),
......
......@@ -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,
......
......@@ -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,
......
......@@ -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]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment