MIB compiler¶
- class pysmi.compiler.MibCompiler(parser, codegen: AbstractCodeGen, writer: AbstractWriter)¶
Top-level, user-facing, composite MIB compiler object.
MibCompiler implements high-level MIB transformation processing logic. It executes its actions by calling the following specialized objects:
readers - to acquire ASN.1 MIB data
searchers - to see if transformed MIB already exists and no processing is necessary
parser - to parse ASN.1 MIB into AST
code generator - to perform actual MIB transformation
borrowers - to fetch pre-transformed MIB if transformation is impossible
writer - to store transformed MIB data
Required components must be passed to MibCompiler on instantiation. Those components are: parser, codegenerator and writer.
Optional components could be set or modified at later phases of MibCompiler life. Unlike singular, required components, optional one can be present in sequences to address many possible sources of data. They are readers, searchers and borrowers.
Creates an instance of MibCompiler class.
- Parameters:
parser – ASN.1 MIB parser object
codegen – MIB transformation object
writer – transformed MIB storing object
- add_borrowers(*borrowers)¶
Add more transformed MIBs repositories to borrow MIBs from.
Whenever MibCompiler.compile encounters MIB module which neither of the searchers can find or fetched ASN.1 MIB module can not be parsed (due to syntax errors), these borrowers objects will be invoked in order of their addition asking each if already transformed MIB can be fetched (borrowed).
- Parameters:
borrowers – borrower object(s)
- Returns:
reference to itself (can be used for call chaining)
- add_searchers(*searchers)¶
Add more transformed MIBs repositories.
MibCompiler.compile will invoke each of configured searcher objects in order of their addition asking each if already transformed MIB module already exists and is more recent than specified.
- Parameters:
searchers – searcher object(s)
- Returns:
reference to itself (can be used for call chaining)
- add_sources(*sources)¶
Add more ASN.1 MIB source repositories.
MibCompiler.compile will invoke each of configured source objects in order of their addition asking each to fetch MIB module specified by name.
- Parameters:
sources – reader object(s)
- Returns:
reference to itself (can be used for call chaining)
- compile(*mibnames, **options)¶
Transform requested and possibly referred MIBs.
The compile method should be invoked when MibCompiler object is operational meaning at least sources are specified.
Once called with a MIB module name, compile will:
fetch ASN.1 MIB module with given name by calling sources
make sure no such transformed MIB already exists (with searchers)
parse ASN.1 MIB text with parser
perform actual MIB transformation into target format with code generator
may attempt to borrow pre-transformed MIB through borrowers
write transformed MIB through writer
The above sequence will be performed for each MIB name given in mibnames and may be performed for all MIBs referred to from MIBs being processed.
- Parameters:
mibnames – list of ASN.1 MIBs names
options – options that affect the way PySMI components work
- Returns:
A dictionary of MIB module names processed (keys) and MibStatus class instances (values)