Srikanth Vavilapalli | 1725e49 | 2014-12-01 17:50:52 -0800 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 2013 Big Switch Networks, Inc. |
| 3 | # |
| 4 | # Licensed under the Eclipse Public License, Version 1.0 (the |
| 5 | # "License"); you may not use this file except in compliance with the |
| 6 | # License. You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.eclipse.org/legal/epl-v10.html |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 13 | # implied. See the License for the specific language governing |
| 14 | # permissions and limitations under the License. |
| 15 | # |
| 16 | |
| 17 | # snmp. |
| 18 | # |
| 19 | |
| 20 | import run_config |
| 21 | import utif |
| 22 | |
| 23 | |
| 24 | # |
| 25 | # -------------------------------------------------------------------------------- |
| 26 | |
| 27 | def create_obj_type_dict(context, obj_type, field): |
| 28 | """ |
| 29 | Should there be some collections of middeleware functions for use by packages? |
| 30 | """ |
| 31 | entries = context.get_table_from_store(obj_type) |
| 32 | result_dict = {} |
| 33 | for entry in entries: |
| 34 | if entry[field] in result_dict: |
| 35 | result_dict[entry[field]].append(entry) |
| 36 | else: |
| 37 | result_dict[entry[field]] = [entry] |
| 38 | |
| 39 | return result_dict |
| 40 | |
| 41 | # |
| 42 | # -------------------------------------------------------------------------------- |
| 43 | |
| 44 | def running_config_snmp(context, config, words): |
| 45 | s_obj_type = 'snmp-server-config' |
| 46 | |
| 47 | snmp_config = context.get_table_from_store(s_obj_type) |
| 48 | if len(snmp_config) > 1: |
| 49 | print 'running_config_snmp: more than one snmp record' |
| 50 | if len(snmp_config) == 0: |
| 51 | return |
| 52 | |
| 53 | snmp_config = snmp_config[0] |
| 54 | |
| 55 | |
| 56 | s_config = [] |
| 57 | if run_config.not_default_value(s_obj_type, 'community', snmp_config.get('community')): |
| 58 | s_config.append('snmp-server community ro %s\n' % |
| 59 | utif.quote_string(snmp_config['community'])) |
| 60 | |
| 61 | if run_config.not_default_value(s_obj_type, 'location', snmp_config.get('location')): |
| 62 | s_config.append('snmp-server location %s\n' % |
| 63 | utif.quote_string(snmp_config['location'])) |
| 64 | |
| 65 | if run_config.not_default_value(s_obj_type, 'contact', snmp_config.get('contact')): |
| 66 | s_config.append('snmp-server contact %s\n' % |
| 67 | utif.quote_string(snmp_config['contact'])) |
| 68 | if run_config.not_default_value(s_obj_type, 'server-enable', snmp_config['server-enable']): |
| 69 | s_config.append('snmp-server enable\n') |
| 70 | |
| 71 | if len(s_config): |
| 72 | config.append('!\n') |
| 73 | config += s_config |
| 74 | |
| 75 | |
| 76 | # |
| 77 | # -------------------------------------------------------------------------------- |
| 78 | |
| 79 | snmp_running_config_tuple = ( |
| 80 | ( |
| 81 | { |
| 82 | 'optional' : False, |
| 83 | 'field' : 'running-config', |
| 84 | 'type' : 'enum', |
| 85 | 'values' : 'snmp', |
| 86 | 'short-help' : 'Configuration for SNMP', |
| 87 | 'doc' : 'running-config|show-snmp', |
| 88 | }, |
| 89 | ), |
| 90 | ) |
| 91 | |
| 92 | run_config.register_running_config('snmp', 2300, None, |
| 93 | running_config_snmp, |
| 94 | snmp_running_config_tuple) |