summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-10-27 23:56:23 +0100
committerChristian Poessinger <christian@poessinger.com>2019-10-27 23:57:10 +0100
commit8d57656ae0417af0f28ec2fac476b86e72dde110 (patch)
tree4848032bc0f9233b158921a5408a229c47fda4d8
parentebcb19b5b9a1ae57b3b0f902d6fb0259fe2ed209 (diff)
downloadvyos-1x-8d57656ae0417af0f28ec2fac476b86e72dde110.tar.gz
vyos-1x-8d57656ae0417af0f28ec2fac476b86e72dde110.zip
snmp: make script extension code more readable
-rwxr-xr-xsrc/conf_mode/snmp.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/conf_mode/snmp.py b/src/conf_mode/snmp.py
index a8c604bdd..b64cccbfa 100755
--- a/src/conf_mode/snmp.py
+++ b/src/conf_mode/snmp.py
@@ -202,7 +202,7 @@ group {{ u.group }} usm {{ u.name }}
{% if script_ext %}
# extension scripts
{%- for ext in script_ext|sort %}
-extend\t{{ext}}\t{{script_ext[ext]}}
+extend {{ ext.name }} {{ ext.script }}
{%- endfor %}
{% endif %}
"""
@@ -238,7 +238,7 @@ default_config_data = {
'v3_traps': [],
'v3_users': [],
'v3_views': [],
- 'script_ext': {}
+ 'script_ext': []
}
def rmfile(file):
@@ -347,9 +347,13 @@ def get_config():
# 'set service snmp script-extensions'
#
if conf.exists('script-extensions'):
- for extname in conf.list_nodes('script-extensions extension-name'):
- snmp['script_ext'][extname] = '/config/user-data/' + conf.return_value('script-extensions extension-name ' + extname + ' script')
+ for extname in conf.list_nodes('script-extensions extension-name'):
+ extension = {
+ 'name': extname,
+ 'script' : conf.return_value('script-extensions extension-name {} script'.format(extname))
+ }
+ snmp['script_ext'].append(extension)
#########################################################################
# ____ _ _ __ __ ____ _____ #
@@ -545,10 +549,10 @@ def verify(snmp):
### check if the configured script actually exist under /config/user-data
if snmp['script_ext']:
for ext in snmp['script_ext']:
- if not os.path.isfile(snmp['script_ext'][ext]):
- print ("WARNING: script: {} doesn't exist".format(snmp['script_ext'][ext]))
+ if not os.path.isfile(ext['script']):
+ print ("WARNING: script: {} doesn't exist".format(ext['script']))
else:
- os.chmod(snmp['script_ext'][ext], S_IRWXU|S_IXGRP|S_IXOTH)
+ os.chmod(ext['script'], S_IRWXU|S_IXGRP|S_IXOTH)
for listen in snmp['listen_address']:
addr = listen[0]