Revision d5a4a8d1 snf-cyclades-app/synnefo/logic/management/commands/pool-show.py
b/snf-cyclades-app/synnefo/logic/management/commands/pool-show.py | ||
---|---|---|
34 | 34 |
from django.core.management.base import BaseCommand, CommandError |
35 | 35 |
from optparse import make_option |
36 | 36 |
|
37 |
from util import pool_table_from_type, pool_map_chunks |
|
38 | 37 |
from synnefo.db.pools import bitarray_to_map |
38 |
from synnefo.db.models import MacPrefixPoolTable, BridgePoolTable |
|
39 |
from synnefo.management import pprint |
|
39 | 40 |
|
40 | 41 |
POOL_CHOICES = ['bridge', 'mac-prefix'] |
41 | 42 |
|
... | ... | |
81 | 82 |
self.stdout.write(line.encode('utf8')) |
82 | 83 |
|
83 | 84 |
step = (type_ == 'bridge') and 64 or 80 |
84 |
print_map('Pool', pool.to_map(), step, self.stdout) |
|
85 |
print_map('Reserved', bitarray_to_map(pool.reserved[:pool_row.size]), |
|
86 |
step, self.stdout) |
|
85 |
pprint.pprint_pool('Available', pool.to_map(), step, self.stdout) |
|
86 |
pprint.pprint_pool('Reserved', |
|
87 |
bitarray_to_map(pool.reserved[:pool_row.size]), |
|
88 |
step, self.stdout) |
|
87 | 89 |
|
88 | 90 |
|
89 |
def print_map(name, pool_map, step, out): |
|
90 |
sep = '*' * 80 |
|
91 |
out.write(sep + "\n") |
|
92 |
out.write("%s: \n" % name) |
|
93 |
out.write(sep + "\n") |
|
94 |
count = 0 |
|
95 |
for chunk in pool_map_chunks(pool_map, step): |
|
96 |
chunk_len = len(chunk) |
|
97 |
out.write(("%s " % count).rjust(4)) |
|
98 |
out.write((chunk + " %d\n") % (count + chunk_len - 1)) |
|
99 |
count += chunk_len |
|
91 |
def pool_table_from_type(type_): |
|
92 |
if type_ == "mac-prefix": |
|
93 |
return MacPrefixPoolTable |
|
94 |
elif type_ == "bridge": |
|
95 |
return BridgePoolTable |
|
96 |
# elif type == "ip": |
|
97 |
# return IPPoolTable |
|
98 |
else: |
|
99 |
raise ValueError("Invalid pool type") |
Also available in: Unified diff