forked from sonic-net/sonic-dbsyncd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lldp_syncd] add new OIDs - lldpRemTable & lldpLocPortTable (sonic-net#5
) * [lldp_syncd] add new OIDs - lldpRemTable & lldpLocPortTable * [lldp_syncd] add new OIDs - lldpLocalSystemData * enhance code style, set default port descr to ' ' instead of '' * [lldp_syncd] introduce cache to avoid writing to db every 5s * review comments - merge conflict, exception handling, pep8 * LLDP_ENTRY_TABLE fix indentation * review comments - move scrap_output() out of class, return '' for missing system capabilities * review comments - test for isinstance dict, move _scrap_output()
- Loading branch information
1 parent
94f2700
commit 37dbf74
Showing
7 changed files
with
386 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
logger.addHandler(logging.NullHandler()) | ||
|
||
from .daemon import LldpSyncDaemon | ||
from .dbsyncd import DBSyncDaemon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import subprocess | ||
from swsssdk import ConfigDBConnector | ||
|
||
from sonic_syncd import SonicSyncDaemon | ||
from . import logger | ||
|
||
|
||
class DBSyncDaemon(SonicSyncDaemon): | ||
""" | ||
A Thread that listens to changes in CONFIG DB, | ||
and contains handlers to configure lldpd accordingly. | ||
""" | ||
|
||
def __init__(self): | ||
super(DBSyncDaemon, self).__init__() | ||
self.config_db = ConfigDBConnector() | ||
self.config_db.connect() | ||
logger.info("[lldp dbsyncd] Connected to configdb") | ||
self.port_table = {} | ||
|
||
def run_command(self, command): | ||
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) | ||
stdout = p.communicate()[0] | ||
p.wait() | ||
if p.returncode != 0: | ||
logger.error("[lldp dbsyncd] command execution returned {}. " | ||
"Command: '{}', stdout: '{}'".format(p.returncode, command, stdout)) | ||
|
||
def port_handler(self, key, data): | ||
""" | ||
Handle updates in 'PORT' table. | ||
""" | ||
# we're interested only in description for now | ||
if self.port_table[key].get("description") != data.get("description"): | ||
new_descr = data.get("description", " ") | ||
logger.info("[lldp dbsyncd] Port {} description changed to {}." | ||
.format(key, new_descr)) | ||
self.run_command("lldpcli configure lldp portidsubtype local {} description '{}'" | ||
.format(key, new_descr)) | ||
# update local cache | ||
self.port_table[key] = data | ||
|
||
def run(self): | ||
self.port_table = self.config_db.get_table('PORT') | ||
# supply LLDP_LOC_ENTRY_TABLE and lldpd with correct values on start | ||
for port_name, attributes in self.port_table.items(): | ||
self.run_command("lldpcli configure lldp portidsubtype local {} description '{}'" | ||
.format(port_name, attributes.get("description", " "))) | ||
|
||
# subscribe for further changes | ||
self.config_db.subscribe('PORT', lambda table, key, data: | ||
self.port_handler(key, data)) | ||
|
||
logger.info("[lldp dbsyncd] Subscribed to configdb PORT table") | ||
self.config_db.listen() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.