Revision 4500650c snf-cyclades-app/synnefo/logic/management/commands/network-inspect.py
b/snf-cyclades-app/synnefo/logic/management/commands/network-inspect.py | ||
---|---|---|
36 | 36 |
from optparse import make_option |
37 | 37 |
|
38 | 38 |
from django.core.management.base import BaseCommand, CommandError |
39 |
from synnefo.management.common import get_network, UUIDCache |
|
39 |
from synnefo.management.common import get_network, UUIDCache, Omit
|
|
40 | 40 |
|
41 | 41 |
from synnefo.db.models import (Backend, BackendNetwork, |
42 | 42 |
pooled_rapi_client) |
... | ... | |
48 | 48 |
help = "Inspect a network on DB and Ganeti." |
49 | 49 |
|
50 | 50 |
option_list = BaseCommand.option_list + ( |
51 |
make_option('--uuids',
|
|
51 |
make_option('--displayname',
|
|
52 | 52 |
action='store_true', |
53 |
dest='use_uuids',
|
|
53 |
dest='displayname',
|
|
54 | 54 |
default=False, |
55 |
help="Display UUIDs instead of user emails"),
|
|
56 |
)
|
|
55 |
help="Display both uuid and display name"),
|
|
56 |
) |
|
57 | 57 |
|
58 | 58 |
def handle(self, *args, **options): |
59 | 59 |
write = self.stdout.write |
... | ... | |
62 | 62 |
|
63 | 63 |
net = get_network(args[0]) |
64 | 64 |
|
65 |
ucache = UUIDCache() |
|
66 |
|
|
67 |
displayname = options['displayname'] |
|
68 |
|
|
65 | 69 |
sep = '-' * 80 + '\n' |
66 |
labels = ('name', 'backend-name', 'state', 'owner', 'subnet', |
|
67 |
'gateway', 'mac_prefix', 'link', 'public', 'dhcp', 'flavor', |
|
68 |
'deleted', 'action', 'pool') |
|
69 |
|
|
70 |
user = net.userid |
|
71 |
if options['use_uuids'] is False: |
|
72 |
ucache = UUIDCache() |
|
73 |
user = ucache.get_user(net.userid) |
|
74 |
|
|
75 |
fields = (net.name, net.backend_id, net.state, user or '', |
|
76 |
str(net.subnet), str(net.gateway), str(net.mac_prefix), |
|
77 |
str(net.link), str(net.public), str(net.dhcp), |
|
78 |
str(net.flavor), str(net.deleted), str(net.action), |
|
79 |
str(splitPoolMap(net.get_pool().to_map(), 64))) |
|
70 |
labels = filter(lambda x: x is not Omit, |
|
71 |
['name', 'backend-name', 'state', 'owner uuid', |
|
72 |
'owner_name' if displayname else Omit, 'subnet', |
|
73 |
'gateway', 'mac_prefix', 'link', 'public', 'dhcp', |
|
74 |
'flavor', 'deleted', 'action', 'pool']) |
|
75 |
|
|
76 |
uuid = net.userid |
|
77 |
if displayname: |
|
78 |
dname = ucache.get_user(uuid) |
|
79 |
|
|
80 |
fields = filter(lambda x: x is not Omit, |
|
81 |
[net.name, net.backend_id, net.state, uuid or '-', |
|
82 |
dname or '-' if displayname else Omit, |
|
83 |
str(net.subnet), str(net.gateway), str(net.mac_prefix), |
|
84 |
str(net.link), str(net.public), str(net.dhcp), |
|
85 |
str(net.flavor), str(net.deleted), str(net.action), |
|
86 |
str(splitPoolMap(net.get_pool().to_map(), 64))]) |
|
80 | 87 |
|
81 | 88 |
write(sep) |
82 | 89 |
write('State of Network in DB\n') |
Also available in: Unified diff