Beispiel #1
0
 def getParentNodeName(self, nodeName, modName=''):
     oid, label, suffix = self.getNodeName(nodeName, modName)
     if len(oid) < 2:
         raise error.NoSuchObjectError(
             str='No parent name for %s::%s at %s' %
             (modName, nodeName, self))
     return oid[:-1], label[:-1], oid[-1:] + suffix
Beispiel #2
0
 def getOrderedNodeName(self, index, modName=''):
     self.indexMib()
     if modName in self.__mibSymbolsIdx:
         mibMod = self.__mibSymbolsIdx[modName]
     else:
         raise error.SmiError('No module %s at %s' % (modName, self))
     if not mibMod['oidToLabelIdx']:
         raise error.NoSuchObjectError(
             str='No variables at MIB module %s at %s' % (modName, self))
     try:
         oid, label = mibMod['oidToLabelIdx'].items()[index]
     except KeyError:
         raise error.NoSuchObjectError(
             str='No symbol at position %s in MIB module %s at %s' %
             (index, modName, self))
     return oid, label, ()
Beispiel #3
0
 def getNextType(self, typeName, modName=''):
     m, t = self.getTypeName(typeName, modName)
     try:
         return self.__mibSymbolsIdx[m]['typeToModIdx'].nextKey(t)
     except KeyError:
         raise error.NoSuchObjectError(str='No type next to %s::%s at %s' %
                                       (modName, typeName, self))
Beispiel #4
0
    def getBranch(self, name, idx):
        """Return a branch of this tree where the 'name' OID may reside"""
        for keyLen in self._vars.getKeysLens():
            subName = name[:keyLen]
            if subName in self._vars:
                return self._vars[subName]

        raise error.NoSuchObjectError(name=name, idx=idx)
Beispiel #5
0
 def getBranch(self, name, idx):
     """Return a branch of this tree where the 'name' OID may reside"""
     name = tuple(name)  # XXX
     if len(self.name) < len(name):
         for keyLen in self._vars.getKeysLens():
             subName = name[:keyLen]
             if self._vars.has_key(subName):
                 return self._vars[subName]
     raise error.NoSuchObjectError(name=name, idx=idx)
Beispiel #6
0
 def getNextNodeName(self, nodeName, modName=''):
     oid, label, suffix = self.getNodeName(nodeName, modName)
     try:
         return self.getNodeName(
             self.__mibSymbolsIdx[modName]['oidToLabelIdx'].nextKey(oid) +
             suffix, modName)
     except KeyError:
         raise error.NoSuchObjectError(str='No name next to %s::%s at %s' %
                                       (modName, nodeName, self))
Beispiel #7
0
 def getNextBranch(self, name, idx=None):
     # Start from the beginning
     if self._vars: first = list(self._vars.keys())[0]
     if self._vars and name < first:
         return self._vars[first]
     else:
         try:
             return self._vars[self._vars.nextKey(name)]
         except KeyError:
             raise error.NoSuchObjectError(idx=idx, name=name)
Beispiel #8
0
 def getFirstTypeName(self, modName=''):
     self.indexMib()
     mibMod = self.__mibSymbolsIdx.get(modName)
     if mibMod is None:
         raise error.SmiError('No module %s at %s' % (modName, self))
     if not mibMod['typeToModIdx']:
         raise error.NoSuchObjectError(
             str='No types at MIB module %s at %s' % (modName, self))
     t = mibMod['typeToModIdx'].keys()[0]
     return mibMod['typeToModIdx'][t], t
Beispiel #9
0
 def getTypeName(self, typeName, modName=''):
     self.indexMib()
     mibMod = self.__mibSymbolsIdx.get(modName)
     if mibMod is None:
         raise error.SmiError('No module %s at %s' % (modName, self))
     m = mibMod['typeToModIdx'].get(typeName)
     if m is None:
         raise error.NoSuchObjectError(str='No such type %s::%s at %s' %
                                       (modName, typeName, self))
     return m, typeName
Beispiel #10
0
 def getFirstNodeName(self, modName=''):
     self.indexMib()
     mibMod = self.__mibSymbolsIdx.get(modName)
     if mibMod is None:
         raise error.SmiError('No module %s at %s' % (modName, self))
     if not mibMod['oidToLabelIdx']:
         raise error.NoSuchObjectError(
             str='No variables at MIB module %s at %s' % (modName, self))
     oid, label = mibMod['oidToLabelIdx'].items()[0]
     return oid, label, ()
Beispiel #11
0
 def getOrderedTypeName(self, index, modName=''):
     self.indexMib()
     if modName in self.__mibSymbolsIdx:
         mibMod = self.__mibSymbolsIdx[modName]
     else:
         raise error.SmiError('No module %s at %s' % (modName, self))
     if not mibMod['typeToModIdx']:
         raise error.NoSuchObjectError(
             str='No types at MIB module %s at %s' % (modName, self))
     t = mibMod['typeToModIdx'].keys()[index]
     return mibMod['typeToModIdx'][t], t
Beispiel #12
0
 def getTypeName(self, typeName, modName=''):
     self.indexMib()
     if modName in self.__mibSymbolsIdx:
         mibMod = self.__mibSymbolsIdx[modName]
     else:
         raise error.SmiError('No module %s at %s' % (modName, self))
     if typeName in mibMod['typeToModIdx']:
         m = mibMod['typeToModIdx'][typeName]
     else:
         raise error.NoSuchObjectError(str='No such type %s::%s at %s' %
                                       (modName, typeName, self))
     return m, typeName
Beispiel #13
0
 def getNodeNameByDesc(self, nodeName, modName=''):
     self.indexMib()
     mibMod = self.__mibSymbolsIdx.get(modName)
     if mibMod is None:
         raise error.SmiError('No module %s at %s' % (modName, self))
     oid = mibMod['varToNameIdx'].get(nodeName)
     if oid is None:
         raise error.NoSuchObjectError(str='No such symbol %s::%s at %s' %
                                       (modName, nodeName, self))
     debug.logger & debug.flagMIB and debug.logger(
         'getNodeNameByDesc: resolved %s:%s -> %s' %
         (modName, nodeName, oid))
     return self.getNodeNameByOid(oid, modName)
Beispiel #14
0
 def getNextBranch(self, name, **context):
     # Start from the beginning
     if self._vars:
         first = list(self._vars.keys())[0]
     else:
         first = ()
     if self._vars and name < first:
         return self._vars[first]
     else:
         try:
             return self._vars[self._vars.nextKey(name)]
         except KeyError:
             raise error.NoSuchObjectError(name=name, idx=context.get('idx'))
Beispiel #15
0
 def getNextNode(self, name, idx=None):
     """Return tree node next to name"""
     try:
         nextNode = self.getBranch(name, idx)
     except error.NoSuchObjectError:
         # Start from the beginning
         if self._vars and name <= self._vars.keys()[0]:
             return self._vars[self._vars.keys()[0]]
         else:
             # Try following the white rabbit at our level
             try:
                 return self._vars[self._vars.nextKey(name)]
             except KeyError:
                 raise error.NoSuchObjectError(idx=idx, name=name)
     else:
         try:
             return nextNode.getNextNode(name, idx)
         except error.NoSuchObjectError:
             try:
                 return self._vars[self._vars.nextKey(nextNode.name)]
             except KeyError:
                 raise error.NoSuchObjectError(idx=idx, name=name)
Beispiel #16
0
 def getNextNode(self, name, idx=None):
     """Return tree node next to name"""
     try:
         nextNode = self.getBranch(name, idx)
     except (error.NoSuchInstanceError, error.NoSuchObjectError):
         return self.getNextBranch(name, idx)
     else:
         try:
             return nextNode.getNextNode(name, idx)
         except (error.NoSuchInstanceError, error.NoSuchObjectError):
             try:
                 return self._vars[self._vars.nextKey(nextNode.name)]
             except KeyError:
                 raise error.NoSuchObjectError(idx=idx, name=name)
Beispiel #17
0
 def getNodeNameByOid(self, nodeName, modName=''):
     self.indexMib()
     mibMod = self.__mibSymbolsIdx.get(modName)
     if mibMod is None:
         raise error.SmiError('No module %s at %s' % (modName, self))
     oid, label, suffix = self.__getOidLabel(nodeName,
                                             mibMod['oidToLabelIdx'],
                                             mibMod['labelToOidIdx'])
     if oid == label:
         raise error.NoSuchObjectError(
             str='Can\'t resolve node name %s::%s at %s' %
             (modName, nodeName, self))
     debug.logger & debug.flagMIB and debug.logger(
         'getNodeNameByOid: resolved %s:%s -> %s' %
         (modName, nodeName, label + suffix))
     return oid, label, suffix
Beispiel #18
0
    def getNodeNameByDesc(self, nodeName, modName=''):
        self.indexMib()

        if modName in self._mibSymbolsIdx:
            mibMod = self._mibSymbolsIdx[modName]

        else:
            raise error.SmiError('No module %s at %s' % (modName, self))

        if nodeName in mibMod['varToNameIdx']:
            oid = mibMod['varToNameIdx'][nodeName]

        else:
            raise error.NoSuchObjectError(str='No such symbol %s::%s at '
                                          '%s' % (modName, nodeName, self))

        debug.logger & debug.FLAG_MIB and debug.logger(
            'getNodeNameByDesc: resolved %s:%s -> '
            '%s' % (modName, nodeName, oid))

        return self.getNodeNameByOid(oid, modName)
Beispiel #19
0
    def getNodeNameByOid(self, nodeName, modName=''):
        self.indexMib()

        if modName in self._mibSymbolsIdx:
            mibMod = self._mibSymbolsIdx[modName]

        else:
            raise error.SmiError('No module %s at %s' % (modName, self))

        oid, label, suffix = self._getOidLabel(nodeName,
                                               mibMod['oidToLabelIdx'],
                                               mibMod['labelToOidIdx'])

        if oid == label:
            raise error.NoSuchObjectError(
                str='Cannot resolve node name %s::%s at '
                '%s' % (modName, nodeName, self))

        debug.logger & debug.FLAG_MIB and debug.logger(
            'getNodeNameByOid: resolved %s:%s -> '
            '%s.%s' % (modName, nodeName, label, suffix))

        return oid, label, suffix
Beispiel #20
0
class MibScalarInstance(MibTree):
    """Scalar MIB variable instance. Implements read/write operations."""
    def __init__(self, typeName, instId, syntax):
        MibTree.__init__(self, typeName + instId, syntax)
        self.typeName = typeName
        self.instId = instId
        self.__oldSyntax = None

    def getNode(self, name, idx=None):
        # Recursion terminator
        if name == self.name:
            return self
        raise error.NoSuchInstanceError(idx=idx, name=name)

    def getNextNode(self, name, idx=None):
        raise error.NoSuchInstanceError(idx=idx, name=name)

    # MIB instrumentation methods

    # Read operation

    def readTest(self, name, val, idx, (acFun, acCtx)):
        if name != self.name:
            raise error.NoSuchObjectError(idx=idx, name=name)
Beispiel #21
0
 def writeVars(self, varBinds, acInfo=(None, None)):
     raise error.NoSuchObjectError(idx=0)
Beispiel #22
0
 def writeVars(self, *varBinds, **context):
     raise error.NoSuchObjectError(idx=0)
Beispiel #23
0
    # Read operation

    def readTest(self, name, val, idx, (acFun, acCtx)):
        if name != self.name:
            raise error.NoSuchObjectError(idx=idx, name=name)

    def readGet(self, name, val, idx, (acFun, acCtx)):
        # Return current variable (name, value). This is the only API method
        # capable of returning anything!
        if name == self.name:
            debug.logger & debug.flagIns and debug.logger(
                'readGet: %s=%s' % (self.name, self.syntax))
            return self.name, self.syntax.clone()
        else:
            raise error.NoSuchObjectError(idx=idx, name=name)

    # Write operation: two-phase commit

    def writeTest(self, name, val, idx, (acFun, acCtx)):
        # Make sure write's allowed
        if name == self.name:
            if hasattr(self.syntax, 'smiWrite'):
                self.__newSyntax = self.syntax.smiWrite(name, val, idx)
            else:
                self.__newSyntax = self.syntax.clone(val)
            if hasattr(self.__newSyntax, 'smiRaisePendingError'):
                self.__newSyntax.smiRaisePendingError()
        else:
            raise error.NoSuchObjectError(idx=idx, name=name)