diff --git a/devices/clients/SNMP_client.py b/devices/clients/SNMP_client.py index 158ce17dfdbe478d9a417d6026fc0d32e3971370..6230386aa300efbf9bf23ac1491b6a10354cba2f 100644 --- a/devices/clients/SNMP_client.py +++ b/devices/clients/SNMP_client.py @@ -26,12 +26,6 @@ snmp_types = { "OID": numpy.str_, } -# numpy_to_snmp_dict = { -# numpy.int64, -# numpy.int64, -# str, -# } - class SNMP_client(CommClient): """ @@ -140,34 +134,25 @@ class SNMP_client(CommClient): dim_x, dim_y, numpy_type = self.setup_value_conversion(attribute) oids = self.get_oids(dim_x, dim_y, oids) - if dtype is None: - dtype = numpy_type - def _read_function(): - vars = self.manager.get(self.host, *oids) + return [snmp_to_numpy_dict[type(i.value)](str(i.value)) for i in vars] - value = [] - for i in vars: - val = snmp_to_numpy_dict[type(i.value)](str(i.value)) - value.append(val) - return value - - if dtype is None: + if dtype is not None: def _write_function(value): if len(oids) == 1 and type(value) != list: value = [value] - else: - for i in range(len(oids)): - self.manager.set(self.host, oids[i], value[i]) + for i in range(len(oids)): + self.manager.set(self.host, oids[i], snmp_types[dtype](value[i])) else: def _write_function(value): if len(oids) == 1 and type(value) != list: value = [value] - else: - for i in range(len(oids)): - self.manager.set(self.host, oids[i], snmp_types[dtype](value[i])) + + for i in range(len(oids)): + self.manager.set(self.host, oids[i], value[i]) + # return the read/write functions return _read_function, _write_function