aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve McIntyre <steve.mcintyre@linaro.org>2018-02-07 00:57:49 +0000
committerSteve McIntyre <steve.mcintyre@linaro.org>2018-02-07 00:57:49 +0000
commitdfeac09a07e353fb9ce1509a85dd851c1f065523 (patch)
tree7fe7502c0fd2046f1aaf8ccb150bceb90c4200fb
parentca115d29c8db3ddc1797555c2c127d8dba0a8d41 (diff)
downloadvland-dfeac09a07e353fb9ce1509a85dd851c1f065523.tar.gz
Plumbed through the get_port_mode() API call
Change-Id: I68257b747a21a84f6898cdeaaa8169e928a3b355
-rw-r--r--db/db.py12
-rw-r--r--util.py2
-rwxr-xr-xvland-admin17
3 files changed, 31 insertions, 0 deletions
diff --git a/db/db.py b/db/db.py
index c258a5e..4fc9444 100644
--- a/db/db.py
+++ b/db/db.py
@@ -549,6 +549,18 @@ class VlanDB:
def get_current_vlan_id_by_port(self, port_id):
return self._get_element("current_vlan_id", "port", "port_id", int(port_id))
+ # Simple lookup: look up a port by ID, and return the mode of that port.
+ #
+ # Returns None on failure.
+ def get_port_mode(self, port_id):
+ is_trunk = self._get_element("is_trunk", "port", "port_id", int(port_id))
+ if is_trunk is not None:
+ if is_trunk:
+ return "trunk"
+ else:
+ return "access"
+ return None
+
# Simple lookup: look up a port by ID, and return the base VLAN
# id of that port.
#
diff --git a/util.py b/util.py
index 59f11ea..738eb00 100644
--- a/util.py
+++ b/util.py
@@ -101,6 +101,8 @@ class VlanUtil:
ret = db.get_ports_by_current_vlan(data['vlan_id'])
elif command == 'db.get_ports_by_base_vlan':
ret = db.get_ports_by_base_vlan(data['vlan_id'])
+ elif command == 'db.get_port_mode':
+ ret = db.get_port_mode(data['port_id'])
elif command == 'db.get_ports_by_trunk':
ret = db.get_ports_by_trunk(data['trunk_id'])
elif command == 'db.get_vlan_by_id':
diff --git a/vland-admin b/vland-admin
index 96a7cfc..f635699 100755
--- a/vland-admin
+++ b/vland-admin
@@ -698,6 +698,23 @@ elif args.which == 'lookup_ports_by_trunk':
except InputError as inst:
print 'Failed: %s' % inst
exitcode = Error.FAILED
+elif args.which == 'get_port_mode':
+ try:
+ mode = call_vland('db_query',
+ {'command':'db.get_port_mode',
+ 'data':
+ {'port_id': args.port_id}})
+ if mode is not None:
+ print 'port_id %s is in mode %s' % (args.port_id, mode)
+ else:
+ print 'No port found for port_id %s' % args.port_id
+ exitcode = Error.NOTFOUND
+ except InputError as inst:
+ print 'Failed: %s' % inst
+ exitcode = Error.FAILED
+ except NotFoundError as inst:
+ print 'Failed: %s' % inst
+ exitcode = Error.NOTFOUND
elif args.which == 'set_port_mode':
try:
port_id = call_vland('vlan_update',