Revision 7a0aa449 snf-cyclades-app/synnefo/logic/management/commands/backend-list.py

b/snf-cyclades-app/synnefo/logic/management/commands/backend-list.py
33 33

  
34 34
from optparse import make_option
35 35
from django.core.management.base import BaseCommand, CommandError
36
from synnefo.management.common import pprint_table
36 37

  
37 38
from synnefo.db.models import Backend
38 39

  
......
54 55

  
55 56
        backends = Backend.objects.order_by('id')
56 57

  
57
        labels = ('id', 'clustername', 'port', 'username', "VMs", 'drained',
58
                  'offline')
59
        columns = (3, 50, 5, 10, 4, 6, 6)
60

  
61
        if not options['csv']:
62
            line = ' '.join(l.rjust(w) for l, w in zip(labels, columns))
63
            sep = '-' * len(line)
64
            self.stdout.write(sep + '\n')
65
            self.stdout.write(line + '\n')
66
            self.stdout.write(sep + '\n')
67

  
58
        headers = ('id', 'clustername', 'port', 'username', "VMs", 'drained',
59
                   'offline')
60
        table = []
68 61
        for backend in backends:
69 62
            id = str(backend.id)
70 63
            vms = str(backend.virtual_machines.filter(deleted=False).count())
71 64
            fields = (id, backend.clustername, str(backend.port),
72 65
                      backend.username, vms, str(backend.drained),
73 66
                      str(backend.offline))
67
            table.append(fields)
74 68

  
75
            if options['csv']:
76
                line = '|'.join(fields)
77
            else:
78
                line = ' '.join(f.rjust(w) for f, w in zip(fields, columns))
79

  
80
            self.stdout.write(line.encode('utf8') + '\n')
69
        separator = " | " if options['csv'] else None
70
        pprint_table(self.stdout, table, headers, separator)

Also available in: Unified diff