Commit 330f8e66 authored by Stratos Psomadakis's avatar Stratos Psomadakis Committed by Christos Stavrakakis
Browse files

Add --uuids option to server-list

parent 412c270f
......@@ -35,7 +35,7 @@ from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from synnefo.management.common import (format_vm_state, get_backend,
filter_results, pprint_table)
filter_results, pprint_table, UUIDCache)
from synnefo.api.util import get_image
from synnefo.db.models import VirtualMachine
......@@ -75,7 +75,12 @@ class Command(BaseCommand):
help="Filter results. Comma seperated list of key `cond` val pairs"
" that displayed entries must satisfy. e.g."
" --filter-by \"operstate=STARTED,id>=22\"."
" Available keys are: %s" % ", ".join(FIELDS))
" Available keys are: %s" % ", ".join(FIELDS)),
make_option('--uuids',
action='store_true',
dest='use_uuids',
default=False,
help="Display UUIDs instead of user emails"),
)
def handle(self, *args, **options):
......@@ -104,6 +109,7 @@ class Command(BaseCommand):
servers = filter_results(servers, filter_by)
cache = ImageCache()
ucache = UUIDCache()
headers = ('id', 'name', 'owner', 'flavor', 'image', 'state',
'backend')
......@@ -124,7 +130,14 @@ class Command(BaseCommand):
state = format_vm_state(server)
fields = (str(server.id), name, server.userid, flavor, image,
user = server.userid
if not options['use_uuids']:
try:
user = ucache.get_user(server.userid)
except:
pass
fields = (str(server.id), name, user, flavor, image,
state, str(server.backend))
table.append(fields)
......
......@@ -44,8 +44,10 @@ 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
from synnefo.settings import (MAX_CIDR_BLOCK, CYCLADES_ASTAKOS_SERVICE_TOKEN,
ASTAKOS_URL)
from synnefo.logic.rapi import GanetiApiError, GanetiRapiClient
from synnefo.lib import astakos
def format_bool(b):
......@@ -61,7 +63,6 @@ def parse_bool(string):
raise Exception("Can not parse string %s to bool" % string)
def format_date(d):
if not d:
return ''
......@@ -259,3 +260,18 @@ def pprint_table(out, table, headers=None, separator=None):
for row in table:
print >> out, sep.join((val.rjust(width).encode('utf8') \
for val, width in zip(row, widths)))
class UUIDCache(object):
def __init__(self):
self.users = {}
def get_user(self, uuid):
if not uuid in self.users:
astakos_url = ASTAKOS_URL.replace("im/authenticate",
"service/api/user_catalogs")
self.users[uuid] = \
astakos.get_displayname(token=CYCLADES_ASTAKOS_SERVICE_TOKEN,
url=astakos_url, uuid=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