Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dockers/docker-snmp/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ RUN apt-get -y purge \
rm -rf /debs /python-wheels ~/.cache

COPY ["start.sh", "/usr/bin/"]
COPY ["snmp_yml_to_configdb.py", "/usr/bin/"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
COPY ["*.j2", "/usr/share/sonic/templates/"]
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
Expand Down
47 changes: 47 additions & 0 deletions dockers/docker-snmp/snmp_yml_to_configdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env python3

import os
import yaml
from swsssdk import ConfigDBConnector

db = ConfigDBConnector()
db.connect()

snmp_comm_config_db = db.get_table('SNMP_COMMUNITY')
snmp_config_db_communities = snmp_comm_config_db.keys()
snmp_general_config_db = db.get_table('SNMP')
snmp_general_keys = snmp_general_config_db.keys()

full_snmp_comm_list = ['snmp_rocommunity', 'snmp_rocommunities', 'snmp_rwcommunity', 'snmp_rwcommunities']


if os.path.exists('/etc/sonic/snmp.yml'):
with open('/etc/sonic/snmp.yml', 'r') as yaml_file:
yaml_snmp_info = yaml.load(yaml_file)

for comm_type in full_snmp_comm_list:
if comm_type in yaml_snmp_info.keys():
if comm_type.startswith('snmp_rocommunities'):
for community in yaml_snmp_info[comm_type]:
if community not in snmp_config_db_communities:
db.set_entry('SNMP_COMMUNITY', community, {"TYPE": "RO"})
elif comm_type.startswith('snmp_rocommunity'):
community = yaml_snmp_info['snmp_rocommunity']
if community not in snmp_config_db_communities:
db.set_entry('SNMP_COMMUNITY', community, {"TYPE": "RO"})
elif comm_type.startswith('snmp_rwcommunities'):
for community in yaml_snmp_info[comm_type]:
if community not in snmp_config_db_communities:
db.set_entry('SNMP_COMMUNITY', community, {"TYPE": "RW"})
elif comm_type.startswith('snmp_rwcommunity'):
community = yaml_snmp_info['snmp_rwcommunity']
if community not in snmp_config_db_communities:
db.set_entry('SNMP_COMMUNITY', community, {"TYPE": "RW"})

if yaml_snmp_info['snmp_location']:
if 'LOCATION' not in snmp_general_keys:
db.set_entry('SNMP', 'LOCATION', {'Location': yaml_snmp_info['snmp_location']})
else:
pass
else:
pass
3 changes: 3 additions & 0 deletions dockers/docker-snmp/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

mkdir -p /etc/ssw /etc/snmp

# Parse snmp.yml and insert the data in Config DB
python /usr/bin/snmp_yml_to_configdb.py

SONIC_CFGGEN_ARGS=" \
-d \
-y /etc/sonic/sonic_version.yml \
Expand Down