Skip to content
Snippets Groups Projects
Commit 9183204a authored by Taya Snijder's avatar Taya Snijder
Browse files

updated write with new code

parent 669baa76
No related branches found
No related tags found
1 merge request!243Resolve L2SS-464 "Replace snmp python library with pysnmp"
......@@ -158,15 +158,18 @@ class SNMP_client(CommClient):
# get all the necessary data to set up the read/write functions from the attribute_wrapper
dim_x, dim_y, numpy_type = self.setup_value_conversion(attribute)
if uses_oids:
# get a list of str of the oids
oids = self.get_oids(dim_x, dim_y, output)
# turn the list of oids in to a tuple of pysnmp objects
obj = (pysnmp.ObjectType(pysnmp.ObjectIdentity(oids)) for i in range(len(oids)))
objID = (pysnmp.ObjectIdentity(oids) for i in range(len(oids)))
obj = (pysnmp.ObjectType(i) for i in objID)
else:
# if a single one
obj = (pysnmp.ObjectType(pysnmp.ObjectIdentity(output[0], output[1], 0)),)
# if its an mib and name thingy
objID = pysnmp.ObjectIdentity(output[0], output[1], 0)
obj = (pysnmp.ObjectType(objID),)
def _read_function():
# get the thingy to get the values
......@@ -191,24 +194,18 @@ class SNMP_client(CommClient):
# return the list of values
return val_lst
if dtype is not None:
def _write_function(value):
set_cmd = pysnmp.setCmd(self.engine, self.community, self.trasport, self.ctx_data, *obj)
errorIndication, errorStatus, errorIndex, varBinds = next(set_cmd)
def _write_function(value):
is_scalar = (self.dim_x + self.dim_y) == 1
if len(oids) == 1 and type(value) != list:
value = [value]
if is_scalar:
write_obj = (pysnmp.ObjectType(objID[0], value),)
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]
write_obj = tuple(pysnmp.ObjectType(objID[i], value[i]) for i in range(len(objID)))
for i in range(len(oids)):
self.manager.set(self.host, oids[i], value[i])
set_cmd = pysnmp.setCmd(self.engine, self.community, self.trasport, self.ctx_data, *write_obj)
errorIndication, errorStatus, errorIndex, varBinds = next(set_cmd)
# return the read/write functions
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment