Expose db.get_vlan_id_by_tag and db.get_vlan_tag_by_id()
Change-Id: I3b48a4bbd33fe46dfebae9994ca1a1035edf7a3c
diff --git a/admin.py b/admin.py
index 4acb13a..de563f1 100644
--- a/admin.py
+++ b/admin.py
@@ -283,6 +283,22 @@
default = None,
nargs = 1,
metavar = "<vlan_id>")
+vlan_group.add_option("--lookup_vlan_by_tag",
+ dest = "lookup_vlan_by_tag",
+ action = "store",
+ type = "int",
+ help = "Find the vlan ID of an existing vlan in the system",
+ default = None,
+ nargs = 1,
+ metavar = "<tag>")
+vlan_group.add_option("--show_vlan_tag",
+ dest = "show_vlan_tag",
+ action = "store",
+ type = "int",
+ help = "Print the vlan tag of an existing vlan in the system",
+ default = None,
+ nargs = 1,
+ metavar = "<vlan_id>")
parser.add_option_group(vlan_group)
(opts, args) = parser.parse_args()
@@ -517,6 +533,30 @@
print 'No vlan found for vlan_id %d' % opts.show_vlan
except InputError as inst:
print 'Failed: %s' % inst
+elif opts.lookup_vlan_by_tag is not None:
+ try:
+ vlan_id = call_vland('db_query',
+ {'command':'db.get_vlan_id_by_tag',
+ 'data':
+ {'tag': opts.lookup_vlan_by_tag}})
+ if vlan_id is not None:
+ print vlan_id
+ else:
+ print 'No vlan found for vlan tag %d' % opts.lookup_vlan_by_tag
+ except InputError as inst:
+ print 'Failed: %s' % inst
+elif opts.show_vlan_tag is not None:
+ try:
+ vlan_tag = call_vland('db_query',
+ {'command':'db.get_vlan_tag_by_id',
+ 'data':
+ {'vlan_id': opts.show_vlan_tag}})
+ if vlan_tag is not None:
+ print vlan_tag
+ else:
+ print 'No vlan found for vlan id %d' % opts.show_vlan_tag
+ except InputError as inst:
+ print 'Failed: %s' % inst
elif opts.status:
print 'Config:'
print ' knows about %d switch(es)' % len(config.switches)