diff --git a/tangostationcontrol/tangostationcontrol/examples/snmp/snmp_client.py b/tangostationcontrol/tangostationcontrol/examples/snmp/snmp_client.py index 6320e240c0c1d3d203462478b9082a816dccee75..e870808500ebd3319857c63dd05cffba832a579c 100644 --- a/tangostationcontrol/tangostationcontrol/examples/snmp/snmp_client.py +++ b/tangostationcontrol/tangostationcontrol/examples/snmp/snmp_client.py @@ -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] + else: + 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