Skip to content

Commit

Permalink
sonic_ax_impl supports redis connection options (sonic-net#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiluo-msft authored Mar 14, 2017
1 parent c38cc59 commit 0c14bcc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/sonic_ax_impl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import ax_interface
import sonic_ax_impl
from . import mibs

LOG_FORMAT = "snmp-subagent [%(name)s] %(levelname)s: %(message)s"

Expand Down Expand Up @@ -63,6 +64,9 @@ def install_fragments():
ax_interface.logger.handlers = sonic_ax_impl.logger.handlers
sswsdk.logger.handlers = sonic_ax_impl.logger.handlers

# init mibs module with command line arguments
mibs.config(**args)

if warn_syslog:
# syslog was unavailable when it should've been.
sonic_ax_impl.logger.warning("Syslog is unavailable. Logging to STDERR.")
Expand Down
7 changes: 6 additions & 1 deletion src/sonic_ax_impl/mibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ASIC_DB = 'ASIC_DB'
COUNTERS_DB = 'COUNTERS_DB'

redis_kwargs = {'unix_socket_path': '/var/run/redis/redis.sock'}

def counter_table(sai_id):
"""
Expand Down Expand Up @@ -39,14 +40,18 @@ def get_index(if_name):
return int(n) + 1


def config(**kwargs):
global redis_kwargs
redis_kwargs = {k:v for (k,v) in kwargs.items() if k in ['unix_socket_path', 'host', 'port']}

def init_sync_d_interface_tables():
"""
DRY helper method. Connects to and initializes interface maps for SyncD-connected MIB(s).
:return: tuple(db_conn, if_name_map, if_id_map, oid_map, if_alias_map)
"""
# SyncD database connector. THIS MUST BE INITIALIZED ON A PER-THREAD BASIS.
# Redis PubSub objects (such as those within sswsdk) are NOT thread-safe.
db_conn = SonicV2Connector()
db_conn = SonicV2Connector(**redis_kwargs)
db_conn.connect(COUNTERS_DB)

# { if_name (SONiC) -> sai_id }
Expand Down

0 comments on commit 0c14bcc

Please sign in to comment.