Revision 90b67503
b/snf-cyclades-app/synnefo/api/management/commands/flavor-list.py | ||
---|---|---|
42 | 42 |
|
43 | 43 |
class Command(BaseCommand): |
44 | 44 |
help = "List flavors" |
45 |
|
|
45 |
|
|
46 | 46 |
option_list = BaseCommand.option_list + ( |
47 | 47 |
make_option('-c', |
48 | 48 |
action='store_true', |
... | ... | |
50 | 50 |
default=False, |
51 | 51 |
help="Use pipes to separate values"), |
52 | 52 |
) |
53 |
|
|
53 |
|
|
54 | 54 |
def handle(self, *args, **options): |
55 | 55 |
if args: |
56 | 56 |
raise CommandError("Command doesn't accept any arguments") |
57 |
|
|
57 |
|
|
58 | 58 |
labels = ('id', 'name', 'cpus', 'ram', 'disk', 'template', 'deleted') |
59 | 59 |
columns = (3, 12, 6, 6, 6, 10, 7) |
60 |
|
|
60 |
|
|
61 | 61 |
if not options['csv']: |
62 | 62 |
line = ' '.join(l.rjust(w) for l, w in zip(labels, columns)) |
63 | 63 |
self.stdout.write(line + '\n') |
64 | 64 |
sep = '-' * len(line) |
65 | 65 |
self.stdout.write(sep + '\n') |
66 |
|
|
67 |
for flavor in Flavor.objects.all(): |
|
66 |
|
|
67 |
for flavor in Flavor.objects.all().order_by('id'):
|
|
68 | 68 |
id = str(flavor.id) |
69 | 69 |
cpu = str(flavor.cpu) |
70 | 70 |
ram = str(flavor.ram) |
... | ... | |
72 | 72 |
deleted = format_bool(flavor.deleted) |
73 | 73 |
fields = (id, flavor.name, cpu, ram, disk, flavor.disk_template, |
74 | 74 |
deleted) |
75 |
|
|
75 |
|
|
76 | 76 |
if options['csv']: |
77 | 77 |
line = '|'.join(fields) |
78 | 78 |
else: |
79 | 79 |
line = ' '.join(f.rjust(w) for f, w in zip(fields, columns)) |
80 |
|
|
80 |
|
|
81 | 81 |
self.stdout.write(line.encode('utf8') + '\n') |
b/snf-cyclades-app/synnefo/api/management/commands/network-list.py | ||
---|---|---|
96 | 96 |
sep = '-' * len(line) |
97 | 97 |
self.stdout.write(sep + '\n') |
98 | 98 |
|
99 |
for network in networks: |
|
99 |
for network in networks.order_by("id"):
|
|
100 | 100 |
fields = [str(network.id), |
101 | 101 |
network.name, |
102 | 102 |
network.type, |
b/snf-cyclades-app/synnefo/api/management/commands/server-list.py | ||
---|---|---|
41 | 41 |
|
42 | 42 |
class Command(BaseCommand): |
43 | 43 |
help = "List servers" |
44 |
|
|
44 |
|
|
45 | 45 |
option_list = BaseCommand.option_list + ( |
46 | 46 |
make_option('-c', |
47 | 47 |
action='store_true', |
... | ... | |
59 | 59 |
make_option('--backend_id', dest='backend_id', |
60 | 60 |
help="List only servers of the specified backend") |
61 | 61 |
) |
62 |
|
|
62 |
|
|
63 | 63 |
def handle(self, *args, **options): |
64 | 64 |
if args: |
65 | 65 |
raise CommandError("Command doesn't accept any arguments") |
66 | 66 |
|
67 | 67 |
if options['backend_id']: |
68 |
servers = \ |
|
69 |
Backend.objects.get(id=options['backend_id']).virtual_machines |
|
68 |
try: |
|
69 |
servers = Backend.objects.get(id=options['backend_id'])\ |
|
70 |
.virtual_machines |
|
71 |
except Backend.DoesNotExist: |
|
72 |
raise CommandError("Backend not found in DB") |
|
70 | 73 |
else: |
71 | 74 |
servers = VirtualMachine.objects |
72 | 75 |
|
... | ... | |
77 | 80 |
|
78 | 81 |
if options['build']: |
79 | 82 |
servers = servers.filter(operstate='BUILD') |
80 |
|
|
83 |
|
|
81 | 84 |
labels = ('id', 'name', 'owner', 'flavor', 'image', 'state', |
82 | 85 |
'backend') |
83 | 86 |
columns = (3, 12, 20, 11, 12, 9, 40) |
84 |
|
|
87 |
|
|
85 | 88 |
if not options['csv']: |
86 | 89 |
line = ' '.join(l.rjust(w) for l, w in zip(labels, columns)) |
87 | 90 |
self.stdout.write(line + '\n') |
88 | 91 |
sep = '-' * len(line) |
89 | 92 |
self.stdout.write(sep + '\n') |
90 |
|
|
91 |
for server in servers: |
|
93 |
|
|
94 |
for server in servers.order_by('id'):
|
|
92 | 95 |
id = str(server.id) |
93 | 96 |
try: |
94 | 97 |
name = server.name.decode('utf8') |
... | ... | |
101 | 104 |
image = server.imageid |
102 | 105 |
fields = (id, name, server.userid, flavor, image, server.operstate, |
103 | 106 |
str(server.backend)) |
104 |
|
|
107 |
|
|
105 | 108 |
if options['csv']: |
106 | 109 |
line = '|'.join(fields) |
107 | 110 |
else: |
108 | 111 |
line = ' '.join(f.rjust(w) for f, w in zip(fields, columns)) |
109 |
|
|
112 |
|
|
110 | 113 |
self.stdout.write(line.encode('utf8') + '\n') |
Also available in: Unified diff