Skip to content

Commit 99fae0e

Browse files
authored
Merge pull request #47 from QualiSystems/bugfix-snmpv3
Bugfix snmpv3
2 parents 3afaafb + ca3a10c commit 99fae0e

8 files changed

Lines changed: 76 additions & 16 deletions

File tree

cloudshell/snmp/core/domain/quali_mib_table.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def get_columns(self, *names):
3434
:param names: list of requested columns names.
3535
:return: a partial table containing only the requested columns.
3636
"""
37-
names = [n for n in names]
3837
return QualiMibTable(
3938
self._name,
4039
OrderedDict(

cloudshell/snmp/core/snmp_service.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ def load_mib_tables(self, mib_list):
6161
for mib in mib_list:
6262
mib_builder.loadModules(mib)
6363

64+
def translate_oid(self, snmp_oid):
65+
"""Translates Raw OID into a human readable identifiers.
66+
67+
:param str snmp_oid: OID string. like: '1.3.6.1.2.1.1.4.0'
68+
:return translated OID name
69+
:rtype str
70+
"""
71+
result = SnmpResponse(
72+
snmp_oid, None, snmp_engine=self._snmp_engine, logger=self._logger
73+
)
74+
75+
return result.mib_id
76+
6477
def set(self, snmp_set_oids): # noqa: A003
6578
"""SNMP Set operation.
6679

cloudshell/snmp/core/tools/snmp_parameters_helper.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ class SnmpParametersConverter(object):
55
AUTH_PRIV = "authPriv"
66

77
class PySnmpVersion:
8-
def __init__(self):
9-
pass
10-
118
V1 = 0
129
V2 = 1
1310
V3 = 3
@@ -44,7 +41,7 @@ def version(self):
4441
def user(self):
4542
if not self._user:
4643
self._user = self.DEFAULT_USER
47-
if hasattr(self.snmp_parameters, "user"):
44+
if hasattr(self.snmp_parameters, "snmp_user"):
4845
self._user = self.snmp_parameters.snmp_user
4946
return self._user
5047

cloudshell/snmp/core/tools/snmp_security.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ def __init__(self, py_snmp_params, logger):
1212
self._logger = logger
1313

1414
def add_security(self, snmp_engine):
15-
if hasattr(self._py_snmp_params, "snmp_password"):
15+
if hasattr(self._py_snmp_params.snmp_parameters, "snmp_password"):
1616
auth_protocol = AUTH_PROTOCOL_MAP.get(
1717
self._py_snmp_params.snmp_parameters.snmp_auth_protocol
1818
)
1919
priv_protocol = PRIV_PROTOCOL_MAP.get(
20-
self._py_snmp_params.snmp_parameters.snmp_priv_protocol
20+
self._py_snmp_params.snmp_parameters.snmp_private_key_protocol
2121
)
2222
config.addV3User(
23-
snmp_engine,
24-
self._py_snmp_params.user,
25-
auth_protocol,
26-
self._py_snmp_params.snmp_parameters.snmp_password,
27-
priv_protocol,
28-
self._py_snmp_params.snmp_parameters.snmp_v3_priv_key,
23+
snmpEngine=snmp_engine,
24+
userName=self._py_snmp_params.user,
25+
authProtocol=auth_protocol,
26+
authKey=self._py_snmp_params.snmp_parameters.snmp_password,
27+
privProtocol=priv_protocol,
28+
privKey=self._py_snmp_params.snmp_parameters.snmp_private_key,
2929
)
3030
else:
3131
config.addV1System(

cloudshell/snmp/snmp_parameters.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import warnings
2+
3+
14
class SnmpParameters(object):
25
class SnmpVersion:
36
def __init__(self):
@@ -112,8 +115,50 @@ def __init__(
112115
self.snmp_user = snmp_user
113116
self.snmp_password = snmp_password
114117
self.snmp_private_key = snmp_private_key
115-
self.auth_protocol = auth_protocol
116-
self.private_key_protocol = private_key_protocol
118+
self.snmp_auth_protocol = auth_protocol
119+
self.snmp_private_key_protocol = private_key_protocol
120+
121+
# For backward compatibility auth_protocol and private_key_protocol
122+
@property
123+
def auth_protocol(self):
124+
warnings.warn(
125+
"auth_protocol is obsolete please use snmp_auth_protocol field instead",
126+
DeprecationWarning,
127+
stacklevel=2,
128+
)
129+
return self.snmp_auth_protocol
130+
131+
@auth_protocol.setter
132+
def auth_protocol(self, value):
133+
warnings.warn(
134+
"auth_protocol is obsolete please use snmp_auth_protocol field instead",
135+
DeprecationWarning,
136+
stacklevel=2,
137+
)
138+
self.snmp_auth_protocol = value
139+
140+
@property
141+
def private_key_protocol(self):
142+
warnings.warn(
143+
"private_key_protocol is obsolete please "
144+
"use snmp_private_key_protocol "
145+
"field instead",
146+
DeprecationWarning,
147+
stacklevel=2,
148+
)
149+
150+
return self.snmp_private_key_protocol
151+
152+
@private_key_protocol.setter
153+
def private_key_protocol(self, value):
154+
warnings.warn(
155+
"private_key_protocol is obsolete please "
156+
"use snmp_private_key_protocol "
157+
"field instead",
158+
DeprecationWarning,
159+
stacklevel=2,
160+
)
161+
self.snmp_private_key_protocol = value
117162

118163
def validate(self):
119164
super(SNMPV3Parameters, self).validate()

tests/snmp/core/domain/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from pkgutil import extend_path
2+
3+
__path__ = extend_path(__path__, __name__)

tests/snmp/core/tools/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from pkgutil import extend_path
2+
3+
__path__ = extend_path(__path__, __name__)

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.0.0
1+
4.0.1

0 commit comments

Comments
 (0)