Revision e4758367 snf-cyclades-app/synnefo/management/pprint.py
b/snf-cyclades-app/synnefo/management/pprint.py | ||
---|---|---|
38 | 38 |
from synnefo.settings import (CYCLADES_SERVICE_TOKEN as ASTAKOS_TOKEN, |
39 | 39 |
ASTAKOS_BASE_URL) |
40 | 40 |
from synnefo.db.models import Backend, pooled_rapi_client |
41 |
from synnefo.db.pools import bitarray_to_map |
|
42 |
|
|
41 | 43 |
from synnefo.logic.rapi import GanetiApiError |
42 | 44 |
from synnefo.logic.reconciliation import nics_from_instance |
43 | 45 |
from synnefo.management.common import get_image |
... | ... | |
124 | 126 |
raise e |
125 | 127 |
|
126 | 128 |
|
129 |
def pprint_subnet_in_db(subnet, stdout=None, title=None): |
|
130 |
if stdout is None: |
|
131 |
stdout = sys.stdout |
|
132 |
if title is None: |
|
133 |
title = "State of Subnet %s in DB" % subnet.id |
|
134 |
info = OrderedDict([("ID", subnet.id), |
|
135 |
("Network_ID", subnet.network.id), |
|
136 |
# If a user names his subnet "-", what happens then? |
|
137 |
("Name", "-" if subnet.name == "" else subnet.name), |
|
138 |
("IP_Version", subnet.ipversion), |
|
139 |
("CIDR", subnet.cidr), |
|
140 |
("Gateway", subnet.gateway), |
|
141 |
("DHCP/SLAAC", subnet.dhcp), |
|
142 |
("Host_Routes", subnet.host_routes), |
|
143 |
("DNS_Nameservers", subnet.dns_nameservers)]) |
|
144 |
pprint_table(stdout, info.items(), None, separator=" | ", title=title) |
|
145 |
|
|
146 |
|
|
147 |
def pprint_ippool(subnet, stdout=None, title=None): |
|
148 |
"""Pretty print IP Pools of a subnet. Only IPv4 subnets have IP Pools""" |
|
149 |
|
|
150 |
if int(subnet.ipversion) != 4: |
|
151 |
return 0 |
|
152 |
|
|
153 |
if stdout is None: |
|
154 |
stdout = sys.stdout |
|
155 |
|
|
156 |
stdout.write("IP Pools of subnet %s" % subnet.id) |
|
157 |
|
|
158 |
for pool in subnet.get_ip_pools(): |
|
159 |
size = pool.pool_size |
|
160 |
available = pool.available.count() |
|
161 |
info = OrderedDict([("First_IP", pool.return_start()), |
|
162 |
("Last_IP", pool.return_end()), |
|
163 |
("Size", size), |
|
164 |
("Available", available)]) |
|
165 |
pprint_table(stdout, info.items(), None, separator=" | ", title=None) |
|
166 |
stdout.write(bitarray_to_map(pool.available[:size])) |
|
167 |
stdout.write("\n\n") |
|
168 |
|
|
169 |
|
|
127 | 170 |
def pool_map_chunks(smap, step=64): |
128 | 171 |
for i in xrange(0, len(smap), step): |
129 | 172 |
yield smap[i:i + step] |
Also available in: Unified diff