Improve output from information-gathering functions
Print out details of switches, ports and VLANs in something readily
parseable instead of just a python "print"
Change-Id: I0369fed47ef827508df920e0d0f9bc620196b1cb
diff --git a/admin.py b/admin.py
index de563f1..f24d329 100644
--- a/admin.py
+++ b/admin.py
@@ -42,13 +42,27 @@
raise InputError("Cannot parse \"%s\" as True or False" % text)
def dump_switch(switch):
- print switch
+ print "switch_id:%d name:%s" % (
+ int(switch[0]),
+ switch[1])
def dump_port(port):
- print port
+ print "port_id:%d name:%s switch_id:%d locked:%s mode:%s base_vlan_id:%d current_vlan_id:%d" % (
+ int(port[0]),
+ port[1],
+ int(port[2]),
+ ("yes" if port[3] is True else "no"),
+ ("trunk" if port[4] is True else "access"),
+ int(port[5]),
+ int(port[6]))
def dump_vlan(vlan):
- print vlan
+ print "vlan_id:%d name:%s tag:%d is_base_vlan:%s, creation_time:%s" % (
+ int(vlan[0]),
+ vlan[1],
+ int(vlan[2]),
+ ("yes" if vlan[3] is True else "no"),
+ vlan[4])
def call_vland(msgtype, msg):
ipc = VlanIpc()
@@ -305,25 +319,16 @@
if opts.list_all_switches:
result = call_vland('db_query', {'command':'db.all_switches', 'data':None})
- count = 0
for line in result:
- print line
- count += 1
- print '%d entries' % count
+ dump_switch(line)
elif opts.list_all_ports:
result = call_vland('db_query', {'command':'db.all_ports', 'data':None})
- count = 0
for line in result:
- print line
- count += 1
- print '%d entries' % count
+ dump_port(line)
elif opts.list_all_vlans:
result = call_vland('db_query', {'command':'db.all_vlans', 'data':None})
- count = 0
for line in result:
- print line
- count += 1
- print '%d entries' % count
+ dump_vlan(line)
elif opts.create_switch is not None:
try:
switch_id = call_vland('db_update',