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