From dfeac09a07e353fb9ce1509a85dd851c1f065523 Mon Sep 17 00:00:00 2001 From: Steve McIntyre Date: Wed, 7 Feb 2018 00:57:49 +0000 Subject: Plumbed through the get_port_mode() API call Change-Id: I68257b747a21a84f6898cdeaaa8169e928a3b355 --- db/db.py | 12 ++++++++++++ util.py | 2 ++ vland-admin | 17 +++++++++++++++++ 3 files changed, 31 insertions(+) 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', -- cgit v1.2.3