blob: ad9b31e8ddbab3f62526cdf51ce073d0e650935e [file] [log] [blame]
Srikanth Vavilapalli1725e492014-12-01 17:50:52 -08001#
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# (c) in 2012 by Big Switch Networks - All rights reserved
18#
19# snmp-server commands
20#
21
22import command
23from midw import local_interfaces_firewall_open
24
25def snmp_validate_firewall(data):
26 intfs = local_interfaces_firewall_open( [ 'udp', 'tcp' ], 161)
27 if len(intfs) == 0:
28 # by issueing a warning, running-config doesn't display the
29 # error during replay.
30 command.sdnsh.warning('SNMP server port not open on any controller-node '
31 'interface. Use firewall rule configuration to open '
32 'SNMP UDP port 161')
33
34
35
36command.add_action('snmp-validate-firewall', snmp_validate_firewall,
37 {'kwargs': { 'data' : '$data',
38 }})
39
40"""
41#
42# --------------------------------------------------------------------------------
43# SNMP command descriptions
44#
45# [no] snmp-server enable
46# [no] snmp-server community <string>
47# [no] snmp-server location <string>
48# [no] snmp-server contact <string>
49#
50SNMP_SERVER_COMMAND_DESCRIPTION = {
51 'name' : 'snmp-server',
52 'mode' : 'config*',
53 'short-help' : 'SMNP configuration, enable server, configure parameters',
54 'doc' : 'snmp|snmp-server',
55 'doc-example' : 'snmp|snmp-server-example',
56 'command-type' : 'update-config',
57 'obj-type' : 'snmp-server-config',
58 'data' : { 'id' : 'snmp' },
59 'args' : (
60 {
61 'choices' : (
62 {
63 'token' : 'enable',
64 'short-help' : 'Enable SNMP',
65 'doc' : 'snmp|snmp-server-enable',
66 'action' : (
67 {
68 'proc' : 'update-config',
69 'data' : {
70 'id' : 'snmp',
71 'server-enable' : True,
72 },
73 },
74 {
75 'proc' : 'snmp-validate-firewall'
76 },
77 ),
78 'no-action' : {
79 'proc' : 'update-config',
80 'data' : {
81 'id' : 'snmp',
82 'server-enable' : False,
83 },
84 },
85 },
86 (
87 {
88 'token' : 'community',
89 'short-help' : 'Set community string and access privs',
90 'data' : { 'community' : None },
91 'doc' : 'snmp|snmp-server-community',
92 },
93 {
94 'token' : 'ro',
95 'short-help' : 'Read-only access with this community string',
96 'optional-for-no' : True,
97 },
98 {
99 'field' : 'community',
100 'type' : 'string',
101 'optional-for-no' : True,
102 'syntax-help' : 'Value for the SNMP commuity string',
103 },
104 ),
105 (
106 {
107 'token' : 'location',
108 'short-help' : 'Text for mib object sysLocation',
109 'data' : { 'location' : None },
110 'doc' : 'snmp|snmp-server-location',
111 },
112 {
113 'field' : 'location',
114 'type' : 'string',
115 'optional-for-no' : True,
116 'syntax-help' : 'Value for the SNMP location string',
117 },
118 ),
119 (
120 {
121 'token' : 'contact',
122 'short-help' : 'Text for mib object sysContact',
123 'data' : { 'contact' : None },
124 'doc' : 'snmp|snmp-server-contact',
125 },
126 {
127 'field' : 'contact',
128 'type' : 'string',
129 'optional-for-no' : True,
130 'syntax-help' : 'Value for the SNMP contact string',
131 },
132 ),
133 ),
134 },
135 )
136}
137"""
138
139def snmp_firewall_interfaces(data):
140 """
141 There is currently only one row of data in the query,
142 add to that a 'interfaces' entity, which lists the interfaces
143 which have the snmp port open
144 """
145 if not hasattr(command, 'query_result'):
146 return
147 if command.query_result == None:
148 return
149
150 intfs = local_interfaces_firewall_open( [ 'udp', 'tcp' ], 161)
151
152 intfs_text = ', '.join([x['discovered-ip'] if x['discovered-ip'] != ''
153 else x['ip'] for x in intfs])
154
155 for q in command.query_result:
156 q['interfaces'] = intfs_text
157
158
159command.add_action('snmp-firewall-interfaces', snmp_firewall_interfaces,
160 {'kwargs': { 'data' : '$data',
161 }})
162
163"""
164SNMP_SERVER_SHOW_COMMAND_DESCRIPTION = {
165 'name' : 'show',
166 'mode' : 'login',
167 'short-help' : 'Show configured snmp details',
168 'doc' : 'snmp|show',
169 'doc-example' : 'snmp|show-example',
170 'command-type' : 'display-table',
171 'obj-type' : 'snmp-server-config',
172 'short-help' : 'Show SNMP configuration',
173 'format' : 'snmp-config-summary',
174 'args' : (
175 'snmp',
176 ),
177 'action' : (
178 {
179 'proc' : 'query-table',
180 },
181 {
182 'proc' : 'snmp-firewall-interfaces'
183 },
184 {
185 'proc' : 'display-table',
186 },
187 ),
188}
189
190import fmtcnv
191
192SNMP_CONFIG_SUMMARY_FORMAT = {
193 'snmp-config-summary' : {
194 'field-orderings' : {
195 'default' : [
196 'server-enable',
197 'community',
198 'location',
199 'contact',
200 'interfaces',
201 ],
202 },
203 'fields' : {
204 'server-enable' : {
205 'verbose-name' : 'SNMP server status',
206 'formatter' : fmtcnv.replace_boolean_with_enable_disable,
207 },
208 'community' : { 'verbose-name' : 'Community string' },
209 'location' : { 'verbose-name' : 'System location' },
210 'contact' : { 'verbose-name' : 'System contact' },
211 },
212 }
213}
214"""