self.streams.debug_stream("Connecting to community: %s, host: %s",self.community,self.host)
self.connected=True
returnTrue
defping(self):
"""
ping the client to make sure the connection with the client is still functional.
"""
pass
def_setup_annotation(self,annotation):
"""
This class's Implementation of the get_mapping function. returns the read and write functions
"""
ifisinstance(annotation,dict):
# check if required path inarg is present
ifannotation.get('oids')isNone:
AssertionError("SNMP get attributes require an oid")
oids=annotation.get("oids")# required
else:
TypeError("SNMP attributes require a dict with oid(s)")
return
returnoids
defsetup_value_conversion(self,attribute):
"""
gives the client access to the attribute_wrapper object in order to access all data it could potentially need.
"""
dim_x=attribute.dim_x
dim_y=attribute.dim_y
returndim_x,dim_y
defget_oids(self,x,y,in_oid):
ifx==0:
x=1
ify==0:
y=1
nof_oids=x*y
ifnof_oids==1:
# is scalar
iftype(in_oid)isstr:
# for ease of handling put single oid in a 1 element list
in_oid=[in_oid]
returnin_oid
eliftype(in_oid)islistandlen(in_oid)==nof_oids:
# already is an array and of the right length
returnin_oid
eliftype(in_oid)islistandlen(in_oid)!=nof_oids:
# already is an array but the wrong length. Unable to handle this
raiseValueError("SNMP oids need to either be a single value or an array the size of the attribute dimensions. got: {} expected: {}x{}={}".format(len(in_oid),x,y,x*y))
else:
out_oids=[]
foriinrange(nof_oids):
out_oids.append(in_oid+".{}".format(i+1))
returnout_oids
defsetup_attribute(self,annotation,attribute):
"""
MANDATORY function: is used by the attribute wrapper to get read/write functions. must return the read and write functions
"""
# process the annotation
oids=self._setup_annotation(annotation)
# get all the necessary data to set up the read/write functions from the attribute_wrapper