示例#1
0
    def uncfgCmdGen(self):
        for authData, paramsName in self.__knownAuths.items():
            if isinstance(authData, CommunityData):
                config.delV1System(
                    self.snmpEngine,
                    authData.securityName
                    )
                config.delTargetParams(
                    self.snmpEngine, paramsName
                    )
            elif isinstance(authData, UsmUserData):
                config.delV3User(
                    self.snmpEngine, authData.securityName
                    )
                config.delTargetParams(
                    self.snmpEngine, paramsName
                    )
            else:
                raise error.PySnmpError('Unsupported SNMP version')
        self.__knownAuths.clear()

        for transportDomain, transport in self.__knownTransports.items():
            config.delSocketTransport(
                self.snmpEngine, transportDomain
                )
            transport.closeTransport()
        self.__knownTransports.clear()

        for addrName in self.__knownTransportAddrs.values():
            config.delTargetAddr(
                self.snmpEngine, addrName
                )
        self.__knownTransportAddrs.clear()
示例#2
0
文件: lcd.py 项目: bbmorten/pysnmp
    def unconfigure(self, snmpEngine, authData=None):
        cache = self._getCache(snmpEngine)
        if authData:
            if isinstance(authData, CommunityData):
                authDataKey = authData.communityIndex
            elif isinstance(authData, UsmUserData):
                authDataKey = authData.userName, authData.securityEngineId
            else:
                raise error.PySnmpError('Unsupported authentication object')
            if authDataKey in cache['auth']:
                authDataKeys = (authDataKey,)
            else:
                raise error.PySnmpError('Unknown authData %s' % (authData,))
        else:
            authDataKeys = list(cache['auth'].keys())

        addrNames, paramsNames = set(), set()

        for authDataKey in authDataKeys:
            authDataX = cache['auth'][authDataKey]
            del cache['auth'][authDataKey]
            if isinstance(authDataX, CommunityData):
                config.delV1System(
                    snmpEngine,
                    authDataX.communityIndex
                )
            elif isinstance(authDataX, UsmUserData):
                config.delV3User(
                    snmpEngine,
                    authDataX.userName,
                    authDataX.securityEngineId
                )
            else:
                raise error.PySnmpError('Unsupported authentication object')

            paramsKey = (authDataX.securityName,
                         authDataX.securityLevel,
                         authDataX.mpModel)
            if paramsKey in cache['parm']:
                paramsName, useCount = cache['parm'][paramsKey]
                useCount -= 1
                if useCount:
                    cache['parm'][paramsKey] = paramsName, useCount
                else:
                    del cache['parm'][paramsKey]
                    config.delTargetParams(
                        snmpEngine, paramsName
                    )
                    paramsNames.add(paramsName)
            else:
                raise error.PySnmpError('Unknown target %s' % (paramsKey,))

            addrKeys = [x for x in cache['addr'] if x[0] == paramsName]

            for addrKey in addrKeys:
                addrName, useCount = cache['addr'][addrKey]
                useCount -= 1
                if useCount:
                    cache['addr'][addrKey] = addrName, useCount
                else:
                    config.delTargetAddr(snmpEngine, addrName)

                    addrNames.add(addrKey)

                    if addrKey[1] in cache['tran']:
                        transport, useCount = cache['tran'][addrKey[1]]
                        if useCount > 1:
                            useCount -= 1
                            cache['tran'][addrKey[1]] = transport, useCount
                        else:
                            config.delTransport(snmpEngine, addrKey[1])
                            transport.closeTransport()
                            del cache['tran'][addrKey[1]]

        return addrNames, paramsNames
示例#3
0
    def unconfigure(self,
                    snmpEngine,
                    authData=None,
                    contextName=null,
                    **options):
        cache = self._getCache(snmpEngine)

        if authData:
            if isinstance(authData, CommunityData):
                authDataKey = authData.communityIndex

            elif isinstance(authData, UsmUserData):
                authDataKey = authData.userName, authData.securityEngineId

            else:
                raise error.PySnmpError('Unsupported authentication object')

            if authDataKey in cache['auth']:
                authDataKeys = (authDataKey, )

            else:
                raise error.PySnmpError('Unknown authData %s' % (authData, ))

        else:
            authDataKeys = list(cache['auth'].keys())

        addrNames, paramsNames = set(), set()

        for authDataKey in authDataKeys:
            authDataX = cache['auth'][authDataKey]

            del cache['auth'][authDataKey]

            if isinstance(authDataX, CommunityData):
                config.delV1System(snmpEngine, authDataX.communityIndex)

            elif isinstance(authDataX, UsmUserData):
                config.delV3User(snmpEngine, authDataX.userName,
                                 authDataX.securityEngineId)

            else:
                raise error.PySnmpError('Unsupported authentication object')

            paramsKey = (authDataX.securityName, authDataX.securityLevel,
                         authDataX.mpModel)

            if paramsKey in cache['parm']:
                paramsName, useCount = cache['parm'][paramsKey]

                useCount -= 1

                if useCount:
                    cache['parm'][paramsKey] = paramsName, useCount

                else:
                    del cache['parm'][paramsKey]

                    config.delTargetParams(snmpEngine, paramsName)

                    paramsNames.add(paramsName)

            else:
                raise error.PySnmpError('Unknown target %s' % (paramsKey, ))

            addrKeys = [x for x in cache['addr'] if x[0] == paramsName]

            for addrKey in addrKeys:
                addrName, useCount = cache['addr'][addrKey]

                useCount -= 1

                if useCount:
                    cache['addr'][addrKey] = addrName, useCount

                else:
                    config.delTargetAddr(snmpEngine, addrName)

                    del cache['addr'][addrKey]

                    addrNames.add(addrKey)

                    if addrKey[1] in cache['tran']:
                        transport, useCount = cache['tran'][addrKey[1]]

                        if useCount > 1:
                            useCount -= 1
                            cache['tran'][addrKey[1]] = transport, useCount

                        else:
                            config.delTransport(snmpEngine, addrKey[1])
                            transport.closeTransport()

                            del cache['tran'][addrKey[1]]

        return addrNames, paramsNames
示例#4
0
    def uncfgCmdGen(self, authData=None):
        if authData:
            if isinstance(authData, CommunityData):
                authDataKey = authData.communityIndex
            elif isinstance(authData, UsmUserData):
                authDataKey = authData.userName, authData.securityEngineId
            else:
                raise error.PySnmpError('Unsupported authentication object')
            if authDataKey in self.__knownAuths:
                authDataKeys = (authDataKey, )
            else:
                raise error.PySnmpError('Unknown authData %s' % (authData, ))
        else:
            authDataKeys = list(self.__knownAuths.keys())

        addrNames, paramsNames = set(), set()

        for authDataKey in authDataKeys:
            authDataX = self.__knownAuths[authDataKey]
            del self.__knownAuths[authDataKey]
            if isinstance(authDataX, CommunityData):
                config.delV1System(self.snmpEngine, authDataX.communityIndex)
            elif isinstance(authDataX, UsmUserData):
                config.delV3User(self.snmpEngine, authDataX.userName,
                                 authDataX.securityEngineId)
            else:
                raise error.PySnmpError('Unsupported authentication object')

            paramsKey = authDataX.securityName, \
                        authDataX.securityLevel, \
                        authDataX.mpModel
            if paramsKey in self.__knownParams:
                paramsName, useCount = self.__knownParams[paramsKey]
                useCount -= 1
                if useCount:
                    self.__knownParams[paramsKey] = paramsName, useCount
                else:
                    del self.__knownParams[paramsKey]
                    config.delTargetParams(self.snmpEngine, paramsName)
                    paramsNames.add(paramsName)
            else:
                raise error.PySnmpError('Unknown target %s' % (paramsKey, ))

            addrKeys = [
                x for x in self.__knownTransportAddrs if x[0] == paramsName
            ]

            for addrKey in addrKeys:
                addrName, useCount = self.__knownTransportAddrs[addrKey]
                useCount -= 1
                if useCount:
                    self.__knownTransportAddrs[addrKey] = addrName, useCount
                else:
                    config.delTargetAddr(self.snmpEngine, addrName)

                    addrNames.add(addrKey)

                    if addrKey[1] in self.__knownTransports:
                        transport, useCount = self.__knownTransports[
                            addrKey[1]]
                        if useCount > 1:
                            useCount -= 1
                            self.__knownTransports[
                                addrKey[1]] = transport, useCount
                        else:
                            config.delTransport(self.snmpEngine, addrKey[1])
                            transport.closeTransport()
                            del self.__knownTransports[addrKey[1]]

        return addrNames, paramsNames
    def uncfgCmdGen(self, authData=None):
        if authData:
            if isinstance(authData, CommunityData):
                authDataKey = authData.communityIndex
            elif isinstance(authData, UsmUserData):
                authDataKey = authData.userName, authData.securityEngineId
            else:
                raise error.PySnmpError('Unsupported authentication object')
            if authDataKey in self.__knownAuths:
                authDataKeys = ( authDataKey, )
            else:
                raise error.PySnmpError('Unknown authData %s' % (authData,))
        else:
            authDataKeys = list(self.__knownAuths.keys())

        addrNames, paramsNames = set(), set()

        for authDataKey in authDataKeys:
            authDataX = self.__knownAuths[authDataKey] 
            del self.__knownAuths[authDataKey]
            if isinstance(authDataX, CommunityData):
                config.delV1System(
                    self.snmpEngine,
                    authDataX.communityIndex
                )
            elif isinstance(authDataX, UsmUserData):
                config.delV3User(
                    self.snmpEngine,
                    authDataX.userName, 
                    authDataX.securityEngineId
                )
            else:
                raise error.PySnmpError('Unsupported authentication object')

            paramsKey = authDataX.securityName, \
                        authDataX.securityLevel, \
                        authDataX.mpModel
            if paramsKey in self.__knownParams:
                paramsName, useCount = self.__knownParams[paramsKey]
                useCount -= 1
                if useCount:
                    self.__knownParams[paramsKey] = paramsName, useCount
                else:
                    del self.__knownParams[paramsKey]
                    config.delTargetParams(
                        self.snmpEngine, paramsName
                    )
                    paramsNames.add(paramsName)
            else:
                raise error.PySnmpError('Unknown target %s' % (paramsKey,))

            addrKeys = [ x for x in self.__knownTransportAddrs if x[0] == paramsName ]

            for addrKey in addrKeys:
                addrName, useCount = self.__knownTransportAddrs[addrKey]
                useCount -= 1
                if useCount:
                    self.__knownTransportAddrs[addrKey] = addrName, useCount
                else:
                    config.delTargetAddr(self.snmpEngine, addrName)

                    addrNames.add(addrKey)

                    if addrKey[1] in self.__knownTransports:
                        transport, useCount = self.__knownTransports[addrKey[1]]
                        if useCount > 1:
                            useCount -= 1
                            self.__knownTransports[addrKey[1]] = transport, useCount
                        else:
                            config.delTransport(self.snmpEngine, addrKey[1])
                            transport.closeTransport()
                            del self.__knownTransports[addrKey[1]]

        return addrNames, paramsNames