diff --git a/tangostationcontrol/tangostationcontrol/clients/snmp_client.py b/tangostationcontrol/tangostationcontrol/clients/snmp_client.py index 1aa527e91558f8ba21e872b21f16fbd094439551..01286464536846b08f2fea4754e7010ee6e2f333 100644 --- a/tangostationcontrol/tangostationcontrol/clients/snmp_client.py +++ b/tangostationcontrol/tangostationcontrol/clients/snmp_client.py @@ -52,13 +52,7 @@ class SNMP_client(CommClient): self.connected = True - def _setup_annotation(self, annotation): - """ - The SNMP client uses a dict and takes the following keys: - mib: the mib name - name: name of the value to read - index (optional) the index if the value thats being read from is a table. - """ + def _process_annotation(self, annotation): # check if the 'mib' and 'name' keys are present if 'mib' in annotation and 'name' in annotation: @@ -94,7 +88,7 @@ class SNMP_client(CommClient): """ # process the annotation - mib, name, idx = self._setup_annotation(annotation) + mib, name, idx = self._process_annotation(annotation) # get all the necessary data to set up the read/write functions from the attribute_wrapper dim_x, dim_y, dtype = self.setup_value_conversion(attribute) @@ -236,10 +230,9 @@ class snmp_attribute: class mib_loader: - def __init__(self): + def __init__(self, mib_dir :str): self.mibBuilder = builder.MibBuilder() - def set_pymib_dir(self, mib_dir : str): abs_path = str(Path().absolute()).replace("\\", "/") if mib_dir[0] != "/": @@ -250,6 +243,7 @@ class mib_loader: mib_source = builder.DirMibSource(dir_path) self.mibBuilder.addMibSources(mib_source) + def load_pymib(self, mib_name): self.mibBuilder.loadModule(mib_name) diff --git a/tangostationcontrol/tangostationcontrol/devices/snmp_device.py b/tangostationcontrol/tangostationcontrol/devices/snmp_device.py index 15ff0ca5e4b2e4c1b3558f217909558d15116e8d..b8d16945a94e98799fc5992c86487a14ac25b3f8 100644 --- a/tangostationcontrol/tangostationcontrol/devices/snmp_device.py +++ b/tangostationcontrol/tangostationcontrol/devices/snmp_device.py @@ -109,8 +109,7 @@ class SNMP(lofar_device): def init_device(self): super().init_device() - # create the mib_loader - loader = mib_loader() + # if the string doesn't start with '/' it is a relative directory and we need to prepend the full path + '/' if self.SNMP_rel_mib_dir[0] != "/": @@ -119,8 +118,8 @@ class SNMP(lofar_device): # if the string does start with mib_path = self.SNMP_rel_mib_dir - # set the directory with the compiled mib files. - loader.set_pymib_dir(mib_path) + # create the mib_loader and set the mib path + loader = mib_loader(mib_path) for i in self.attr_list(): try: