Ejemplo n.º 1
0
class DomainBase(object):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky", "domain")
        self.myAgent = None
        self.myNetworkOperationRetryMax = 100
        self.myNetworkOperationRetryIntervalMili = 100

    def __str__(self):
        return "name=%s" % self.myName

    def init(self, agent, name):
        self.myInitGuard.crashIfInitDone()
        self.myName = name
        self._log.setInstance(self.myName)
        self.myAgent = agent

        res = self.specificInit()
        if res != ReturnCodes.kOk:
            for logFunc in self._log('init-specific-failed').errorFunc():
                logFunc('specificInit() failed. res=%s', res)
            a.infra.process.processFatal("domain %s: specificInif() failed.",
                                         self.myName)

        for logFunc in self._log("init").debug2Func():
            logFunc("Initialized")
        self.myInitGuard.initDone()

    def destroy(self):
        raise NotImplementedError()

    def shutdown(self):
        for logFunc in self._log("shutdown").noticeFunc():
            logFunc("shutting down")
        self.specificShutdown()

    def setNetworkOperationRetryLimits(self, maxRetries, retryIntervalMili):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                "set-network-operation-retry-limits").debug3Func():
            logFunc(
                "setNetworkOperationRetryLimits(): called: retryIntervalMili=%s, maxRetries=%s",
                retryIntervalMili, maxRetries)
        self.myNetworkOperationRetryMax = maxRetries
        self.myNetworkOperationRetryIntervalMili = retryIntervalMili

    def getName(self):
        self.myInitGuard.isInitOrCrash()
        return self.myName
Ejemplo n.º 2
0
class DomainBase (object):

    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky", "domain")
        self.myAgent = None
        self.myNetworkOperationRetryMax=100
        self.myNetworkOperationRetryIntervalMili=100

    def __str__ (self):
        return "name=%s" % self.myName

    def init (self, agent, name):
        self.myInitGuard.crashIfInitDone()
        self.myName=name
        self._log.setInstance(self.myName)
        self.myAgent=agent

        res = self.specificInit()
        if res != ReturnCodes.kOk:
            for logFunc in self._log('init-specific-failed').errorFunc(): logFunc('specificInit() failed. res=%s', res)
            a.infra.process.processFatal("domain %s: specificInif() failed.", self.myName)

        for logFunc in self._log("init").debug2Func(): logFunc("Initialized")
        self.myInitGuard.initDone()

    def destroy(self):
        raise NotImplementedError()
    
    def shutdown (self):
        for logFunc in self._log("shutdown").noticeFunc(): logFunc("shutting down")
        self.specificShutdown()

    def setNetworkOperationRetryLimits(self, maxRetries, retryIntervalMili):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log("set-network-operation-retry-limits").debug3Func():
            logFunc("setNetworkOperationRetryLimits(): called: retryIntervalMili=%s, maxRetries=%s",
                    retryIntervalMili, maxRetries)
        self.myNetworkOperationRetryMax = maxRetries
        self.myNetworkOperationRetryIntervalMili = retryIntervalMili
    
    def getName (self):
        self.myInitGuard.isInitOrCrash()
        return self.myName
Ejemplo n.º 3
0
class BlinkyArpMaapi(ArpMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-arp")
        self.domain = None

        self.testTimeoutMsecRequested = False
        self.testTimeoutMsec = None
        self.testTimeoutMsecSet = False

        self.testIntervalMsecRequested = False
        self.testIntervalMsec = None
        self.testIntervalMsecSet = False

        self.upPeriodRequested = False
        self.upPeriod = None
        self.upPeriodSet = False

        self.downPeriodRequested = False
        self.downPeriod = None
        self.downPeriodSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestTestTimeoutMsec(True)

        self.requestTestIntervalMsec(True)

        self.requestUpPeriod(True)

        self.requestDownPeriod(True)

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestTestTimeoutMsec(True)

        self.requestTestIntervalMsec(True)

        self.requestUpPeriod(True)

        self.requestDownPeriod(True)

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestTestTimeoutMsec(False)

        self.requestTestIntervalMsec(False)

        self.requestUpPeriod(False)

        self.requestDownPeriod(False)

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestTestTimeoutMsec(False)

        self.requestTestIntervalMsec(False)

        self.requestUpPeriod(False)

        self.requestDownPeriod(False)

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

        self.setTestTimeoutMsec(None)
        self.testTimeoutMsecSet = False

        self.setTestIntervalMsec(None)
        self.testIntervalMsecSet = False

        self.setUpPeriod(None)
        self.upPeriodSet = False

        self.setDownPeriod(None)
        self.downPeriodSet = False

    def write(self, interface, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(interface, trxContext)

    def read(self, interface, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(interface, False, trxContext)

    def readAllOrFail(self, interface, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(interface, True, trxContext)

    def requestTestTimeoutMsec(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-testtimeoutmsec').debug3Func():
            logFunc('called. requested=%s', requested)
        self.testTimeoutMsecRequested = requested
        self.testTimeoutMsecSet = False

    def isTestTimeoutMsecRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-testtimeoutmsec-requested').debug3Func():
            logFunc('called. requested=%s', self.testTimeoutMsecRequested)
        return self.testTimeoutMsecRequested

    def getTestTimeoutMsec(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-testtimeoutmsec').debug3Func():
            logFunc(
                'called. self.testTimeoutMsecSet=%s, self.testTimeoutMsec=%s',
                self.testTimeoutMsecSet, self.testTimeoutMsec)
        if self.testTimeoutMsecSet:
            return self.testTimeoutMsec
        return None

    def hasTestTimeoutMsec(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-testtimeoutmsec').debug3Func():
            logFunc(
                'called. self.testTimeoutMsecSet=%s, self.testTimeoutMsec=%s',
                self.testTimeoutMsecSet, self.testTimeoutMsec)
        if self.testTimeoutMsecSet:
            return True
        return False

    def setTestTimeoutMsec(self, testTimeoutMsec):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-testtimeoutmsec').debug3Func():
            logFunc('called. testTimeoutMsec=%s, old=%s', testTimeoutMsec,
                    self.testTimeoutMsec)
        self.testTimeoutMsecSet = True
        self.testTimeoutMsec = testTimeoutMsec

    def requestTestIntervalMsec(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-testintervalmsec').debug3Func():
            logFunc('called. requested=%s', requested)
        self.testIntervalMsecRequested = requested
        self.testIntervalMsecSet = False

    def isTestIntervalMsecRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-testintervalmsec-requested').debug3Func():
            logFunc('called. requested=%s', self.testIntervalMsecRequested)
        return self.testIntervalMsecRequested

    def getTestIntervalMsec(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-testintervalmsec').debug3Func():
            logFunc(
                'called. self.testIntervalMsecSet=%s, self.testIntervalMsec=%s',
                self.testIntervalMsecSet, self.testIntervalMsec)
        if self.testIntervalMsecSet:
            return self.testIntervalMsec
        return None

    def hasTestIntervalMsec(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-testintervalmsec').debug3Func():
            logFunc(
                'called. self.testIntervalMsecSet=%s, self.testIntervalMsec=%s',
                self.testIntervalMsecSet, self.testIntervalMsec)
        if self.testIntervalMsecSet:
            return True
        return False

    def setTestIntervalMsec(self, testIntervalMsec):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-testintervalmsec').debug3Func():
            logFunc('called. testIntervalMsec=%s, old=%s', testIntervalMsec,
                    self.testIntervalMsec)
        self.testIntervalMsecSet = True
        self.testIntervalMsec = testIntervalMsec

    def requestUpPeriod(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-upperiod').debug3Func():
            logFunc('called. requested=%s', requested)
        self.upPeriodRequested = requested
        self.upPeriodSet = False

    def isUpPeriodRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-upperiod-requested').debug3Func():
            logFunc('called. requested=%s', self.upPeriodRequested)
        return self.upPeriodRequested

    def getUpPeriod(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-upperiod').debug3Func():
            logFunc('called. self.upPeriodSet=%s, self.upPeriod=%s',
                    self.upPeriodSet, self.upPeriod)
        if self.upPeriodSet:
            return self.upPeriod
        return None

    def hasUpPeriod(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-upperiod').debug3Func():
            logFunc('called. self.upPeriodSet=%s, self.upPeriod=%s',
                    self.upPeriodSet, self.upPeriod)
        if self.upPeriodSet:
            return True
        return False

    def setUpPeriod(self, upPeriod):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-upperiod').debug3Func():
            logFunc('called. upPeriod=%s, old=%s', upPeriod, self.upPeriod)
        self.upPeriodSet = True
        self.upPeriod = upPeriod

    def requestDownPeriod(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-downperiod').debug3Func():
            logFunc('called. requested=%s', requested)
        self.downPeriodRequested = requested
        self.downPeriodSet = False

    def isDownPeriodRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-downperiod-requested').debug3Func():
            logFunc('called. requested=%s', self.downPeriodRequested)
        return self.downPeriodRequested

    def getDownPeriod(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-downperiod').debug3Func():
            logFunc('called. self.downPeriodSet=%s, self.downPeriod=%s',
                    self.downPeriodSet, self.downPeriod)
        if self.downPeriodSet:
            return self.downPeriod
        return None

    def hasDownPeriod(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-downperiod').debug3Func():
            logFunc('called. self.downPeriodSet=%s, self.downPeriod=%s',
                    self.downPeriodSet, self.downPeriod)
        if self.downPeriodSet:
            return True
        return False

    def setDownPeriod(self, downPeriod):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-downperiod').debug3Func():
            logFunc('called. downPeriod=%s, old=%s', downPeriod,
                    self.downPeriod)
        self.downPeriodSet = True
        self.downPeriod = downPeriod

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        self.testTimeoutMsec = 0
        self.testTimeoutMsecSet = False

        self.testIntervalMsec = 0
        self.testIntervalMsecSet = False

        self.upPeriod = 0
        self.upPeriodSet = False

        self.downPeriod = 0
        self.downPeriodSet = False

    def _getSelfKeyPath(self, interface, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("arp",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
             "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("ipv4",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
             "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("connectivity-check",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
             "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)

        ancestorVal = Value()
        ancestorVal.setString(interface)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("interface",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
             "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("interfaces",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
             "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, interface, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(interface, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(interface, None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, interface, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(interface, None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, interface, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.hasTestTimeoutMsec():
            valTestTimeoutMsec = Value()
            if self.testTimeoutMsec is not None:
                valTestTimeoutMsec.setInt64(self.testTimeoutMsec)
            else:
                valTestTimeoutMsec.setEmpty()
            tagValueList.push(
                ("test-timeout-msec",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"),
                valTestTimeoutMsec)

        if self.hasTestIntervalMsec():
            valTestIntervalMsec = Value()
            if self.testIntervalMsec is not None:
                valTestIntervalMsec.setInt64(self.testIntervalMsec)
            else:
                valTestIntervalMsec.setEmpty()
            tagValueList.push(
                ("test-interval-msec",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"),
                valTestIntervalMsec)

        if self.hasUpPeriod():
            valUpPeriod = Value()
            if self.upPeriod is not None:
                valUpPeriod.setInt64(self.upPeriod)
            else:
                valUpPeriod.setEmpty()
            tagValueList.push(
                ("up-period",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"),
                valUpPeriod)

        if self.hasDownPeriod():
            valDownPeriod = Value()
            if self.downPeriod is not None:
                valDownPeriod.setInt64(self.downPeriod)
            else:
                valDownPeriod.setEmpty()
            tagValueList.push(
                ("down-period",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"),
                valDownPeriod)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isTestTimeoutMsecRequested():
            valTestTimeoutMsec = Value()
            valTestTimeoutMsec.setEmpty()
            tagValueList.push(
                ("test-timeout-msec",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"),
                valTestTimeoutMsec)

        if self.isTestIntervalMsecRequested():
            valTestIntervalMsec = Value()
            valTestIntervalMsec.setEmpty()
            tagValueList.push(
                ("test-interval-msec",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"),
                valTestIntervalMsec)

        if self.isUpPeriodRequested():
            valUpPeriod = Value()
            valUpPeriod.setEmpty()
            tagValueList.push(
                ("up-period",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"),
                valUpPeriod)

        if self.isDownPeriodRequested():
            valDownPeriod = Value()
            valDownPeriod.setEmpty()
            tagValueList.push(
                ("down-period",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"),
                valDownPeriod)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isTestTimeoutMsecRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "test-timeout-msec") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-testtimeoutmsec'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "testTimeoutMsec", "test-timeout-msec",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-test-timeout-msec-bad-value'
                ).infoFunc():
                    logFunc('testTimeoutMsec not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setTestTimeoutMsec(tempVar)
            for logFunc in self._log(
                    'read-tag-values-test-timeout-msec').debug3Func():
                logFunc(
                    'read testTimeoutMsec. testTimeoutMsec=%s, tempValue=%s',
                    self.testTimeoutMsec, tempValue.getType())

        if self.isTestIntervalMsecRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "test-interval-msec") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-testintervalmsec'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "testIntervalMsec", "test-interval-msec",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-test-interval-msec-bad-value'
                ).infoFunc():
                    logFunc('testIntervalMsec not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setTestIntervalMsec(tempVar)
            for logFunc in self._log(
                    'read-tag-values-test-interval-msec').debug3Func():
                logFunc(
                    'read testIntervalMsec. testIntervalMsec=%s, tempValue=%s',
                    self.testIntervalMsec, tempValue.getType())

        if self.isUpPeriodRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "up-period") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-upperiod'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "upPeriod", "up-period",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-up-period-bad-value').infoFunc():
                    logFunc('upPeriod not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setUpPeriod(tempVar)
            for logFunc in self._log('read-tag-values-up-period').debug3Func():
                logFunc('read upPeriod. upPeriod=%s, tempValue=%s',
                        self.upPeriod, tempValue.getType())

        if self.isDownPeriodRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "down-period") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-downperiod'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "downPeriod", "down-period",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-down-period-bad-value').infoFunc():
                    logFunc('downPeriod not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setDownPeriod(tempVar)
            for logFunc in self._log(
                    'read-tag-values-down-period').debug3Func():
                logFunc('read downPeriod. downPeriod=%s, tempValue=%s',
                        self.downPeriod, tempValue.getType())

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 4
0
class BlinkyStatusMaapi(StatusMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-status")
        self.domain = None

        self.versionRequested = False
        self.version = None
        self.versionSet = False

        self.healthRequested = False
        self.health = None
        self.healthSet = False

        self.numOfCracksRequested = False
        self.numOfCracks = None
        self.numOfCracksSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestVersion(True)

        self.requestHealth(True)

        self.requestNumOfCracks(True)

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestVersion(False)

        self.requestHealth(False)

        self.requestNumOfCracks(False)

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestVersion(True)

        self.requestHealth(True)

        self.requestNumOfCracks(True)

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestVersion(False)

        self.requestHealth(False)

        self.requestNumOfCracks(False)

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

    def write(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(trxContext)

    def read(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(False, trxContext)

    def readAllOrFail(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(True, trxContext)

    def requestVersion(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-version').debug3Func():
            logFunc('called. requested=%s', requested)
        self.versionRequested = requested
        self.versionSet = False

    def isVersionRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-version-requested').debug3Func():
            logFunc('called. requested=%s', self.versionRequested)
        return self.versionRequested

    def getVersion(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-version').debug3Func():
            logFunc('called. self.versionSet=%s, self.version=%s',
                    self.versionSet, self.version)
        if self.versionSet:
            return self.version
        return None

    def hasVersion(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-version').debug3Func():
            logFunc('called. self.versionSet=%s, self.version=%s',
                    self.versionSet, self.version)
        if self.versionSet:
            return True
        return False

    def setVersion(self, version):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-version').debug3Func():
            logFunc('called. version=%s, old=%s', version, self.version)
        self.versionSet = True
        self.version = version

    def requestHealth(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-health').debug3Func():
            logFunc('called. requested=%s', requested)
        self.healthRequested = requested
        self.healthSet = False

    def isHealthRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-health-requested').debug3Func():
            logFunc('called. requested=%s', self.healthRequested)
        return self.healthRequested

    def getHealth(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-health').debug3Func():
            logFunc('called. self.healthSet=%s, self.health=%s',
                    self.healthSet, self.health)
        if self.healthSet:
            return self.health
        return None

    def hasHealth(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-health').debug3Func():
            logFunc('called. self.healthSet=%s, self.health=%s',
                    self.healthSet, self.health)
        if self.healthSet:
            return True
        return False

    def setHealth(self, health):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-health').debug3Func():
            logFunc('called. health=%s, old=%s', health, self.health)
        self.healthSet = True
        self.health = health

    def requestNumOfCracks(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-numofcracks').debug3Func():
            logFunc('called. requested=%s', requested)
        self.numOfCracksRequested = requested
        self.numOfCracksSet = False

    def isNumOfCracksRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-numofcracks-requested').debug3Func():
            logFunc('called. requested=%s', self.numOfCracksRequested)
        return self.numOfCracksRequested

    def getNumOfCracks(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-numofcracks').debug3Func():
            logFunc('called. self.numOfCracksSet=%s, self.numOfCracks=%s',
                    self.numOfCracksSet, self.numOfCracks)
        if self.numOfCracksSet:
            return self.numOfCracks
        return None

    def hasNumOfCracks(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-numofcracks').debug3Func():
            logFunc('called. self.numOfCracksSet=%s, self.numOfCracks=%s',
                    self.numOfCracksSet, self.numOfCracks)
        if self.numOfCracksSet:
            return True
        return False

    def setNumOfCracks(self, numOfCracks):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-numofcracks').debug3Func():
            logFunc('called. numOfCracks=%s, old=%s', numOfCracks,
                    self.numOfCracks)
        self.numOfCracksSet = True
        self.numOfCracks = numOfCracks

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        self.version = 0
        self.versionSet = False

        self.health = 0
        self.healthSet = False

        self.numOfCracks = 0
        self.numOfCracksSet = False

    def _getSelfKeyPath(self, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag((
            "status",
            "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example",
            "se"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag((
            "chair",
            "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example",
            "se"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isVersionRequested():
            valVersion = Value()
            valVersion.setEmpty()
            tagValueList.push((
                "version",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"
            ), valVersion)

        if self.isHealthRequested():
            valHealth = Value()
            valHealth.setEmpty()
            tagValueList.push((
                "health",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"
            ), valHealth)

        if self.isNumOfCracksRequested():
            valNumOfCracks = Value()
            valNumOfCracks.setEmpty()
            tagValueList.push((
                "num-of-cracks",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"
            ), valNumOfCracks)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isVersionRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "version") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-version'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "version", "version",
                        "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-version-bad-value').infoFunc():
                    logFunc('version not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setVersion(tempVar)
            for logFunc in self._log('read-tag-values-version').debug3Func():
                logFunc('read version. version=%s, tempValue=%s', self.version,
                        tempValue.getType())

        if self.isHealthRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "health") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-health'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "health", "health",
                        "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-health-bad-value').infoFunc():
                    logFunc('health not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setHealth(tempVar)
            for logFunc in self._log('read-tag-values-health').debug3Func():
                logFunc('read health. health=%s, tempValue=%s', self.health,
                        tempValue.getType())

        if self.isNumOfCracksRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "num-of-cracks") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-numofcracks'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "numOfCracks", "num-of-cracks",
                        "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-num-of-cracks-bad-value').infoFunc():
                    logFunc('numOfCracks not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setNumOfCracks(tempVar)
            for logFunc in self._log(
                    'read-tag-values-num-of-cracks').debug3Func():
                logFunc('read numOfCracks. numOfCracks=%s, tempValue=%s',
                        self.numOfCracks, tempValue.getType())

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 5
0
class BlinkyDeviceMaapi(DeviceMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-device")
        self.domain = None

        

        
        self.idRequested = False
        self.id = None
        self.idSet = False
        
        self.fruIdRequested = False
        self.fruId = None
        self.fruIdSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestId(True)
        
        self.requestFruId(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestId(True)
        
        self.requestFruId(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestId(False)
        
        self.requestFruId(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestId(False)
        
        self.requestFruId(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setId(None)
        self.idSet = False
        
        self.setFruId(None)
        self.fruIdSet = False
        
        

    def write (self
              , powerSupply
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(powerSupply, trxContext)

    def read (self
              , powerSupply
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(powerSupply, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , powerSupply
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(powerSupply, 
                                  True,
                                  trxContext)



    def requestId (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-id').debug3Func(): logFunc('called. requested=%s', requested)
        self.idRequested = requested
        self.idSet = False

    def isIdRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-id-requested').debug3Func(): logFunc('called. requested=%s', self.idRequested)
        return self.idRequested

    def getId (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-id').debug3Func(): logFunc('called. self.idSet=%s, self.id=%s', self.idSet, self.id)
        if self.idSet:
            return self.id
        return None

    def hasId (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-id').debug3Func(): logFunc('called. self.idSet=%s, self.id=%s', self.idSet, self.id)
        if self.idSet:
            return True
        return False

    def setId (self, id):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-id').debug3Func(): logFunc('called. id=%s, old=%s', id, self.id)
        self.idSet = True
        self.id = id

    def requestFruId (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-fruid').debug3Func(): logFunc('called. requested=%s', requested)
        self.fruIdRequested = requested
        self.fruIdSet = False

    def isFruIdRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-fruid-requested').debug3Func(): logFunc('called. requested=%s', self.fruIdRequested)
        return self.fruIdRequested

    def getFruId (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-fruid').debug3Func(): logFunc('called. self.fruIdSet=%s, self.fruId=%s', self.fruIdSet, self.fruId)
        if self.fruIdSet:
            return self.fruId
        return None

    def hasFruId (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-fruid').debug3Func(): logFunc('called. self.fruIdSet=%s, self.fruId=%s', self.fruIdSet, self.fruId)
        if self.fruIdSet:
            return True
        return False

    def setFruId (self, fruId):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-fruid').debug3Func(): logFunc('called. fruId=%s, old=%s', fruId, self.fruId)
        self.fruIdSet = True
        self.fruId = fruId


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.id = 0
        self.idSet = False
        
        self.fruId = 0
        self.fruIdSet = False
        

    def _getSelfKeyPath (self, powerSupply
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("device", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power", "qt-pltf-pwr"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("system-defaults", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power", "qt-pltf-pwr"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(powerSupply);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("power-supply", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power", "qt-pltf-pwr"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("power", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power", "qt-pltf-pwr"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("platform", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform", "qt-pltf"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        powerSupply, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(powerSupply, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(powerSupply, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       powerSupply, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(powerSupply, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               powerSupply, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasId():
            valId = Value()
            if self.id is not None:
                valId.setString(self.id)
            else:
                valId.setEmpty()
            tagValueList.push(("id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power"), valId)
        
        if self.hasFruId():
            valFruId = Value()
            if self.fruId is not None:
                valFruId.setString(self.fruId)
            else:
                valFruId.setEmpty()
            tagValueList.push(("fru-id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power"), valFruId)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isIdRequested():
            valId = Value()
            valId.setEmpty()
            tagValueList.push(("id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power"), valId)
        
        if self.isFruIdRequested():
            valFruId = Value()
            valFruId.setEmpty()
            tagValueList.push(("fru-id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power"), valFruId)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isIdRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "id") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-id').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "id", "id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-id-bad-value').infoFunc(): logFunc('id not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setId(tempVar)
            for logFunc in self._log('read-tag-values-id').debug3Func(): logFunc('read id. id=%s, tempValue=%s', self.id, tempValue.getType())
        
        if self.isFruIdRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "fru-id") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-fruid').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "fruId", "fru-id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-fru-id-bad-value').infoFunc(): logFunc('fruId not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setFruId(tempVar)
            for logFunc in self._log('read-tag-values-fru-id').debug3Func(): logFunc('read fruId. fruId=%s, tempValue=%s', self.fruId, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 6
0
class BlinkyStatusMaapi(StatusMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-status")
        self.domain = None

        

        
        self.operationalStatusRequested = False
        self.operationalStatus = None
        self.operationalStatusSet = False
        
        self.operationalStatusReasonRequested = False
        self.operationalStatusReason = None
        self.operationalStatusReasonSet = False
        
        self.locationRequested = False
        self.location = None
        self.locationSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestOperationalStatus(True)
        
        self.requestOperationalStatusReason(True)
        
        self.requestLocation(True)
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestOperationalStatus(False)
        
        self.requestOperationalStatusReason(False)
        
        self.requestLocation(False)
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestOperationalStatus(True)
        
        self.requestOperationalStatusReason(True)
        
        self.requestLocation(True)
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestOperationalStatus(False)
        
        self.requestOperationalStatusReason(False)
        
        self.requestLocation(False)
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        

    def write (self
              , fan
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(fan, trxContext)

    def read (self
              , fan
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(fan, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , fan
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(fan, 
                                  True,
                                  trxContext)



    def requestOperationalStatus (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-operationalstatus').debug3Func(): logFunc('called. requested=%s', requested)
        self.operationalStatusRequested = requested
        self.operationalStatusSet = False

    def isOperationalStatusRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-operationalstatus-requested').debug3Func(): logFunc('called. requested=%s', self.operationalStatusRequested)
        return self.operationalStatusRequested

    def getOperationalStatus (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-operationalstatus').debug3Func(): logFunc('called. self.operationalStatusSet=%s, self.operationalStatus=%s', self.operationalStatusSet, self.operationalStatus)
        if self.operationalStatusSet:
            return self.operationalStatus
        return None

    def hasOperationalStatus (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-operationalstatus').debug3Func(): logFunc('called. self.operationalStatusSet=%s, self.operationalStatus=%s', self.operationalStatusSet, self.operationalStatus)
        if self.operationalStatusSet:
            return True
        return False

    def setOperationalStatus (self, operationalStatus):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-operationalstatus').debug3Func(): logFunc('called. operationalStatus=%s, old=%s', operationalStatus, self.operationalStatus)
        self.operationalStatusSet = True
        self.operationalStatus = operationalStatus

    def requestOperationalStatusReason (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-operationalstatusreason').debug3Func(): logFunc('called. requested=%s', requested)
        self.operationalStatusReasonRequested = requested
        self.operationalStatusReasonSet = False

    def isOperationalStatusReasonRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-operationalstatusreason-requested').debug3Func(): logFunc('called. requested=%s', self.operationalStatusReasonRequested)
        return self.operationalStatusReasonRequested

    def getOperationalStatusReason (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-operationalstatusreason').debug3Func(): logFunc('called. self.operationalStatusReasonSet=%s, self.operationalStatusReason=%s', self.operationalStatusReasonSet, self.operationalStatusReason)
        if self.operationalStatusReasonSet:
            return self.operationalStatusReason
        return None

    def hasOperationalStatusReason (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-operationalstatusreason').debug3Func(): logFunc('called. self.operationalStatusReasonSet=%s, self.operationalStatusReason=%s', self.operationalStatusReasonSet, self.operationalStatusReason)
        if self.operationalStatusReasonSet:
            return True
        return False

    def setOperationalStatusReason (self, operationalStatusReason):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-operationalstatusreason').debug3Func(): logFunc('called. operationalStatusReason=%s, old=%s', operationalStatusReason, self.operationalStatusReason)
        self.operationalStatusReasonSet = True
        self.operationalStatusReason = operationalStatusReason

    def requestLocation (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-location').debug3Func(): logFunc('called. requested=%s', requested)
        self.locationRequested = requested
        self.locationSet = False

    def isLocationRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-location-requested').debug3Func(): logFunc('called. requested=%s', self.locationRequested)
        return self.locationRequested

    def getLocation (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-location').debug3Func(): logFunc('called. self.locationSet=%s, self.location=%s', self.locationSet, self.location)
        if self.locationSet:
            return self.location
        return None

    def hasLocation (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-location').debug3Func(): logFunc('called. self.locationSet=%s, self.location=%s', self.locationSet, self.location)
        if self.locationSet:
            return True
        return False

    def setLocation (self, location):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-location').debug3Func(): logFunc('called. location=%s, old=%s', location, self.location)
        self.locationSet = True
        self.location = location


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.operationalStatus = 0
        self.operationalStatusSet = False
        
        self.operationalStatusReason = 0
        self.operationalStatusReasonSet = False
        
        self.location = 0
        self.locationSet = False
        

    def _getSelfKeyPath (self, fan
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans", "qt-pltf-fans"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(fan);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("fan", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans", "qt-pltf-fans"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("fans", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans", "qt-pltf-fans"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("platform", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform", "qt-pltf"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        fan, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(fan, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(fan, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       fan, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(fan, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               fan, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isOperationalStatusRequested():
            valOperationalStatus = Value()
            valOperationalStatus.setEmpty()
            tagValueList.push(("operational-status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans"), valOperationalStatus)
        
        if self.isOperationalStatusReasonRequested():
            valOperationalStatusReason = Value()
            valOperationalStatusReason.setEmpty()
            tagValueList.push(("operational-status-reason", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans"), valOperationalStatusReason)
        
        if self.isLocationRequested():
            valLocation = Value()
            valLocation.setEmpty()
            tagValueList.push(("location", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans"), valLocation)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isOperationalStatusRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "operational-status") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-operationalstatus').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "operationalStatus", "operational-status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-operational-status-bad-value').infoFunc(): logFunc('operationalStatus not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setOperationalStatus(tempVar)
            for logFunc in self._log('read-tag-values-operational-status').debug3Func(): logFunc('read operationalStatus. operationalStatus=%s, tempValue=%s', self.operationalStatus, tempValue.getType())
        
        if self.isOperationalStatusReasonRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "operational-status-reason") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-operationalstatusreason').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "operationalStatusReason", "operational-status-reason", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-operational-status-reason-bad-value').infoFunc(): logFunc('operationalStatusReason not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setOperationalStatusReason(tempVar)
            for logFunc in self._log('read-tag-values-operational-status-reason').debug3Func(): logFunc('read operationalStatusReason. operationalStatusReason=%s, tempValue=%s', self.operationalStatusReason, tempValue.getType())
        
        if self.isLocationRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "location") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-location').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "location", "location", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-location-bad-value').infoFunc(): logFunc('location not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setLocation(tempVar)
            for logFunc in self._log('read-tag-values-location').debug3Func(): logFunc('read location. location=%s, tempValue=%s', self.location, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 7
0
class BlinkyDecisionMaapi(DecisionMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-decision")
        self.domain = None

        

        
        self.logBacktraceRequested = False
        self.logBacktrace = None
        self.logBacktraceSet = False
        
        self.ignoreConditionRequested = False
        self.ignoreCondition = None
        self.ignoreConditionSet = False
        
        self.logRequested = False
        self.log = None
        self.logSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestLogBacktrace(True)
        
        self.requestIgnoreCondition(True)
        
        self.requestLog(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestLogBacktrace(True)
        
        self.requestIgnoreCondition(True)
        
        self.requestLog(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestLogBacktrace(False)
        
        self.requestIgnoreCondition(False)
        
        self.requestLog(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestLogBacktrace(False)
        
        self.requestIgnoreCondition(False)
        
        self.requestLog(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setLogBacktrace(None)
        self.logBacktraceSet = False
        
        self.setIgnoreCondition(None)
        self.ignoreConditionSet = False
        
        self.setLog(None)
        self.logSet = False
        
        

    def write (self
              , loggerClass
              , instance
              , rule
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(loggerClass, instance, rule, trxContext)

    def read (self
              , loggerClass
              , instance
              , rule
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(loggerClass, instance, rule, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , loggerClass
                       , instance
                       , rule
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(loggerClass, instance, rule, 
                                  True,
                                  trxContext)



    def requestLogBacktrace (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-logbacktrace').debug3Func(): logFunc('called. requested=%s', requested)
        self.logBacktraceRequested = requested
        self.logBacktraceSet = False

    def isLogBacktraceRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-logbacktrace-requested').debug3Func(): logFunc('called. requested=%s', self.logBacktraceRequested)
        return self.logBacktraceRequested

    def getLogBacktrace (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-logbacktrace').debug3Func(): logFunc('called. self.logBacktraceSet=%s, self.logBacktrace=%s', self.logBacktraceSet, self.logBacktrace)
        if self.logBacktraceSet:
            return self.logBacktrace
        return None

    def hasLogBacktrace (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-logbacktrace').debug3Func(): logFunc('called. self.logBacktraceSet=%s, self.logBacktrace=%s', self.logBacktraceSet, self.logBacktrace)
        if self.logBacktraceSet:
            return True
        return False

    def setLogBacktrace (self, logBacktrace):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-logbacktrace').debug3Func(): logFunc('called. logBacktrace=%s, old=%s', logBacktrace, self.logBacktrace)
        self.logBacktraceSet = True
        self.logBacktrace = logBacktrace

    def requestIgnoreCondition (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-ignorecondition').debug3Func(): logFunc('called. requested=%s', requested)
        self.ignoreConditionRequested = requested
        self.ignoreConditionSet = False

    def isIgnoreConditionRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-ignorecondition-requested').debug3Func(): logFunc('called. requested=%s', self.ignoreConditionRequested)
        return self.ignoreConditionRequested

    def getIgnoreCondition (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-ignorecondition').debug3Func(): logFunc('called. self.ignoreConditionSet=%s, self.ignoreCondition=%s', self.ignoreConditionSet, self.ignoreCondition)
        if self.ignoreConditionSet:
            return self.ignoreCondition
        return None

    def hasIgnoreCondition (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-ignorecondition').debug3Func(): logFunc('called. self.ignoreConditionSet=%s, self.ignoreCondition=%s', self.ignoreConditionSet, self.ignoreCondition)
        if self.ignoreConditionSet:
            return True
        return False

    def setIgnoreCondition (self, ignoreCondition):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-ignorecondition').debug3Func(): logFunc('called. ignoreCondition=%s, old=%s', ignoreCondition, self.ignoreCondition)
        self.ignoreConditionSet = True
        self.ignoreCondition = ignoreCondition

    def requestLog (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-log').debug3Func(): logFunc('called. requested=%s', requested)
        self.logRequested = requested
        self.logSet = False

    def isLogRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-log-requested').debug3Func(): logFunc('called. requested=%s', self.logRequested)
        return self.logRequested

    def getLog (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-log').debug3Func(): logFunc('called. self.logSet=%s, self.log=%s', self.logSet, self.log)
        if self.logSet:
            return self.log
        return None

    def hasLog (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-log').debug3Func(): logFunc('called. self.logSet=%s, self.log=%s', self.logSet, self.log)
        if self.logSet:
            return True
        return False

    def setLog (self, log):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-log').debug3Func(): logFunc('called. log=%s, old=%s', log, self.log)
        self.logSet = True
        self.log = log


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.logBacktrace = 0
        self.logBacktraceSet = False
        
        self.ignoreCondition = 0
        self.ignoreConditionSet = False
        
        self.log = 0
        self.logSet = False
        

    def _getSelfKeyPath (self, loggerClass
                         , instance
                         , rule
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("decision", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(rule);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("rule", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(instance);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("instance", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(loggerClass);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("logger-class", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        loggerClass, 
                        instance, 
                        rule, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(loggerClass, 
                                         instance, 
                                         rule, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(loggerClass, 
                                       instance, 
                                       rule, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       loggerClass, 
                       instance, 
                       rule, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(loggerClass, 
                                       instance, 
                                       rule, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               loggerClass, 
                               instance, 
                               rule, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasLogBacktrace():
            valLogBacktrace = Value()
            if self.logBacktrace is not None:
                valLogBacktrace.setEnum(self.logBacktrace.getValue())
            else:
                valLogBacktrace.setEmpty()
            tagValueList.push(("log-backtrace", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valLogBacktrace)
        
        if self.hasIgnoreCondition():
            valIgnoreCondition = Value()
            if self.ignoreCondition is not None:
                valIgnoreCondition.setEnum(self.ignoreCondition.getValue())
            else:
                valIgnoreCondition.setEmpty()
            tagValueList.push(("ignore-condition", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valIgnoreCondition)
        
        if self.hasLog():
            valLog = Value()
            if self.log is not None:
                valLog.setEnum(self.log.getValue())
            else:
                valLog.setEmpty()
            tagValueList.push(("log", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valLog)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isLogBacktraceRequested():
            valLogBacktrace = Value()
            valLogBacktrace.setEmpty()
            tagValueList.push(("log-backtrace", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valLogBacktrace)
        
        if self.isIgnoreConditionRequested():
            valIgnoreCondition = Value()
            valIgnoreCondition.setEmpty()
            tagValueList.push(("ignore-condition", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valIgnoreCondition)
        
        if self.isLogRequested():
            valLog = Value()
            valLog.setEmpty()
            tagValueList.push(("log", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valLog)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isLogBacktraceRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "log-backtrace") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-logbacktrace').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "logBacktrace", "log-backtrace", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-log-backtrace-bad-value').infoFunc(): logFunc('logBacktrace not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setLogBacktrace(tempVar)
            for logFunc in self._log('read-tag-values-log-backtrace').debug3Func(): logFunc('read logBacktrace. logBacktrace=%s, tempValue=%s', self.logBacktrace, tempValue.getType())
        
        if self.isIgnoreConditionRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "ignore-condition") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-ignorecondition').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "ignoreCondition", "ignore-condition", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-ignore-condition-bad-value').infoFunc(): logFunc('ignoreCondition not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setIgnoreCondition(tempVar)
            for logFunc in self._log('read-tag-values-ignore-condition').debug3Func(): logFunc('read ignoreCondition. ignoreCondition=%s, tempValue=%s', self.ignoreCondition, tempValue.getType())
        
        if self.isLogRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "log") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-log').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "log", "log", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-log-bad-value').infoFunc(): logFunc('log not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setLog(tempVar)
            for logFunc in self._log('read-tag-values-log').debug3Func(): logFunc('read log. log=%s, tempValue=%s', self.log, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 8
0
class BlinkyBbbMaapi(BbbMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-bbb")
        self.domain = None

        

        
        self.b4int64Requested = False
        self.b4int64 = None
        self.b4int64Set = False
        
        self.b6strRequested = False
        self.b6str = None
        self.b6strSet = False
        
        self.b3strRequested = False
        self.b3str = None
        self.b3strSet = False
        
        self.b5strRequested = False
        self.b5str = None
        self.b5strSet = False
        
        self.b7strRequested = False
        self.b7str = None
        self.b7strSet = False
        
        self.b9strRequested = False
        self.b9str = None
        self.b9strSet = False
        
        self.b1strRequested = False
        self.b1str = None
        self.b1strSet = False
        
        self.b8strRequested = False
        self.b8str = None
        self.b8strSet = False
        
        self.b2strRequested = False
        self.b2str = None
        self.b2strSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestB4int64(True)
        
        self.requestB6str(True)
        
        self.requestB3str(True)
        
        self.requestB5str(True)
        
        self.requestB7str(True)
        
        self.requestB9str(True)
        
        self.requestB1str(True)
        
        self.requestB8str(True)
        
        self.requestB2str(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestB4int64(True)
        
        self.requestB6str(True)
        
        self.requestB3str(True)
        
        self.requestB5str(True)
        
        self.requestB7str(True)
        
        self.requestB9str(True)
        
        self.requestB1str(True)
        
        self.requestB8str(True)
        
        self.requestB2str(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestB4int64(False)
        
        self.requestB6str(False)
        
        self.requestB3str(False)
        
        self.requestB5str(False)
        
        self.requestB7str(False)
        
        self.requestB9str(False)
        
        self.requestB1str(False)
        
        self.requestB8str(False)
        
        self.requestB2str(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestB4int64(False)
        
        self.requestB6str(False)
        
        self.requestB3str(False)
        
        self.requestB5str(False)
        
        self.requestB7str(False)
        
        self.requestB9str(False)
        
        self.requestB1str(False)
        
        self.requestB8str(False)
        
        self.requestB2str(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setB4int64(None)
        self.b4int64Set = False
        
        self.setB6str(None)
        self.b6strSet = False
        
        self.setB3str(None)
        self.b3strSet = False
        
        self.setB5str(None)
        self.b5strSet = False
        
        self.setB7str(None)
        self.b7strSet = False
        
        self.setB9str(None)
        self.b9strSet = False
        
        self.setB1str(None)
        self.b1strSet = False
        
        self.setB8str(None)
        self.b8strSet = False
        
        self.setB2str(None)
        self.b2strSet = False
        
        

    def write (self
              , lll
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(lll, trxContext)

    def read (self
              , lll
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(lll, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , lll
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(lll, 
                                  True,
                                  trxContext)



    def requestB4int64 (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-b4int64').debug3Func(): logFunc('called. requested=%s', requested)
        self.b4int64Requested = requested
        self.b4int64Set = False

    def isB4int64Requested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-b4int64-requested').debug3Func(): logFunc('called. requested=%s', self.b4int64Requested)
        return self.b4int64Requested

    def getB4int64 (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-b4int64').debug3Func(): logFunc('called. self.b4int64Set=%s, self.b4int64=%s', self.b4int64Set, self.b4int64)
        if self.b4int64Set:
            return self.b4int64
        return None

    def hasB4int64 (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-b4int64').debug3Func(): logFunc('called. self.b4int64Set=%s, self.b4int64=%s', self.b4int64Set, self.b4int64)
        if self.b4int64Set:
            return True
        return False

    def setB4int64 (self, b4int64):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-b4int64').debug3Func(): logFunc('called. b4int64=%s, old=%s', b4int64, self.b4int64)
        self.b4int64Set = True
        self.b4int64 = b4int64

    def requestB6str (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-b6str').debug3Func(): logFunc('called. requested=%s', requested)
        self.b6strRequested = requested
        self.b6strSet = False

    def isB6strRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-b6str-requested').debug3Func(): logFunc('called. requested=%s', self.b6strRequested)
        return self.b6strRequested

    def getB6str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-b6str').debug3Func(): logFunc('called. self.b6strSet=%s, self.b6str=%s', self.b6strSet, self.b6str)
        if self.b6strSet:
            return self.b6str
        return None

    def hasB6str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-b6str').debug3Func(): logFunc('called. self.b6strSet=%s, self.b6str=%s', self.b6strSet, self.b6str)
        if self.b6strSet:
            return True
        return False

    def setB6str (self, b6str):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-b6str').debug3Func(): logFunc('called. b6str=%s, old=%s', b6str, self.b6str)
        self.b6strSet = True
        self.b6str = b6str

    def requestB3str (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-b3str').debug3Func(): logFunc('called. requested=%s', requested)
        self.b3strRequested = requested
        self.b3strSet = False

    def isB3strRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-b3str-requested').debug3Func(): logFunc('called. requested=%s', self.b3strRequested)
        return self.b3strRequested

    def getB3str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-b3str').debug3Func(): logFunc('called. self.b3strSet=%s, self.b3str=%s', self.b3strSet, self.b3str)
        if self.b3strSet:
            return self.b3str
        return None

    def hasB3str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-b3str').debug3Func(): logFunc('called. self.b3strSet=%s, self.b3str=%s', self.b3strSet, self.b3str)
        if self.b3strSet:
            return True
        return False

    def setB3str (self, b3str):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-b3str').debug3Func(): logFunc('called. b3str=%s, old=%s', b3str, self.b3str)
        self.b3strSet = True
        self.b3str = b3str

    def requestB5str (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-b5str').debug3Func(): logFunc('called. requested=%s', requested)
        self.b5strRequested = requested
        self.b5strSet = False

    def isB5strRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-b5str-requested').debug3Func(): logFunc('called. requested=%s', self.b5strRequested)
        return self.b5strRequested

    def getB5str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-b5str').debug3Func(): logFunc('called. self.b5strSet=%s, self.b5str=%s', self.b5strSet, self.b5str)
        if self.b5strSet:
            return self.b5str
        return None

    def hasB5str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-b5str').debug3Func(): logFunc('called. self.b5strSet=%s, self.b5str=%s', self.b5strSet, self.b5str)
        if self.b5strSet:
            return True
        return False

    def setB5str (self, b5str):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-b5str').debug3Func(): logFunc('called. b5str=%s, old=%s', b5str, self.b5str)
        self.b5strSet = True
        self.b5str = b5str

    def requestB7str (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-b7str').debug3Func(): logFunc('called. requested=%s', requested)
        self.b7strRequested = requested
        self.b7strSet = False

    def isB7strRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-b7str-requested').debug3Func(): logFunc('called. requested=%s', self.b7strRequested)
        return self.b7strRequested

    def getB7str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-b7str').debug3Func(): logFunc('called. self.b7strSet=%s, self.b7str=%s', self.b7strSet, self.b7str)
        if self.b7strSet:
            return self.b7str
        return None

    def hasB7str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-b7str').debug3Func(): logFunc('called. self.b7strSet=%s, self.b7str=%s', self.b7strSet, self.b7str)
        if self.b7strSet:
            return True
        return False

    def setB7str (self, b7str):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-b7str').debug3Func(): logFunc('called. b7str=%s, old=%s', b7str, self.b7str)
        self.b7strSet = True
        self.b7str = b7str

    def requestB9str (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-b9str').debug3Func(): logFunc('called. requested=%s', requested)
        self.b9strRequested = requested
        self.b9strSet = False

    def isB9strRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-b9str-requested').debug3Func(): logFunc('called. requested=%s', self.b9strRequested)
        return self.b9strRequested

    def getB9str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-b9str').debug3Func(): logFunc('called. self.b9strSet=%s, self.b9str=%s', self.b9strSet, self.b9str)
        if self.b9strSet:
            return self.b9str
        return None

    def hasB9str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-b9str').debug3Func(): logFunc('called. self.b9strSet=%s, self.b9str=%s', self.b9strSet, self.b9str)
        if self.b9strSet:
            return True
        return False

    def setB9str (self, b9str):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-b9str').debug3Func(): logFunc('called. b9str=%s, old=%s', b9str, self.b9str)
        self.b9strSet = True
        self.b9str = b9str

    def requestB1str (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-b1str').debug3Func(): logFunc('called. requested=%s', requested)
        self.b1strRequested = requested
        self.b1strSet = False

    def isB1strRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-b1str-requested').debug3Func(): logFunc('called. requested=%s', self.b1strRequested)
        return self.b1strRequested

    def getB1str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-b1str').debug3Func(): logFunc('called. self.b1strSet=%s, self.b1str=%s', self.b1strSet, self.b1str)
        if self.b1strSet:
            return self.b1str
        return None

    def hasB1str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-b1str').debug3Func(): logFunc('called. self.b1strSet=%s, self.b1str=%s', self.b1strSet, self.b1str)
        if self.b1strSet:
            return True
        return False

    def setB1str (self, b1str):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-b1str').debug3Func(): logFunc('called. b1str=%s, old=%s', b1str, self.b1str)
        self.b1strSet = True
        self.b1str = b1str

    def requestB8str (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-b8str').debug3Func(): logFunc('called. requested=%s', requested)
        self.b8strRequested = requested
        self.b8strSet = False

    def isB8strRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-b8str-requested').debug3Func(): logFunc('called. requested=%s', self.b8strRequested)
        return self.b8strRequested

    def getB8str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-b8str').debug3Func(): logFunc('called. self.b8strSet=%s, self.b8str=%s', self.b8strSet, self.b8str)
        if self.b8strSet:
            return self.b8str
        return None

    def hasB8str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-b8str').debug3Func(): logFunc('called. self.b8strSet=%s, self.b8str=%s', self.b8strSet, self.b8str)
        if self.b8strSet:
            return True
        return False

    def setB8str (self, b8str):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-b8str').debug3Func(): logFunc('called. b8str=%s, old=%s', b8str, self.b8str)
        self.b8strSet = True
        self.b8str = b8str

    def requestB2str (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-b2str').debug3Func(): logFunc('called. requested=%s', requested)
        self.b2strRequested = requested
        self.b2strSet = False

    def isB2strRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-b2str-requested').debug3Func(): logFunc('called. requested=%s', self.b2strRequested)
        return self.b2strRequested

    def getB2str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-b2str').debug3Func(): logFunc('called. self.b2strSet=%s, self.b2str=%s', self.b2strSet, self.b2str)
        if self.b2strSet:
            return self.b2str
        return None

    def hasB2str (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-b2str').debug3Func(): logFunc('called. self.b2strSet=%s, self.b2str=%s', self.b2strSet, self.b2str)
        if self.b2strSet:
            return True
        return False

    def setB2str (self, b2str):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-b2str').debug3Func(): logFunc('called. b2str=%s, old=%s', b2str, self.b2str)
        self.b2strSet = True
        self.b2str = b2str


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.b4int64 = 0
        self.b4int64Set = False
        
        self.b6str = 0
        self.b6strSet = False
        
        self.b3str = 0
        self.b3strSet = False
        
        self.b5str = 0
        self.b5strSet = False
        
        self.b7str = 0
        self.b7strSet = False
        
        self.b9str = 0
        self.b9strSet = False
        
        self.b1str = 0
        self.b1strSet = False
        
        self.b8str = 0
        self.b8strSet = False
        
        self.b2str = 0
        self.b2strSet = False
        

    def _getSelfKeyPath (self, lll
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("bbb", "http://qwilt.com/model/benchmark", "bnch"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(lll);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("lll", "http://qwilt.com/model/benchmark", "bnch"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("base", "http://qwilt.com/model/benchmark", "bnch"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        lll, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(lll, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(lll, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       lll, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(lll, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               lll, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasB4int64():
            valB4int64 = Value()
            if self.b4int64 is not None:
                valB4int64.setInt64(self.b4int64)
            else:
                valB4int64.setEmpty()
            tagValueList.push(("b4int64", "http://qwilt.com/model/benchmark"), valB4int64)
        
        if self.hasB6str():
            valB6str = Value()
            if self.b6str is not None:
                valB6str.setString(self.b6str)
            else:
                valB6str.setEmpty()
            tagValueList.push(("b6str", "http://qwilt.com/model/benchmark"), valB6str)
        
        if self.hasB3str():
            valB3str = Value()
            if self.b3str is not None:
                valB3str.setString(self.b3str)
            else:
                valB3str.setEmpty()
            tagValueList.push(("b3str", "http://qwilt.com/model/benchmark"), valB3str)
        
        if self.hasB5str():
            valB5str = Value()
            if self.b5str is not None:
                valB5str.setString(self.b5str)
            else:
                valB5str.setEmpty()
            tagValueList.push(("b5str", "http://qwilt.com/model/benchmark"), valB5str)
        
        if self.hasB7str():
            valB7str = Value()
            if self.b7str is not None:
                valB7str.setString(self.b7str)
            else:
                valB7str.setEmpty()
            tagValueList.push(("b7str", "http://qwilt.com/model/benchmark"), valB7str)
        
        if self.hasB9str():
            valB9str = Value()
            if self.b9str is not None:
                valB9str.setString(self.b9str)
            else:
                valB9str.setEmpty()
            tagValueList.push(("b9str", "http://qwilt.com/model/benchmark"), valB9str)
        
        if self.hasB1str():
            valB1str = Value()
            if self.b1str is not None:
                valB1str.setString(self.b1str)
            else:
                valB1str.setEmpty()
            tagValueList.push(("b1str", "http://qwilt.com/model/benchmark"), valB1str)
        
        if self.hasB8str():
            valB8str = Value()
            if self.b8str is not None:
                valB8str.setString(self.b8str)
            else:
                valB8str.setEmpty()
            tagValueList.push(("b8str", "http://qwilt.com/model/benchmark"), valB8str)
        
        if self.hasB2str():
            valB2str = Value()
            if self.b2str is not None:
                valB2str.setString(self.b2str)
            else:
                valB2str.setEmpty()
            tagValueList.push(("b2str", "http://qwilt.com/model/benchmark"), valB2str)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isB4int64Requested():
            valB4int64 = Value()
            valB4int64.setEmpty()
            tagValueList.push(("b4int64", "http://qwilt.com/model/benchmark"), valB4int64)
        
        if self.isB6strRequested():
            valB6str = Value()
            valB6str.setEmpty()
            tagValueList.push(("b6str", "http://qwilt.com/model/benchmark"), valB6str)
        
        if self.isB3strRequested():
            valB3str = Value()
            valB3str.setEmpty()
            tagValueList.push(("b3str", "http://qwilt.com/model/benchmark"), valB3str)
        
        if self.isB5strRequested():
            valB5str = Value()
            valB5str.setEmpty()
            tagValueList.push(("b5str", "http://qwilt.com/model/benchmark"), valB5str)
        
        if self.isB7strRequested():
            valB7str = Value()
            valB7str.setEmpty()
            tagValueList.push(("b7str", "http://qwilt.com/model/benchmark"), valB7str)
        
        if self.isB9strRequested():
            valB9str = Value()
            valB9str.setEmpty()
            tagValueList.push(("b9str", "http://qwilt.com/model/benchmark"), valB9str)
        
        if self.isB1strRequested():
            valB1str = Value()
            valB1str.setEmpty()
            tagValueList.push(("b1str", "http://qwilt.com/model/benchmark"), valB1str)
        
        if self.isB8strRequested():
            valB8str = Value()
            valB8str.setEmpty()
            tagValueList.push(("b8str", "http://qwilt.com/model/benchmark"), valB8str)
        
        if self.isB2strRequested():
            valB2str = Value()
            valB2str.setEmpty()
            tagValueList.push(("b2str", "http://qwilt.com/model/benchmark"), valB2str)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isB4int64Requested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "b4int64") or \
                (ns != "http://qwilt.com/model/benchmark"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-b4int64').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "b4int64", "b4int64", "http://qwilt.com/model/benchmark", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-b4int64-bad-value').infoFunc(): logFunc('b4int64 not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setB4int64(tempVar)
            for logFunc in self._log('read-tag-values-b4int64').debug3Func(): logFunc('read b4int64. b4int64=%s, tempValue=%s', self.b4int64, tempValue.getType())
        
        if self.isB6strRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "b6str") or \
                (ns != "http://qwilt.com/model/benchmark"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-b6str').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "b6str", "b6str", "http://qwilt.com/model/benchmark", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-b6str-bad-value').infoFunc(): logFunc('b6str not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setB6str(tempVar)
            for logFunc in self._log('read-tag-values-b6str').debug3Func(): logFunc('read b6str. b6str=%s, tempValue=%s', self.b6str, tempValue.getType())
        
        if self.isB3strRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "b3str") or \
                (ns != "http://qwilt.com/model/benchmark"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-b3str').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "b3str", "b3str", "http://qwilt.com/model/benchmark", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-b3str-bad-value').infoFunc(): logFunc('b3str not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setB3str(tempVar)
            for logFunc in self._log('read-tag-values-b3str').debug3Func(): logFunc('read b3str. b3str=%s, tempValue=%s', self.b3str, tempValue.getType())
        
        if self.isB5strRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "b5str") or \
                (ns != "http://qwilt.com/model/benchmark"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-b5str').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "b5str", "b5str", "http://qwilt.com/model/benchmark", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-b5str-bad-value').infoFunc(): logFunc('b5str not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setB5str(tempVar)
            for logFunc in self._log('read-tag-values-b5str').debug3Func(): logFunc('read b5str. b5str=%s, tempValue=%s', self.b5str, tempValue.getType())
        
        if self.isB7strRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "b7str") or \
                (ns != "http://qwilt.com/model/benchmark"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-b7str').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "b7str", "b7str", "http://qwilt.com/model/benchmark", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-b7str-bad-value').infoFunc(): logFunc('b7str not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setB7str(tempVar)
            for logFunc in self._log('read-tag-values-b7str').debug3Func(): logFunc('read b7str. b7str=%s, tempValue=%s', self.b7str, tempValue.getType())
        
        if self.isB9strRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "b9str") or \
                (ns != "http://qwilt.com/model/benchmark"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-b9str').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "b9str", "b9str", "http://qwilt.com/model/benchmark", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-b9str-bad-value').infoFunc(): logFunc('b9str not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setB9str(tempVar)
            for logFunc in self._log('read-tag-values-b9str').debug3Func(): logFunc('read b9str. b9str=%s, tempValue=%s', self.b9str, tempValue.getType())
        
        if self.isB1strRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "b1str") or \
                (ns != "http://qwilt.com/model/benchmark"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-b1str').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "b1str", "b1str", "http://qwilt.com/model/benchmark", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-b1str-bad-value').infoFunc(): logFunc('b1str not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setB1str(tempVar)
            for logFunc in self._log('read-tag-values-b1str').debug3Func(): logFunc('read b1str. b1str=%s, tempValue=%s', self.b1str, tempValue.getType())
        
        if self.isB8strRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "b8str") or \
                (ns != "http://qwilt.com/model/benchmark"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-b8str').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "b8str", "b8str", "http://qwilt.com/model/benchmark", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-b8str-bad-value').infoFunc(): logFunc('b8str not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setB8str(tempVar)
            for logFunc in self._log('read-tag-values-b8str').debug3Func(): logFunc('read b8str. b8str=%s, tempValue=%s', self.b8str, tempValue.getType())
        
        if self.isB2strRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "b2str") or \
                (ns != "http://qwilt.com/model/benchmark"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-b2str').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "b2str", "b2str", "http://qwilt.com/model/benchmark", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-b2str-bad-value').infoFunc(): logFunc('b2str not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setB2str(tempVar)
            for logFunc in self._log('read-tag-values-b2str').debug3Func(): logFunc('read b2str. b2str=%s, tempValue=%s', self.b2str, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 9
0
class BlinkyIpv6Maapi(Ipv6MaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-ipv6")
        self.domain = None

        
        self.statusObj = None
        
        self.neighborDiscoveryObj = None
        
        self.pingObj = None
        
        self.countersObj = None
        

        
        self.methodRequested = False
        self.method = None
        self.methodSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestMethod(True)
        
        
        
        if not self.statusObj:
            self.statusObj = self.newStatus()
            self.statusObj.requestConfigAndOper()
        
        if not self.neighborDiscoveryObj:
            self.neighborDiscoveryObj = self.newNeighborDiscovery()
            self.neighborDiscoveryObj.requestConfigAndOper()
        
        if not self.pingObj:
            self.pingObj = self.newPing()
            self.pingObj.requestConfigAndOper()
        
        if not self.countersObj:
            self.countersObj = self.newCounters()
            self.countersObj.requestConfigAndOper()
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestMethod(True)
        
        
        
        if not self.statusObj:
            self.statusObj = self.newStatus()
            self.statusObj.requestConfig()
        
        if not self.neighborDiscoveryObj:
            self.neighborDiscoveryObj = self.newNeighborDiscovery()
            self.neighborDiscoveryObj.requestConfig()
        
        if not self.pingObj:
            self.pingObj = self.newPing()
            self.pingObj.requestConfig()
        
        if not self.countersObj:
            self.countersObj = self.newCounters()
            self.countersObj.requestConfig()
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestMethod(False)
        
        
        
        if not self.statusObj:
            self.statusObj = self.newStatus()
            self.statusObj.requestOper()
        
        if not self.neighborDiscoveryObj:
            self.neighborDiscoveryObj = self.newNeighborDiscovery()
            self.neighborDiscoveryObj.requestOper()
        
        if not self.pingObj:
            self.pingObj = self.newPing()
            self.pingObj.requestOper()
        
        if not self.countersObj:
            self.countersObj = self.newCounters()
            self.countersObj.requestOper()
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestMethod(False)
        
        
        
        if not self.statusObj:
            self.statusObj = self.newStatus()
            self.statusObj.clearAllRequested()
        
        if not self.neighborDiscoveryObj:
            self.neighborDiscoveryObj = self.newNeighborDiscovery()
            self.neighborDiscoveryObj.clearAllRequested()
        
        if not self.pingObj:
            self.pingObj = self.newPing()
            self.pingObj.clearAllRequested()
        
        if not self.countersObj:
            self.countersObj = self.newCounters()
            self.countersObj.clearAllRequested()
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setMethod(None)
        self.methodSet = False
        
        
        if self.statusObj:
            self.statusObj.clearAllSet()
        
        if self.neighborDiscoveryObj:
            self.neighborDiscoveryObj.clearAllSet()
        
        if self.pingObj:
            self.pingObj.clearAllSet()
        
        if self.countersObj:
            self.countersObj.clearAllSet()
        

    def write (self
              , interface
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(interface, trxContext)

    def read (self
              , interface
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(interface, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , interface
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(interface, 
                                  True,
                                  trxContext)

    def newStatus (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-status').debug3Func(): logFunc('called.')
        status = BlinkyStatusMaapi(self._log)
        status.init(self.domain)
        return status

    def setStatusObj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-status').debug3Func(): logFunc('called. obj=%s', obj)
        self.statusObj = obj

    def getStatusObj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-status').debug3Func(): logFunc('called. self.statusObj=%s', self.statusObj)
        return self.statusObj

    def hasStatus (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-status').debug3Func(): logFunc('called. self.statusObj=%s', self.statusObj)
        if self.statusObj:
            return True
        return False

    def newNeighborDiscovery (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-neighbordiscovery').debug3Func(): logFunc('called.')
        neighborDiscovery = BlinkyNeighborDiscoveryMaapi(self._log)
        neighborDiscovery.init(self.domain)
        return neighborDiscovery

    def setNeighborDiscoveryObj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-neighbordiscovery').debug3Func(): logFunc('called. obj=%s', obj)
        self.neighborDiscoveryObj = obj

    def getNeighborDiscoveryObj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-neighbordiscovery').debug3Func(): logFunc('called. self.neighborDiscoveryObj=%s', self.neighborDiscoveryObj)
        return self.neighborDiscoveryObj

    def hasNeighborDiscovery (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-neighbordiscovery').debug3Func(): logFunc('called. self.neighborDiscoveryObj=%s', self.neighborDiscoveryObj)
        if self.neighborDiscoveryObj:
            return True
        return False

    def newPing (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-ping').debug3Func(): logFunc('called.')
        ping = BlinkyPingMaapi(self._log)
        ping.init(self.domain)
        return ping

    def setPingObj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-ping').debug3Func(): logFunc('called. obj=%s', obj)
        self.pingObj = obj

    def getPingObj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-ping').debug3Func(): logFunc('called. self.pingObj=%s', self.pingObj)
        return self.pingObj

    def hasPing (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-ping').debug3Func(): logFunc('called. self.pingObj=%s', self.pingObj)
        if self.pingObj:
            return True
        return False

    def newCounters (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-counters').debug3Func(): logFunc('called.')
        counters = BlinkyCountersMaapi(self._log)
        counters.init(self.domain)
        return counters

    def setCountersObj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-counters').debug3Func(): logFunc('called. obj=%s', obj)
        self.countersObj = obj

    def getCountersObj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-counters').debug3Func(): logFunc('called. self.countersObj=%s', self.countersObj)
        return self.countersObj

    def hasCounters (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-counters').debug3Func(): logFunc('called. self.countersObj=%s', self.countersObj)
        if self.countersObj:
            return True
        return False



    def requestMethod (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-method').debug3Func(): logFunc('called. requested=%s', requested)
        self.methodRequested = requested
        self.methodSet = False

    def isMethodRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-method-requested').debug3Func(): logFunc('called. requested=%s', self.methodRequested)
        return self.methodRequested

    def getMethod (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-method').debug3Func(): logFunc('called. self.methodSet=%s, self.method=%s', self.methodSet, self.method)
        if self.methodSet:
            return self.method
        return None

    def hasMethod (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-method').debug3Func(): logFunc('called. self.methodSet=%s, self.method=%s', self.methodSet, self.method)
        if self.methodSet:
            return True
        return False

    def setMethod (self, method):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-method').debug3Func(): logFunc('called. method=%s, old=%s', method, self.method)
        self.methodSet = True
        self.method = method


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        
        if self.statusObj:
            self.statusObj._clearAllReadData()
        
        if self.neighborDiscoveryObj:
            self.neighborDiscoveryObj._clearAllReadData()
        
        if self.pingObj:
            self.pingObj._clearAllReadData()
        
        if self.countersObj:
            self.countersObj._clearAllReadData()
        

        
        self.method = 0
        self.methodSet = False
        

    def _getSelfKeyPath (self, interface
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("ipv6", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("connectivity-check", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(interface);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("interface", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("interfaces", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        interface, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(interface, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(interface, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       interface, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(interface, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               interface, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        
        if self.statusObj:
            res = self.statusObj._collectItemsToDelete(interface, 
                                                                          
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-status-failed').errorFunc(): logFunc('statusObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        
        if self.neighborDiscoveryObj:
            res = self.neighborDiscoveryObj._collectItemsToDelete(interface, 
                                                                          
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-neighbor-discovery-failed').errorFunc(): logFunc('neighborDiscoveryObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        
        if self.pingObj:
            res = self.pingObj._collectItemsToDelete(interface, 
                                                                          
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-ping-failed').errorFunc(): logFunc('pingObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        
        if self.countersObj:
            res = self.countersObj._collectItemsToDelete(interface, 
                                                                          
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-counters-failed').errorFunc(): logFunc('countersObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasMethod():
            valMethod = Value()
            if self.method is not None:
                valMethod.setEnum(self.method.getValue())
            else:
                valMethod.setEmpty()
            tagValueList.push(("method", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valMethod)
        

        
        if self.statusObj:
            valBegin = Value()
            (tag, ns, prefix) = ("status" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.statusObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-status-failed').errorFunc(): logFunc('statusObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.neighborDiscoveryObj:
            valBegin = Value()
            (tag, ns, prefix) = ("neighbor-discovery" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.neighborDiscoveryObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-neighbor-discovery-failed').errorFunc(): logFunc('neighborDiscoveryObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.pingObj:
            valBegin = Value()
            (tag, ns, prefix) = ("ping" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.pingObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-ping-failed').errorFunc(): logFunc('pingObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.countersObj:
            valBegin = Value()
            (tag, ns, prefix) = ("counters" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.countersObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-counters-failed').errorFunc(): logFunc('countersObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isMethodRequested():
            valMethod = Value()
            valMethod.setEmpty()
            tagValueList.push(("method", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valMethod)
        

        
        if self.statusObj:
            valBegin = Value()
            (tag, ns, prefix) = ("status" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.statusObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-status-failed').errorFunc(): logFunc('statusObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.neighborDiscoveryObj:
            valBegin = Value()
            (tag, ns, prefix) = ("neighbor-discovery" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.neighborDiscoveryObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-neighbor-discovery-failed').errorFunc(): logFunc('neighborDiscoveryObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.pingObj:
            valBegin = Value()
            (tag, ns, prefix) = ("ping" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.pingObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-ping-failed').errorFunc(): logFunc('pingObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.countersObj:
            valBegin = Value()
            (tag, ns, prefix) = ("counters" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.countersObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-counters-failed').errorFunc(): logFunc('countersObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isMethodRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "method") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-method').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "method", "method", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-method-bad-value').infoFunc(): logFunc('method not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setMethod(tempVar)
            for logFunc in self._log('read-tag-values-method').debug3Func(): logFunc('read method. method=%s, tempValue=%s', self.method, tempValue.getType())
        

        
        if self.statusObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "status") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.statusObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-status-failed').errorFunc(): logFunc('statusObj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "status") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        
        if self.neighborDiscoveryObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "neighbor-discovery") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "neighbor-discovery", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.neighborDiscoveryObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-neighbor-discovery-failed').errorFunc(): logFunc('neighborDiscoveryObj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "neighbor-discovery") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "neighbor-discovery", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        
        if self.pingObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "ping") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "ping", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.pingObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-ping-failed').errorFunc(): logFunc('pingObj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "ping") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "ping", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        
        if self.countersObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "counters") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "counters", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.countersObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-counters-failed').errorFunc(): logFunc('countersObj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "counters") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "counters", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 10
0
class BlinkySizeMaapi(SizeMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-size")
        self.domain = None

        self.widthRequested = False
        self.width = None
        self.widthSet = False

        self.lengthRequested = False
        self.length = None
        self.lengthSet = False

        self.patternNameRequested = False
        self.patternName = None
        self.patternNameSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestWidth(True)

        self.requestLength(True)

        self.requestPatternName(True)

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestWidth(True)

        self.requestLength(True)

        self.requestPatternName(True)

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestWidth(False)

        self.requestLength(False)

        self.requestPatternName(False)

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestWidth(False)

        self.requestLength(False)

        self.requestPatternName(False)

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

        self.setWidth(None)
        self.widthSet = False

        self.setLength(None)
        self.lengthSet = False

        self.setPatternName(None)
        self.patternNameSet = False

    def write(self, lake, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(lake, trxContext)

    def read(self, lake, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(lake, False, trxContext)

    def readAllOrFail(self, lake, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(lake, True, trxContext)

    def requestWidth(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-width').debug3Func():
            logFunc('called. requested=%s', requested)
        self.widthRequested = requested
        self.widthSet = False

    def isWidthRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-width-requested').debug3Func():
            logFunc('called. requested=%s', self.widthRequested)
        return self.widthRequested

    def getWidth(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-width').debug3Func():
            logFunc('called. self.widthSet=%s, self.width=%s', self.widthSet,
                    self.width)
        if self.widthSet:
            return self.width
        return None

    def hasWidth(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-width').debug3Func():
            logFunc('called. self.widthSet=%s, self.width=%s', self.widthSet,
                    self.width)
        if self.widthSet:
            return True
        return False

    def setWidth(self, width):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-width').debug3Func():
            logFunc('called. width=%s, old=%s', width, self.width)
        self.widthSet = True
        self.width = width

    def requestLength(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-length').debug3Func():
            logFunc('called. requested=%s', requested)
        self.lengthRequested = requested
        self.lengthSet = False

    def isLengthRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-length-requested').debug3Func():
            logFunc('called. requested=%s', self.lengthRequested)
        return self.lengthRequested

    def getLength(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-length').debug3Func():
            logFunc('called. self.lengthSet=%s, self.length=%s',
                    self.lengthSet, self.length)
        if self.lengthSet:
            return self.length
        return None

    def hasLength(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-length').debug3Func():
            logFunc('called. self.lengthSet=%s, self.length=%s',
                    self.lengthSet, self.length)
        if self.lengthSet:
            return True
        return False

    def setLength(self, length):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-length').debug3Func():
            logFunc('called. length=%s, old=%s', length, self.length)
        self.lengthSet = True
        self.length = length

    def requestPatternName(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-patternname').debug3Func():
            logFunc('called. requested=%s', requested)
        self.patternNameRequested = requested
        self.patternNameSet = False

    def isPatternNameRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-patternname-requested').debug3Func():
            logFunc('called. requested=%s', self.patternNameRequested)
        return self.patternNameRequested

    def getPatternName(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-patternname').debug3Func():
            logFunc('called. self.patternNameSet=%s, self.patternName=%s',
                    self.patternNameSet, self.patternName)
        if self.patternNameSet:
            return self.patternName
        return None

    def hasPatternName(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-patternname').debug3Func():
            logFunc('called. self.patternNameSet=%s, self.patternName=%s',
                    self.patternNameSet, self.patternName)
        if self.patternNameSet:
            return True
        return False

    def setPatternName(self, patternName):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-patternname').debug3Func():
            logFunc('called. patternName=%s, old=%s', patternName,
                    self.patternName)
        self.patternNameSet = True
        self.patternName = patternName

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        self.width = 0
        self.widthSet = False

        self.length = 0
        self.lengthSet = False

        self.patternName = 0
        self.patternNameSet = False

    def _getSelfKeyPath(self, lake, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("size", "http://qwilt.com/model/lake-example", "lake-example"))
        keyPath.addKeyPathPrefix(xmlVal)

        ancestorVal = Value()
        ancestorVal.setString(lake)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("lake", "http://qwilt.com/model/lake-example", "lake-example"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, lake, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(lake, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(lake, None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, lake, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(lake, None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, lake, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.hasWidth():
            valWidth = Value()
            if self.width is not None:
                valWidth.setInt64(self.width)
            else:
                valWidth.setEmpty()
            tagValueList.push(("width", "http://qwilt.com/model/lake-example"),
                              valWidth)

        if self.hasLength():
            valLength = Value()
            if self.length is not None:
                valLength.setInt64(self.length)
            else:
                valLength.setEmpty()
            tagValueList.push(
                ("length", "http://qwilt.com/model/lake-example"), valLength)

        if self.hasPatternName():
            valPatternName = Value()
            if self.patternName is not None:
                valPatternName.setString(self.patternName)
            else:
                valPatternName.setEmpty()
            tagValueList.push(
                ("pattern-name", "http://qwilt.com/model/lake-example"),
                valPatternName)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isWidthRequested():
            valWidth = Value()
            valWidth.setEmpty()
            tagValueList.push(("width", "http://qwilt.com/model/lake-example"),
                              valWidth)

        if self.isLengthRequested():
            valLength = Value()
            valLength.setEmpty()
            tagValueList.push(
                ("length", "http://qwilt.com/model/lake-example"), valLength)

        if self.isPatternNameRequested():
            valPatternName = Value()
            valPatternName.setEmpty()
            tagValueList.push(
                ("pattern-name", "http://qwilt.com/model/lake-example"),
                valPatternName)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isWidthRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "width") or \
                (ns != "http://qwilt.com/model/lake-example"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-width').errorFunc(
                        ):
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "width", "width",
                        "http://qwilt.com/model/lake-example", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-width-bad-value').infoFunc():
                    logFunc('width not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setWidth(tempVar)
            for logFunc in self._log('read-tag-values-width').debug3Func():
                logFunc('read width. width=%s, tempValue=%s', self.width,
                        tempValue.getType())

        if self.isLengthRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "length") or \
                (ns != "http://qwilt.com/model/lake-example"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-length'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "length", "length",
                        "http://qwilt.com/model/lake-example", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-length-bad-value').infoFunc():
                    logFunc('length not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setLength(tempVar)
            for logFunc in self._log('read-tag-values-length').debug3Func():
                logFunc('read length. length=%s, tempValue=%s', self.length,
                        tempValue.getType())

        if self.isPatternNameRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "pattern-name") or \
                (ns != "http://qwilt.com/model/lake-example"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-patternname'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "patternName", "pattern-name",
                        "http://qwilt.com/model/lake-example", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-pattern-name-bad-value').infoFunc():
                    logFunc('patternName not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setPatternName(tempVar)
            for logFunc in self._log(
                    'read-tag-values-pattern-name').debug3Func():
                logFunc('read patternName. patternName=%s, tempValue=%s',
                        self.patternName, tempValue.getType())

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 11
0
class BlinkyRaidArrayMaapi(RaidArrayMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-raidArray")
        self.domain = None

        

        
        self.osDeviceRequested = False
        self.osDevice = None
        self.osDeviceSet = False
        
        self.implementationRequested = False
        self.implementation = None
        self.implementationSet = False
        
        self.raidTypeRequested = False
        self.raidType = None
        self.raidTypeSet = False
        
        self.nameRequested = False
        self.name = None
        self.nameSet = False
        
        self.autoInitRequested = False
        self.autoInit = None
        self.autoInitSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestOsDevice(True)
        
        self.requestImplementation(True)
        
        self.requestRaidType(True)
        
        self.requestName(True)
        
        self.requestAutoInit(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestOsDevice(True)
        
        self.requestImplementation(True)
        
        self.requestRaidType(True)
        
        self.requestName(True)
        
        self.requestAutoInit(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestOsDevice(False)
        
        self.requestImplementation(False)
        
        self.requestRaidType(False)
        
        self.requestName(False)
        
        self.requestAutoInit(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestOsDevice(False)
        
        self.requestImplementation(False)
        
        self.requestRaidType(False)
        
        self.requestName(False)
        
        self.requestAutoInit(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setOsDevice(None)
        self.osDeviceSet = False
        
        self.setImplementation(None)
        self.implementationSet = False
        
        self.setRaidType(None)
        self.raidTypeSet = False
        
        self.setName(None)
        self.nameSet = False
        
        self.setAutoInit(None)
        self.autoInitSet = False
        
        

    def write (self
              , disk
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(disk, trxContext)

    def read (self
              , disk
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(disk, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , disk
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(disk, 
                                  True,
                                  trxContext)



    def requestOsDevice (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-osdevice').debug3Func(): logFunc('called. requested=%s', requested)
        self.osDeviceRequested = requested
        self.osDeviceSet = False

    def isOsDeviceRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-osdevice-requested').debug3Func(): logFunc('called. requested=%s', self.osDeviceRequested)
        return self.osDeviceRequested

    def getOsDevice (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-osdevice').debug3Func(): logFunc('called. self.osDeviceSet=%s, self.osDevice=%s', self.osDeviceSet, self.osDevice)
        if self.osDeviceSet:
            return self.osDevice
        return None

    def hasOsDevice (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-osdevice').debug3Func(): logFunc('called. self.osDeviceSet=%s, self.osDevice=%s', self.osDeviceSet, self.osDevice)
        if self.osDeviceSet:
            return True
        return False

    def setOsDevice (self, osDevice):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-osdevice').debug3Func(): logFunc('called. osDevice=%s, old=%s', osDevice, self.osDevice)
        self.osDeviceSet = True
        self.osDevice = osDevice

    def requestImplementation (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-implementation').debug3Func(): logFunc('called. requested=%s', requested)
        self.implementationRequested = requested
        self.implementationSet = False

    def isImplementationRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-implementation-requested').debug3Func(): logFunc('called. requested=%s', self.implementationRequested)
        return self.implementationRequested

    def getImplementation (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-implementation').debug3Func(): logFunc('called. self.implementationSet=%s, self.implementation=%s', self.implementationSet, self.implementation)
        if self.implementationSet:
            return self.implementation
        return None

    def hasImplementation (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-implementation').debug3Func(): logFunc('called. self.implementationSet=%s, self.implementation=%s', self.implementationSet, self.implementation)
        if self.implementationSet:
            return True
        return False

    def setImplementation (self, implementation):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-implementation').debug3Func(): logFunc('called. implementation=%s, old=%s', implementation, self.implementation)
        self.implementationSet = True
        self.implementation = implementation

    def requestRaidType (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-raidtype').debug3Func(): logFunc('called. requested=%s', requested)
        self.raidTypeRequested = requested
        self.raidTypeSet = False

    def isRaidTypeRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-raidtype-requested').debug3Func(): logFunc('called. requested=%s', self.raidTypeRequested)
        return self.raidTypeRequested

    def getRaidType (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-raidtype').debug3Func(): logFunc('called. self.raidTypeSet=%s, self.raidType=%s', self.raidTypeSet, self.raidType)
        if self.raidTypeSet:
            return self.raidType
        return None

    def hasRaidType (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-raidtype').debug3Func(): logFunc('called. self.raidTypeSet=%s, self.raidType=%s', self.raidTypeSet, self.raidType)
        if self.raidTypeSet:
            return True
        return False

    def setRaidType (self, raidType):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-raidtype').debug3Func(): logFunc('called. raidType=%s, old=%s', raidType, self.raidType)
        self.raidTypeSet = True
        self.raidType = raidType

    def requestName (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-name').debug3Func(): logFunc('called. requested=%s', requested)
        self.nameRequested = requested
        self.nameSet = False

    def isNameRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-name-requested').debug3Func(): logFunc('called. requested=%s', self.nameRequested)
        return self.nameRequested

    def getName (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-name').debug3Func(): logFunc('called. self.nameSet=%s, self.name=%s', self.nameSet, self.name)
        if self.nameSet:
            return self.name
        return None

    def hasName (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-name').debug3Func(): logFunc('called. self.nameSet=%s, self.name=%s', self.nameSet, self.name)
        if self.nameSet:
            return True
        return False

    def setName (self, name):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-name').debug3Func(): logFunc('called. name=%s, old=%s', name, self.name)
        self.nameSet = True
        self.name = name

    def requestAutoInit (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-autoinit').debug3Func(): logFunc('called. requested=%s', requested)
        self.autoInitRequested = requested
        self.autoInitSet = False

    def isAutoInitRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-autoinit-requested').debug3Func(): logFunc('called. requested=%s', self.autoInitRequested)
        return self.autoInitRequested

    def getAutoInit (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-autoinit').debug3Func(): logFunc('called. self.autoInitSet=%s, self.autoInit=%s', self.autoInitSet, self.autoInit)
        if self.autoInitSet:
            return self.autoInit
        return None

    def hasAutoInit (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-autoinit').debug3Func(): logFunc('called. self.autoInitSet=%s, self.autoInit=%s', self.autoInitSet, self.autoInit)
        if self.autoInitSet:
            return True
        return False

    def setAutoInit (self, autoInit):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-autoinit').debug3Func(): logFunc('called. autoInit=%s, old=%s', autoInit, self.autoInit)
        self.autoInitSet = True
        self.autoInit = autoInit


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.osDevice = 0
        self.osDeviceSet = False
        
        self.implementation = 0
        self.implementationSet = False
        
        self.raidType = 0
        self.raidTypeSet = False
        
        self.name = 0
        self.nameSet = False
        
        self.autoInit = 0
        self.autoInitSet = False
        

    def _getSelfKeyPath (self, disk
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("raid-array", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk", "qt-strg-dsk"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("system-defaults", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk", "qt-strg-dsk"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(disk);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("disk", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk", "qt-strg-dsk"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("storage", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage", "qt-strg"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        disk, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(disk, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(disk, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       disk, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(disk, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               disk, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasOsDevice():
            valOsDevice = Value()
            if self.osDevice is not None:
                valOsDevice.setString(self.osDevice)
            else:
                valOsDevice.setEmpty()
            tagValueList.push(("os-device", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"), valOsDevice)
        
        if self.hasImplementation():
            valImplementation = Value()
            if self.implementation is not None:
                valImplementation.setEnum(self.implementation.getValue())
            else:
                valImplementation.setEmpty()
            tagValueList.push(("implementation", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"), valImplementation)
        
        if self.hasRaidType():
            valRaidType = Value()
            if self.raidType is not None:
                valRaidType.setEnum(self.raidType.getValue())
            else:
                valRaidType.setEmpty()
            tagValueList.push(("raid-type", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"), valRaidType)
        
        if self.hasName():
            valName = Value()
            if self.name is not None:
                valName.setString(self.name)
            else:
                valName.setEmpty()
            tagValueList.push(("name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"), valName)
        
        if self.hasAutoInit():
            valAutoInit = Value()
            if self.autoInit is not None:
                valAutoInit.setBool(self.autoInit)
            else:
                valAutoInit.setEmpty()
            tagValueList.push(("auto-init", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"), valAutoInit)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isOsDeviceRequested():
            valOsDevice = Value()
            valOsDevice.setEmpty()
            tagValueList.push(("os-device", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"), valOsDevice)
        
        if self.isImplementationRequested():
            valImplementation = Value()
            valImplementation.setEmpty()
            tagValueList.push(("implementation", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"), valImplementation)
        
        if self.isRaidTypeRequested():
            valRaidType = Value()
            valRaidType.setEmpty()
            tagValueList.push(("raid-type", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"), valRaidType)
        
        if self.isNameRequested():
            valName = Value()
            valName.setEmpty()
            tagValueList.push(("name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"), valName)
        
        if self.isAutoInitRequested():
            valAutoInit = Value()
            valAutoInit.setEmpty()
            tagValueList.push(("auto-init", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"), valAutoInit)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isOsDeviceRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "os-device") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-osdevice').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "osDevice", "os-device", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-os-device-bad-value').infoFunc(): logFunc('osDevice not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setOsDevice(tempVar)
            for logFunc in self._log('read-tag-values-os-device').debug3Func(): logFunc('read osDevice. osDevice=%s, tempValue=%s', self.osDevice, tempValue.getType())
        
        if self.isImplementationRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "implementation") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-implementation').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "implementation", "implementation", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-implementation-bad-value').infoFunc(): logFunc('implementation not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setImplementation(tempVar)
            for logFunc in self._log('read-tag-values-implementation').debug3Func(): logFunc('read implementation. implementation=%s, tempValue=%s', self.implementation, tempValue.getType())
        
        if self.isRaidTypeRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "raid-type") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-raidtype').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "raidType", "raid-type", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-raid-type-bad-value').infoFunc(): logFunc('raidType not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setRaidType(tempVar)
            for logFunc in self._log('read-tag-values-raid-type').debug3Func(): logFunc('read raidType. raidType=%s, tempValue=%s', self.raidType, tempValue.getType())
        
        if self.isNameRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "name") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-name').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "name", "name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-name-bad-value').infoFunc(): logFunc('name not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setName(tempVar)
            for logFunc in self._log('read-tag-values-name').debug3Func(): logFunc('read name. name=%s, tempValue=%s', self.name, tempValue.getType())
        
        if self.isAutoInitRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "auto-init") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-autoinit').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "autoInit", "auto-init", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asBool()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-auto-init-bad-value').infoFunc(): logFunc('autoInit not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setAutoInit(tempVar)
            for logFunc in self._log('read-tag-values-auto-init').debug3Func(): logFunc('read autoInit. autoInit=%s, tempValue=%s', self.autoInit, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 12
0
class BlinkyDpdkMaapi(DpdkMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-dpdk")
        self.domain = None

        

        
        self.channelQueueSizeRequested = False
        self.channelQueueSize = None
        self.channelQueueSizeSet = False
        
        self.memSizeRequested = False
        self.memSize = None
        self.memSizeSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestChannelQueueSize(True)
        
        self.requestMemSize(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestChannelQueueSize(True)
        
        self.requestMemSize(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestChannelQueueSize(False)
        
        self.requestMemSize(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestChannelQueueSize(False)
        
        self.requestMemSize(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setChannelQueueSize(None)
        self.channelQueueSizeSet = False
        
        self.setMemSize(None)
        self.memSizeSet = False
        
        

    def write (self
              , line
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(line, trxContext)

    def read (self
              , line
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(line, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , line
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(line, 
                                  True,
                                  trxContext)



    def requestChannelQueueSize (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-channelqueuesize').debug3Func(): logFunc('called. requested=%s', requested)
        self.channelQueueSizeRequested = requested
        self.channelQueueSizeSet = False

    def isChannelQueueSizeRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-channelqueuesize-requested').debug3Func(): logFunc('called. requested=%s', self.channelQueueSizeRequested)
        return self.channelQueueSizeRequested

    def getChannelQueueSize (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-channelqueuesize').debug3Func(): logFunc('called. self.channelQueueSizeSet=%s, self.channelQueueSize=%s', self.channelQueueSizeSet, self.channelQueueSize)
        if self.channelQueueSizeSet:
            return self.channelQueueSize
        return None

    def hasChannelQueueSize (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-channelqueuesize').debug3Func(): logFunc('called. self.channelQueueSizeSet=%s, self.channelQueueSize=%s', self.channelQueueSizeSet, self.channelQueueSize)
        if self.channelQueueSizeSet:
            return True
        return False

    def setChannelQueueSize (self, channelQueueSize):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-channelqueuesize').debug3Func(): logFunc('called. channelQueueSize=%s, old=%s', channelQueueSize, self.channelQueueSize)
        self.channelQueueSizeSet = True
        self.channelQueueSize = channelQueueSize

    def requestMemSize (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-memsize').debug3Func(): logFunc('called. requested=%s', requested)
        self.memSizeRequested = requested
        self.memSizeSet = False

    def isMemSizeRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-memsize-requested').debug3Func(): logFunc('called. requested=%s', self.memSizeRequested)
        return self.memSizeRequested

    def getMemSize (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-memsize').debug3Func(): logFunc('called. self.memSizeSet=%s, self.memSize=%s', self.memSizeSet, self.memSize)
        if self.memSizeSet:
            return self.memSize
        return None

    def hasMemSize (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-memsize').debug3Func(): logFunc('called. self.memSizeSet=%s, self.memSize=%s', self.memSizeSet, self.memSize)
        if self.memSizeSet:
            return True
        return False

    def setMemSize (self, memSize):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-memsize').debug3Func(): logFunc('called. memSize=%s, old=%s', memSize, self.memSize)
        self.memSizeSet = True
        self.memSize = memSize


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.channelQueueSize = 0
        self.channelQueueSizeSet = False
        
        self.memSize = 0
        self.memSizeSet = False
        

    def _getSelfKeyPath (self, line
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("dpdk", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("dispatcher", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("system-defaults", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(line);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("line", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("content", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", "qtc"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        line, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(line, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(line, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       line, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(line, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               line, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasChannelQueueSize():
            valChannelQueueSize = Value()
            if self.channelQueueSize is not None:
                valChannelQueueSize.setInt64(self.channelQueueSize)
            else:
                valChannelQueueSize.setEmpty()
            tagValueList.push(("channel-queue-size", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valChannelQueueSize)
        
        if self.hasMemSize():
            valMemSize = Value()
            if self.memSize is not None:
                valMemSize.setInt64(self.memSize)
            else:
                valMemSize.setEmpty()
            tagValueList.push(("mem-size", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valMemSize)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isChannelQueueSizeRequested():
            valChannelQueueSize = Value()
            valChannelQueueSize.setEmpty()
            tagValueList.push(("channel-queue-size", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valChannelQueueSize)
        
        if self.isMemSizeRequested():
            valMemSize = Value()
            valMemSize.setEmpty()
            tagValueList.push(("mem-size", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valMemSize)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isChannelQueueSizeRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "channel-queue-size") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-channelqueuesize').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "channelQueueSize", "channel-queue-size", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-channel-queue-size-bad-value').infoFunc(): logFunc('channelQueueSize not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setChannelQueueSize(tempVar)
            for logFunc in self._log('read-tag-values-channel-queue-size').debug3Func(): logFunc('read channelQueueSize. channelQueueSize=%s, tempValue=%s', self.channelQueueSize, tempValue.getType())
        
        if self.isMemSizeRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "mem-size") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-memsize').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "memSize", "mem-size", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-mem-size-bad-value').infoFunc(): logFunc('memSize not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setMemSize(tempVar)
            for logFunc in self._log('read-tag-values-mem-size').debug3Func(): logFunc('read memSize. memSize=%s, tempValue=%s', self.memSize, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 13
0
class BlinkyDeviceMaapi(DeviceMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-device")
        self.domain = None

        

        
        self.pciDeviceIdRequested = False
        self.pciDeviceId = None
        self.pciDeviceIdSet = False
        
        self.countersClearEventRequested = False
        self.countersClearEvent = None
        self.countersClearEventSet = False
        
        self.pciVendorIdRequested = False
        self.pciVendorId = None
        self.pciVendorIdSet = False
        
        self.pciIndexRequested = False
        self.pciIndex = None
        self.pciIndexSet = False
        
        self.osNameRequested = False
        self.osName = None
        self.osNameSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestPciDeviceId(True)
        
        self.requestCountersClearEvent(True)
        
        self.requestPciVendorId(True)
        
        self.requestPciIndex(True)
        
        self.requestOsName(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestPciDeviceId(True)
        
        self.requestCountersClearEvent(True)
        
        self.requestPciVendorId(True)
        
        self.requestPciIndex(True)
        
        self.requestOsName(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestPciDeviceId(False)
        
        self.requestCountersClearEvent(False)
        
        self.requestPciVendorId(False)
        
        self.requestPciIndex(False)
        
        self.requestOsName(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestPciDeviceId(False)
        
        self.requestCountersClearEvent(False)
        
        self.requestPciVendorId(False)
        
        self.requestPciIndex(False)
        
        self.requestOsName(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setPciDeviceId(None)
        self.pciDeviceIdSet = False
        
        self.setCountersClearEvent(None)
        self.countersClearEventSet = False
        
        self.setPciVendorId(None)
        self.pciVendorIdSet = False
        
        self.setPciIndex(None)
        self.pciIndexSet = False
        
        self.setOsName(None)
        self.osNameSet = False
        
        

    def write (self
              , interface
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(interface, trxContext)

    def read (self
              , interface
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(interface, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , interface
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(interface, 
                                  True,
                                  trxContext)



    def requestPciDeviceId (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-pcideviceid').debug3Func(): logFunc('called. requested=%s', requested)
        self.pciDeviceIdRequested = requested
        self.pciDeviceIdSet = False

    def isPciDeviceIdRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-pcideviceid-requested').debug3Func(): logFunc('called. requested=%s', self.pciDeviceIdRequested)
        return self.pciDeviceIdRequested

    def getPciDeviceId (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-pcideviceid').debug3Func(): logFunc('called. self.pciDeviceIdSet=%s, self.pciDeviceId=%s', self.pciDeviceIdSet, self.pciDeviceId)
        if self.pciDeviceIdSet:
            return self.pciDeviceId
        return None

    def hasPciDeviceId (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-pcideviceid').debug3Func(): logFunc('called. self.pciDeviceIdSet=%s, self.pciDeviceId=%s', self.pciDeviceIdSet, self.pciDeviceId)
        if self.pciDeviceIdSet:
            return True
        return False

    def setPciDeviceId (self, pciDeviceId):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-pcideviceid').debug3Func(): logFunc('called. pciDeviceId=%s, old=%s', pciDeviceId, self.pciDeviceId)
        self.pciDeviceIdSet = True
        self.pciDeviceId = pciDeviceId

    def requestCountersClearEvent (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-countersclearevent').debug3Func(): logFunc('called. requested=%s', requested)
        self.countersClearEventRequested = requested
        self.countersClearEventSet = False

    def isCountersClearEventRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-countersclearevent-requested').debug3Func(): logFunc('called. requested=%s', self.countersClearEventRequested)
        return self.countersClearEventRequested

    def getCountersClearEvent (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-countersclearevent').debug3Func(): logFunc('called. self.countersClearEventSet=%s, self.countersClearEvent=%s', self.countersClearEventSet, self.countersClearEvent)
        if self.countersClearEventSet:
            return self.countersClearEvent
        return None

    def hasCountersClearEvent (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-countersclearevent').debug3Func(): logFunc('called. self.countersClearEventSet=%s, self.countersClearEvent=%s', self.countersClearEventSet, self.countersClearEvent)
        if self.countersClearEventSet:
            return True
        return False

    def setCountersClearEvent (self, countersClearEvent):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-countersclearevent').debug3Func(): logFunc('called. countersClearEvent=%s, old=%s', countersClearEvent, self.countersClearEvent)
        self.countersClearEventSet = True
        self.countersClearEvent = countersClearEvent

    def requestPciVendorId (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-pcivendorid').debug3Func(): logFunc('called. requested=%s', requested)
        self.pciVendorIdRequested = requested
        self.pciVendorIdSet = False

    def isPciVendorIdRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-pcivendorid-requested').debug3Func(): logFunc('called. requested=%s', self.pciVendorIdRequested)
        return self.pciVendorIdRequested

    def getPciVendorId (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-pcivendorid').debug3Func(): logFunc('called. self.pciVendorIdSet=%s, self.pciVendorId=%s', self.pciVendorIdSet, self.pciVendorId)
        if self.pciVendorIdSet:
            return self.pciVendorId
        return None

    def hasPciVendorId (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-pcivendorid').debug3Func(): logFunc('called. self.pciVendorIdSet=%s, self.pciVendorId=%s', self.pciVendorIdSet, self.pciVendorId)
        if self.pciVendorIdSet:
            return True
        return False

    def setPciVendorId (self, pciVendorId):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-pcivendorid').debug3Func(): logFunc('called. pciVendorId=%s, old=%s', pciVendorId, self.pciVendorId)
        self.pciVendorIdSet = True
        self.pciVendorId = pciVendorId

    def requestPciIndex (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-pciindex').debug3Func(): logFunc('called. requested=%s', requested)
        self.pciIndexRequested = requested
        self.pciIndexSet = False

    def isPciIndexRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-pciindex-requested').debug3Func(): logFunc('called. requested=%s', self.pciIndexRequested)
        return self.pciIndexRequested

    def getPciIndex (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-pciindex').debug3Func(): logFunc('called. self.pciIndexSet=%s, self.pciIndex=%s', self.pciIndexSet, self.pciIndex)
        if self.pciIndexSet:
            return self.pciIndex
        return None

    def hasPciIndex (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-pciindex').debug3Func(): logFunc('called. self.pciIndexSet=%s, self.pciIndex=%s', self.pciIndexSet, self.pciIndex)
        if self.pciIndexSet:
            return True
        return False

    def setPciIndex (self, pciIndex):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-pciindex').debug3Func(): logFunc('called. pciIndex=%s, old=%s', pciIndex, self.pciIndex)
        self.pciIndexSet = True
        self.pciIndex = pciIndex

    def requestOsName (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-osname').debug3Func(): logFunc('called. requested=%s', requested)
        self.osNameRequested = requested
        self.osNameSet = False

    def isOsNameRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-osname-requested').debug3Func(): logFunc('called. requested=%s', self.osNameRequested)
        return self.osNameRequested

    def getOsName (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-osname').debug3Func(): logFunc('called. self.osNameSet=%s, self.osName=%s', self.osNameSet, self.osName)
        if self.osNameSet:
            return self.osName
        return None

    def hasOsName (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-osname').debug3Func(): logFunc('called. self.osNameSet=%s, self.osName=%s', self.osNameSet, self.osName)
        if self.osNameSet:
            return True
        return False

    def setOsName (self, osName):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-osname').debug3Func(): logFunc('called. osName=%s, old=%s', osName, self.osName)
        self.osNameSet = True
        self.osName = osName


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.pciDeviceId = 0
        self.pciDeviceIdSet = False
        
        self.countersClearEvent = 0
        self.countersClearEventSet = False
        
        self.pciVendorId = 0
        self.pciVendorIdSet = False
        
        self.pciIndex = 0
        self.pciIndexSet = False
        
        self.osName = 0
        self.osNameSet = False
        

    def _getSelfKeyPath (self, interface
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("device", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("system-defaults", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(interface);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("interface", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("interfaces", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        interface, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(interface, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(interface, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       interface, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(interface, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               interface, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasPciDeviceId():
            valPciDeviceId = Value()
            if self.pciDeviceId is not None:
                valPciDeviceId.setString(self.pciDeviceId)
            else:
                valPciDeviceId.setEmpty()
            tagValueList.push(("pci-device-id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valPciDeviceId)
        
        if self.hasCountersClearEvent():
            valCountersClearEvent = Value()
            if self.countersClearEvent is not None:
                valCountersClearEvent.setEnum(self.countersClearEvent.getValue())
            else:
                valCountersClearEvent.setEmpty()
            tagValueList.push(("counters-clear-event", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valCountersClearEvent)
        
        if self.hasPciVendorId():
            valPciVendorId = Value()
            if self.pciVendorId is not None:
                valPciVendorId.setString(self.pciVendorId)
            else:
                valPciVendorId.setEmpty()
            tagValueList.push(("pci-vendor-id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valPciVendorId)
        
        if self.hasPciIndex():
            valPciIndex = Value()
            if self.pciIndex is not None:
                valPciIndex.setUint64(self.pciIndex)
            else:
                valPciIndex.setEmpty()
            tagValueList.push(("pci-index", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valPciIndex)
        
        if self.hasOsName():
            valOsName = Value()
            if self.osName is not None:
                valOsName.setString(self.osName)
            else:
                valOsName.setEmpty()
            tagValueList.push(("os-name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valOsName)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isPciDeviceIdRequested():
            valPciDeviceId = Value()
            valPciDeviceId.setEmpty()
            tagValueList.push(("pci-device-id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valPciDeviceId)
        
        if self.isCountersClearEventRequested():
            valCountersClearEvent = Value()
            valCountersClearEvent.setEmpty()
            tagValueList.push(("counters-clear-event", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valCountersClearEvent)
        
        if self.isPciVendorIdRequested():
            valPciVendorId = Value()
            valPciVendorId.setEmpty()
            tagValueList.push(("pci-vendor-id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valPciVendorId)
        
        if self.isPciIndexRequested():
            valPciIndex = Value()
            valPciIndex.setEmpty()
            tagValueList.push(("pci-index", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valPciIndex)
        
        if self.isOsNameRequested():
            valOsName = Value()
            valOsName.setEmpty()
            tagValueList.push(("os-name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valOsName)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isPciDeviceIdRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "pci-device-id") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-pcideviceid').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "pciDeviceId", "pci-device-id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-pci-device-id-bad-value').infoFunc(): logFunc('pciDeviceId not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setPciDeviceId(tempVar)
            for logFunc in self._log('read-tag-values-pci-device-id').debug3Func(): logFunc('read pciDeviceId. pciDeviceId=%s, tempValue=%s', self.pciDeviceId, tempValue.getType())
        
        if self.isCountersClearEventRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "counters-clear-event") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-countersclearevent').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "countersClearEvent", "counters-clear-event", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-counters-clear-event-bad-value').infoFunc(): logFunc('countersClearEvent not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setCountersClearEvent(tempVar)
            for logFunc in self._log('read-tag-values-counters-clear-event').debug3Func(): logFunc('read countersClearEvent. countersClearEvent=%s, tempValue=%s', self.countersClearEvent, tempValue.getType())
        
        if self.isPciVendorIdRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "pci-vendor-id") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-pcivendorid').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "pciVendorId", "pci-vendor-id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-pci-vendor-id-bad-value').infoFunc(): logFunc('pciVendorId not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setPciVendorId(tempVar)
            for logFunc in self._log('read-tag-values-pci-vendor-id').debug3Func(): logFunc('read pciVendorId. pciVendorId=%s, tempValue=%s', self.pciVendorId, tempValue.getType())
        
        if self.isPciIndexRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "pci-index") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-pciindex').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "pciIndex", "pci-index", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asUint64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-pci-index-bad-value').infoFunc(): logFunc('pciIndex not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setPciIndex(tempVar)
            for logFunc in self._log('read-tag-values-pci-index').debug3Func(): logFunc('read pciIndex. pciIndex=%s, tempValue=%s', self.pciIndex, tempValue.getType())
        
        if self.isOsNameRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "os-name") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-osname').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "osName", "os-name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-os-name-bad-value').infoFunc(): logFunc('osName not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setOsName(tempVar)
            for logFunc in self._log('read-tag-values-os-name').debug3Func(): logFunc('read osName. osName=%s, tempValue=%s', self.osName, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 14
0
class BlinkyThresholdsMaapi(ThresholdsMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-thresholds")
        self.domain = None

        self.pollLatencyErrorRequested = False
        self.pollLatencyError = None
        self.pollLatencyErrorSet = False

        self.overallPollDurationWarningRequested = False
        self.overallPollDurationWarning = None
        self.overallPollDurationWarningSet = False

        self.pollLatencyWarningRequested = False
        self.pollLatencyWarning = None
        self.pollLatencyWarningSet = False

        self.singlePollDurationWarningRequested = False
        self.singlePollDurationWarning = None
        self.singlePollDurationWarningSet = False

        self.singlePollDurationErrorRequested = False
        self.singlePollDurationError = None
        self.singlePollDurationErrorSet = False

        self.overallPollDurationErrorRequested = False
        self.overallPollDurationError = None
        self.overallPollDurationErrorSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestPollLatencyError(True)

        self.requestOverallPollDurationWarning(True)

        self.requestPollLatencyWarning(True)

        self.requestSinglePollDurationWarning(True)

        self.requestSinglePollDurationError(True)

        self.requestOverallPollDurationError(True)

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestPollLatencyError(True)

        self.requestOverallPollDurationWarning(True)

        self.requestPollLatencyWarning(True)

        self.requestSinglePollDurationWarning(True)

        self.requestSinglePollDurationError(True)

        self.requestOverallPollDurationError(True)

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestPollLatencyError(False)

        self.requestOverallPollDurationWarning(False)

        self.requestPollLatencyWarning(False)

        self.requestSinglePollDurationWarning(False)

        self.requestSinglePollDurationError(False)

        self.requestOverallPollDurationError(False)

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestPollLatencyError(False)

        self.requestOverallPollDurationWarning(False)

        self.requestPollLatencyWarning(False)

        self.requestSinglePollDurationWarning(False)

        self.requestSinglePollDurationError(False)

        self.requestOverallPollDurationError(False)

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

        self.setPollLatencyError(None)
        self.pollLatencyErrorSet = False

        self.setOverallPollDurationWarning(None)
        self.overallPollDurationWarningSet = False

        self.setPollLatencyWarning(None)
        self.pollLatencyWarningSet = False

        self.setSinglePollDurationWarning(None)
        self.singlePollDurationWarningSet = False

        self.setSinglePollDurationError(None)
        self.singlePollDurationErrorSet = False

        self.setOverallPollDurationError(None)
        self.overallPollDurationErrorSet = False

    def write(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(trxContext)

    def read(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(False, trxContext)

    def readAllOrFail(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(True, trxContext)

    def requestPollLatencyError(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-polllatencyerror').debug3Func():
            logFunc('called. requested=%s', requested)
        self.pollLatencyErrorRequested = requested
        self.pollLatencyErrorSet = False

    def isPollLatencyErrorRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-polllatencyerror-requested').debug3Func():
            logFunc('called. requested=%s', self.pollLatencyErrorRequested)
        return self.pollLatencyErrorRequested

    def getPollLatencyError(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-polllatencyerror').debug3Func():
            logFunc(
                'called. self.pollLatencyErrorSet=%s, self.pollLatencyError=%s',
                self.pollLatencyErrorSet, self.pollLatencyError)
        if self.pollLatencyErrorSet:
            return self.pollLatencyError
        return None

    def hasPollLatencyError(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-polllatencyerror').debug3Func():
            logFunc(
                'called. self.pollLatencyErrorSet=%s, self.pollLatencyError=%s',
                self.pollLatencyErrorSet, self.pollLatencyError)
        if self.pollLatencyErrorSet:
            return True
        return False

    def setPollLatencyError(self, pollLatencyError):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-polllatencyerror').debug3Func():
            logFunc('called. pollLatencyError=%s, old=%s', pollLatencyError,
                    self.pollLatencyError)
        self.pollLatencyErrorSet = True
        self.pollLatencyError = pollLatencyError

    def requestOverallPollDurationWarning(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'request-overallpolldurationwarning').debug3Func():
            logFunc('called. requested=%s', requested)
        self.overallPollDurationWarningRequested = requested
        self.overallPollDurationWarningSet = False

    def isOverallPollDurationWarningRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-overallpolldurationwarning-requested').debug3Func():
            logFunc('called. requested=%s',
                    self.overallPollDurationWarningRequested)
        return self.overallPollDurationWarningRequested

    def getOverallPollDurationWarning(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'get-overallpolldurationwarning').debug3Func():
            logFunc(
                'called. self.overallPollDurationWarningSet=%s, self.overallPollDurationWarning=%s',
                self.overallPollDurationWarningSet,
                self.overallPollDurationWarning)
        if self.overallPollDurationWarningSet:
            return self.overallPollDurationWarning
        return None

    def hasOverallPollDurationWarning(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'has-overallpolldurationwarning').debug3Func():
            logFunc(
                'called. self.overallPollDurationWarningSet=%s, self.overallPollDurationWarning=%s',
                self.overallPollDurationWarningSet,
                self.overallPollDurationWarning)
        if self.overallPollDurationWarningSet:
            return True
        return False

    def setOverallPollDurationWarning(self, overallPollDurationWarning):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'set-overallpolldurationwarning').debug3Func():
            logFunc('called. overallPollDurationWarning=%s, old=%s',
                    overallPollDurationWarning,
                    self.overallPollDurationWarning)
        self.overallPollDurationWarningSet = True
        self.overallPollDurationWarning = overallPollDurationWarning

    def requestPollLatencyWarning(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-polllatencywarning').debug3Func():
            logFunc('called. requested=%s', requested)
        self.pollLatencyWarningRequested = requested
        self.pollLatencyWarningSet = False

    def isPollLatencyWarningRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-polllatencywarning-requested').debug3Func():
            logFunc('called. requested=%s', self.pollLatencyWarningRequested)
        return self.pollLatencyWarningRequested

    def getPollLatencyWarning(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-polllatencywarning').debug3Func():
            logFunc(
                'called. self.pollLatencyWarningSet=%s, self.pollLatencyWarning=%s',
                self.pollLatencyWarningSet, self.pollLatencyWarning)
        if self.pollLatencyWarningSet:
            return self.pollLatencyWarning
        return None

    def hasPollLatencyWarning(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-polllatencywarning').debug3Func():
            logFunc(
                'called. self.pollLatencyWarningSet=%s, self.pollLatencyWarning=%s',
                self.pollLatencyWarningSet, self.pollLatencyWarning)
        if self.pollLatencyWarningSet:
            return True
        return False

    def setPollLatencyWarning(self, pollLatencyWarning):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-polllatencywarning').debug3Func():
            logFunc('called. pollLatencyWarning=%s, old=%s',
                    pollLatencyWarning, self.pollLatencyWarning)
        self.pollLatencyWarningSet = True
        self.pollLatencyWarning = pollLatencyWarning

    def requestSinglePollDurationWarning(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'request-singlepolldurationwarning').debug3Func():
            logFunc('called. requested=%s', requested)
        self.singlePollDurationWarningRequested = requested
        self.singlePollDurationWarningSet = False

    def isSinglePollDurationWarningRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-singlepolldurationwarning-requested').debug3Func():
            logFunc('called. requested=%s',
                    self.singlePollDurationWarningRequested)
        return self.singlePollDurationWarningRequested

    def getSinglePollDurationWarning(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-singlepolldurationwarning').debug3Func():
            logFunc(
                'called. self.singlePollDurationWarningSet=%s, self.singlePollDurationWarning=%s',
                self.singlePollDurationWarningSet,
                self.singlePollDurationWarning)
        if self.singlePollDurationWarningSet:
            return self.singlePollDurationWarning
        return None

    def hasSinglePollDurationWarning(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-singlepolldurationwarning').debug3Func():
            logFunc(
                'called. self.singlePollDurationWarningSet=%s, self.singlePollDurationWarning=%s',
                self.singlePollDurationWarningSet,
                self.singlePollDurationWarning)
        if self.singlePollDurationWarningSet:
            return True
        return False

    def setSinglePollDurationWarning(self, singlePollDurationWarning):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-singlepolldurationwarning').debug3Func():
            logFunc('called. singlePollDurationWarning=%s, old=%s',
                    singlePollDurationWarning, self.singlePollDurationWarning)
        self.singlePollDurationWarningSet = True
        self.singlePollDurationWarning = singlePollDurationWarning

    def requestSinglePollDurationError(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'request-singlepolldurationerror').debug3Func():
            logFunc('called. requested=%s', requested)
        self.singlePollDurationErrorRequested = requested
        self.singlePollDurationErrorSet = False

    def isSinglePollDurationErrorRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-singlepolldurationerror-requested').debug3Func():
            logFunc('called. requested=%s',
                    self.singlePollDurationErrorRequested)
        return self.singlePollDurationErrorRequested

    def getSinglePollDurationError(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-singlepolldurationerror').debug3Func():
            logFunc(
                'called. self.singlePollDurationErrorSet=%s, self.singlePollDurationError=%s',
                self.singlePollDurationErrorSet, self.singlePollDurationError)
        if self.singlePollDurationErrorSet:
            return self.singlePollDurationError
        return None

    def hasSinglePollDurationError(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-singlepolldurationerror').debug3Func():
            logFunc(
                'called. self.singlePollDurationErrorSet=%s, self.singlePollDurationError=%s',
                self.singlePollDurationErrorSet, self.singlePollDurationError)
        if self.singlePollDurationErrorSet:
            return True
        return False

    def setSinglePollDurationError(self, singlePollDurationError):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-singlepolldurationerror').debug3Func():
            logFunc('called. singlePollDurationError=%s, old=%s',
                    singlePollDurationError, self.singlePollDurationError)
        self.singlePollDurationErrorSet = True
        self.singlePollDurationError = singlePollDurationError

    def requestOverallPollDurationError(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'request-overallpolldurationerror').debug3Func():
            logFunc('called. requested=%s', requested)
        self.overallPollDurationErrorRequested = requested
        self.overallPollDurationErrorSet = False

    def isOverallPollDurationErrorRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-overallpolldurationerror-requested').debug3Func():
            logFunc('called. requested=%s',
                    self.overallPollDurationErrorRequested)
        return self.overallPollDurationErrorRequested

    def getOverallPollDurationError(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-overallpolldurationerror').debug3Func():
            logFunc(
                'called. self.overallPollDurationErrorSet=%s, self.overallPollDurationError=%s',
                self.overallPollDurationErrorSet,
                self.overallPollDurationError)
        if self.overallPollDurationErrorSet:
            return self.overallPollDurationError
        return None

    def hasOverallPollDurationError(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-overallpolldurationerror').debug3Func():
            logFunc(
                'called. self.overallPollDurationErrorSet=%s, self.overallPollDurationError=%s',
                self.overallPollDurationErrorSet,
                self.overallPollDurationError)
        if self.overallPollDurationErrorSet:
            return True
        return False

    def setOverallPollDurationError(self, overallPollDurationError):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-overallpolldurationerror').debug3Func():
            logFunc('called. overallPollDurationError=%s, old=%s',
                    overallPollDurationError, self.overallPollDurationError)
        self.overallPollDurationErrorSet = True
        self.overallPollDurationError = overallPollDurationError

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        self.pollLatencyError = 0
        self.pollLatencyErrorSet = False

        self.overallPollDurationWarning = 0
        self.overallPollDurationWarningSet = False

        self.pollLatencyWarning = 0
        self.pollLatencyWarningSet = False

        self.singlePollDurationWarning = 0
        self.singlePollDurationWarningSet = False

        self.singlePollDurationError = 0
        self.singlePollDurationErrorSet = False

        self.overallPollDurationError = 0
        self.overallPollDurationErrorSet = False

    def _getSelfKeyPath(self, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag((
            "thresholds",
            "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
            "qt-pltf-mngr"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag((
            "system-defaults",
            "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
            "qt-pltf-mngr"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag((
            "manager",
            "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
            "qt-pltf-mngr"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("platform",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform",
             "qt-pltf"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.hasPollLatencyError():
            valPollLatencyError = Value()
            if self.pollLatencyError is not None:
                valPollLatencyError.setInt64(self.pollLatencyError)
            else:
                valPollLatencyError.setEmpty()
            tagValueList.push((
                "poll-latency-error",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valPollLatencyError)

        if self.hasOverallPollDurationWarning():
            valOverallPollDurationWarning = Value()
            if self.overallPollDurationWarning is not None:
                valOverallPollDurationWarning.setInt64(
                    self.overallPollDurationWarning)
            else:
                valOverallPollDurationWarning.setEmpty()
            tagValueList.push((
                "overall-poll-duration-warning",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valOverallPollDurationWarning)

        if self.hasPollLatencyWarning():
            valPollLatencyWarning = Value()
            if self.pollLatencyWarning is not None:
                valPollLatencyWarning.setInt64(self.pollLatencyWarning)
            else:
                valPollLatencyWarning.setEmpty()
            tagValueList.push((
                "poll-latency-warning",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valPollLatencyWarning)

        if self.hasSinglePollDurationWarning():
            valSinglePollDurationWarning = Value()
            if self.singlePollDurationWarning is not None:
                valSinglePollDurationWarning.setInt64(
                    self.singlePollDurationWarning)
            else:
                valSinglePollDurationWarning.setEmpty()
            tagValueList.push((
                "single-poll-duration-warning",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valSinglePollDurationWarning)

        if self.hasSinglePollDurationError():
            valSinglePollDurationError = Value()
            if self.singlePollDurationError is not None:
                valSinglePollDurationError.setInt64(
                    self.singlePollDurationError)
            else:
                valSinglePollDurationError.setEmpty()
            tagValueList.push((
                "single-poll-duration-error",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valSinglePollDurationError)

        if self.hasOverallPollDurationError():
            valOverallPollDurationError = Value()
            if self.overallPollDurationError is not None:
                valOverallPollDurationError.setInt64(
                    self.overallPollDurationError)
            else:
                valOverallPollDurationError.setEmpty()
            tagValueList.push((
                "overall-poll-duration-error",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valOverallPollDurationError)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isPollLatencyErrorRequested():
            valPollLatencyError = Value()
            valPollLatencyError.setEmpty()
            tagValueList.push((
                "poll-latency-error",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valPollLatencyError)

        if self.isOverallPollDurationWarningRequested():
            valOverallPollDurationWarning = Value()
            valOverallPollDurationWarning.setEmpty()
            tagValueList.push((
                "overall-poll-duration-warning",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valOverallPollDurationWarning)

        if self.isPollLatencyWarningRequested():
            valPollLatencyWarning = Value()
            valPollLatencyWarning.setEmpty()
            tagValueList.push((
                "poll-latency-warning",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valPollLatencyWarning)

        if self.isSinglePollDurationWarningRequested():
            valSinglePollDurationWarning = Value()
            valSinglePollDurationWarning.setEmpty()
            tagValueList.push((
                "single-poll-duration-warning",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valSinglePollDurationWarning)

        if self.isSinglePollDurationErrorRequested():
            valSinglePollDurationError = Value()
            valSinglePollDurationError.setEmpty()
            tagValueList.push((
                "single-poll-duration-error",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valSinglePollDurationError)

        if self.isOverallPollDurationErrorRequested():
            valOverallPollDurationError = Value()
            valOverallPollDurationError.setEmpty()
            tagValueList.push((
                "overall-poll-duration-error",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valOverallPollDurationError)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isPollLatencyErrorRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "poll-latency-error") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-polllatencyerror'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "pollLatencyError", "poll-latency-error",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-poll-latency-error-bad-value'
                ).infoFunc():
                    logFunc('pollLatencyError not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setPollLatencyError(tempVar)
            for logFunc in self._log(
                    'read-tag-values-poll-latency-error').debug3Func():
                logFunc(
                    'read pollLatencyError. pollLatencyError=%s, tempValue=%s',
                    self.pollLatencyError, tempValue.getType())

        if self.isOverallPollDurationWarningRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "overall-poll-duration-warning") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-overallpolldurationwarning'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "overallPollDurationWarning",
                        "overall-poll-duration-warning",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-overall-poll-duration-warning-bad-value'
                ).infoFunc():
                    logFunc('overallPollDurationWarning not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setOverallPollDurationWarning(tempVar)
            for logFunc in self._log(
                    'read-tag-values-overall-poll-duration-warning'
            ).debug3Func():
                logFunc(
                    'read overallPollDurationWarning. overallPollDurationWarning=%s, tempValue=%s',
                    self.overallPollDurationWarning, tempValue.getType())

        if self.isPollLatencyWarningRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "poll-latency-warning") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-polllatencywarning'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "pollLatencyWarning", "poll-latency-warning",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-poll-latency-warning-bad-value'
                ).infoFunc():
                    logFunc('pollLatencyWarning not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setPollLatencyWarning(tempVar)
            for logFunc in self._log(
                    'read-tag-values-poll-latency-warning').debug3Func():
                logFunc(
                    'read pollLatencyWarning. pollLatencyWarning=%s, tempValue=%s',
                    self.pollLatencyWarning, tempValue.getType())

        if self.isSinglePollDurationWarningRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "single-poll-duration-warning") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-singlepolldurationwarning'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "singlePollDurationWarning",
                        "single-poll-duration-warning",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-single-poll-duration-warning-bad-value'
                ).infoFunc():
                    logFunc('singlePollDurationWarning not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setSinglePollDurationWarning(tempVar)
            for logFunc in self._log(
                    'read-tag-values-single-poll-duration-warning').debug3Func(
                    ):
                logFunc(
                    'read singlePollDurationWarning. singlePollDurationWarning=%s, tempValue=%s',
                    self.singlePollDurationWarning, tempValue.getType())

        if self.isSinglePollDurationErrorRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "single-poll-duration-error") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-singlepolldurationerror'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "singlePollDurationError",
                        "single-poll-duration-error",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-single-poll-duration-error-bad-value'
                ).infoFunc():
                    logFunc('singlePollDurationError not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setSinglePollDurationError(tempVar)
            for logFunc in self._log(
                    'read-tag-values-single-poll-duration-error').debug3Func():
                logFunc(
                    'read singlePollDurationError. singlePollDurationError=%s, tempValue=%s',
                    self.singlePollDurationError, tempValue.getType())

        if self.isOverallPollDurationErrorRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "overall-poll-duration-error") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-overallpolldurationerror'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "overallPollDurationError",
                        "overall-poll-duration-error",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-overall-poll-duration-error-bad-value'
                ).infoFunc():
                    logFunc('overallPollDurationError not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setOverallPollDurationError(tempVar)
            for logFunc in self._log(
                    'read-tag-values-overall-poll-duration-error').debug3Func(
                    ):
                logFunc(
                    'read overallPollDurationError. overallPollDurationError=%s, tempValue=%s',
                    self.overallPollDurationError, tempValue.getType())

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 15
0
class BlinkyOpLMaapi(OpLMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-opL")
        self.domain = None

        

        
        self.configDummyRequested = False
        self.configDummy = None
        self.configDummySet = False
        
        self.valueOpL1Requested = False
        self.valueOpL1 = None
        self.valueOpL1Set = False
        
        self.valueOpL2Requested = False
        self.valueOpL2 = None
        self.valueOpL2Set = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestConfigDummy(True)
        
        
        self.requestValueOpL1(True)
        
        self.requestValueOpL2(True)
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestConfigDummy(True)
        
        
        self.requestValueOpL1(False)
        
        self.requestValueOpL2(False)
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestConfigDummy(False)
        
        
        self.requestValueOpL1(True)
        
        self.requestValueOpL2(True)
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestConfigDummy(False)
        
        
        self.requestValueOpL1(False)
        
        self.requestValueOpL2(False)
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setConfigDummy(None)
        self.configDummySet = False
        
        

    def write (self
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(trxContext)

    def read (self
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  True,
                                  trxContext)



    def requestConfigDummy (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-configdummy').debug3Func(): logFunc('called. requested=%s', requested)
        self.configDummyRequested = requested
        self.configDummySet = False

    def isConfigDummyRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-configdummy-requested').debug3Func(): logFunc('called. requested=%s', self.configDummyRequested)
        return self.configDummyRequested

    def getConfigDummy (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-configdummy').debug3Func(): logFunc('called. self.configDummySet=%s, self.configDummy=%s', self.configDummySet, self.configDummy)
        if self.configDummySet:
            return self.configDummy
        return None

    def hasConfigDummy (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-configdummy').debug3Func(): logFunc('called. self.configDummySet=%s, self.configDummy=%s', self.configDummySet, self.configDummy)
        if self.configDummySet:
            return True
        return False

    def setConfigDummy (self, configDummy):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-configdummy').debug3Func(): logFunc('called. configDummy=%s, old=%s', configDummy, self.configDummy)
        self.configDummySet = True
        self.configDummy = configDummy

    def requestValueOpL1 (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-valueopl1').debug3Func(): logFunc('called. requested=%s', requested)
        self.valueOpL1Requested = requested
        self.valueOpL1Set = False

    def isValueOpL1Requested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-valueopl1-requested').debug3Func(): logFunc('called. requested=%s', self.valueOpL1Requested)
        return self.valueOpL1Requested

    def getValueOpL1 (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-valueopl1').debug3Func(): logFunc('called. self.valueOpL1Set=%s, self.valueOpL1=%s', self.valueOpL1Set, self.valueOpL1)
        if self.valueOpL1Set:
            return self.valueOpL1
        return None

    def hasValueOpL1 (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-valueopl1').debug3Func(): logFunc('called. self.valueOpL1Set=%s, self.valueOpL1=%s', self.valueOpL1Set, self.valueOpL1)
        if self.valueOpL1Set:
            return True
        return False

    def setValueOpL1 (self, valueOpL1):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-valueopl1').debug3Func(): logFunc('called. valueOpL1=%s, old=%s', valueOpL1, self.valueOpL1)
        self.valueOpL1Set = True
        self.valueOpL1 = valueOpL1

    def requestValueOpL2 (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-valueopl2').debug3Func(): logFunc('called. requested=%s', requested)
        self.valueOpL2Requested = requested
        self.valueOpL2Set = False

    def isValueOpL2Requested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-valueopl2-requested').debug3Func(): logFunc('called. requested=%s', self.valueOpL2Requested)
        return self.valueOpL2Requested

    def getValueOpL2 (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-valueopl2').debug3Func(): logFunc('called. self.valueOpL2Set=%s, self.valueOpL2=%s', self.valueOpL2Set, self.valueOpL2)
        if self.valueOpL2Set:
            return self.valueOpL2
        return None

    def hasValueOpL2 (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-valueopl2').debug3Func(): logFunc('called. self.valueOpL2Set=%s, self.valueOpL2=%s', self.valueOpL2Set, self.valueOpL2)
        if self.valueOpL2Set:
            return True
        return False

    def setValueOpL2 (self, valueOpL2):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-valueopl2').debug3Func(): logFunc('called. valueOpL2=%s, old=%s', valueOpL2, self.valueOpL2)
        self.valueOpL2Set = True
        self.valueOpL2 = valueOpL2


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.configDummy = 0
        self.configDummySet = False
        
        self.valueOpL1 = 0
        self.valueOpL1Set = False
        
        self.valueOpL2 = 0
        self.valueOpL2Set = False
        

    def _getSelfKeyPath (self
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("op-l", "http://qwilt.com/model/oper", "oper"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("config-a", "http://qwilt.com/model/oper", "oper"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasConfigDummy():
            valConfigDummy = Value()
            if self.configDummy is not None:
                valConfigDummy.setInt64(self.configDummy)
            else:
                valConfigDummy.setEmpty()
            tagValueList.push(("config-dummy", "http://qwilt.com/model/oper"), valConfigDummy)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isConfigDummyRequested():
            valConfigDummy = Value()
            valConfigDummy.setEmpty()
            tagValueList.push(("config-dummy", "http://qwilt.com/model/oper"), valConfigDummy)
        
        if self.isValueOpL1Requested():
            valValueOpL1 = Value()
            valValueOpL1.setEmpty()
            tagValueList.push(("value-op-l1", "http://qwilt.com/model/oper"), valValueOpL1)
        
        if self.isValueOpL2Requested():
            valValueOpL2 = Value()
            valValueOpL2.setEmpty()
            tagValueList.push(("value-op-l2", "http://qwilt.com/model/oper"), valValueOpL2)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isConfigDummyRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "config-dummy") or \
                (ns != "http://qwilt.com/model/oper"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-configdummy').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "configDummy", "config-dummy", "http://qwilt.com/model/oper", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-config-dummy-bad-value').infoFunc(): logFunc('configDummy not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setConfigDummy(tempVar)
            for logFunc in self._log('read-tag-values-config-dummy').debug3Func(): logFunc('read configDummy. configDummy=%s, tempValue=%s', self.configDummy, tempValue.getType())
        
        if self.isValueOpL1Requested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "value-op-l1") or \
                (ns != "http://qwilt.com/model/oper"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-valueopl1').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "valueOpL1", "value-op-l1", "http://qwilt.com/model/oper", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-value-op-l1-bad-value').infoFunc(): logFunc('valueOpL1 not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setValueOpL1(tempVar)
            for logFunc in self._log('read-tag-values-value-op-l1').debug3Func(): logFunc('read valueOpL1. valueOpL1=%s, tempValue=%s', self.valueOpL1, tempValue.getType())
        
        if self.isValueOpL2Requested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "value-op-l2") or \
                (ns != "http://qwilt.com/model/oper"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-valueopl2').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "valueOpL2", "value-op-l2", "http://qwilt.com/model/oper", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-value-op-l2-bad-value').infoFunc(): logFunc('valueOpL2 not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setValueOpL2(tempVar)
            for logFunc in self._log('read-tag-values-value-op-l2').debug3Func(): logFunc('read valueOpL2. valueOpL2=%s, tempValue=%s', self.valueOpL2, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 16
0
class BlinkyHouseKeeperMaapi(HouseKeeperMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-houseKeeper")
        self.domain = None

        

        
        self.threadPriorityRequested = False
        self.threadPriority = None
        self.threadPrioritySet = False
        
        self.sleepMsecRequested = False
        self.sleepMsec = None
        self.sleepMsecSet = False
        
        self.countersUpdateIntervalMsecRequested = False
        self.countersUpdateIntervalMsec = None
        self.countersUpdateIntervalMsecSet = False
        
        self.threadAffinityRequested = False
        self.threadAffinity = None
        self.threadAffinitySet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestThreadPriority(True)
        
        self.requestSleepMsec(True)
        
        self.requestCountersUpdateIntervalMsec(True)
        
        self.requestThreadAffinity(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestThreadPriority(True)
        
        self.requestSleepMsec(True)
        
        self.requestCountersUpdateIntervalMsec(True)
        
        self.requestThreadAffinity(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestThreadPriority(False)
        
        self.requestSleepMsec(False)
        
        self.requestCountersUpdateIntervalMsec(False)
        
        self.requestThreadAffinity(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestThreadPriority(False)
        
        self.requestSleepMsec(False)
        
        self.requestCountersUpdateIntervalMsec(False)
        
        self.requestThreadAffinity(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setThreadPriority(None)
        self.threadPrioritySet = False
        
        self.setSleepMsec(None)
        self.sleepMsecSet = False
        
        self.setCountersUpdateIntervalMsec(None)
        self.countersUpdateIntervalMsecSet = False
        
        self.setThreadAffinity(None)
        self.threadAffinitySet = False
        
        

    def write (self
              , line
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(line, trxContext)

    def read (self
              , line
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(line, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , line
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(line, 
                                  True,
                                  trxContext)



    def requestThreadPriority (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-threadpriority').debug3Func(): logFunc('called. requested=%s', requested)
        self.threadPriorityRequested = requested
        self.threadPrioritySet = False

    def isThreadPriorityRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-threadpriority-requested').debug3Func(): logFunc('called. requested=%s', self.threadPriorityRequested)
        return self.threadPriorityRequested

    def getThreadPriority (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-threadpriority').debug3Func(): logFunc('called. self.threadPrioritySet=%s, self.threadPriority=%s', self.threadPrioritySet, self.threadPriority)
        if self.threadPrioritySet:
            return self.threadPriority
        return None

    def hasThreadPriority (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-threadpriority').debug3Func(): logFunc('called. self.threadPrioritySet=%s, self.threadPriority=%s', self.threadPrioritySet, self.threadPriority)
        if self.threadPrioritySet:
            return True
        return False

    def setThreadPriority (self, threadPriority):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-threadpriority').debug3Func(): logFunc('called. threadPriority=%s, old=%s', threadPriority, self.threadPriority)
        self.threadPrioritySet = True
        self.threadPriority = threadPriority

    def requestSleepMsec (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-sleepmsec').debug3Func(): logFunc('called. requested=%s', requested)
        self.sleepMsecRequested = requested
        self.sleepMsecSet = False

    def isSleepMsecRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-sleepmsec-requested').debug3Func(): logFunc('called. requested=%s', self.sleepMsecRequested)
        return self.sleepMsecRequested

    def getSleepMsec (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-sleepmsec').debug3Func(): logFunc('called. self.sleepMsecSet=%s, self.sleepMsec=%s', self.sleepMsecSet, self.sleepMsec)
        if self.sleepMsecSet:
            return self.sleepMsec
        return None

    def hasSleepMsec (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-sleepmsec').debug3Func(): logFunc('called. self.sleepMsecSet=%s, self.sleepMsec=%s', self.sleepMsecSet, self.sleepMsec)
        if self.sleepMsecSet:
            return True
        return False

    def setSleepMsec (self, sleepMsec):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-sleepmsec').debug3Func(): logFunc('called. sleepMsec=%s, old=%s', sleepMsec, self.sleepMsec)
        self.sleepMsecSet = True
        self.sleepMsec = sleepMsec

    def requestCountersUpdateIntervalMsec (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-countersupdateintervalmsec').debug3Func(): logFunc('called. requested=%s', requested)
        self.countersUpdateIntervalMsecRequested = requested
        self.countersUpdateIntervalMsecSet = False

    def isCountersUpdateIntervalMsecRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-countersupdateintervalmsec-requested').debug3Func(): logFunc('called. requested=%s', self.countersUpdateIntervalMsecRequested)
        return self.countersUpdateIntervalMsecRequested

    def getCountersUpdateIntervalMsec (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-countersupdateintervalmsec').debug3Func(): logFunc('called. self.countersUpdateIntervalMsecSet=%s, self.countersUpdateIntervalMsec=%s', self.countersUpdateIntervalMsecSet, self.countersUpdateIntervalMsec)
        if self.countersUpdateIntervalMsecSet:
            return self.countersUpdateIntervalMsec
        return None

    def hasCountersUpdateIntervalMsec (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-countersupdateintervalmsec').debug3Func(): logFunc('called. self.countersUpdateIntervalMsecSet=%s, self.countersUpdateIntervalMsec=%s', self.countersUpdateIntervalMsecSet, self.countersUpdateIntervalMsec)
        if self.countersUpdateIntervalMsecSet:
            return True
        return False

    def setCountersUpdateIntervalMsec (self, countersUpdateIntervalMsec):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-countersupdateintervalmsec').debug3Func(): logFunc('called. countersUpdateIntervalMsec=%s, old=%s', countersUpdateIntervalMsec, self.countersUpdateIntervalMsec)
        self.countersUpdateIntervalMsecSet = True
        self.countersUpdateIntervalMsec = countersUpdateIntervalMsec

    def requestThreadAffinity (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-threadaffinity').debug3Func(): logFunc('called. requested=%s', requested)
        self.threadAffinityRequested = requested
        self.threadAffinitySet = False

    def isThreadAffinityRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-threadaffinity-requested').debug3Func(): logFunc('called. requested=%s', self.threadAffinityRequested)
        return self.threadAffinityRequested

    def getThreadAffinity (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-threadaffinity').debug3Func(): logFunc('called. self.threadAffinitySet=%s, self.threadAffinity=%s', self.threadAffinitySet, self.threadAffinity)
        if self.threadAffinitySet:
            return self.threadAffinity
        return None

    def hasThreadAffinity (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-threadaffinity').debug3Func(): logFunc('called. self.threadAffinitySet=%s, self.threadAffinity=%s', self.threadAffinitySet, self.threadAffinity)
        if self.threadAffinitySet:
            return True
        return False

    def setThreadAffinity (self, threadAffinity):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-threadaffinity').debug3Func(): logFunc('called. threadAffinity=%s, old=%s', threadAffinity, self.threadAffinity)
        self.threadAffinitySet = True
        self.threadAffinity = threadAffinity


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.threadPriority = 0
        self.threadPrioritySet = False
        
        self.sleepMsec = 0
        self.sleepMsecSet = False
        
        self.countersUpdateIntervalMsec = 0
        self.countersUpdateIntervalMsecSet = False
        
        self.threadAffinity = 0
        self.threadAffinitySet = False
        

    def _getSelfKeyPath (self, line
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("house-keeper", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("dispatcher", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(line);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("line", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("content", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", "qtc"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        line, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(line, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(line, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       line, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(line, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               line, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasThreadPriority():
            valThreadPriority = Value()
            if self.threadPriority is not None:
                valThreadPriority.setString(self.threadPriority)
            else:
                valThreadPriority.setEmpty()
            tagValueList.push(("thread-priority", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valThreadPriority)
        
        if self.hasSleepMsec():
            valSleepMsec = Value()
            if self.sleepMsec is not None:
                valSleepMsec.setInt64(self.sleepMsec)
            else:
                valSleepMsec.setEmpty()
            tagValueList.push(("sleep-msec", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valSleepMsec)
        
        if self.hasCountersUpdateIntervalMsec():
            valCountersUpdateIntervalMsec = Value()
            if self.countersUpdateIntervalMsec is not None:
                valCountersUpdateIntervalMsec.setInt64(self.countersUpdateIntervalMsec)
            else:
                valCountersUpdateIntervalMsec.setEmpty()
            tagValueList.push(("counters-update-interval-msec", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valCountersUpdateIntervalMsec)
        
        if self.hasThreadAffinity():
            valThreadAffinity = Value()
            if self.threadAffinity is not None:
                valThreadAffinity.setString(self.threadAffinity)
            else:
                valThreadAffinity.setEmpty()
            tagValueList.push(("thread-affinity", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valThreadAffinity)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isThreadPriorityRequested():
            valThreadPriority = Value()
            valThreadPriority.setEmpty()
            tagValueList.push(("thread-priority", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valThreadPriority)
        
        if self.isSleepMsecRequested():
            valSleepMsec = Value()
            valSleepMsec.setEmpty()
            tagValueList.push(("sleep-msec", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valSleepMsec)
        
        if self.isCountersUpdateIntervalMsecRequested():
            valCountersUpdateIntervalMsec = Value()
            valCountersUpdateIntervalMsec.setEmpty()
            tagValueList.push(("counters-update-interval-msec", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valCountersUpdateIntervalMsec)
        
        if self.isThreadAffinityRequested():
            valThreadAffinity = Value()
            valThreadAffinity.setEmpty()
            tagValueList.push(("thread-affinity", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valThreadAffinity)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isThreadPriorityRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "thread-priority") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-threadpriority').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "threadPriority", "thread-priority", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-thread-priority-bad-value').infoFunc(): logFunc('threadPriority not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setThreadPriority(tempVar)
            for logFunc in self._log('read-tag-values-thread-priority').debug3Func(): logFunc('read threadPriority. threadPriority=%s, tempValue=%s', self.threadPriority, tempValue.getType())
        
        if self.isSleepMsecRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "sleep-msec") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-sleepmsec').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "sleepMsec", "sleep-msec", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-sleep-msec-bad-value').infoFunc(): logFunc('sleepMsec not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setSleepMsec(tempVar)
            for logFunc in self._log('read-tag-values-sleep-msec').debug3Func(): logFunc('read sleepMsec. sleepMsec=%s, tempValue=%s', self.sleepMsec, tempValue.getType())
        
        if self.isCountersUpdateIntervalMsecRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "counters-update-interval-msec") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-countersupdateintervalmsec').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "countersUpdateIntervalMsec", "counters-update-interval-msec", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-counters-update-interval-msec-bad-value').infoFunc(): logFunc('countersUpdateIntervalMsec not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setCountersUpdateIntervalMsec(tempVar)
            for logFunc in self._log('read-tag-values-counters-update-interval-msec').debug3Func(): logFunc('read countersUpdateIntervalMsec. countersUpdateIntervalMsec=%s, tempValue=%s', self.countersUpdateIntervalMsec, tempValue.getType())
        
        if self.isThreadAffinityRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "thread-affinity") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-threadaffinity').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "threadAffinity", "thread-affinity", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-thread-affinity-bad-value').infoFunc(): logFunc('threadAffinity not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setThreadAffinity(tempVar)
            for logFunc in self._log('read-tag-values-thread-affinity').debug3Func(): logFunc('read threadAffinity. threadAffinity=%s, tempValue=%s', self.threadAffinity, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 17
0
class BlinkyHousekeeperMaapi(HousekeeperMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-housekeeper")
        self.domain = None

        
        self.thresholdsObj = None
        
        self.logArchivingObj = None
        

        
        self.enabledRequested = False
        self.enabled = None
        self.enabledSet = False
        
        self.pollIntervalRequested = False
        self.pollInterval = None
        self.pollIntervalSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestEnabled(True)
        
        self.requestPollInterval(True)
        
        
        
        if not self.thresholdsObj:
            self.thresholdsObj = self.newThresholds()
            self.thresholdsObj.requestConfigAndOper()
        
        if not self.logArchivingObj:
            self.logArchivingObj = self.newLogArchiving()
            self.logArchivingObj.requestConfigAndOper()
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestEnabled(True)
        
        self.requestPollInterval(True)
        
        
        
        if not self.thresholdsObj:
            self.thresholdsObj = self.newThresholds()
            self.thresholdsObj.requestConfig()
        
        if not self.logArchivingObj:
            self.logArchivingObj = self.newLogArchiving()
            self.logArchivingObj.requestConfig()
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestEnabled(False)
        
        self.requestPollInterval(False)
        
        
        
        if not self.thresholdsObj:
            self.thresholdsObj = self.newThresholds()
            self.thresholdsObj.requestOper()
        
        if not self.logArchivingObj:
            self.logArchivingObj = self.newLogArchiving()
            self.logArchivingObj.requestOper()
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestEnabled(False)
        
        self.requestPollInterval(False)
        
        
        
        if not self.thresholdsObj:
            self.thresholdsObj = self.newThresholds()
            self.thresholdsObj.clearAllRequested()
        
        if not self.logArchivingObj:
            self.logArchivingObj = self.newLogArchiving()
            self.logArchivingObj.clearAllRequested()
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setEnabled(None)
        self.enabledSet = False
        
        self.setPollInterval(None)
        self.pollIntervalSet = False
        
        
        if self.thresholdsObj:
            self.thresholdsObj.clearAllSet()
        
        if self.logArchivingObj:
            self.logArchivingObj.clearAllSet()
        

    def write (self
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(trxContext)

    def read (self
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  True,
                                  trxContext)

    def newThresholds (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-thresholds').debug3Func(): logFunc('called.')
        thresholds = BlinkyThresholdsMaapi(self._log)
        thresholds.init(self.domain)
        return thresholds

    def setThresholdsObj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-thresholds').debug3Func(): logFunc('called. obj=%s', obj)
        self.thresholdsObj = obj

    def getThresholdsObj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-thresholds').debug3Func(): logFunc('called. self.thresholdsObj=%s', self.thresholdsObj)
        return self.thresholdsObj

    def hasThresholds (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-thresholds').debug3Func(): logFunc('called. self.thresholdsObj=%s', self.thresholdsObj)
        if self.thresholdsObj:
            return True
        return False

    def newLogArchiving (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-logarchiving').debug3Func(): logFunc('called.')
        logArchiving = BlinkyLogArchivingMaapi(self._log)
        logArchiving.init(self.domain)
        return logArchiving

    def setLogArchivingObj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-logarchiving').debug3Func(): logFunc('called. obj=%s', obj)
        self.logArchivingObj = obj

    def getLogArchivingObj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-logarchiving').debug3Func(): logFunc('called. self.logArchivingObj=%s', self.logArchivingObj)
        return self.logArchivingObj

    def hasLogArchiving (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-logarchiving').debug3Func(): logFunc('called. self.logArchivingObj=%s', self.logArchivingObj)
        if self.logArchivingObj:
            return True
        return False



    def requestEnabled (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-enabled').debug3Func(): logFunc('called. requested=%s', requested)
        self.enabledRequested = requested
        self.enabledSet = False

    def isEnabledRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-enabled-requested').debug3Func(): logFunc('called. requested=%s', self.enabledRequested)
        return self.enabledRequested

    def getEnabled (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-enabled').debug3Func(): logFunc('called. self.enabledSet=%s, self.enabled=%s', self.enabledSet, self.enabled)
        if self.enabledSet:
            return self.enabled
        return None

    def hasEnabled (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-enabled').debug3Func(): logFunc('called. self.enabledSet=%s, self.enabled=%s', self.enabledSet, self.enabled)
        if self.enabledSet:
            return True
        return False

    def setEnabled (self, enabled):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-enabled').debug3Func(): logFunc('called. enabled=%s, old=%s', enabled, self.enabled)
        self.enabledSet = True
        self.enabled = enabled

    def requestPollInterval (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-pollinterval').debug3Func(): logFunc('called. requested=%s', requested)
        self.pollIntervalRequested = requested
        self.pollIntervalSet = False

    def isPollIntervalRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-pollinterval-requested').debug3Func(): logFunc('called. requested=%s', self.pollIntervalRequested)
        return self.pollIntervalRequested

    def getPollInterval (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-pollinterval').debug3Func(): logFunc('called. self.pollIntervalSet=%s, self.pollInterval=%s', self.pollIntervalSet, self.pollInterval)
        if self.pollIntervalSet:
            return self.pollInterval
        return None

    def hasPollInterval (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-pollinterval').debug3Func(): logFunc('called. self.pollIntervalSet=%s, self.pollInterval=%s', self.pollIntervalSet, self.pollInterval)
        if self.pollIntervalSet:
            return True
        return False

    def setPollInterval (self, pollInterval):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-pollinterval').debug3Func(): logFunc('called. pollInterval=%s, old=%s', pollInterval, self.pollInterval)
        self.pollIntervalSet = True
        self.pollInterval = pollInterval


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        
        if self.thresholdsObj:
            self.thresholdsObj._clearAllReadData()
        
        if self.logArchivingObj:
            self.logArchivingObj._clearAllReadData()
        

        
        self.enabled = 0
        self.enabledSet = False
        
        self.pollInterval = 0
        self.pollIntervalSet = False
        

    def _getSelfKeyPath (self
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("housekeeper", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", "qt-log"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("system-defaults", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", "qt-log"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("log", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", "qt-log"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        
        if self.thresholdsObj:
            res = self.thresholdsObj._collectItemsToDelete(
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-thresholds-failed').errorFunc(): logFunc('thresholdsObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        
        if self.logArchivingObj:
            res = self.logArchivingObj._collectItemsToDelete(
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-log-archiving-failed').errorFunc(): logFunc('logArchivingObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasEnabled():
            valEnabled = Value()
            if self.enabled is not None:
                valEnabled.setBool(self.enabled)
            else:
                valEnabled.setEmpty()
            tagValueList.push(("enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valEnabled)
        
        if self.hasPollInterval():
            valPollInterval = Value()
            if self.pollInterval is not None:
                valPollInterval.setInt64(self.pollInterval)
            else:
                valPollInterval.setEmpty()
            tagValueList.push(("poll-interval", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valPollInterval)
        

        
        if self.thresholdsObj:
            valBegin = Value()
            (tag, ns, prefix) = ("thresholds" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", "qt-log")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.thresholdsObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-thresholds-failed').errorFunc(): logFunc('thresholdsObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.logArchivingObj:
            valBegin = Value()
            (tag, ns, prefix) = ("log-archiving" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", "qt-log")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.logArchivingObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-log-archiving-failed').errorFunc(): logFunc('logArchivingObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isEnabledRequested():
            valEnabled = Value()
            valEnabled.setEmpty()
            tagValueList.push(("enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valEnabled)
        
        if self.isPollIntervalRequested():
            valPollInterval = Value()
            valPollInterval.setEmpty()
            tagValueList.push(("poll-interval", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valPollInterval)
        

        
        if self.thresholdsObj:
            valBegin = Value()
            (tag, ns, prefix) = ("thresholds" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", "qt-log")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.thresholdsObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-thresholds-failed').errorFunc(): logFunc('thresholdsObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.logArchivingObj:
            valBegin = Value()
            (tag, ns, prefix) = ("log-archiving" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", "qt-log")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.logArchivingObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-log-archiving-failed').errorFunc(): logFunc('logArchivingObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isEnabledRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "enabled") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-enabled').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "enabled", "enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asBool()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-enabled-bad-value').infoFunc(): logFunc('enabled not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setEnabled(tempVar)
            for logFunc in self._log('read-tag-values-enabled').debug3Func(): logFunc('read enabled. enabled=%s, tempValue=%s', self.enabled, tempValue.getType())
        
        if self.isPollIntervalRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "poll-interval") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-pollinterval').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "pollInterval", "poll-interval", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-poll-interval-bad-value').infoFunc(): logFunc('pollInterval not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setPollInterval(tempVar)
            for logFunc in self._log('read-tag-values-poll-interval').debug3Func(): logFunc('read pollInterval. pollInterval=%s, tempValue=%s', self.pollInterval, tempValue.getType())
        

        
        if self.thresholdsObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "thresholds") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "thresholds", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.thresholdsObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-thresholds-failed').errorFunc(): logFunc('thresholdsObj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "thresholds") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "thresholds", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        
        if self.logArchivingObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "log-archiving") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "log-archiving", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.logArchivingObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-log-archiving-failed').errorFunc(): logFunc('logArchivingObj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "log-archiving") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "log-archiving", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 18
0
class BlinkyDeliveryMaapi(DeliveryMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-delivery")
        self.domain = None

        
        self.ipv4Obj = None
        
        self.ipv6Obj = None
        

        
        self.preferredDeliveryInterfaceRequested = False
        self.preferredDeliveryInterface = None
        self.preferredDeliveryInterfaceSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestPreferredDeliveryInterface(True)
        
        
        
        if not self.ipv4Obj:
            self.ipv4Obj = self.newIpv4()
            self.ipv4Obj.requestConfigAndOper()
        
        if not self.ipv6Obj:
            self.ipv6Obj = self.newIpv6()
            self.ipv6Obj.requestConfigAndOper()
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestPreferredDeliveryInterface(True)
        
        
        
        if not self.ipv4Obj:
            self.ipv4Obj = self.newIpv4()
            self.ipv4Obj.requestConfig()
        
        if not self.ipv6Obj:
            self.ipv6Obj = self.newIpv6()
            self.ipv6Obj.requestConfig()
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestPreferredDeliveryInterface(False)
        
        
        
        if not self.ipv4Obj:
            self.ipv4Obj = self.newIpv4()
            self.ipv4Obj.requestOper()
        
        if not self.ipv6Obj:
            self.ipv6Obj = self.newIpv6()
            self.ipv6Obj.requestOper()
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestPreferredDeliveryInterface(False)
        
        
        
        if not self.ipv4Obj:
            self.ipv4Obj = self.newIpv4()
            self.ipv4Obj.clearAllRequested()
        
        if not self.ipv6Obj:
            self.ipv6Obj = self.newIpv6()
            self.ipv6Obj.clearAllRequested()
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setPreferredDeliveryInterface(None)
        self.preferredDeliveryInterfaceSet = False
        
        
        if self.ipv4Obj:
            self.ipv4Obj.clearAllSet()
        
        if self.ipv6Obj:
            self.ipv6Obj.clearAllSet()
        

    def write (self
              , interface
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(interface, trxContext)

    def read (self
              , interface
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(interface, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , interface
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(interface, 
                                  True,
                                  trxContext)

    def newIpv4 (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-ipv4').debug3Func(): logFunc('called.')
        ipv4 = BlinkyIpv4Maapi(self._log)
        ipv4.init(self.domain)
        return ipv4

    def setIpv4Obj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-ipv4').debug3Func(): logFunc('called. obj=%s', obj)
        self.ipv4Obj = obj

    def getIpv4Obj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-ipv4').debug3Func(): logFunc('called. self.ipv4Obj=%s', self.ipv4Obj)
        return self.ipv4Obj

    def hasIpv4 (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-ipv4').debug3Func(): logFunc('called. self.ipv4Obj=%s', self.ipv4Obj)
        if self.ipv4Obj:
            return True
        return False

    def newIpv6 (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-ipv6').debug3Func(): logFunc('called.')
        ipv6 = BlinkyIpv6Maapi(self._log)
        ipv6.init(self.domain)
        return ipv6

    def setIpv6Obj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-ipv6').debug3Func(): logFunc('called. obj=%s', obj)
        self.ipv6Obj = obj

    def getIpv6Obj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-ipv6').debug3Func(): logFunc('called. self.ipv6Obj=%s', self.ipv6Obj)
        return self.ipv6Obj

    def hasIpv6 (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-ipv6').debug3Func(): logFunc('called. self.ipv6Obj=%s', self.ipv6Obj)
        if self.ipv6Obj:
            return True
        return False



    def requestPreferredDeliveryInterface (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-preferreddeliveryinterface').debug3Func(): logFunc('called. requested=%s', requested)
        self.preferredDeliveryInterfaceRequested = requested
        self.preferredDeliveryInterfaceSet = False

    def isPreferredDeliveryInterfaceRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-preferreddeliveryinterface-requested').debug3Func(): logFunc('called. requested=%s', self.preferredDeliveryInterfaceRequested)
        return self.preferredDeliveryInterfaceRequested

    def getPreferredDeliveryInterface (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-preferreddeliveryinterface').debug3Func(): logFunc('called. self.preferredDeliveryInterfaceSet=%s, self.preferredDeliveryInterface=%s', self.preferredDeliveryInterfaceSet, self.preferredDeliveryInterface)
        if self.preferredDeliveryInterfaceSet:
            return self.preferredDeliveryInterface
        return None

    def hasPreferredDeliveryInterface (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-preferreddeliveryinterface').debug3Func(): logFunc('called. self.preferredDeliveryInterfaceSet=%s, self.preferredDeliveryInterface=%s', self.preferredDeliveryInterfaceSet, self.preferredDeliveryInterface)
        if self.preferredDeliveryInterfaceSet:
            return True
        return False

    def setPreferredDeliveryInterface (self, preferredDeliveryInterface):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-preferreddeliveryinterface').debug3Func(): logFunc('called. preferredDeliveryInterface=%s, old=%s', preferredDeliveryInterface, self.preferredDeliveryInterface)
        self.preferredDeliveryInterfaceSet = True
        self.preferredDeliveryInterface = preferredDeliveryInterface


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        
        if self.ipv4Obj:
            self.ipv4Obj._clearAllReadData()
        
        if self.ipv6Obj:
            self.ipv6Obj._clearAllReadData()
        

        
        self.preferredDeliveryInterface = 0
        self.preferredDeliveryInterfaceSet = False
        

    def _getSelfKeyPath (self, interface
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("delivery", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces", "qtc-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(interface);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("interface", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces", "qtc-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("interfaces", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces", "qtc-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("content", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", "qtc"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        interface, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(interface, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(interface, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       interface, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(interface, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               interface, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        
        if self.ipv4Obj:
            res = self.ipv4Obj._collectItemsToDelete(interface, 
                                                                          
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-ipv4-failed').errorFunc(): logFunc('ipv4Obj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        
        if self.ipv6Obj:
            res = self.ipv6Obj._collectItemsToDelete(interface, 
                                                                          
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-ipv6-failed').errorFunc(): logFunc('ipv6Obj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasPreferredDeliveryInterface():
            valPreferredDeliveryInterface = Value()
            if self.preferredDeliveryInterface is not None:
                valPreferredDeliveryInterface.setString(self.preferredDeliveryInterface)
            else:
                valPreferredDeliveryInterface.setEmpty()
            tagValueList.push(("preferred-delivery-interface", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces"), valPreferredDeliveryInterface)
        

        
        if self.ipv4Obj:
            valBegin = Value()
            (tag, ns, prefix) = ("ipv4" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces", "qtc-if")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.ipv4Obj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-ipv4-failed').errorFunc(): logFunc('ipv4Obj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.ipv6Obj:
            valBegin = Value()
            (tag, ns, prefix) = ("ipv6" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces", "qtc-if")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.ipv6Obj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-ipv6-failed').errorFunc(): logFunc('ipv6Obj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isPreferredDeliveryInterfaceRequested():
            valPreferredDeliveryInterface = Value()
            valPreferredDeliveryInterface.setEmpty()
            tagValueList.push(("preferred-delivery-interface", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces"), valPreferredDeliveryInterface)
        

        
        if self.ipv4Obj:
            valBegin = Value()
            (tag, ns, prefix) = ("ipv4" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces", "qtc-if")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.ipv4Obj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-ipv4-failed').errorFunc(): logFunc('ipv4Obj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.ipv6Obj:
            valBegin = Value()
            (tag, ns, prefix) = ("ipv6" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces", "qtc-if")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.ipv6Obj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-ipv6-failed').errorFunc(): logFunc('ipv6Obj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isPreferredDeliveryInterfaceRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "preferred-delivery-interface") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-preferreddeliveryinterface').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "preferredDeliveryInterface", "preferred-delivery-interface", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-preferred-delivery-interface-bad-value').infoFunc(): logFunc('preferredDeliveryInterface not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setPreferredDeliveryInterface(tempVar)
            for logFunc in self._log('read-tag-values-preferred-delivery-interface').debug3Func(): logFunc('read preferredDeliveryInterface. preferredDeliveryInterface=%s, tempValue=%s', self.preferredDeliveryInterface, tempValue.getType())
        

        
        if self.ipv4Obj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "ipv4") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "ipv4", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.ipv4Obj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-ipv4-failed').errorFunc(): logFunc('ipv4Obj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "ipv4") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "ipv4", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        
        if self.ipv6Obj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "ipv6") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "ipv6", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.ipv6Obj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-ipv6-failed').errorFunc(): logFunc('ipv6Obj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "ipv6") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "ipv6", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-interfaces", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 19
0
class BlinkyPredictionMaapi(PredictionMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-prediction")
        self.domain = None

        

        
        self.estimatedDeliveryTrxPerConnectionRequested = False
        self.estimatedDeliveryTrxPerConnection = None
        self.estimatedDeliveryTrxPerConnectionSet = False
        
        self.simulatedDiskSizeGbRequested = False
        self.simulatedDiskSizeGb = None
        self.simulatedDiskSizeGbSet = False
        
        self.deliveryMaxActiveConnectionsRequested = False
        self.deliveryMaxActiveConnections = None
        self.deliveryMaxActiveConnectionsSet = False
        
        self.enabledRequested = False
        self.enabled = None
        self.enabledSet = False
        
        self.deliveryMaxBwMbpsRequested = False
        self.deliveryMaxBwMbps = None
        self.deliveryMaxBwMbpsSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestEstimatedDeliveryTrxPerConnection(True)
        
        self.requestSimulatedDiskSizeGb(True)
        
        self.requestDeliveryMaxActiveConnections(True)
        
        self.requestEnabled(True)
        
        self.requestDeliveryMaxBwMbps(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestEstimatedDeliveryTrxPerConnection(True)
        
        self.requestSimulatedDiskSizeGb(True)
        
        self.requestDeliveryMaxActiveConnections(True)
        
        self.requestEnabled(True)
        
        self.requestDeliveryMaxBwMbps(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestEstimatedDeliveryTrxPerConnection(False)
        
        self.requestSimulatedDiskSizeGb(False)
        
        self.requestDeliveryMaxActiveConnections(False)
        
        self.requestEnabled(False)
        
        self.requestDeliveryMaxBwMbps(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestEstimatedDeliveryTrxPerConnection(False)
        
        self.requestSimulatedDiskSizeGb(False)
        
        self.requestDeliveryMaxActiveConnections(False)
        
        self.requestEnabled(False)
        
        self.requestDeliveryMaxBwMbps(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setEstimatedDeliveryTrxPerConnection(None)
        self.estimatedDeliveryTrxPerConnectionSet = False
        
        self.setSimulatedDiskSizeGb(None)
        self.simulatedDiskSizeGbSet = False
        
        self.setDeliveryMaxActiveConnections(None)
        self.deliveryMaxActiveConnectionsSet = False
        
        self.setEnabled(None)
        self.enabledSet = False
        
        self.setDeliveryMaxBwMbps(None)
        self.deliveryMaxBwMbpsSet = False
        
        

    def write (self
              , line
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(line, trxContext)

    def read (self
              , line
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(line, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , line
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(line, 
                                  True,
                                  trxContext)



    def requestEstimatedDeliveryTrxPerConnection (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-estimateddeliverytrxperconnection').debug3Func(): logFunc('called. requested=%s', requested)
        self.estimatedDeliveryTrxPerConnectionRequested = requested
        self.estimatedDeliveryTrxPerConnectionSet = False

    def isEstimatedDeliveryTrxPerConnectionRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-estimateddeliverytrxperconnection-requested').debug3Func(): logFunc('called. requested=%s', self.estimatedDeliveryTrxPerConnectionRequested)
        return self.estimatedDeliveryTrxPerConnectionRequested

    def getEstimatedDeliveryTrxPerConnection (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-estimateddeliverytrxperconnection').debug3Func(): logFunc('called. self.estimatedDeliveryTrxPerConnectionSet=%s, self.estimatedDeliveryTrxPerConnection=%s', self.estimatedDeliveryTrxPerConnectionSet, self.estimatedDeliveryTrxPerConnection)
        if self.estimatedDeliveryTrxPerConnectionSet:
            return self.estimatedDeliveryTrxPerConnection
        return None

    def hasEstimatedDeliveryTrxPerConnection (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-estimateddeliverytrxperconnection').debug3Func(): logFunc('called. self.estimatedDeliveryTrxPerConnectionSet=%s, self.estimatedDeliveryTrxPerConnection=%s', self.estimatedDeliveryTrxPerConnectionSet, self.estimatedDeliveryTrxPerConnection)
        if self.estimatedDeliveryTrxPerConnectionSet:
            return True
        return False

    def setEstimatedDeliveryTrxPerConnection (self, estimatedDeliveryTrxPerConnection):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-estimateddeliverytrxperconnection').debug3Func(): logFunc('called. estimatedDeliveryTrxPerConnection=%s, old=%s', estimatedDeliveryTrxPerConnection, self.estimatedDeliveryTrxPerConnection)
        self.estimatedDeliveryTrxPerConnectionSet = True
        self.estimatedDeliveryTrxPerConnection = estimatedDeliveryTrxPerConnection

    def requestSimulatedDiskSizeGb (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-simulateddisksizegb').debug3Func(): logFunc('called. requested=%s', requested)
        self.simulatedDiskSizeGbRequested = requested
        self.simulatedDiskSizeGbSet = False

    def isSimulatedDiskSizeGbRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-simulateddisksizegb-requested').debug3Func(): logFunc('called. requested=%s', self.simulatedDiskSizeGbRequested)
        return self.simulatedDiskSizeGbRequested

    def getSimulatedDiskSizeGb (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-simulateddisksizegb').debug3Func(): logFunc('called. self.simulatedDiskSizeGbSet=%s, self.simulatedDiskSizeGb=%s', self.simulatedDiskSizeGbSet, self.simulatedDiskSizeGb)
        if self.simulatedDiskSizeGbSet:
            return self.simulatedDiskSizeGb
        return None

    def hasSimulatedDiskSizeGb (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-simulateddisksizegb').debug3Func(): logFunc('called. self.simulatedDiskSizeGbSet=%s, self.simulatedDiskSizeGb=%s', self.simulatedDiskSizeGbSet, self.simulatedDiskSizeGb)
        if self.simulatedDiskSizeGbSet:
            return True
        return False

    def setSimulatedDiskSizeGb (self, simulatedDiskSizeGb):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-simulateddisksizegb').debug3Func(): logFunc('called. simulatedDiskSizeGb=%s, old=%s', simulatedDiskSizeGb, self.simulatedDiskSizeGb)
        self.simulatedDiskSizeGbSet = True
        self.simulatedDiskSizeGb = simulatedDiskSizeGb

    def requestDeliveryMaxActiveConnections (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-deliverymaxactiveconnections').debug3Func(): logFunc('called. requested=%s', requested)
        self.deliveryMaxActiveConnectionsRequested = requested
        self.deliveryMaxActiveConnectionsSet = False

    def isDeliveryMaxActiveConnectionsRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-deliverymaxactiveconnections-requested').debug3Func(): logFunc('called. requested=%s', self.deliveryMaxActiveConnectionsRequested)
        return self.deliveryMaxActiveConnectionsRequested

    def getDeliveryMaxActiveConnections (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-deliverymaxactiveconnections').debug3Func(): logFunc('called. self.deliveryMaxActiveConnectionsSet=%s, self.deliveryMaxActiveConnections=%s', self.deliveryMaxActiveConnectionsSet, self.deliveryMaxActiveConnections)
        if self.deliveryMaxActiveConnectionsSet:
            return self.deliveryMaxActiveConnections
        return None

    def hasDeliveryMaxActiveConnections (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-deliverymaxactiveconnections').debug3Func(): logFunc('called. self.deliveryMaxActiveConnectionsSet=%s, self.deliveryMaxActiveConnections=%s', self.deliveryMaxActiveConnectionsSet, self.deliveryMaxActiveConnections)
        if self.deliveryMaxActiveConnectionsSet:
            return True
        return False

    def setDeliveryMaxActiveConnections (self, deliveryMaxActiveConnections):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-deliverymaxactiveconnections').debug3Func(): logFunc('called. deliveryMaxActiveConnections=%s, old=%s', deliveryMaxActiveConnections, self.deliveryMaxActiveConnections)
        self.deliveryMaxActiveConnectionsSet = True
        self.deliveryMaxActiveConnections = deliveryMaxActiveConnections

    def requestEnabled (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-enabled').debug3Func(): logFunc('called. requested=%s', requested)
        self.enabledRequested = requested
        self.enabledSet = False

    def isEnabledRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-enabled-requested').debug3Func(): logFunc('called. requested=%s', self.enabledRequested)
        return self.enabledRequested

    def getEnabled (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-enabled').debug3Func(): logFunc('called. self.enabledSet=%s, self.enabled=%s', self.enabledSet, self.enabled)
        if self.enabledSet:
            return self.enabled
        return None

    def hasEnabled (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-enabled').debug3Func(): logFunc('called. self.enabledSet=%s, self.enabled=%s', self.enabledSet, self.enabled)
        if self.enabledSet:
            return True
        return False

    def setEnabled (self, enabled):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-enabled').debug3Func(): logFunc('called. enabled=%s, old=%s', enabled, self.enabled)
        self.enabledSet = True
        self.enabled = enabled

    def requestDeliveryMaxBwMbps (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-deliverymaxbwmbps').debug3Func(): logFunc('called. requested=%s', requested)
        self.deliveryMaxBwMbpsRequested = requested
        self.deliveryMaxBwMbpsSet = False

    def isDeliveryMaxBwMbpsRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-deliverymaxbwmbps-requested').debug3Func(): logFunc('called. requested=%s', self.deliveryMaxBwMbpsRequested)
        return self.deliveryMaxBwMbpsRequested

    def getDeliveryMaxBwMbps (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-deliverymaxbwmbps').debug3Func(): logFunc('called. self.deliveryMaxBwMbpsSet=%s, self.deliveryMaxBwMbps=%s', self.deliveryMaxBwMbpsSet, self.deliveryMaxBwMbps)
        if self.deliveryMaxBwMbpsSet:
            return self.deliveryMaxBwMbps
        return None

    def hasDeliveryMaxBwMbps (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-deliverymaxbwmbps').debug3Func(): logFunc('called. self.deliveryMaxBwMbpsSet=%s, self.deliveryMaxBwMbps=%s', self.deliveryMaxBwMbpsSet, self.deliveryMaxBwMbps)
        if self.deliveryMaxBwMbpsSet:
            return True
        return False

    def setDeliveryMaxBwMbps (self, deliveryMaxBwMbps):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-deliverymaxbwmbps').debug3Func(): logFunc('called. deliveryMaxBwMbps=%s, old=%s', deliveryMaxBwMbps, self.deliveryMaxBwMbps)
        self.deliveryMaxBwMbpsSet = True
        self.deliveryMaxBwMbps = deliveryMaxBwMbps


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.estimatedDeliveryTrxPerConnection = 0
        self.estimatedDeliveryTrxPerConnectionSet = False
        
        self.simulatedDiskSizeGb = 0
        self.simulatedDiskSizeGbSet = False
        
        self.deliveryMaxActiveConnections = 0
        self.deliveryMaxActiveConnectionsSet = False
        
        self.enabled = 0
        self.enabledSet = False
        
        self.deliveryMaxBwMbps = 0
        self.deliveryMaxBwMbpsSet = False
        

    def _getSelfKeyPath (self, line
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("prediction", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("analyzer", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("system-defaults", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(line);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("line", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("content", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", "qtc"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        line, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(line, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(line, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       line, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(line, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               line, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasEstimatedDeliveryTrxPerConnection():
            valEstimatedDeliveryTrxPerConnection = Value()
            if self.estimatedDeliveryTrxPerConnection is not None:
                valEstimatedDeliveryTrxPerConnection.setInt64(self.estimatedDeliveryTrxPerConnection)
            else:
                valEstimatedDeliveryTrxPerConnection.setEmpty()
            tagValueList.push(("estimated-delivery-trx-per-connection", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valEstimatedDeliveryTrxPerConnection)
        
        if self.hasSimulatedDiskSizeGb():
            valSimulatedDiskSizeGb = Value()
            if self.simulatedDiskSizeGb is not None:
                valSimulatedDiskSizeGb.setInt64(self.simulatedDiskSizeGb)
            else:
                valSimulatedDiskSizeGb.setEmpty()
            tagValueList.push(("simulated-disk-size-gb", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valSimulatedDiskSizeGb)
        
        if self.hasDeliveryMaxActiveConnections():
            valDeliveryMaxActiveConnections = Value()
            if self.deliveryMaxActiveConnections is not None:
                valDeliveryMaxActiveConnections.setInt64(self.deliveryMaxActiveConnections)
            else:
                valDeliveryMaxActiveConnections.setEmpty()
            tagValueList.push(("delivery-max-active-connections", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valDeliveryMaxActiveConnections)
        
        if self.hasEnabled():
            valEnabled = Value()
            if self.enabled is not None:
                valEnabled.setBool(self.enabled)
            else:
                valEnabled.setEmpty()
            tagValueList.push(("enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valEnabled)
        
        if self.hasDeliveryMaxBwMbps():
            valDeliveryMaxBwMbps = Value()
            if self.deliveryMaxBwMbps is not None:
                valDeliveryMaxBwMbps.setInt64(self.deliveryMaxBwMbps)
            else:
                valDeliveryMaxBwMbps.setEmpty()
            tagValueList.push(("delivery-max-bw-mbps", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valDeliveryMaxBwMbps)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isEstimatedDeliveryTrxPerConnectionRequested():
            valEstimatedDeliveryTrxPerConnection = Value()
            valEstimatedDeliveryTrxPerConnection.setEmpty()
            tagValueList.push(("estimated-delivery-trx-per-connection", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valEstimatedDeliveryTrxPerConnection)
        
        if self.isSimulatedDiskSizeGbRequested():
            valSimulatedDiskSizeGb = Value()
            valSimulatedDiskSizeGb.setEmpty()
            tagValueList.push(("simulated-disk-size-gb", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valSimulatedDiskSizeGb)
        
        if self.isDeliveryMaxActiveConnectionsRequested():
            valDeliveryMaxActiveConnections = Value()
            valDeliveryMaxActiveConnections.setEmpty()
            tagValueList.push(("delivery-max-active-connections", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valDeliveryMaxActiveConnections)
        
        if self.isEnabledRequested():
            valEnabled = Value()
            valEnabled.setEmpty()
            tagValueList.push(("enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valEnabled)
        
        if self.isDeliveryMaxBwMbpsRequested():
            valDeliveryMaxBwMbps = Value()
            valDeliveryMaxBwMbps.setEmpty()
            tagValueList.push(("delivery-max-bw-mbps", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valDeliveryMaxBwMbps)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isEstimatedDeliveryTrxPerConnectionRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "estimated-delivery-trx-per-connection") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-estimateddeliverytrxperconnection').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "estimatedDeliveryTrxPerConnection", "estimated-delivery-trx-per-connection", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-estimated-delivery-trx-per-connection-bad-value').infoFunc(): logFunc('estimatedDeliveryTrxPerConnection not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setEstimatedDeliveryTrxPerConnection(tempVar)
            for logFunc in self._log('read-tag-values-estimated-delivery-trx-per-connection').debug3Func(): logFunc('read estimatedDeliveryTrxPerConnection. estimatedDeliveryTrxPerConnection=%s, tempValue=%s', self.estimatedDeliveryTrxPerConnection, tempValue.getType())
        
        if self.isSimulatedDiskSizeGbRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "simulated-disk-size-gb") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-simulateddisksizegb').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "simulatedDiskSizeGb", "simulated-disk-size-gb", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-simulated-disk-size-gb-bad-value').infoFunc(): logFunc('simulatedDiskSizeGb not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setSimulatedDiskSizeGb(tempVar)
            for logFunc in self._log('read-tag-values-simulated-disk-size-gb').debug3Func(): logFunc('read simulatedDiskSizeGb. simulatedDiskSizeGb=%s, tempValue=%s', self.simulatedDiskSizeGb, tempValue.getType())
        
        if self.isDeliveryMaxActiveConnectionsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "delivery-max-active-connections") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-deliverymaxactiveconnections').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "deliveryMaxActiveConnections", "delivery-max-active-connections", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-delivery-max-active-connections-bad-value').infoFunc(): logFunc('deliveryMaxActiveConnections not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setDeliveryMaxActiveConnections(tempVar)
            for logFunc in self._log('read-tag-values-delivery-max-active-connections').debug3Func(): logFunc('read deliveryMaxActiveConnections. deliveryMaxActiveConnections=%s, tempValue=%s', self.deliveryMaxActiveConnections, tempValue.getType())
        
        if self.isEnabledRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "enabled") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-enabled').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "enabled", "enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asBool()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-enabled-bad-value').infoFunc(): logFunc('enabled not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setEnabled(tempVar)
            for logFunc in self._log('read-tag-values-enabled').debug3Func(): logFunc('read enabled. enabled=%s, tempValue=%s', self.enabled, tempValue.getType())
        
        if self.isDeliveryMaxBwMbpsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "delivery-max-bw-mbps") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-deliverymaxbwmbps').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "deliveryMaxBwMbps", "delivery-max-bw-mbps", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-delivery-max-bw-mbps-bad-value').infoFunc(): logFunc('deliveryMaxBwMbps not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setDeliveryMaxBwMbps(tempVar)
            for logFunc in self._log('read-tag-values-delivery-max-bw-mbps').debug3Func(): logFunc('read deliveryMaxBwMbps. deliveryMaxBwMbps=%s, tempValue=%s', self.deliveryMaxBwMbps, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 20
0
class BlinkyInstanceMaapi(InstanceMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-instance")
        self.domain = None

        
        self.internalObj = None
        
        self.destinationListObj = None
        
        self.systemDefaultsObj = None
        
        self.ruleListObj = None
        

        
        self.nameRequested = False
        self.name = None
        self.nameSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestName(True)
        
        
        
        if not self.internalObj:
            self.internalObj = self.newInternal()
            self.internalObj.requestConfigAndOper()
        
        if not self.destinationListObj:
            self.destinationListObj = self.newDestinationList()
            self.destinationListObj.requestConfigAndOper()
        
        if not self.systemDefaultsObj:
            self.systemDefaultsObj = self.newSystemDefaults()
            self.systemDefaultsObj.requestConfigAndOper()
        
        if not self.ruleListObj:
            self.ruleListObj = self.newRuleList()
            self.ruleListObj.requestConfigAndOper()
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestName(True)
        
        
        
        if not self.internalObj:
            self.internalObj = self.newInternal()
            self.internalObj.requestConfig()
        
        if not self.destinationListObj:
            self.destinationListObj = self.newDestinationList()
            self.destinationListObj.requestConfig()
        
        if not self.systemDefaultsObj:
            self.systemDefaultsObj = self.newSystemDefaults()
            self.systemDefaultsObj.requestConfig()
        
        if not self.ruleListObj:
            self.ruleListObj = self.newRuleList()
            self.ruleListObj.requestConfig()
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestName(False)
        
        
        
        if not self.internalObj:
            self.internalObj = self.newInternal()
            self.internalObj.requestOper()
        
        if not self.destinationListObj:
            self.destinationListObj = self.newDestinationList()
            self.destinationListObj.requestOper()
        
        if not self.systemDefaultsObj:
            self.systemDefaultsObj = self.newSystemDefaults()
            self.systemDefaultsObj.requestOper()
        
        if not self.ruleListObj:
            self.ruleListObj = self.newRuleList()
            self.ruleListObj.requestOper()
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestName(False)
        
        
        
        if not self.internalObj:
            self.internalObj = self.newInternal()
            self.internalObj.clearAllRequested()
        
        if not self.destinationListObj:
            self.destinationListObj = self.newDestinationList()
            self.destinationListObj.clearAllRequested()
        
        if not self.systemDefaultsObj:
            self.systemDefaultsObj = self.newSystemDefaults()
            self.systemDefaultsObj.clearAllRequested()
        
        if not self.ruleListObj:
            self.ruleListObj = self.newRuleList()
            self.ruleListObj.clearAllRequested()
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setName(None)
        self.nameSet = False
        
        
        if self.internalObj:
            self.internalObj.clearAllSet()
        
        if self.destinationListObj:
            self.destinationListObj.clearAllSet()
        
        if self.systemDefaultsObj:
            self.systemDefaultsObj.clearAllSet()
        
        if self.ruleListObj:
            self.ruleListObj.clearAllSet()
        

    def write (self
              , loggerClass
              , instance
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(loggerClass, instance, trxContext)

    def read (self
              , loggerClass
              , instance
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(loggerClass, instance, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , loggerClass
                       , instance
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(loggerClass, instance, 
                                  True,
                                  trxContext)

    def newInternal (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-internal').debug3Func(): logFunc('called.')
        internal = BlinkyInternalMaapi(self._log)
        internal.init(self.domain)
        return internal

    def setInternalObj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-internal').debug3Func(): logFunc('called. obj=%s', obj)
        self.internalObj = obj

    def getInternalObj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-internal').debug3Func(): logFunc('called. self.internalObj=%s', self.internalObj)
        return self.internalObj

    def hasInternal (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-internal').debug3Func(): logFunc('called. self.internalObj=%s', self.internalObj)
        if self.internalObj:
            return True
        return False

    def newDestinationList (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-destinationlist').debug3Func(): logFunc('called.')
        destinationList = BlinkyDestinationMaapiList(self._log)
        destinationList.init(self.domain)
        return destinationList

    def setDestinationListObj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-destinationlist').debug3Func(): logFunc('called. obj=%s', obj)
        self.destinationListObj = obj

    def getDestinationListObj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-destinationlist').debug3Func(): logFunc('called. self.destinationListObj=%s', self.destinationListObj)
        return self.destinationListObj

    def hasDestinationList (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-destinationlist').debug3Func(): logFunc('called. self.destinationListObj=%s', self.destinationListObj)
        if self.destinationListObj:
            return True
        return False

    def newSystemDefaults (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-systemdefaults').debug3Func(): logFunc('called.')
        systemDefaults = BlinkySystemDefaultsMaapi(self._log)
        systemDefaults.init(self.domain)
        return systemDefaults

    def setSystemDefaultsObj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-systemdefaults').debug3Func(): logFunc('called. obj=%s', obj)
        self.systemDefaultsObj = obj

    def getSystemDefaultsObj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-systemdefaults').debug3Func(): logFunc('called. self.systemDefaultsObj=%s', self.systemDefaultsObj)
        return self.systemDefaultsObj

    def hasSystemDefaults (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-systemdefaults').debug3Func(): logFunc('called. self.systemDefaultsObj=%s', self.systemDefaultsObj)
        if self.systemDefaultsObj:
            return True
        return False

    def newRuleList (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-rulelist').debug3Func(): logFunc('called.')
        ruleList = BlinkyRuleMaapiList(self._log)
        ruleList.init(self.domain)
        return ruleList

    def setRuleListObj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-rulelist').debug3Func(): logFunc('called. obj=%s', obj)
        self.ruleListObj = obj

    def getRuleListObj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-rulelist').debug3Func(): logFunc('called. self.ruleListObj=%s', self.ruleListObj)
        return self.ruleListObj

    def hasRuleList (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-rulelist').debug3Func(): logFunc('called. self.ruleListObj=%s', self.ruleListObj)
        if self.ruleListObj:
            return True
        return False



    def requestName (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-name').debug3Func(): logFunc('called. requested=%s', requested)
        self.nameRequested = requested
        self.nameSet = False

    def isNameRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-name-requested').debug3Func(): logFunc('called. requested=%s', self.nameRequested)
        return self.nameRequested

    def getName (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-name').debug3Func(): logFunc('called. self.nameSet=%s, self.name=%s', self.nameSet, self.name)
        if self.nameSet:
            return self.name
        return None

    def hasName (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-name').debug3Func(): logFunc('called. self.nameSet=%s, self.name=%s', self.nameSet, self.name)
        if self.nameSet:
            return True
        return False

    def setName (self, name):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-name').debug3Func(): logFunc('called. name=%s, old=%s', name, self.name)
        self.nameSet = True
        self.name = name


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        
        if self.internalObj:
            self.internalObj._clearAllReadData()
        
        if self.destinationListObj:
            self.destinationListObj._clearAllReadData()
        
        if self.systemDefaultsObj:
            self.systemDefaultsObj._clearAllReadData()
        
        if self.ruleListObj:
            self.ruleListObj._clearAllReadData()
        

        
        self.name = 0
        self.nameSet = False
        

    def _getSelfKeyPath (self, loggerClass
                         , instance
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        ancestorVal = Value()
        ancestorVal.setString(instance);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("instance", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(loggerClass);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("logger-class", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        loggerClass, 
                        instance, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(loggerClass, 
                                         instance, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(loggerClass, 
                                       instance, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       loggerClass, 
                       instance, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(loggerClass, 
                                       instance, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               loggerClass, 
                               instance, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        
        if self.internalObj:
            res = self.internalObj._collectItemsToDelete(loggerClass, 
                                                                          instance, 
                                                                          
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-internal-failed').errorFunc(): logFunc('internalObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        
        if self.destinationListObj:
            res = self.destinationListObj._collectItemsToDelete(loggerClass, 
                                                                          instance, 
                                                                          
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-destination-failed').errorFunc(): logFunc('destinationListObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        
        if self.systemDefaultsObj:
            res = self.systemDefaultsObj._collectItemsToDelete(loggerClass, 
                                                                          instance, 
                                                                          
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-system-defaults-failed').errorFunc(): logFunc('systemDefaultsObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        
        if self.ruleListObj:
            res = self.ruleListObj._collectItemsToDelete(loggerClass, 
                                                                          instance, 
                                                                          
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-rule-failed').errorFunc(): logFunc('ruleListObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasName():
            valName = Value()
            if self.name is not None:
                valName.setString(self.name)
            else:
                valName.setEmpty()
            tagValueList.push(("name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valName)
        

        
        if self.internalObj:
            valBegin = Value()
            (tag, ns, prefix) = ("internal" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.internalObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-internal-failed').errorFunc(): logFunc('internalObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.destinationListObj:
            valBegin = Value()
            (tag, ns, prefix) = ("destination" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.destinationListObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-destination-failed').errorFunc(): logFunc('destinationListObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.systemDefaultsObj:
            valBegin = Value()
            (tag, ns, prefix) = ("system-defaults" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.systemDefaultsObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-system-defaults-failed').errorFunc(): logFunc('systemDefaultsObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.ruleListObj:
            valBegin = Value()
            (tag, ns, prefix) = ("rule" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.ruleListObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-rule-failed').errorFunc(): logFunc('ruleListObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isNameRequested():
            valName = Value()
            valName.setEmpty()
            tagValueList.push(("name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valName)
        

        
        if self.internalObj:
            valBegin = Value()
            (tag, ns, prefix) = ("internal" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.internalObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-internal-failed').errorFunc(): logFunc('internalObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.destinationListObj:
            valBegin = Value()
            (tag, ns, prefix) = ("destination" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.destinationListObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-destination-failed').errorFunc(): logFunc('destinationListObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.systemDefaultsObj:
            valBegin = Value()
            (tag, ns, prefix) = ("system-defaults" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.systemDefaultsObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-system-defaults-failed').errorFunc(): logFunc('systemDefaultsObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.ruleListObj:
            valBegin = Value()
            (tag, ns, prefix) = ("rule" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.ruleListObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-rule-failed').errorFunc(): logFunc('ruleListObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isNameRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "name") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-name').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "name", "name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-name-bad-value').infoFunc(): logFunc('name not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setName(tempVar)
            for logFunc in self._log('read-tag-values-name').debug3Func(): logFunc('read name. name=%s, tempValue=%s', self.name, tempValue.getType())
        

        
        if self.internalObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "internal") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "internal", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.internalObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-internal-failed').errorFunc(): logFunc('internalObj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "internal") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "internal", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        
        if self.destinationListObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "destination") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "destination", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.destinationListObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-destination-failed').errorFunc(): logFunc('destinationListObj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "destination") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "destination", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        
        if self.systemDefaultsObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "system-defaults") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "system-defaults", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.systemDefaultsObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-system-defaults-failed').errorFunc(): logFunc('systemDefaultsObj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "system-defaults") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "system-defaults", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        
        if self.ruleListObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "rule") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "rule", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.ruleListObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-rule-failed').errorFunc(): logFunc('ruleListObj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "rule") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "rule", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 21
0
class BlinkyAddressMaapi(AddressMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-address")
        self.domain = None

        

        
        self.ipRequested = False
        self.ip = None
        self.ipSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestIp(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestIp(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestIp(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestIp(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setIp(None)
        self.ipSet = False
        
        

    def write (self
              , interface
              , address
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(interface, address, trxContext)

    def read (self
              , interface
              , address
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(interface, address, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , interface
                       , address
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(interface, address, 
                                  True,
                                  trxContext)



    def requestIp (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-ip').debug3Func(): logFunc('called. requested=%s', requested)
        self.ipRequested = requested
        self.ipSet = False

    def isIpRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-ip-requested').debug3Func(): logFunc('called. requested=%s', self.ipRequested)
        return self.ipRequested

    def getIp (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-ip').debug3Func(): logFunc('called. self.ipSet=%s, self.ip=%s', self.ipSet, self.ip)
        if self.ipSet:
            return self.ip
        return None

    def hasIp (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-ip').debug3Func(): logFunc('called. self.ipSet=%s, self.ip=%s', self.ipSet, self.ip)
        if self.ipSet:
            return True
        return False

    def setIp (self, ip):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-ip').debug3Func(): logFunc('called. ip=%s, old=%s', ip, self.ip)
        self.ipSet = True
        self.ip = ip


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.ip = 0
        self.ipSet = False
        

    def _getSelfKeyPath (self, interface
                         , address
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        ancestorVal = Value()
        ancestorVal.setString(address);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("address", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("ipv6", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(interface);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("interface", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("interfaces", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        interface, 
                        address, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(interface, 
                                         address, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(interface, 
                                       address, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       interface, 
                       address, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(interface, 
                                       address, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               interface, 
                               address, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasIp():
            valIp = Value()
            if self.ip is not None:
                valIp.setString(self.ip)
            else:
                valIp.setEmpty()
            tagValueList.push(("ip", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valIp)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isIpRequested():
            valIp = Value()
            valIp.setEmpty()
            tagValueList.push(("ip", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valIp)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isIpRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "ip") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-ip').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "ip", "ip", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-ip-bad-value').infoFunc(): logFunc('ip not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setIp(tempVar)
            for logFunc in self._log('read-tag-values-ip').debug3Func(): logFunc('read ip. ip=%s, tempValue=%s', self.ip, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 22
0
class BlinkyQShellMaapi(QShellMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-qShell")
        self.domain = None

        self.ipcObj = None

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        if not self.ipcObj:
            self.ipcObj = self.newIpc()
            self.ipcObj.requestConfigAndOper()

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        if not self.ipcObj:
            self.ipcObj = self.newIpc()
            self.ipcObj.requestConfig()

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        if not self.ipcObj:
            self.ipcObj = self.newIpc()
            self.ipcObj.requestOper()

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        if not self.ipcObj:
            self.ipcObj = self.newIpc()
            self.ipcObj.clearAllRequested()

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

        if self.ipcObj:
            self.ipcObj.clearAllSet()

    def write(self, line, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(line, trxContext)

    def read(self, line, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(line, False, trxContext)

    def readAllOrFail(self, line, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(line, True, trxContext)

    def newIpc(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-ipc').debug3Func():
            logFunc('called.')
        ipc = BlinkyIpcMaapi(self._log)
        ipc.init(self.domain)
        return ipc

    def setIpcObj(self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-ipc').debug3Func():
            logFunc('called. obj=%s', obj)
        self.ipcObj = obj

    def getIpcObj(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-ipc').debug3Func():
            logFunc('called. self.ipcObj=%s', self.ipcObj)
        return self.ipcObj

    def hasIpc(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-ipc').debug3Func():
            logFunc('called. self.ipcObj=%s', self.ipcObj)
        if self.ipcObj:
            return True
        return False

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        if self.ipcObj:
            self.ipcObj._clearAllReadData()

    def _getSelfKeyPath(self, line, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("q-shell",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
             "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)

        ancestorVal = Value()
        ancestorVal.setString(line)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("line",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
             "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("content",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", "qtc"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, line, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(line, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(line, None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, line, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(line, None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, line, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        if self.ipcObj:
            res = self.ipcObj._collectItemsToDelete(line, itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'collect-items-to-delete-ipc-failed').errorFunc():
                    logFunc('ipcObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.ipcObj:
            valBegin = Value()
            (tag, ns, prefix) = (
                "ipc",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
                "qtc-line")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.ipcObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'fill-write-tag-values-ipc-failed').errorFunc():
                    logFunc('ipcObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.ipcObj:
            valBegin = Value()
            (tag, ns, prefix) = (
                "ipc",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
                "qtc-line")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.ipcObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'fill-read-tag-values-ipc-failed').errorFunc():
                    logFunc('ipcObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.ipcObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "ipc") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-begin').errorFunc():
                    logFunc(
                        'got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                        "ipc",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
                        Value.kXmlBegin, tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            res = self.ipcObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'read-tag-values-ipc-failed').errorFunc():
                    logFunc('ipcObj._readTagValues() failed. tagValueList=%s',
                            tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "ipc") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-end').errorFunc():
                    logFunc(
                        'got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                        "ipc",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
                        Value.kXmlEnd, tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 23
0
class BlinkyHouseKeeperMaapi(HouseKeeperMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-houseKeeper")
        self.domain = None

        
        self.subTaskIntervalObj = None
        

        
        self.threadPriorityRequested = False
        self.threadPriority = None
        self.threadPrioritySet = False
        
        self.threadAffinityRequested = False
        self.threadAffinity = None
        self.threadAffinitySet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestThreadPriority(True)
        
        self.requestThreadAffinity(True)
        
        
        
        if not self.subTaskIntervalObj:
            self.subTaskIntervalObj = self.newSubTaskInterval()
            self.subTaskIntervalObj.requestConfigAndOper()
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestThreadPriority(True)
        
        self.requestThreadAffinity(True)
        
        
        
        if not self.subTaskIntervalObj:
            self.subTaskIntervalObj = self.newSubTaskInterval()
            self.subTaskIntervalObj.requestConfig()
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestThreadPriority(False)
        
        self.requestThreadAffinity(False)
        
        
        
        if not self.subTaskIntervalObj:
            self.subTaskIntervalObj = self.newSubTaskInterval()
            self.subTaskIntervalObj.requestOper()
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestThreadPriority(False)
        
        self.requestThreadAffinity(False)
        
        
        
        if not self.subTaskIntervalObj:
            self.subTaskIntervalObj = self.newSubTaskInterval()
            self.subTaskIntervalObj.clearAllRequested()
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setThreadPriority(None)
        self.threadPrioritySet = False
        
        self.setThreadAffinity(None)
        self.threadAffinitySet = False
        
        
        if self.subTaskIntervalObj:
            self.subTaskIntervalObj.clearAllSet()
        

    def write (self
              , line
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(line, trxContext)

    def read (self
              , line
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(line, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , line
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(line, 
                                  True,
                                  trxContext)

    def newSubTaskInterval (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-subtaskinterval').debug3Func(): logFunc('called.')
        subTaskInterval = BlinkySubTaskIntervalMaapi(self._log)
        subTaskInterval.init(self.domain)
        return subTaskInterval

    def setSubTaskIntervalObj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-subtaskinterval').debug3Func(): logFunc('called. obj=%s', obj)
        self.subTaskIntervalObj = obj

    def getSubTaskIntervalObj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-subtaskinterval').debug3Func(): logFunc('called. self.subTaskIntervalObj=%s', self.subTaskIntervalObj)
        return self.subTaskIntervalObj

    def hasSubTaskInterval (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-subtaskinterval').debug3Func(): logFunc('called. self.subTaskIntervalObj=%s', self.subTaskIntervalObj)
        if self.subTaskIntervalObj:
            return True
        return False



    def requestThreadPriority (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-threadpriority').debug3Func(): logFunc('called. requested=%s', requested)
        self.threadPriorityRequested = requested
        self.threadPrioritySet = False

    def isThreadPriorityRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-threadpriority-requested').debug3Func(): logFunc('called. requested=%s', self.threadPriorityRequested)
        return self.threadPriorityRequested

    def getThreadPriority (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-threadpriority').debug3Func(): logFunc('called. self.threadPrioritySet=%s, self.threadPriority=%s', self.threadPrioritySet, self.threadPriority)
        if self.threadPrioritySet:
            return self.threadPriority
        return None

    def hasThreadPriority (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-threadpriority').debug3Func(): logFunc('called. self.threadPrioritySet=%s, self.threadPriority=%s', self.threadPrioritySet, self.threadPriority)
        if self.threadPrioritySet:
            return True
        return False

    def setThreadPriority (self, threadPriority):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-threadpriority').debug3Func(): logFunc('called. threadPriority=%s, old=%s', threadPriority, self.threadPriority)
        self.threadPrioritySet = True
        self.threadPriority = threadPriority

    def requestThreadAffinity (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-threadaffinity').debug3Func(): logFunc('called. requested=%s', requested)
        self.threadAffinityRequested = requested
        self.threadAffinitySet = False

    def isThreadAffinityRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-threadaffinity-requested').debug3Func(): logFunc('called. requested=%s', self.threadAffinityRequested)
        return self.threadAffinityRequested

    def getThreadAffinity (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-threadaffinity').debug3Func(): logFunc('called. self.threadAffinitySet=%s, self.threadAffinity=%s', self.threadAffinitySet, self.threadAffinity)
        if self.threadAffinitySet:
            return self.threadAffinity
        return None

    def hasThreadAffinity (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-threadaffinity').debug3Func(): logFunc('called. self.threadAffinitySet=%s, self.threadAffinity=%s', self.threadAffinitySet, self.threadAffinity)
        if self.threadAffinitySet:
            return True
        return False

    def setThreadAffinity (self, threadAffinity):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-threadaffinity').debug3Func(): logFunc('called. threadAffinity=%s, old=%s', threadAffinity, self.threadAffinity)
        self.threadAffinitySet = True
        self.threadAffinity = threadAffinity


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        
        if self.subTaskIntervalObj:
            self.subTaskIntervalObj._clearAllReadData()
        

        
        self.threadPriority = 0
        self.threadPrioritySet = False
        
        self.threadAffinity = 0
        self.threadAffinitySet = False
        

    def _getSelfKeyPath (self, line
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("house-keeper", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("analyzer", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(line);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("line", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("content", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", "qtc"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        line, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(line, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(line, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       line, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(line, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               line, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        
        if self.subTaskIntervalObj:
            res = self.subTaskIntervalObj._collectItemsToDelete(line, 
                                                                          
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-sub-task-interval-failed').errorFunc(): logFunc('subTaskIntervalObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasThreadPriority():
            valThreadPriority = Value()
            if self.threadPriority is not None:
                valThreadPriority.setString(self.threadPriority)
            else:
                valThreadPriority.setEmpty()
            tagValueList.push(("thread-priority", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valThreadPriority)
        
        if self.hasThreadAffinity():
            valThreadAffinity = Value()
            if self.threadAffinity is not None:
                valThreadAffinity.setString(self.threadAffinity)
            else:
                valThreadAffinity.setEmpty()
            tagValueList.push(("thread-affinity", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valThreadAffinity)
        

        
        if self.subTaskIntervalObj:
            valBegin = Value()
            (tag, ns, prefix) = ("sub-task-interval" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.subTaskIntervalObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-sub-task-interval-failed').errorFunc(): logFunc('subTaskIntervalObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isThreadPriorityRequested():
            valThreadPriority = Value()
            valThreadPriority.setEmpty()
            tagValueList.push(("thread-priority", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valThreadPriority)
        
        if self.isThreadAffinityRequested():
            valThreadAffinity = Value()
            valThreadAffinity.setEmpty()
            tagValueList.push(("thread-affinity", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valThreadAffinity)
        

        
        if self.subTaskIntervalObj:
            valBegin = Value()
            (tag, ns, prefix) = ("sub-task-interval" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.subTaskIntervalObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-sub-task-interval-failed').errorFunc(): logFunc('subTaskIntervalObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isThreadPriorityRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "thread-priority") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-threadpriority').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "threadPriority", "thread-priority", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-thread-priority-bad-value').infoFunc(): logFunc('threadPriority not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setThreadPriority(tempVar)
            for logFunc in self._log('read-tag-values-thread-priority').debug3Func(): logFunc('read threadPriority. threadPriority=%s, tempValue=%s', self.threadPriority, tempValue.getType())
        
        if self.isThreadAffinityRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "thread-affinity") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-threadaffinity').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "threadAffinity", "thread-affinity", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-thread-affinity-bad-value').infoFunc(): logFunc('threadAffinity not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setThreadAffinity(tempVar)
            for logFunc in self._log('read-tag-values-thread-affinity').debug3Func(): logFunc('read threadAffinity. threadAffinity=%s, tempValue=%s', self.threadAffinity, tempValue.getType())
        

        
        if self.subTaskIntervalObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "sub-task-interval") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "sub-task-interval", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.subTaskIntervalObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-sub-task-interval-failed').errorFunc(): logFunc('subTaskIntervalObj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "sub-task-interval") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "sub-task-interval", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 24
0
class BlinkyDeliveryMaapi(DeliveryMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-delivery")
        self.domain = None

        
        self.blockerObj = None
        

        
        self.maxActiveConnectionsRequested = False
        self.maxActiveConnections = None
        self.maxActiveConnectionsSet = False
        
        self.enabledRequested = False
        self.enabled = None
        self.enabledSet = False
        
        self.maxRedirectRateRequested = False
        self.maxRedirectRate = None
        self.maxRedirectRateSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestMaxActiveConnections(True)
        
        self.requestEnabled(True)
        
        self.requestMaxRedirectRate(True)
        
        
        
        if not self.blockerObj:
            self.blockerObj = self.newBlocker()
            self.blockerObj.requestConfigAndOper()
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestMaxActiveConnections(True)
        
        self.requestEnabled(True)
        
        self.requestMaxRedirectRate(True)
        
        
        
        if not self.blockerObj:
            self.blockerObj = self.newBlocker()
            self.blockerObj.requestConfig()
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestMaxActiveConnections(False)
        
        self.requestEnabled(False)
        
        self.requestMaxRedirectRate(False)
        
        
        
        if not self.blockerObj:
            self.blockerObj = self.newBlocker()
            self.blockerObj.requestOper()
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestMaxActiveConnections(False)
        
        self.requestEnabled(False)
        
        self.requestMaxRedirectRate(False)
        
        
        
        if not self.blockerObj:
            self.blockerObj = self.newBlocker()
            self.blockerObj.clearAllRequested()
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setMaxActiveConnections(None)
        self.maxActiveConnectionsSet = False
        
        self.setEnabled(None)
        self.enabledSet = False
        
        self.setMaxRedirectRate(None)
        self.maxRedirectRateSet = False
        
        
        if self.blockerObj:
            self.blockerObj.clearAllSet()
        

    def write (self
              , line
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(line, trxContext)

    def read (self
              , line
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(line, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , line
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(line, 
                                  True,
                                  trxContext)

    def newBlocker (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-blocker').debug3Func(): logFunc('called.')
        blocker = BlinkyBlockerMaapi(self._log)
        blocker.init(self.domain)
        return blocker

    def setBlockerObj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-blocker').debug3Func(): logFunc('called. obj=%s', obj)
        self.blockerObj = obj

    def getBlockerObj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-blocker').debug3Func(): logFunc('called. self.blockerObj=%s', self.blockerObj)
        return self.blockerObj

    def hasBlocker (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-blocker').debug3Func(): logFunc('called. self.blockerObj=%s', self.blockerObj)
        if self.blockerObj:
            return True
        return False



    def requestMaxActiveConnections (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-maxactiveconnections').debug3Func(): logFunc('called. requested=%s', requested)
        self.maxActiveConnectionsRequested = requested
        self.maxActiveConnectionsSet = False

    def isMaxActiveConnectionsRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-maxactiveconnections-requested').debug3Func(): logFunc('called. requested=%s', self.maxActiveConnectionsRequested)
        return self.maxActiveConnectionsRequested

    def getMaxActiveConnections (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-maxactiveconnections').debug3Func(): logFunc('called. self.maxActiveConnectionsSet=%s, self.maxActiveConnections=%s', self.maxActiveConnectionsSet, self.maxActiveConnections)
        if self.maxActiveConnectionsSet:
            return self.maxActiveConnections
        return None

    def hasMaxActiveConnections (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-maxactiveconnections').debug3Func(): logFunc('called. self.maxActiveConnectionsSet=%s, self.maxActiveConnections=%s', self.maxActiveConnectionsSet, self.maxActiveConnections)
        if self.maxActiveConnectionsSet:
            return True
        return False

    def setMaxActiveConnections (self, maxActiveConnections):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-maxactiveconnections').debug3Func(): logFunc('called. maxActiveConnections=%s, old=%s', maxActiveConnections, self.maxActiveConnections)
        self.maxActiveConnectionsSet = True
        self.maxActiveConnections = maxActiveConnections

    def requestEnabled (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-enabled').debug3Func(): logFunc('called. requested=%s', requested)
        self.enabledRequested = requested
        self.enabledSet = False

    def isEnabledRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-enabled-requested').debug3Func(): logFunc('called. requested=%s', self.enabledRequested)
        return self.enabledRequested

    def getEnabled (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-enabled').debug3Func(): logFunc('called. self.enabledSet=%s, self.enabled=%s', self.enabledSet, self.enabled)
        if self.enabledSet:
            return self.enabled
        return None

    def hasEnabled (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-enabled').debug3Func(): logFunc('called. self.enabledSet=%s, self.enabled=%s', self.enabledSet, self.enabled)
        if self.enabledSet:
            return True
        return False

    def setEnabled (self, enabled):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-enabled').debug3Func(): logFunc('called. enabled=%s, old=%s', enabled, self.enabled)
        self.enabledSet = True
        self.enabled = enabled

    def requestMaxRedirectRate (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-maxredirectrate').debug3Func(): logFunc('called. requested=%s', requested)
        self.maxRedirectRateRequested = requested
        self.maxRedirectRateSet = False

    def isMaxRedirectRateRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-maxredirectrate-requested').debug3Func(): logFunc('called. requested=%s', self.maxRedirectRateRequested)
        return self.maxRedirectRateRequested

    def getMaxRedirectRate (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-maxredirectrate').debug3Func(): logFunc('called. self.maxRedirectRateSet=%s, self.maxRedirectRate=%s', self.maxRedirectRateSet, self.maxRedirectRate)
        if self.maxRedirectRateSet:
            return self.maxRedirectRate
        return None

    def hasMaxRedirectRate (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-maxredirectrate').debug3Func(): logFunc('called. self.maxRedirectRateSet=%s, self.maxRedirectRate=%s', self.maxRedirectRateSet, self.maxRedirectRate)
        if self.maxRedirectRateSet:
            return True
        return False

    def setMaxRedirectRate (self, maxRedirectRate):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-maxredirectrate').debug3Func(): logFunc('called. maxRedirectRate=%s, old=%s', maxRedirectRate, self.maxRedirectRate)
        self.maxRedirectRateSet = True
        self.maxRedirectRate = maxRedirectRate


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        
        if self.blockerObj:
            self.blockerObj._clearAllReadData()
        

        
        self.maxActiveConnections = 0
        self.maxActiveConnectionsSet = False
        
        self.enabled = 0
        self.enabledSet = False
        
        self.maxRedirectRate = 0
        self.maxRedirectRateSet = False
        

    def _getSelfKeyPath (self, line
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("delivery", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("analyzer", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("system-defaults", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(line);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("line", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("content", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", "qtc"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        line, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(line, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(line, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       line, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(line, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               line, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        
        if self.blockerObj:
            res = self.blockerObj._collectItemsToDelete(line, 
                                                                          
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-blocker-failed').errorFunc(): logFunc('blockerObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasMaxActiveConnections():
            valMaxActiveConnections = Value()
            if self.maxActiveConnections is not None:
                valMaxActiveConnections.setInt64(self.maxActiveConnections)
            else:
                valMaxActiveConnections.setEmpty()
            tagValueList.push(("max-active-connections", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valMaxActiveConnections)
        
        if self.hasEnabled():
            valEnabled = Value()
            if self.enabled is not None:
                valEnabled.setBool(self.enabled)
            else:
                valEnabled.setEmpty()
            tagValueList.push(("enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valEnabled)
        
        if self.hasMaxRedirectRate():
            valMaxRedirectRate = Value()
            if self.maxRedirectRate is not None:
                valMaxRedirectRate.setInt64(self.maxRedirectRate)
            else:
                valMaxRedirectRate.setEmpty()
            tagValueList.push(("max-redirect-rate", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valMaxRedirectRate)
        

        
        if self.blockerObj:
            valBegin = Value()
            (tag, ns, prefix) = ("blocker" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.blockerObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-blocker-failed').errorFunc(): logFunc('blockerObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isMaxActiveConnectionsRequested():
            valMaxActiveConnections = Value()
            valMaxActiveConnections.setEmpty()
            tagValueList.push(("max-active-connections", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valMaxActiveConnections)
        
        if self.isEnabledRequested():
            valEnabled = Value()
            valEnabled.setEmpty()
            tagValueList.push(("enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valEnabled)
        
        if self.isMaxRedirectRateRequested():
            valMaxRedirectRate = Value()
            valMaxRedirectRate.setEmpty()
            tagValueList.push(("max-redirect-rate", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valMaxRedirectRate)
        

        
        if self.blockerObj:
            valBegin = Value()
            (tag, ns, prefix) = ("blocker" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.blockerObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-blocker-failed').errorFunc(): logFunc('blockerObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isMaxActiveConnectionsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "max-active-connections") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-maxactiveconnections').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "maxActiveConnections", "max-active-connections", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-max-active-connections-bad-value').infoFunc(): logFunc('maxActiveConnections not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setMaxActiveConnections(tempVar)
            for logFunc in self._log('read-tag-values-max-active-connections').debug3Func(): logFunc('read maxActiveConnections. maxActiveConnections=%s, tempValue=%s', self.maxActiveConnections, tempValue.getType())
        
        if self.isEnabledRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "enabled") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-enabled').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "enabled", "enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asBool()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-enabled-bad-value').infoFunc(): logFunc('enabled not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setEnabled(tempVar)
            for logFunc in self._log('read-tag-values-enabled').debug3Func(): logFunc('read enabled. enabled=%s, tempValue=%s', self.enabled, tempValue.getType())
        
        if self.isMaxRedirectRateRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "max-redirect-rate") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-maxredirectrate').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "maxRedirectRate", "max-redirect-rate", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-max-redirect-rate-bad-value').infoFunc(): logFunc('maxRedirectRate not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setMaxRedirectRate(tempVar)
            for logFunc in self._log('read-tag-values-max-redirect-rate').debug3Func(): logFunc('read maxRedirectRate. maxRedirectRate=%s, tempValue=%s', self.maxRedirectRate, tempValue.getType())
        

        
        if self.blockerObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "blocker") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "blocker", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.blockerObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-blocker-failed').errorFunc(): logFunc('blockerObj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "blocker") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "blocker", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 25
0
class BlinkyLakeMaapi(LakeMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-lake")
        self.domain = None

        self.fish_ListObj = None

        self.sizeObj = None

        self.ipRequested = False
        self.ip = None
        self.ipSet = False

        self.nameRequested = False
        self.name = None
        self.nameSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestIp(True)

        self.requestName(True)

        if not self.fish_ListObj:
            self.fish_ListObj = self.newFish_List()
            self.fish_ListObj.requestConfigAndOper()

        if not self.sizeObj:
            self.sizeObj = self.newSize()
            self.sizeObj.requestConfigAndOper()

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestIp(True)

        self.requestName(True)

        if not self.fish_ListObj:
            self.fish_ListObj = self.newFish_List()
            self.fish_ListObj.requestConfig()

        if not self.sizeObj:
            self.sizeObj = self.newSize()
            self.sizeObj.requestConfig()

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestIp(False)

        self.requestName(False)

        if not self.fish_ListObj:
            self.fish_ListObj = self.newFish_List()
            self.fish_ListObj.requestOper()

        if not self.sizeObj:
            self.sizeObj = self.newSize()
            self.sizeObj.requestOper()

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestIp(False)

        self.requestName(False)

        if not self.fish_ListObj:
            self.fish_ListObj = self.newFish_List()
            self.fish_ListObj.clearAllRequested()

        if not self.sizeObj:
            self.sizeObj = self.newSize()
            self.sizeObj.clearAllRequested()

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

        self.setIp(None)
        self.ipSet = False

        self.setName(None)
        self.nameSet = False

        if self.fish_ListObj:
            self.fish_ListObj.clearAllSet()

        if self.sizeObj:
            self.sizeObj.clearAllSet()

    def write(self, lake, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(lake, trxContext)

    def read(self, lake, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(lake, False, trxContext)

    def readAllOrFail(self, lake, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(lake, True, trxContext)

    def newFish_List(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-fish_list').debug3Func():
            logFunc('called.')
        fish_List = BlinkyFishMaapiList(self._log)
        fish_List.init(self.domain)
        return fish_List

    def setFish_ListObj(self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-fish_list').debug3Func():
            logFunc('called. obj=%s', obj)
        self.fish_ListObj = obj

    def getFish_ListObj(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-fish_list').debug3Func():
            logFunc('called. self.fish_ListObj=%s', self.fish_ListObj)
        return self.fish_ListObj

    def hasFish_List(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-fish_list').debug3Func():
            logFunc('called. self.fish_ListObj=%s', self.fish_ListObj)
        if self.fish_ListObj:
            return True
        return False

    def newSize(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-size').debug3Func():
            logFunc('called.')
        size = BlinkySizeMaapi(self._log)
        size.init(self.domain)
        return size

    def setSizeObj(self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-size').debug3Func():
            logFunc('called. obj=%s', obj)
        self.sizeObj = obj

    def getSizeObj(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-size').debug3Func():
            logFunc('called. self.sizeObj=%s', self.sizeObj)
        return self.sizeObj

    def hasSize(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-size').debug3Func():
            logFunc('called. self.sizeObj=%s', self.sizeObj)
        if self.sizeObj:
            return True
        return False

    def requestIp(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-ip').debug3Func():
            logFunc('called. requested=%s', requested)
        self.ipRequested = requested
        self.ipSet = False

    def isIpRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-ip-requested').debug3Func():
            logFunc('called. requested=%s', self.ipRequested)
        return self.ipRequested

    def getIp(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-ip').debug3Func():
            logFunc('called. self.ipSet=%s, self.ip=%s', self.ipSet, self.ip)
        if self.ipSet:
            return self.ip
        return None

    def hasIp(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-ip').debug3Func():
            logFunc('called. self.ipSet=%s, self.ip=%s', self.ipSet, self.ip)
        if self.ipSet:
            return True
        return False

    def setIp(self, ip):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-ip').debug3Func():
            logFunc('called. ip=%s, old=%s', ip, self.ip)
        self.ipSet = True
        self.ip = ip

    def requestName(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-name').debug3Func():
            logFunc('called. requested=%s', requested)
        self.nameRequested = requested
        self.nameSet = False

    def isNameRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-name-requested').debug3Func():
            logFunc('called. requested=%s', self.nameRequested)
        return self.nameRequested

    def getName(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-name').debug3Func():
            logFunc('called. self.nameSet=%s, self.name=%s', self.nameSet,
                    self.name)
        if self.nameSet:
            return self.name
        return None

    def hasName(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-name').debug3Func():
            logFunc('called. self.nameSet=%s, self.name=%s', self.nameSet,
                    self.name)
        if self.nameSet:
            return True
        return False

    def setName(self, name):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-name').debug3Func():
            logFunc('called. name=%s, old=%s', name, self.name)
        self.nameSet = True
        self.name = name

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        if self.fish_ListObj:
            self.fish_ListObj._clearAllReadData()

        if self.sizeObj:
            self.sizeObj._clearAllReadData()

        self.ip = 0
        self.ipSet = False

        self.name = 0
        self.nameSet = False

    def _getSelfKeyPath(self, lake, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        ancestorVal = Value()
        ancestorVal.setString(lake)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("lake", "http://qwilt.com/model/lake-example", "lake-example"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, lake, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(lake, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(lake, None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, lake, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(lake, None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, lake, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        if self.fish_ListObj:
            res = self.fish_ListObj._collectItemsToDelete(lake, itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'collect-items-to-delete-fish-failed').errorFunc():
                    logFunc(
                        'fish_ListObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError

        if self.sizeObj:
            res = self.sizeObj._collectItemsToDelete(lake, itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'collect-items-to-delete-size-failed').errorFunc():
                    logFunc('sizeObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.hasIp():
            valIp = Value()
            if self.ip is not None:
                valIp.setIPv4(self.ip)
            else:
                valIp.setEmpty()
            tagValueList.push(("ip", "http://qwilt.com/model/lake-example"),
                              valIp)

        if self.hasName():
            valName = Value()
            if self.name is not None:
                valName.setString(self.name)
            else:
                valName.setEmpty()
            tagValueList.push(("name", "http://qwilt.com/model/lake-example"),
                              valName)

        if self.fish_ListObj:
            valBegin = Value()
            (tag, ns, prefix) = ("fish", "http://qwilt.com/model/lake-example",
                                 "lake-example")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.fish_ListObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'fill-write-tag-values-fish-failed').errorFunc():
                    logFunc(
                        'fish_ListObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)

        if self.sizeObj:
            valBegin = Value()
            (tag, ns, prefix) = ("size", "http://qwilt.com/model/lake-example",
                                 "lake-example")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.sizeObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'fill-write-tag-values-size-failed').errorFunc():
                    logFunc('sizeObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isIpRequested():
            valIp = Value()
            valIp.setEmpty()
            tagValueList.push(("ip", "http://qwilt.com/model/lake-example"),
                              valIp)

        if self.isNameRequested():
            valName = Value()
            valName.setEmpty()
            tagValueList.push(("name", "http://qwilt.com/model/lake-example"),
                              valName)

        if self.fish_ListObj:
            valBegin = Value()
            (tag, ns, prefix) = ("fish", "http://qwilt.com/model/lake-example",
                                 "lake-example")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.fish_ListObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'fill-read-tag-values-fish-failed').errorFunc():
                    logFunc('fish_ListObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)

        if self.sizeObj:
            valBegin = Value()
            (tag, ns, prefix) = ("size", "http://qwilt.com/model/lake-example",
                                 "lake-example")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.sizeObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'fill-read-tag-values-size-failed').errorFunc():
                    logFunc('sizeObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isIpRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "ip") or \
                (ns != "http://qwilt.com/model/lake-example"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-ip').errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "ip", "ip", "http://qwilt.com/model/lake-example", tag,
                        ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = (tempValue.asIPv4())
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-ip-bad-value').infoFunc():
                    logFunc('ip not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setIp(tempVar)
            for logFunc in self._log('read-tag-values-ip').debug3Func():
                logFunc('read ip. ip=%s, tempValue=%s', self.ip,
                        tempValue.getType())

        if self.isNameRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "name") or \
                (ns != "http://qwilt.com/model/lake-example"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-name').errorFunc(
                        ):
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "name", "name", "http://qwilt.com/model/lake-example",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-name-bad-value').infoFunc():
                    logFunc('name not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setName(tempVar)
            for logFunc in self._log('read-tag-values-name').debug3Func():
                logFunc('read name. name=%s, tempValue=%s', self.name,
                        tempValue.getType())

        if self.fish_ListObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "fish") or \
                (ns != "http://qwilt.com/model/lake-example") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-begin').errorFunc():
                    logFunc(
                        'got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                        "fish", "http://qwilt.com/model/lake-example",
                        Value.kXmlBegin, tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            res = self.fish_ListObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'read-tag-values-fish-failed').errorFunc():
                    logFunc(
                        'fish_ListObj._readTagValues() failed. tagValueList=%s',
                        tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "fish") or \
                (ns != "http://qwilt.com/model/lake-example") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-end').errorFunc():
                    logFunc(
                        'got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                        "fish", "http://qwilt.com/model/lake-example",
                        Value.kXmlEnd, tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

        if self.sizeObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "size") or \
                (ns != "http://qwilt.com/model/lake-example") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-begin').errorFunc():
                    logFunc(
                        'got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                        "size", "http://qwilt.com/model/lake-example",
                        Value.kXmlBegin, tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            res = self.sizeObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'read-tag-values-size-failed').errorFunc():
                    logFunc('sizeObj._readTagValues() failed. tagValueList=%s',
                            tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "size") or \
                (ns != "http://qwilt.com/model/lake-example") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-end').errorFunc():
                    logFunc(
                        'got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                        "size", "http://qwilt.com/model/lake-example",
                        Value.kXmlEnd, tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 26
0
class BlinkyPrefixMaapiList(PrefixMaapiListBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-prefix")
        self.domain = None

        self.prefixs = {}
        self.prefixKeys = []

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def newPrefix(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-prefix').debug3Func():
            logFunc('called.')
        prefix = BlinkyPrefixMaapi(self._log)
        prefix.init(self.domain)
        return prefix

    def setPrefixObj(self, key, prefixObj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-prefix-obj').debug3Func():
            logFunc('called. key=%s, prefixObj=%s', key, prefixObj)
        if key not in self.prefixs:
            self.prefixKeys.append(key)
        self.prefixs[str(key)] = prefixObj

    def getPrefixObj(self, key):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-prefix-obj').debug3Func():
            logFunc('called. key=%s', key)
        if str(key) in self.prefixs.keys():
            for logFunc in self._log('get-prefix-obj-done').debug3Func():
                logFunc('Done. found key=%s, obj=%s', key,
                        self.prefixs[str(key)])
            return self.prefixs[str(key)]
        for logFunc in self._log('get-prefix-obj-missing').errorFunc():
            logFunc('prefix %s not in prefixs. existing items: %s', key,
                    self.prefixs.keys())
        return None

    def deletePrefix(self, key):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('delete-prefix').debug3Func():
            logFunc('called. key=%s', key)
        if str(key) not in self.prefixKeys:
            for logFunc in self._log('delete-prefix-not-found').warningFunc():
                logFunc('key=%s is missing from the prefixKeys list', key)
            if str(key) in self.prefixs.keys():
                # internal problem - list & dictionary are not synced
                for logFunc in self._log(
                        'delete-prefix-not-found-but-in-dict').errorFunc():
                    logFunc(
                        'prefixs dictionary & prefixKeys list are out-of-sync. key %s exists in dict but not in list',
                        key)
            return ReturnCodes.kGeneralError
        if str(key) not in self.prefixs.keys():
            # internal problem - list & dictionary are not synced
            for logFunc in self._log(
                    'delete-prefix-not-found-but-in-list').errorFunc():
                logFunc(
                    'prefixs dictionary & prefixKeys list are out-of-sync. key %s exists in list but not in dict',
                    key)
            return ReturnCodes.kGeneralError

        self.prefixKeys.remove(str(key))
        del self.prefixs[str(key)]

    def hasPrefixObj(self, key):
        self.myInitGuard.isInitOrCrash()
        has = False
        if str(key) in self.prefixs.keys():
            if self.prefixs[str(key)]:
                has = True
        for logFunc in self._log('has-prefix-done').debug3Func():
            logFunc('done. key=%s exists=%s', key, has)
        return has

    def getListKeys(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-list-keys').debug3Func():
            logFunc('called. keys=%s', [str(x) for x in self.prefixKeys])
        return self.prefixKeys

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called.')
        for prefix in self.prefixs.values():
            prefix.requestConfigAndOper()

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called.')
        for prefix in self.prefixs.values():
            prefix.requestConfig()

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called.')
        for prefix in self.prefixs.values():
            prefix.requestOper()

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called.')
        for prefix in self.prefixs.values():
            prefix.clearAllRequested()

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')
        for prefix in self.prefixs.values():
            if prefix:
                prefix._clearAllReadData()

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')
        for key in self.prefixs.keys():
            if self.prefixs[key]:
                self.prefixs[key].clearAllSet()
            else:
                self.prefixKeys.remove(str(key))
                del self.prefixs[str(key)]

    def _getSelfKeyPath(self, zone, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS. junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("ipv6", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content",
             "qtc"))
        keyPath.addKeyPathPrefix(xmlVal)

        ancestorVal = Value()
        ancestorVal.setString(zone)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("zone", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content",
             "qtc"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("zones",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", "qtc"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("content",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", "qtc"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def readListKeys(self, zone, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-list-keys').debug3Func():
            logFunc('called')

        # clear the old map
        self.prefixs = {}
        self.prefixKeys = []

        keyPath = self._getSelfKeyPath(zone, None)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("prefix",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", "qtc"))
        keyPath.addKeyPathPostfix(xmlVal)

        keys = []

        res = self.domain.readMaapiKeys(keyPath, keys, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-list-keys-domain-failed').errorFunc():
                logFunc('domain.readMaapiKeys() failed')
            return ReturnCodes.kGeneralError

        for key in keys:
            self.prefixKeys.append(key.getCannonicalStr())
            self.prefixs[key.getCannonicalStr()] = None

        return ReturnCodes.kOk

    def write(self, zone, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(zone, trxContext)

    def read(self, zone, trxContext=None):
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(zone, False, trxContext)

    def readAllOrFail(self, zone, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(zone, True, trxContext)

    def _internalWrite(self, zone, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called.')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'internal-write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(zone, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(zone, None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, zone, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'internal-read-fill-read-tag-values-failed').errorFunc():
                logFunc('_fillReadTagValues() failed')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(zone, None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'internal-read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed.')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'internal-read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed.')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, zone, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for key in self.prefixs.keys():
            if self.prefixs[key]:
                res = self.prefixs[key]._collectItemsToDelete(
                    zone, key, itemsToDelete)
                if res != ReturnCodes.kOk:
                    for logFunc in self._log(
                            'collect-items-to-delete-prefix-failed').errorFunc(
                            ):
                        logFunc(
                            'prefixObj._collectItemsToDelete() failed. key=%s. PARAMS',
                            key)
                    return ReturnCodes.kGeneralError

            else:
                keyPath = self._getSelfKeyPath(zone, None)
                xmlVal = Value()
                xmlVal.setXmlTag(
                    ("prefix",
                     "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content",
                     "qtc"))
                keyPath.addKeyPathPostfix(xmlVal)
                valKey = Value()
                valKey.setString(key)
                keyPath.addKeyPathPostfix(valKey)

                itemsToDelete.append(keyPath)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        for key in self.prefixs.keys():
            if self.prefixs[key]:
                valBegin = Value()
                (tag, ns, prefix) = (
                    "prefix",
                    "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content",
                    "qtc")
                valBegin.setXmlBegin((tag, ns, prefix))
                tagValueList.push((tag, ns), valBegin)

                valKey = Value()
                valKey.setString(key)
                tagValueList.push((
                    "prefix",
                    "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"),
                                  valKey)

                tagValueListLen = tagValueList.getLen()

                res = self.prefixs[key]._fillWriteTagValues(tagValueList)
                if res != ReturnCodes.kOk:
                    for logFunc in self._log(
                            'fill-write-tag-values-prefix-failed').errorFunc():
                        logFunc('prefix._fillWriteTagValues() failed. key=%s',
                                key)
                    return ReturnCodes.kGeneralError

                if tagValueList.getLen() == tagValueListLen:
                    # descendant didn't add anything, no need to read it.
                    tagValueList.pop()
                    tagValueList.pop()
                else:
                    valEnd = Value()
                    valEnd.setXmlEnd((tag, ns, prefix))
                    tagValueList.push((tag, ns), valEnd)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        for key in self.prefixs.keys():
            if self.prefixs[key]:
                valBegin = Value()
                (tag, ns, prefix) = (
                    "prefix",
                    "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content",
                    "qtc")
                valBegin.setXmlBegin((tag, ns, prefix))
                tagValueList.push((tag, ns), valBegin)

                valKey = Value()
                valKey.setString(key)
                tagValueList.push((
                    "prefix",
                    "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"),
                                  valKey)

                tagValueListLen = tagValueList.getLen()

                res = self.prefixs[key]._fillReadTagValues(tagValueList)
                if res != ReturnCodes.kOk:
                    for logFunc in self._log(
                            'fill-read-tag-values-prefix-failed').errorFunc():
                        logFunc('prefix._fillReadTagValues() failed. key=%s',
                                key)
                    return ReturnCodes.kGeneralError

                if tagValueList.getLen() == tagValueListLen:
                    # descendant didn't add anything, no need to read it.
                    tagValueList.pop()
                    tagValueList.pop()
                else:
                    valEnd = Value()
                    valEnd.setXmlEnd((tag, ns, prefix))
                    tagValueList.push((tag, ns), valEnd)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. tagValueList=%s, readAllOrFail=%s', tagValueList,
                    readAllOrFail)

        res = ReturnCodes.kOk

        for key in self.prefixs.keys():
            if self.prefixs[key]:
                ((tag, ns), valBegin) = tagValueList.popFront()
                if (tag != "prefix") or \
                    (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content") or \
                    (valBegin.getType() != Value.kXmlBegin):
                    for logFunc in self._log(
                            'reag-tag-values-unexpected-tag-begin').errorFunc(
                            ):
                        logFunc(
                            'got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                            "prefix",
                            "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content",
                            Value.kXmlBegin, tag, ns, valBegin.getType())
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError

                ((tag, ns), valKey) = tagValueList.popFront()
                if (tag != "prefix") or \
                    (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"):
                    for logFunc in self._log(
                            'reag-tag-values-unexpected-tag-key').errorFunc():
                        logFunc(
                            'got unexpected tag-value for key. expected: (%s, %s), got: (%s, %s)',
                            "prefix",
                            "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content",
                            tag, ns)
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError

                key = (valKey.asIPv6Prefix())
                if res != ReturnCodes.kOk:
                    if readAllOrFail:
                        self._clearAllReadData()
                    return ReturnCodes.kGeneralError

                res = self.prefixs[key]._readTagValues(tagValueList,
                                                       readAllOrFail)
                if res != ReturnCodes.kOk:
                    for logFunc in self._log(
                            'read-tag-values-prefix-failed').errorFunc():
                        logFunc('prefix._readTagValues() failed. key=%s', key)
                    if readAllOrFail:
                        self._clearAllReadData()
                    return ReturnCodes.kGeneralError

                ((tag, ns), valEnd) = tagValueList.popFront()
                if (tag != "prefix") or \
                    (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content") or \
                    (valEnd.getType() != Value.kXmlEnd):
                    for logFunc in self._log(
                            'reag-tag-values-unexpected-tag-end').errorFunc():
                        logFunc(
                            'got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                            "prefix",
                            "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content",
                            Value.kXmlEnd, tag, ns, valEnd.getType())
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. tagValueList=%s, readAllOrFail=%s', tagValueList,
                    readAllOrFail)
        return ReturnCodes.kOk
Ejemplo n.º 27
0
class BlinkyStatusMaapi(StatusMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-status")
        self.domain = None

        self.actualMethodRequested = False
        self.actualMethod = None
        self.actualMethodSet = False

        self.operationalStatusRequested = False
        self.operationalStatus = None
        self.operationalStatusSet = False

        self.operationalStatusReasonRequested = False
        self.operationalStatusReason = None
        self.operationalStatusReasonSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestActualMethod(True)

        self.requestOperationalStatus(True)

        self.requestOperationalStatusReason(True)

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestActualMethod(False)

        self.requestOperationalStatus(False)

        self.requestOperationalStatusReason(False)

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestActualMethod(True)

        self.requestOperationalStatus(True)

        self.requestOperationalStatusReason(True)

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestActualMethod(False)

        self.requestOperationalStatus(False)

        self.requestOperationalStatusReason(False)

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

    def write(self, interface, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(interface, trxContext)

    def read(self, interface, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(interface, False, trxContext)

    def readAllOrFail(self, interface, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(interface, True, trxContext)

    def requestActualMethod(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-actualmethod').debug3Func():
            logFunc('called. requested=%s', requested)
        self.actualMethodRequested = requested
        self.actualMethodSet = False

    def isActualMethodRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-actualmethod-requested').debug3Func():
            logFunc('called. requested=%s', self.actualMethodRequested)
        return self.actualMethodRequested

    def getActualMethod(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-actualmethod').debug3Func():
            logFunc('called. self.actualMethodSet=%s, self.actualMethod=%s',
                    self.actualMethodSet, self.actualMethod)
        if self.actualMethodSet:
            return self.actualMethod
        return None

    def hasActualMethod(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-actualmethod').debug3Func():
            logFunc('called. self.actualMethodSet=%s, self.actualMethod=%s',
                    self.actualMethodSet, self.actualMethod)
        if self.actualMethodSet:
            return True
        return False

    def setActualMethod(self, actualMethod):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-actualmethod').debug3Func():
            logFunc('called. actualMethod=%s, old=%s', actualMethod,
                    self.actualMethod)
        self.actualMethodSet = True
        self.actualMethod = actualMethod

    def requestOperationalStatus(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-operationalstatus').debug3Func():
            logFunc('called. requested=%s', requested)
        self.operationalStatusRequested = requested
        self.operationalStatusSet = False

    def isOperationalStatusRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-operationalstatus-requested').debug3Func():
            logFunc('called. requested=%s', self.operationalStatusRequested)
        return self.operationalStatusRequested

    def getOperationalStatus(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-operationalstatus').debug3Func():
            logFunc(
                'called. self.operationalStatusSet=%s, self.operationalStatus=%s',
                self.operationalStatusSet, self.operationalStatus)
        if self.operationalStatusSet:
            return self.operationalStatus
        return None

    def hasOperationalStatus(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-operationalstatus').debug3Func():
            logFunc(
                'called. self.operationalStatusSet=%s, self.operationalStatus=%s',
                self.operationalStatusSet, self.operationalStatus)
        if self.operationalStatusSet:
            return True
        return False

    def setOperationalStatus(self, operationalStatus):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-operationalstatus').debug3Func():
            logFunc('called. operationalStatus=%s, old=%s', operationalStatus,
                    self.operationalStatus)
        self.operationalStatusSet = True
        self.operationalStatus = operationalStatus

    def requestOperationalStatusReason(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'request-operationalstatusreason').debug3Func():
            logFunc('called. requested=%s', requested)
        self.operationalStatusReasonRequested = requested
        self.operationalStatusReasonSet = False

    def isOperationalStatusReasonRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-operationalstatusreason-requested').debug3Func():
            logFunc('called. requested=%s',
                    self.operationalStatusReasonRequested)
        return self.operationalStatusReasonRequested

    def getOperationalStatusReason(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-operationalstatusreason').debug3Func():
            logFunc(
                'called. self.operationalStatusReasonSet=%s, self.operationalStatusReason=%s',
                self.operationalStatusReasonSet, self.operationalStatusReason)
        if self.operationalStatusReasonSet:
            return self.operationalStatusReason
        return None

    def hasOperationalStatusReason(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-operationalstatusreason').debug3Func():
            logFunc(
                'called. self.operationalStatusReasonSet=%s, self.operationalStatusReason=%s',
                self.operationalStatusReasonSet, self.operationalStatusReason)
        if self.operationalStatusReasonSet:
            return True
        return False

    def setOperationalStatusReason(self, operationalStatusReason):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-operationalstatusreason').debug3Func():
            logFunc('called. operationalStatusReason=%s, old=%s',
                    operationalStatusReason, self.operationalStatusReason)
        self.operationalStatusReasonSet = True
        self.operationalStatusReason = operationalStatusReason

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        self.actualMethod = 0
        self.actualMethodSet = False

        self.operationalStatus = 0
        self.operationalStatusSet = False

        self.operationalStatusReason = 0
        self.operationalStatusReasonSet = False

    def _getSelfKeyPath(self, interface, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("status",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
             "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("ipv4",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
             "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("connectivity-check",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
             "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)

        ancestorVal = Value()
        ancestorVal.setString(interface)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("interface",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
             "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("interfaces",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
             "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, interface, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(interface, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(interface, None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, interface, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(interface, None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, interface, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isActualMethodRequested():
            valActualMethod = Value()
            valActualMethod.setEmpty()
            tagValueList.push(
                ("actual-method",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"),
                valActualMethod)

        if self.isOperationalStatusRequested():
            valOperationalStatus = Value()
            valOperationalStatus.setEmpty()
            tagValueList.push(
                ("operational-status",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"),
                valOperationalStatus)

        if self.isOperationalStatusReasonRequested():
            valOperationalStatusReason = Value()
            valOperationalStatusReason.setEmpty()
            tagValueList.push(
                ("operational-status-reason",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"),
                valOperationalStatusReason)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isActualMethodRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "actual-method") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-actualmethod'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "actualMethod", "actual-method",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-actual-method-bad-value').infoFunc():
                    logFunc('actualMethod not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setActualMethod(tempVar)
            for logFunc in self._log(
                    'read-tag-values-actual-method').debug3Func():
                logFunc('read actualMethod. actualMethod=%s, tempValue=%s',
                        self.actualMethod, tempValue.getType())

        if self.isOperationalStatusRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "operational-status") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-operationalstatus'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "operationalStatus", "operational-status",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-operational-status-bad-value'
                ).infoFunc():
                    logFunc('operationalStatus not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setOperationalStatus(tempVar)
            for logFunc in self._log(
                    'read-tag-values-operational-status').debug3Func():
                logFunc(
                    'read operationalStatus. operationalStatus=%s, tempValue=%s',
                    self.operationalStatus, tempValue.getType())

        if self.isOperationalStatusReasonRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "operational-status-reason") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-operationalstatusreason'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "operationalStatusReason", "operational-status-reason",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-operational-status-reason-bad-value'
                ).infoFunc():
                    logFunc('operationalStatusReason not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setOperationalStatusReason(tempVar)
            for logFunc in self._log(
                    'read-tag-values-operational-status-reason').debug3Func():
                logFunc(
                    'read operationalStatusReason. operationalStatusReason=%s, tempValue=%s',
                    self.operationalStatusReason, tempValue.getType())

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
class BlinkyTestGenerationUnderscoreMaapi(TestGenerationUnderscoreMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-testGenerationUnderscore")
        self.domain = None

        

        
        self.nameRequested = False
        self.name = None
        self.nameSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestName(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestName(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestName(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestName(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setName(None)
        self.nameSet = False
        
        

    def write (self
              , lake
              , fish_
              , testGenerationUnderscore
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(lake, fish_, testGenerationUnderscore, trxContext)

    def read (self
              , lake
              , fish_
              , testGenerationUnderscore
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(lake, fish_, testGenerationUnderscore, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , lake
                       , fish_
                       , testGenerationUnderscore
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(lake, fish_, testGenerationUnderscore, 
                                  True,
                                  trxContext)



    def requestName (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-name').debug3Func(): logFunc('called. requested=%s', requested)
        self.nameRequested = requested
        self.nameSet = False

    def isNameRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-name-requested').debug3Func(): logFunc('called. requested=%s', self.nameRequested)
        return self.nameRequested

    def getName (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-name').debug3Func(): logFunc('called. self.nameSet=%s, self.name=%s', self.nameSet, self.name)
        if self.nameSet:
            return self.name
        return None

    def hasName (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-name').debug3Func(): logFunc('called. self.nameSet=%s, self.name=%s', self.nameSet, self.name)
        if self.nameSet:
            return True
        return False

    def setName (self, name):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-name').debug3Func(): logFunc('called. name=%s, old=%s', name, self.name)
        self.nameSet = True
        self.name = name


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.name = 0
        self.nameSet = False
        

    def _getSelfKeyPath (self, lake
                         , fish_
                         , testGenerationUnderscore
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        ancestorVal = Value()
        ancestorVal.setString(testGenerationUnderscore);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("test-generation_underscore", "http://qwilt.com/model/lake-example", "lake-example"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(fish_);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("fish", "http://qwilt.com/model/lake-example", "lake-example"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(lake);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("lake", "http://qwilt.com/model/lake-example", "lake-example"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        lake, 
                        fish_, 
                        testGenerationUnderscore, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(lake, 
                                         fish_, 
                                         testGenerationUnderscore, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(lake, 
                                       fish_, 
                                       testGenerationUnderscore, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       lake, 
                       fish_, 
                       testGenerationUnderscore, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(lake, 
                                       fish_, 
                                       testGenerationUnderscore, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               lake, 
                               fish_, 
                               testGenerationUnderscore, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasName():
            valName = Value()
            if self.name is not None:
                valName.setString(self.name)
            else:
                valName.setEmpty()
            tagValueList.push(("name", "http://qwilt.com/model/lake-example"), valName)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isNameRequested():
            valName = Value()
            valName.setEmpty()
            tagValueList.push(("name", "http://qwilt.com/model/lake-example"), valName)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isNameRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "name") or \
                (ns != "http://qwilt.com/model/lake-example"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-name').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "name", "name", "http://qwilt.com/model/lake-example", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-name-bad-value').infoFunc(): logFunc('name not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setName(tempVar)
            for logFunc in self._log('read-tag-values-name').debug3Func(): logFunc('read name. name=%s, tempValue=%s', self.name, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 29
0
class BlinkyTimeoutsMaapi(TimeoutsMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-timeouts")
        self.domain = None

        

        
        self.getLogicalDiskStatusRequested = False
        self.getLogicalDiskStatus = None
        self.getLogicalDiskStatusSet = False
        
        self.getPhysicalStatusRequested = False
        self.getPhysicalStatus = None
        self.getPhysicalStatusSet = False
        
        self.activateLogicalDiskRequested = False
        self.activateLogicalDisk = None
        self.activateLogicalDiskSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestGetLogicalDiskStatus(True)
        
        self.requestGetPhysicalStatus(True)
        
        self.requestActivateLogicalDisk(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestGetLogicalDiskStatus(True)
        
        self.requestGetPhysicalStatus(True)
        
        self.requestActivateLogicalDisk(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestGetLogicalDiskStatus(False)
        
        self.requestGetPhysicalStatus(False)
        
        self.requestActivateLogicalDisk(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestGetLogicalDiskStatus(False)
        
        self.requestGetPhysicalStatus(False)
        
        self.requestActivateLogicalDisk(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setGetLogicalDiskStatus(None)
        self.getLogicalDiskStatusSet = False
        
        self.setGetPhysicalStatus(None)
        self.getPhysicalStatusSet = False
        
        self.setActivateLogicalDisk(None)
        self.activateLogicalDiskSet = False
        
        

    def write (self
              , controller
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(controller, trxContext)

    def read (self
              , controller
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(controller, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , controller
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(controller, 
                                  True,
                                  trxContext)



    def requestGetLogicalDiskStatus (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-getlogicaldiskstatus').debug3Func(): logFunc('called. requested=%s', requested)
        self.getLogicalDiskStatusRequested = requested
        self.getLogicalDiskStatusSet = False

    def isGetLogicalDiskStatusRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-getlogicaldiskstatus-requested').debug3Func(): logFunc('called. requested=%s', self.getLogicalDiskStatusRequested)
        return self.getLogicalDiskStatusRequested

    def getGetLogicalDiskStatus (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-getlogicaldiskstatus').debug3Func(): logFunc('called. self.getLogicalDiskStatusSet=%s, self.getLogicalDiskStatus=%s', self.getLogicalDiskStatusSet, self.getLogicalDiskStatus)
        if self.getLogicalDiskStatusSet:
            return self.getLogicalDiskStatus
        return None

    def hasGetLogicalDiskStatus (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-getlogicaldiskstatus').debug3Func(): logFunc('called. self.getLogicalDiskStatusSet=%s, self.getLogicalDiskStatus=%s', self.getLogicalDiskStatusSet, self.getLogicalDiskStatus)
        if self.getLogicalDiskStatusSet:
            return True
        return False

    def setGetLogicalDiskStatus (self, getLogicalDiskStatus):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-getlogicaldiskstatus').debug3Func(): logFunc('called. getLogicalDiskStatus=%s, old=%s', getLogicalDiskStatus, self.getLogicalDiskStatus)
        self.getLogicalDiskStatusSet = True
        self.getLogicalDiskStatus = getLogicalDiskStatus

    def requestGetPhysicalStatus (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-getphysicalstatus').debug3Func(): logFunc('called. requested=%s', requested)
        self.getPhysicalStatusRequested = requested
        self.getPhysicalStatusSet = False

    def isGetPhysicalStatusRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-getphysicalstatus-requested').debug3Func(): logFunc('called. requested=%s', self.getPhysicalStatusRequested)
        return self.getPhysicalStatusRequested

    def getGetPhysicalStatus (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-getphysicalstatus').debug3Func(): logFunc('called. self.getPhysicalStatusSet=%s, self.getPhysicalStatus=%s', self.getPhysicalStatusSet, self.getPhysicalStatus)
        if self.getPhysicalStatusSet:
            return self.getPhysicalStatus
        return None

    def hasGetPhysicalStatus (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-getphysicalstatus').debug3Func(): logFunc('called. self.getPhysicalStatusSet=%s, self.getPhysicalStatus=%s', self.getPhysicalStatusSet, self.getPhysicalStatus)
        if self.getPhysicalStatusSet:
            return True
        return False

    def setGetPhysicalStatus (self, getPhysicalStatus):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-getphysicalstatus').debug3Func(): logFunc('called. getPhysicalStatus=%s, old=%s', getPhysicalStatus, self.getPhysicalStatus)
        self.getPhysicalStatusSet = True
        self.getPhysicalStatus = getPhysicalStatus

    def requestActivateLogicalDisk (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-activatelogicaldisk').debug3Func(): logFunc('called. requested=%s', requested)
        self.activateLogicalDiskRequested = requested
        self.activateLogicalDiskSet = False

    def isActivateLogicalDiskRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-activatelogicaldisk-requested').debug3Func(): logFunc('called. requested=%s', self.activateLogicalDiskRequested)
        return self.activateLogicalDiskRequested

    def getActivateLogicalDisk (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-activatelogicaldisk').debug3Func(): logFunc('called. self.activateLogicalDiskSet=%s, self.activateLogicalDisk=%s', self.activateLogicalDiskSet, self.activateLogicalDisk)
        if self.activateLogicalDiskSet:
            return self.activateLogicalDisk
        return None

    def hasActivateLogicalDisk (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-activatelogicaldisk').debug3Func(): logFunc('called. self.activateLogicalDiskSet=%s, self.activateLogicalDisk=%s', self.activateLogicalDiskSet, self.activateLogicalDisk)
        if self.activateLogicalDiskSet:
            return True
        return False

    def setActivateLogicalDisk (self, activateLogicalDisk):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-activatelogicaldisk').debug3Func(): logFunc('called. activateLogicalDisk=%s, old=%s', activateLogicalDisk, self.activateLogicalDisk)
        self.activateLogicalDiskSet = True
        self.activateLogicalDisk = activateLogicalDisk


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.getLogicalDiskStatus = 0
        self.getLogicalDiskStatusSet = False
        
        self.getPhysicalStatus = 0
        self.getPhysicalStatusSet = False
        
        self.activateLogicalDisk = 0
        self.activateLogicalDiskSet = False
        

    def _getSelfKeyPath (self, controller
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("timeouts", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller", "qt-strg-ctrl"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("system-defaults", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller", "qt-strg-ctrl"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(controller);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("controller", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller", "qt-strg-ctrl"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("storage", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage", "qt-strg"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        controller, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(controller, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(controller, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       controller, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(controller, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               controller, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasGetLogicalDiskStatus():
            valGetLogicalDiskStatus = Value()
            if self.getLogicalDiskStatus is not None:
                valGetLogicalDiskStatus.setInt64(self.getLogicalDiskStatus)
            else:
                valGetLogicalDiskStatus.setEmpty()
            tagValueList.push(("get-logical-disk-status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller"), valGetLogicalDiskStatus)
        
        if self.hasGetPhysicalStatus():
            valGetPhysicalStatus = Value()
            if self.getPhysicalStatus is not None:
                valGetPhysicalStatus.setInt64(self.getPhysicalStatus)
            else:
                valGetPhysicalStatus.setEmpty()
            tagValueList.push(("get-physical-status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller"), valGetPhysicalStatus)
        
        if self.hasActivateLogicalDisk():
            valActivateLogicalDisk = Value()
            if self.activateLogicalDisk is not None:
                valActivateLogicalDisk.setInt64(self.activateLogicalDisk)
            else:
                valActivateLogicalDisk.setEmpty()
            tagValueList.push(("activate-logical-disk", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller"), valActivateLogicalDisk)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isGetLogicalDiskStatusRequested():
            valGetLogicalDiskStatus = Value()
            valGetLogicalDiskStatus.setEmpty()
            tagValueList.push(("get-logical-disk-status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller"), valGetLogicalDiskStatus)
        
        if self.isGetPhysicalStatusRequested():
            valGetPhysicalStatus = Value()
            valGetPhysicalStatus.setEmpty()
            tagValueList.push(("get-physical-status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller"), valGetPhysicalStatus)
        
        if self.isActivateLogicalDiskRequested():
            valActivateLogicalDisk = Value()
            valActivateLogicalDisk.setEmpty()
            tagValueList.push(("activate-logical-disk", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller"), valActivateLogicalDisk)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isGetLogicalDiskStatusRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "get-logical-disk-status") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-getlogicaldiskstatus').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "getLogicalDiskStatus", "get-logical-disk-status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-get-logical-disk-status-bad-value').infoFunc(): logFunc('getLogicalDiskStatus not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setGetLogicalDiskStatus(tempVar)
            for logFunc in self._log('read-tag-values-get-logical-disk-status').debug3Func(): logFunc('read getLogicalDiskStatus. getLogicalDiskStatus=%s, tempValue=%s', self.getLogicalDiskStatus, tempValue.getType())
        
        if self.isGetPhysicalStatusRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "get-physical-status") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-getphysicalstatus').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "getPhysicalStatus", "get-physical-status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-get-physical-status-bad-value').infoFunc(): logFunc('getPhysicalStatus not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setGetPhysicalStatus(tempVar)
            for logFunc in self._log('read-tag-values-get-physical-status').debug3Func(): logFunc('read getPhysicalStatus. getPhysicalStatus=%s, tempValue=%s', self.getPhysicalStatus, tempValue.getType())
        
        if self.isActivateLogicalDiskRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "activate-logical-disk") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-activatelogicaldisk').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "activateLogicalDisk", "activate-logical-disk", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-activate-logical-disk-bad-value').infoFunc(): logFunc('activateLogicalDisk not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setActivateLogicalDisk(tempVar)
            for logFunc in self._log('read-tag-values-activate-logical-disk').debug3Func(): logFunc('read activateLogicalDisk. activateLogicalDisk=%s, tempValue=%s', self.activateLogicalDisk, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 30
0
class BlinkyCountersMaapi(CountersMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-counters")
        self.domain = None

        

        
        self.strTestRequested = False
        self.strTest = None
        self.strTestSet = False
        
        self.moodRequested = False
        self.mood = None
        self.moodSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestStrTest(True)
        
        self.requestMood(True)
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestStrTest(False)
        
        self.requestMood(False)
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestStrTest(True)
        
        self.requestMood(True)
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestStrTest(False)
        
        self.requestMood(False)
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        

    def write (self
              , alien
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(alien, trxContext)

    def read (self
              , alien
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(alien, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , alien
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(alien, 
                                  True,
                                  trxContext)



    def requestStrTest (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-strtest').debug3Func(): logFunc('called. requested=%s', requested)
        self.strTestRequested = requested
        self.strTestSet = False

    def isStrTestRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-strtest-requested').debug3Func(): logFunc('called. requested=%s', self.strTestRequested)
        return self.strTestRequested

    def getStrTest (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-strtest').debug3Func(): logFunc('called. self.strTestSet=%s, self.strTest=%s', self.strTestSet, self.strTest)
        if self.strTestSet:
            return self.strTest
        return None

    def hasStrTest (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-strtest').debug3Func(): logFunc('called. self.strTestSet=%s, self.strTest=%s', self.strTestSet, self.strTest)
        if self.strTestSet:
            return True
        return False

    def setStrTest (self, strTest):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-strtest').debug3Func(): logFunc('called. strTest=%s, old=%s', strTest, self.strTest)
        self.strTestSet = True
        self.strTest = strTest

    def requestMood (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-mood').debug3Func(): logFunc('called. requested=%s', requested)
        self.moodRequested = requested
        self.moodSet = False

    def isMoodRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-mood-requested').debug3Func(): logFunc('called. requested=%s', self.moodRequested)
        return self.moodRequested

    def getMood (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-mood').debug3Func(): logFunc('called. self.moodSet=%s, self.mood=%s', self.moodSet, self.mood)
        if self.moodSet:
            return self.mood
        return None

    def hasMood (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-mood').debug3Func(): logFunc('called. self.moodSet=%s, self.mood=%s', self.moodSet, self.mood)
        if self.moodSet:
            return True
        return False

    def setMood (self, mood):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-mood').debug3Func(): logFunc('called. mood=%s, old=%s', mood, self.mood)
        self.moodSet = True
        self.mood = mood


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.strTest = 0
        self.strTestSet = False
        
        self.mood = 0
        self.moodSet = False
        

    def _getSelfKeyPath (self, alien
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("counters", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/oper-example", "oe"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("status-wrapper", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/oper-example", "oe"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(alien);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("alien", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/oper-example", "oe"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("root", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/oper-example", "oe"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        alien, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(alien, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(alien, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       alien, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(alien, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               alien, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isStrTestRequested():
            valStrTest = Value()
            valStrTest.setEmpty()
            tagValueList.push(("str-test", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/oper-example"), valStrTest)
        
        if self.isMoodRequested():
            valMood = Value()
            valMood.setEmpty()
            tagValueList.push(("mood", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/oper-example"), valMood)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isStrTestRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "str-test") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/oper-example"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-strtest').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "strTest", "str-test", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/oper-example", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-str-test-bad-value').infoFunc(): logFunc('strTest not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setStrTest(tempVar)
            for logFunc in self._log('read-tag-values-str-test').debug3Func(): logFunc('read strTest. strTest=%s, tempValue=%s', self.strTest, tempValue.getType())
        
        if self.isMoodRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "mood") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/oper-example"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-mood').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "mood", "mood", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/oper-example", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asUint64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-mood-bad-value').infoFunc(): logFunc('mood not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setMood(tempVar)
            for logFunc in self._log('read-tag-values-mood').debug3Func(): logFunc('read mood. mood=%s, tempValue=%s', self.mood, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 31
0
class BlinkyStatusMaapi(StatusMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-status")
        self.domain = None

        

        
        self.tableLastChangeTicksRequested = False
        self.tableLastChangeTicks = None
        self.tableLastChangeTicksSet = False
        
        self.interfaceNumberRequested = False
        self.interfaceNumber = None
        self.interfaceNumberSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestTableLastChangeTicks(True)
        
        self.requestInterfaceNumber(True)
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestTableLastChangeTicks(False)
        
        self.requestInterfaceNumber(False)
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestTableLastChangeTicks(True)
        
        self.requestInterfaceNumber(True)
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestTableLastChangeTicks(False)
        
        self.requestInterfaceNumber(False)
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        

    def write (self
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(trxContext)

    def read (self
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  True,
                                  trxContext)



    def requestTableLastChangeTicks (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-tablelastchangeticks').debug3Func(): logFunc('called. requested=%s', requested)
        self.tableLastChangeTicksRequested = requested
        self.tableLastChangeTicksSet = False

    def isTableLastChangeTicksRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-tablelastchangeticks-requested').debug3Func(): logFunc('called. requested=%s', self.tableLastChangeTicksRequested)
        return self.tableLastChangeTicksRequested

    def getTableLastChangeTicks (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-tablelastchangeticks').debug3Func(): logFunc('called. self.tableLastChangeTicksSet=%s, self.tableLastChangeTicks=%s', self.tableLastChangeTicksSet, self.tableLastChangeTicks)
        if self.tableLastChangeTicksSet:
            return self.tableLastChangeTicks
        return None

    def hasTableLastChangeTicks (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-tablelastchangeticks').debug3Func(): logFunc('called. self.tableLastChangeTicksSet=%s, self.tableLastChangeTicks=%s', self.tableLastChangeTicksSet, self.tableLastChangeTicks)
        if self.tableLastChangeTicksSet:
            return True
        return False

    def setTableLastChangeTicks (self, tableLastChangeTicks):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-tablelastchangeticks').debug3Func(): logFunc('called. tableLastChangeTicks=%s, old=%s', tableLastChangeTicks, self.tableLastChangeTicks)
        self.tableLastChangeTicksSet = True
        self.tableLastChangeTicks = tableLastChangeTicks

    def requestInterfaceNumber (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-interfacenumber').debug3Func(): logFunc('called. requested=%s', requested)
        self.interfaceNumberRequested = requested
        self.interfaceNumberSet = False

    def isInterfaceNumberRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-interfacenumber-requested').debug3Func(): logFunc('called. requested=%s', self.interfaceNumberRequested)
        return self.interfaceNumberRequested

    def getInterfaceNumber (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-interfacenumber').debug3Func(): logFunc('called. self.interfaceNumberSet=%s, self.interfaceNumber=%s', self.interfaceNumberSet, self.interfaceNumber)
        if self.interfaceNumberSet:
            return self.interfaceNumber
        return None

    def hasInterfaceNumber (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-interfacenumber').debug3Func(): logFunc('called. self.interfaceNumberSet=%s, self.interfaceNumber=%s', self.interfaceNumberSet, self.interfaceNumber)
        if self.interfaceNumberSet:
            return True
        return False

    def setInterfaceNumber (self, interfaceNumber):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-interfacenumber').debug3Func(): logFunc('called. interfaceNumber=%s, old=%s', interfaceNumber, self.interfaceNumber)
        self.interfaceNumberSet = True
        self.interfaceNumber = interfaceNumber


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.tableLastChangeTicks = 0
        self.tableLastChangeTicksSet = False
        
        self.interfaceNumber = 0
        self.interfaceNumberSet = False
        

    def _getSelfKeyPath (self
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("interfaces", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isTableLastChangeTicksRequested():
            valTableLastChangeTicks = Value()
            valTableLastChangeTicks.setEmpty()
            tagValueList.push(("table-last-change-ticks", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valTableLastChangeTicks)
        
        if self.isInterfaceNumberRequested():
            valInterfaceNumber = Value()
            valInterfaceNumber.setEmpty()
            tagValueList.push(("interface-number", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valInterfaceNumber)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isTableLastChangeTicksRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "table-last-change-ticks") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-tablelastchangeticks').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "tableLastChangeTicks", "table-last-change-ticks", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asUint32()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-table-last-change-ticks-bad-value').infoFunc(): logFunc('tableLastChangeTicks not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setTableLastChangeTicks(tempVar)
            for logFunc in self._log('read-tag-values-table-last-change-ticks').debug3Func(): logFunc('read tableLastChangeTicks. tableLastChangeTicks=%s, tempValue=%s', self.tableLastChangeTicks, tempValue.getType())
        
        if self.isInterfaceNumberRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "interface-number") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-interfacenumber').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "interfaceNumber", "interface-number", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt32()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-interface-number-bad-value').infoFunc(): logFunc('interfaceNumber not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setInterfaceNumber(tempVar)
            for logFunc in self._log('read-tag-values-interface-number').debug3Func(): logFunc('read interfaceNumber. interfaceNumber=%s, tempValue=%s', self.interfaceNumber, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 32
0
class BlinkyAlarmMaapi(AlarmMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-alarm")
        self.domain = None

        self.noRedundancyReasonRequested = False
        self.noRedundancyReason = None
        self.noRedundancyReasonSet = False

        self.noRedundancyRequested = False
        self.noRedundancy = None
        self.noRedundancySet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestNoRedundancyReason(True)

        self.requestNoRedundancy(True)

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestNoRedundancyReason(False)

        self.requestNoRedundancy(False)

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestNoRedundancyReason(True)

        self.requestNoRedundancy(True)

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestNoRedundancyReason(False)

        self.requestNoRedundancy(False)

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

    def write(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(trxContext)

    def read(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(False, trxContext)

    def readAllOrFail(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(True, trxContext)

    def requestNoRedundancyReason(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-noredundancyreason').debug3Func():
            logFunc('called. requested=%s', requested)
        self.noRedundancyReasonRequested = requested
        self.noRedundancyReasonSet = False

    def isNoRedundancyReasonRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-noredundancyreason-requested').debug3Func():
            logFunc('called. requested=%s', self.noRedundancyReasonRequested)
        return self.noRedundancyReasonRequested

    def getNoRedundancyReason(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-noredundancyreason').debug3Func():
            logFunc(
                'called. self.noRedundancyReasonSet=%s, self.noRedundancyReason=%s',
                self.noRedundancyReasonSet, self.noRedundancyReason)
        if self.noRedundancyReasonSet:
            return self.noRedundancyReason
        return None

    def hasNoRedundancyReason(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-noredundancyreason').debug3Func():
            logFunc(
                'called. self.noRedundancyReasonSet=%s, self.noRedundancyReason=%s',
                self.noRedundancyReasonSet, self.noRedundancyReason)
        if self.noRedundancyReasonSet:
            return True
        return False

    def setNoRedundancyReason(self, noRedundancyReason):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-noredundancyreason').debug3Func():
            logFunc('called. noRedundancyReason=%s, old=%s',
                    noRedundancyReason, self.noRedundancyReason)
        self.noRedundancyReasonSet = True
        self.noRedundancyReason = noRedundancyReason

    def requestNoRedundancy(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-noredundancy').debug3Func():
            logFunc('called. requested=%s', requested)
        self.noRedundancyRequested = requested
        self.noRedundancySet = False

    def isNoRedundancyRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-noredundancy-requested').debug3Func():
            logFunc('called. requested=%s', self.noRedundancyRequested)
        return self.noRedundancyRequested

    def getNoRedundancy(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-noredundancy').debug3Func():
            logFunc('called. self.noRedundancySet=%s, self.noRedundancy=%s',
                    self.noRedundancySet, self.noRedundancy)
        if self.noRedundancySet:
            return self.noRedundancy
        return None

    def hasNoRedundancy(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-noredundancy').debug3Func():
            logFunc('called. self.noRedundancySet=%s, self.noRedundancy=%s',
                    self.noRedundancySet, self.noRedundancy)
        if self.noRedundancySet:
            return True
        return False

    def setNoRedundancy(self, noRedundancy):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-noredundancy').debug3Func():
            logFunc('called. noRedundancy=%s, old=%s', noRedundancy,
                    self.noRedundancy)
        self.noRedundancySet = True
        self.noRedundancy = noRedundancy

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        self.noRedundancyReason = 0
        self.noRedundancyReasonSet = False

        self.noRedundancy = 0
        self.noRedundancySet = False

    def _getSelfKeyPath(self, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("alarm",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans",
             "qt-pltf-fans"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("fans",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans",
             "qt-pltf-fans"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("platform",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform",
             "qt-pltf"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isNoRedundancyReasonRequested():
            valNoRedundancyReason = Value()
            valNoRedundancyReason.setEmpty()
            tagValueList.push((
                "no-redundancy-reason",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans"
            ), valNoRedundancyReason)

        if self.isNoRedundancyRequested():
            valNoRedundancy = Value()
            valNoRedundancy.setEmpty()
            tagValueList.push((
                "no-redundancy",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans"
            ), valNoRedundancy)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isNoRedundancyReasonRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "no-redundancy-reason") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-noredundancyreason'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "noRedundancyReason", "no-redundancy-reason",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-no-redundancy-reason-bad-value'
                ).infoFunc():
                    logFunc('noRedundancyReason not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setNoRedundancyReason(tempVar)
            for logFunc in self._log(
                    'read-tag-values-no-redundancy-reason').debug3Func():
                logFunc(
                    'read noRedundancyReason. noRedundancyReason=%s, tempValue=%s',
                    self.noRedundancyReason, tempValue.getType())

        if self.isNoRedundancyRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "no-redundancy") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-noredundancy'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "noRedundancy", "no-redundancy",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-fans",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asBool()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-no-redundancy-bad-value').infoFunc():
                    logFunc('noRedundancy not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setNoRedundancy(tempVar)
            for logFunc in self._log(
                    'read-tag-values-no-redundancy').debug3Func():
                logFunc('read noRedundancy. noRedundancy=%s, tempValue=%s',
                        self.noRedundancy, tempValue.getType())

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 33
0
class BlinkyCountersMaapi(CountersMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-counters")
        self.domain = None

        

        
        self.silentDroppedPacketsRequested = False
        self.silentDroppedPackets = None
        self.silentDroppedPacketsSet = False
        
        self.inPacketsRequested = False
        self.inPackets = None
        self.inPacketsSet = False
        
        self.inBadVersionPacketsRequested = False
        self.inBadVersionPackets = None
        self.inBadVersionPacketsSet = False
        
        self.inBadCommunityUsePacketsRequested = False
        self.inBadCommunityUsePackets = None
        self.inBadCommunityUsePacketsSet = False
        
        self.inAsnParseErrorsRequested = False
        self.inAsnParseErrors = None
        self.inAsnParseErrorsSet = False
        
        self.inBadCommunityPacketsRequested = False
        self.inBadCommunityPackets = None
        self.inBadCommunityPacketsSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestSilentDroppedPackets(True)
        
        self.requestInPackets(True)
        
        self.requestInBadVersionPackets(True)
        
        self.requestInBadCommunityUsePackets(True)
        
        self.requestInAsnParseErrors(True)
        
        self.requestInBadCommunityPackets(True)
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestSilentDroppedPackets(False)
        
        self.requestInPackets(False)
        
        self.requestInBadVersionPackets(False)
        
        self.requestInBadCommunityUsePackets(False)
        
        self.requestInAsnParseErrors(False)
        
        self.requestInBadCommunityPackets(False)
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestSilentDroppedPackets(True)
        
        self.requestInPackets(True)
        
        self.requestInBadVersionPackets(True)
        
        self.requestInBadCommunityUsePackets(True)
        
        self.requestInAsnParseErrors(True)
        
        self.requestInBadCommunityPackets(True)
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestSilentDroppedPackets(False)
        
        self.requestInPackets(False)
        
        self.requestInBadVersionPackets(False)
        
        self.requestInBadCommunityUsePackets(False)
        
        self.requestInAsnParseErrors(False)
        
        self.requestInBadCommunityPackets(False)
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        

    def write (self
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(trxContext)

    def read (self
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  True,
                                  trxContext)



    def requestSilentDroppedPackets (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-silentdroppedpackets').debug3Func(): logFunc('called. requested=%s', requested)
        self.silentDroppedPacketsRequested = requested
        self.silentDroppedPacketsSet = False

    def isSilentDroppedPacketsRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-silentdroppedpackets-requested').debug3Func(): logFunc('called. requested=%s', self.silentDroppedPacketsRequested)
        return self.silentDroppedPacketsRequested

    def getSilentDroppedPackets (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-silentdroppedpackets').debug3Func(): logFunc('called. self.silentDroppedPacketsSet=%s, self.silentDroppedPackets=%s', self.silentDroppedPacketsSet, self.silentDroppedPackets)
        if self.silentDroppedPacketsSet:
            return self.silentDroppedPackets
        return None

    def hasSilentDroppedPackets (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-silentdroppedpackets').debug3Func(): logFunc('called. self.silentDroppedPacketsSet=%s, self.silentDroppedPackets=%s', self.silentDroppedPacketsSet, self.silentDroppedPackets)
        if self.silentDroppedPacketsSet:
            return True
        return False

    def setSilentDroppedPackets (self, silentDroppedPackets):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-silentdroppedpackets').debug3Func(): logFunc('called. silentDroppedPackets=%s, old=%s', silentDroppedPackets, self.silentDroppedPackets)
        self.silentDroppedPacketsSet = True
        self.silentDroppedPackets = silentDroppedPackets

    def requestInPackets (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-inpackets').debug3Func(): logFunc('called. requested=%s', requested)
        self.inPacketsRequested = requested
        self.inPacketsSet = False

    def isInPacketsRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-inpackets-requested').debug3Func(): logFunc('called. requested=%s', self.inPacketsRequested)
        return self.inPacketsRequested

    def getInPackets (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-inpackets').debug3Func(): logFunc('called. self.inPacketsSet=%s, self.inPackets=%s', self.inPacketsSet, self.inPackets)
        if self.inPacketsSet:
            return self.inPackets
        return None

    def hasInPackets (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-inpackets').debug3Func(): logFunc('called. self.inPacketsSet=%s, self.inPackets=%s', self.inPacketsSet, self.inPackets)
        if self.inPacketsSet:
            return True
        return False

    def setInPackets (self, inPackets):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-inpackets').debug3Func(): logFunc('called. inPackets=%s, old=%s', inPackets, self.inPackets)
        self.inPacketsSet = True
        self.inPackets = inPackets

    def requestInBadVersionPackets (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-inbadversionpackets').debug3Func(): logFunc('called. requested=%s', requested)
        self.inBadVersionPacketsRequested = requested
        self.inBadVersionPacketsSet = False

    def isInBadVersionPacketsRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-inbadversionpackets-requested').debug3Func(): logFunc('called. requested=%s', self.inBadVersionPacketsRequested)
        return self.inBadVersionPacketsRequested

    def getInBadVersionPackets (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-inbadversionpackets').debug3Func(): logFunc('called. self.inBadVersionPacketsSet=%s, self.inBadVersionPackets=%s', self.inBadVersionPacketsSet, self.inBadVersionPackets)
        if self.inBadVersionPacketsSet:
            return self.inBadVersionPackets
        return None

    def hasInBadVersionPackets (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-inbadversionpackets').debug3Func(): logFunc('called. self.inBadVersionPacketsSet=%s, self.inBadVersionPackets=%s', self.inBadVersionPacketsSet, self.inBadVersionPackets)
        if self.inBadVersionPacketsSet:
            return True
        return False

    def setInBadVersionPackets (self, inBadVersionPackets):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-inbadversionpackets').debug3Func(): logFunc('called. inBadVersionPackets=%s, old=%s', inBadVersionPackets, self.inBadVersionPackets)
        self.inBadVersionPacketsSet = True
        self.inBadVersionPackets = inBadVersionPackets

    def requestInBadCommunityUsePackets (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-inbadcommunityusepackets').debug3Func(): logFunc('called. requested=%s', requested)
        self.inBadCommunityUsePacketsRequested = requested
        self.inBadCommunityUsePacketsSet = False

    def isInBadCommunityUsePacketsRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-inbadcommunityusepackets-requested').debug3Func(): logFunc('called. requested=%s', self.inBadCommunityUsePacketsRequested)
        return self.inBadCommunityUsePacketsRequested

    def getInBadCommunityUsePackets (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-inbadcommunityusepackets').debug3Func(): logFunc('called. self.inBadCommunityUsePacketsSet=%s, self.inBadCommunityUsePackets=%s', self.inBadCommunityUsePacketsSet, self.inBadCommunityUsePackets)
        if self.inBadCommunityUsePacketsSet:
            return self.inBadCommunityUsePackets
        return None

    def hasInBadCommunityUsePackets (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-inbadcommunityusepackets').debug3Func(): logFunc('called. self.inBadCommunityUsePacketsSet=%s, self.inBadCommunityUsePackets=%s', self.inBadCommunityUsePacketsSet, self.inBadCommunityUsePackets)
        if self.inBadCommunityUsePacketsSet:
            return True
        return False

    def setInBadCommunityUsePackets (self, inBadCommunityUsePackets):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-inbadcommunityusepackets').debug3Func(): logFunc('called. inBadCommunityUsePackets=%s, old=%s', inBadCommunityUsePackets, self.inBadCommunityUsePackets)
        self.inBadCommunityUsePacketsSet = True
        self.inBadCommunityUsePackets = inBadCommunityUsePackets

    def requestInAsnParseErrors (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-inasnparseerrors').debug3Func(): logFunc('called. requested=%s', requested)
        self.inAsnParseErrorsRequested = requested
        self.inAsnParseErrorsSet = False

    def isInAsnParseErrorsRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-inasnparseerrors-requested').debug3Func(): logFunc('called. requested=%s', self.inAsnParseErrorsRequested)
        return self.inAsnParseErrorsRequested

    def getInAsnParseErrors (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-inasnparseerrors').debug3Func(): logFunc('called. self.inAsnParseErrorsSet=%s, self.inAsnParseErrors=%s', self.inAsnParseErrorsSet, self.inAsnParseErrors)
        if self.inAsnParseErrorsSet:
            return self.inAsnParseErrors
        return None

    def hasInAsnParseErrors (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-inasnparseerrors').debug3Func(): logFunc('called. self.inAsnParseErrorsSet=%s, self.inAsnParseErrors=%s', self.inAsnParseErrorsSet, self.inAsnParseErrors)
        if self.inAsnParseErrorsSet:
            return True
        return False

    def setInAsnParseErrors (self, inAsnParseErrors):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-inasnparseerrors').debug3Func(): logFunc('called. inAsnParseErrors=%s, old=%s', inAsnParseErrors, self.inAsnParseErrors)
        self.inAsnParseErrorsSet = True
        self.inAsnParseErrors = inAsnParseErrors

    def requestInBadCommunityPackets (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-inbadcommunitypackets').debug3Func(): logFunc('called. requested=%s', requested)
        self.inBadCommunityPacketsRequested = requested
        self.inBadCommunityPacketsSet = False

    def isInBadCommunityPacketsRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-inbadcommunitypackets-requested').debug3Func(): logFunc('called. requested=%s', self.inBadCommunityPacketsRequested)
        return self.inBadCommunityPacketsRequested

    def getInBadCommunityPackets (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-inbadcommunitypackets').debug3Func(): logFunc('called. self.inBadCommunityPacketsSet=%s, self.inBadCommunityPackets=%s', self.inBadCommunityPacketsSet, self.inBadCommunityPackets)
        if self.inBadCommunityPacketsSet:
            return self.inBadCommunityPackets
        return None

    def hasInBadCommunityPackets (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-inbadcommunitypackets').debug3Func(): logFunc('called. self.inBadCommunityPacketsSet=%s, self.inBadCommunityPackets=%s', self.inBadCommunityPacketsSet, self.inBadCommunityPackets)
        if self.inBadCommunityPacketsSet:
            return True
        return False

    def setInBadCommunityPackets (self, inBadCommunityPackets):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-inbadcommunitypackets').debug3Func(): logFunc('called. inBadCommunityPackets=%s, old=%s', inBadCommunityPackets, self.inBadCommunityPackets)
        self.inBadCommunityPacketsSet = True
        self.inBadCommunityPackets = inBadCommunityPackets


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.silentDroppedPackets = 0
        self.silentDroppedPacketsSet = False
        
        self.inPackets = 0
        self.inPacketsSet = False
        
        self.inBadVersionPackets = 0
        self.inBadVersionPacketsSet = False
        
        self.inBadCommunityUsePackets = 0
        self.inBadCommunityUsePacketsSet = False
        
        self.inAsnParseErrors = 0
        self.inAsnParseErrorsSet = False
        
        self.inBadCommunityPackets = 0
        self.inBadCommunityPacketsSet = False
        

    def _getSelfKeyPath (self
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("counters", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp", "qt-snmp"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("snmp", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp", "qt-snmp"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isSilentDroppedPacketsRequested():
            valSilentDroppedPackets = Value()
            valSilentDroppedPackets.setEmpty()
            tagValueList.push(("silent-dropped-packets", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"), valSilentDroppedPackets)
        
        if self.isInPacketsRequested():
            valInPackets = Value()
            valInPackets.setEmpty()
            tagValueList.push(("in-packets", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"), valInPackets)
        
        if self.isInBadVersionPacketsRequested():
            valInBadVersionPackets = Value()
            valInBadVersionPackets.setEmpty()
            tagValueList.push(("in-bad-version-packets", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"), valInBadVersionPackets)
        
        if self.isInBadCommunityUsePacketsRequested():
            valInBadCommunityUsePackets = Value()
            valInBadCommunityUsePackets.setEmpty()
            tagValueList.push(("in-bad-community-use-packets", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"), valInBadCommunityUsePackets)
        
        if self.isInAsnParseErrorsRequested():
            valInAsnParseErrors = Value()
            valInAsnParseErrors.setEmpty()
            tagValueList.push(("in-asn-parse-errors", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"), valInAsnParseErrors)
        
        if self.isInBadCommunityPacketsRequested():
            valInBadCommunityPackets = Value()
            valInBadCommunityPackets.setEmpty()
            tagValueList.push(("in-bad-community-packets", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"), valInBadCommunityPackets)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isSilentDroppedPacketsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "silent-dropped-packets") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-silentdroppedpackets').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "silentDroppedPackets", "silent-dropped-packets", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-silent-dropped-packets-bad-value').infoFunc(): logFunc('silentDroppedPackets not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setSilentDroppedPackets(tempVar)
            for logFunc in self._log('read-tag-values-silent-dropped-packets').debug3Func(): logFunc('read silentDroppedPackets. silentDroppedPackets=%s, tempValue=%s', self.silentDroppedPackets, tempValue.getType())
        
        if self.isInPacketsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "in-packets") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-inpackets').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "inPackets", "in-packets", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-in-packets-bad-value').infoFunc(): logFunc('inPackets not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setInPackets(tempVar)
            for logFunc in self._log('read-tag-values-in-packets').debug3Func(): logFunc('read inPackets. inPackets=%s, tempValue=%s', self.inPackets, tempValue.getType())
        
        if self.isInBadVersionPacketsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "in-bad-version-packets") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-inbadversionpackets').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "inBadVersionPackets", "in-bad-version-packets", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-in-bad-version-packets-bad-value').infoFunc(): logFunc('inBadVersionPackets not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setInBadVersionPackets(tempVar)
            for logFunc in self._log('read-tag-values-in-bad-version-packets').debug3Func(): logFunc('read inBadVersionPackets. inBadVersionPackets=%s, tempValue=%s', self.inBadVersionPackets, tempValue.getType())
        
        if self.isInBadCommunityUsePacketsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "in-bad-community-use-packets") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-inbadcommunityusepackets').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "inBadCommunityUsePackets", "in-bad-community-use-packets", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-in-bad-community-use-packets-bad-value').infoFunc(): logFunc('inBadCommunityUsePackets not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setInBadCommunityUsePackets(tempVar)
            for logFunc in self._log('read-tag-values-in-bad-community-use-packets').debug3Func(): logFunc('read inBadCommunityUsePackets. inBadCommunityUsePackets=%s, tempValue=%s', self.inBadCommunityUsePackets, tempValue.getType())
        
        if self.isInAsnParseErrorsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "in-asn-parse-errors") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-inasnparseerrors').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "inAsnParseErrors", "in-asn-parse-errors", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-in-asn-parse-errors-bad-value').infoFunc(): logFunc('inAsnParseErrors not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setInAsnParseErrors(tempVar)
            for logFunc in self._log('read-tag-values-in-asn-parse-errors').debug3Func(): logFunc('read inAsnParseErrors. inAsnParseErrors=%s, tempValue=%s', self.inAsnParseErrors, tempValue.getType())
        
        if self.isInBadCommunityPacketsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "in-bad-community-packets") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-inbadcommunitypackets').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "inBadCommunityPackets", "in-bad-community-packets", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-in-bad-community-packets-bad-value').infoFunc(): logFunc('inBadCommunityPackets not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setInBadCommunityPackets(tempVar)
            for logFunc in self._log('read-tag-values-in-bad-community-packets').debug3Func(): logFunc('read inBadCommunityPackets. inBadCommunityPackets=%s, tempValue=%s', self.inBadCommunityPackets, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 34
0
class BlinkyArpMaapi(ArpMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-arp")
        self.domain = None

        

        
        self.testTimeoutMsecRequested = False
        self.testTimeoutMsec = None
        self.testTimeoutMsecSet = False
        
        self.testIntervalMsecRequested = False
        self.testIntervalMsec = None
        self.testIntervalMsecSet = False
        
        self.upPeriodRequested = False
        self.upPeriod = None
        self.upPeriodSet = False
        
        self.downPeriodRequested = False
        self.downPeriod = None
        self.downPeriodSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestTestTimeoutMsec(True)
        
        self.requestTestIntervalMsec(True)
        
        self.requestUpPeriod(True)
        
        self.requestDownPeriod(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestTestTimeoutMsec(True)
        
        self.requestTestIntervalMsec(True)
        
        self.requestUpPeriod(True)
        
        self.requestDownPeriod(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestTestTimeoutMsec(False)
        
        self.requestTestIntervalMsec(False)
        
        self.requestUpPeriod(False)
        
        self.requestDownPeriod(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestTestTimeoutMsec(False)
        
        self.requestTestIntervalMsec(False)
        
        self.requestUpPeriod(False)
        
        self.requestDownPeriod(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setTestTimeoutMsec(None)
        self.testTimeoutMsecSet = False
        
        self.setTestIntervalMsec(None)
        self.testIntervalMsecSet = False
        
        self.setUpPeriod(None)
        self.upPeriodSet = False
        
        self.setDownPeriod(None)
        self.downPeriodSet = False
        
        

    def write (self
              , interface
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(interface, trxContext)

    def read (self
              , interface
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(interface, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , interface
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(interface, 
                                  True,
                                  trxContext)



    def requestTestTimeoutMsec (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-testtimeoutmsec').debug3Func(): logFunc('called. requested=%s', requested)
        self.testTimeoutMsecRequested = requested
        self.testTimeoutMsecSet = False

    def isTestTimeoutMsecRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-testtimeoutmsec-requested').debug3Func(): logFunc('called. requested=%s', self.testTimeoutMsecRequested)
        return self.testTimeoutMsecRequested

    def getTestTimeoutMsec (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-testtimeoutmsec').debug3Func(): logFunc('called. self.testTimeoutMsecSet=%s, self.testTimeoutMsec=%s', self.testTimeoutMsecSet, self.testTimeoutMsec)
        if self.testTimeoutMsecSet:
            return self.testTimeoutMsec
        return None

    def hasTestTimeoutMsec (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-testtimeoutmsec').debug3Func(): logFunc('called. self.testTimeoutMsecSet=%s, self.testTimeoutMsec=%s', self.testTimeoutMsecSet, self.testTimeoutMsec)
        if self.testTimeoutMsecSet:
            return True
        return False

    def setTestTimeoutMsec (self, testTimeoutMsec):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-testtimeoutmsec').debug3Func(): logFunc('called. testTimeoutMsec=%s, old=%s', testTimeoutMsec, self.testTimeoutMsec)
        self.testTimeoutMsecSet = True
        self.testTimeoutMsec = testTimeoutMsec

    def requestTestIntervalMsec (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-testintervalmsec').debug3Func(): logFunc('called. requested=%s', requested)
        self.testIntervalMsecRequested = requested
        self.testIntervalMsecSet = False

    def isTestIntervalMsecRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-testintervalmsec-requested').debug3Func(): logFunc('called. requested=%s', self.testIntervalMsecRequested)
        return self.testIntervalMsecRequested

    def getTestIntervalMsec (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-testintervalmsec').debug3Func(): logFunc('called. self.testIntervalMsecSet=%s, self.testIntervalMsec=%s', self.testIntervalMsecSet, self.testIntervalMsec)
        if self.testIntervalMsecSet:
            return self.testIntervalMsec
        return None

    def hasTestIntervalMsec (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-testintervalmsec').debug3Func(): logFunc('called. self.testIntervalMsecSet=%s, self.testIntervalMsec=%s', self.testIntervalMsecSet, self.testIntervalMsec)
        if self.testIntervalMsecSet:
            return True
        return False

    def setTestIntervalMsec (self, testIntervalMsec):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-testintervalmsec').debug3Func(): logFunc('called. testIntervalMsec=%s, old=%s', testIntervalMsec, self.testIntervalMsec)
        self.testIntervalMsecSet = True
        self.testIntervalMsec = testIntervalMsec

    def requestUpPeriod (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-upperiod').debug3Func(): logFunc('called. requested=%s', requested)
        self.upPeriodRequested = requested
        self.upPeriodSet = False

    def isUpPeriodRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-upperiod-requested').debug3Func(): logFunc('called. requested=%s', self.upPeriodRequested)
        return self.upPeriodRequested

    def getUpPeriod (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-upperiod').debug3Func(): logFunc('called. self.upPeriodSet=%s, self.upPeriod=%s', self.upPeriodSet, self.upPeriod)
        if self.upPeriodSet:
            return self.upPeriod
        return None

    def hasUpPeriod (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-upperiod').debug3Func(): logFunc('called. self.upPeriodSet=%s, self.upPeriod=%s', self.upPeriodSet, self.upPeriod)
        if self.upPeriodSet:
            return True
        return False

    def setUpPeriod (self, upPeriod):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-upperiod').debug3Func(): logFunc('called. upPeriod=%s, old=%s', upPeriod, self.upPeriod)
        self.upPeriodSet = True
        self.upPeriod = upPeriod

    def requestDownPeriod (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-downperiod').debug3Func(): logFunc('called. requested=%s', requested)
        self.downPeriodRequested = requested
        self.downPeriodSet = False

    def isDownPeriodRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-downperiod-requested').debug3Func(): logFunc('called. requested=%s', self.downPeriodRequested)
        return self.downPeriodRequested

    def getDownPeriod (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-downperiod').debug3Func(): logFunc('called. self.downPeriodSet=%s, self.downPeriod=%s', self.downPeriodSet, self.downPeriod)
        if self.downPeriodSet:
            return self.downPeriod
        return None

    def hasDownPeriod (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-downperiod').debug3Func(): logFunc('called. self.downPeriodSet=%s, self.downPeriod=%s', self.downPeriodSet, self.downPeriod)
        if self.downPeriodSet:
            return True
        return False

    def setDownPeriod (self, downPeriod):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-downperiod').debug3Func(): logFunc('called. downPeriod=%s, old=%s', downPeriod, self.downPeriod)
        self.downPeriodSet = True
        self.downPeriod = downPeriod


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.testTimeoutMsec = 0
        self.testTimeoutMsecSet = False
        
        self.testIntervalMsec = 0
        self.testIntervalMsecSet = False
        
        self.upPeriod = 0
        self.upPeriodSet = False
        
        self.downPeriod = 0
        self.downPeriodSet = False
        

    def _getSelfKeyPath (self, interface
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("arp", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("ipv4", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("connectivity-check", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(interface);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("interface", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("interfaces", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        interface, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(interface, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(interface, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       interface, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(interface, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               interface, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasTestTimeoutMsec():
            valTestTimeoutMsec = Value()
            if self.testTimeoutMsec is not None:
                valTestTimeoutMsec.setInt64(self.testTimeoutMsec)
            else:
                valTestTimeoutMsec.setEmpty()
            tagValueList.push(("test-timeout-msec", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valTestTimeoutMsec)
        
        if self.hasTestIntervalMsec():
            valTestIntervalMsec = Value()
            if self.testIntervalMsec is not None:
                valTestIntervalMsec.setInt64(self.testIntervalMsec)
            else:
                valTestIntervalMsec.setEmpty()
            tagValueList.push(("test-interval-msec", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valTestIntervalMsec)
        
        if self.hasUpPeriod():
            valUpPeriod = Value()
            if self.upPeriod is not None:
                valUpPeriod.setInt64(self.upPeriod)
            else:
                valUpPeriod.setEmpty()
            tagValueList.push(("up-period", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valUpPeriod)
        
        if self.hasDownPeriod():
            valDownPeriod = Value()
            if self.downPeriod is not None:
                valDownPeriod.setInt64(self.downPeriod)
            else:
                valDownPeriod.setEmpty()
            tagValueList.push(("down-period", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valDownPeriod)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isTestTimeoutMsecRequested():
            valTestTimeoutMsec = Value()
            valTestTimeoutMsec.setEmpty()
            tagValueList.push(("test-timeout-msec", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valTestTimeoutMsec)
        
        if self.isTestIntervalMsecRequested():
            valTestIntervalMsec = Value()
            valTestIntervalMsec.setEmpty()
            tagValueList.push(("test-interval-msec", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valTestIntervalMsec)
        
        if self.isUpPeriodRequested():
            valUpPeriod = Value()
            valUpPeriod.setEmpty()
            tagValueList.push(("up-period", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valUpPeriod)
        
        if self.isDownPeriodRequested():
            valDownPeriod = Value()
            valDownPeriod.setEmpty()
            tagValueList.push(("down-period", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valDownPeriod)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isTestTimeoutMsecRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "test-timeout-msec") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-testtimeoutmsec').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "testTimeoutMsec", "test-timeout-msec", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-test-timeout-msec-bad-value').infoFunc(): logFunc('testTimeoutMsec not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setTestTimeoutMsec(tempVar)
            for logFunc in self._log('read-tag-values-test-timeout-msec').debug3Func(): logFunc('read testTimeoutMsec. testTimeoutMsec=%s, tempValue=%s', self.testTimeoutMsec, tempValue.getType())
        
        if self.isTestIntervalMsecRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "test-interval-msec") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-testintervalmsec').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "testIntervalMsec", "test-interval-msec", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-test-interval-msec-bad-value').infoFunc(): logFunc('testIntervalMsec not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setTestIntervalMsec(tempVar)
            for logFunc in self._log('read-tag-values-test-interval-msec').debug3Func(): logFunc('read testIntervalMsec. testIntervalMsec=%s, tempValue=%s', self.testIntervalMsec, tempValue.getType())
        
        if self.isUpPeriodRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "up-period") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-upperiod').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "upPeriod", "up-period", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-up-period-bad-value').infoFunc(): logFunc('upPeriod not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setUpPeriod(tempVar)
            for logFunc in self._log('read-tag-values-up-period').debug3Func(): logFunc('read upPeriod. upPeriod=%s, tempValue=%s', self.upPeriod, tempValue.getType())
        
        if self.isDownPeriodRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "down-period") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-downperiod').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "downPeriod", "down-period", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-down-period-bad-value').infoFunc(): logFunc('downPeriod not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setDownPeriod(tempVar)
            for logFunc in self._log('read-tag-values-down-period').debug3Func(): logFunc('read downPeriod. downPeriod=%s, tempValue=%s', self.downPeriod, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 35
0
class BlinkySimulateMaapi(SimulateMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-simulate")
        self.domain = None

        self.idRequested = False
        self.id = None
        self.idSet = False

        self.nameRequested = False
        self.name = None
        self.nameSet = False

        self.entityRequested = False
        self.entity = None
        self.entitySet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestId(True)

        self.requestName(True)

        self.requestEntity(True)

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestId(True)

        self.requestName(True)

        self.requestEntity(True)

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestId(False)

        self.requestName(False)

        self.requestEntity(False)

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestId(False)

        self.requestName(False)

        self.requestEntity(False)

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

        self.setId(None)
        self.idSet = False

        self.setName(None)
        self.nameSet = False

        self.setEntity(None)
        self.entitySet = False

    def write(self, simulate, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(simulate, trxContext)

    def read(self, simulate, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(simulate, False, trxContext)

    def readAllOrFail(self, simulate, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(simulate, True, trxContext)

    def requestId(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-id').debug3Func():
            logFunc('called. requested=%s', requested)
        self.idRequested = requested
        self.idSet = False

    def isIdRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-id-requested').debug3Func():
            logFunc('called. requested=%s', self.idRequested)
        return self.idRequested

    def getId(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-id').debug3Func():
            logFunc('called. self.idSet=%s, self.id=%s', self.idSet, self.id)
        if self.idSet:
            return self.id
        return None

    def hasId(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-id').debug3Func():
            logFunc('called. self.idSet=%s, self.id=%s', self.idSet, self.id)
        if self.idSet:
            return True
        return False

    def setId(self, id):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-id').debug3Func():
            logFunc('called. id=%s, old=%s', id, self.id)
        self.idSet = True
        self.id = id

    def requestName(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-name').debug3Func():
            logFunc('called. requested=%s', requested)
        self.nameRequested = requested
        self.nameSet = False

    def isNameRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-name-requested').debug3Func():
            logFunc('called. requested=%s', self.nameRequested)
        return self.nameRequested

    def getName(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-name').debug3Func():
            logFunc('called. self.nameSet=%s, self.name=%s', self.nameSet,
                    self.name)
        if self.nameSet:
            return self.name
        return None

    def hasName(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-name').debug3Func():
            logFunc('called. self.nameSet=%s, self.name=%s', self.nameSet,
                    self.name)
        if self.nameSet:
            return True
        return False

    def setName(self, name):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-name').debug3Func():
            logFunc('called. name=%s, old=%s', name, self.name)
        self.nameSet = True
        self.name = name

    def requestEntity(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-entity').debug3Func():
            logFunc('called. requested=%s', requested)
        self.entityRequested = requested
        self.entitySet = False

    def isEntityRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-entity-requested').debug3Func():
            logFunc('called. requested=%s', self.entityRequested)
        return self.entityRequested

    def getEntity(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-entity').debug3Func():
            logFunc('called. self.entitySet=%s, self.entity=%s',
                    self.entitySet, self.entity)
        if self.entitySet:
            return self.entity
        return None

    def hasEntity(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-entity').debug3Func():
            logFunc('called. self.entitySet=%s, self.entity=%s',
                    self.entitySet, self.entity)
        if self.entitySet:
            return True
        return False

    def setEntity(self, entity):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-entity').debug3Func():
            logFunc('called. entity=%s, old=%s', entity, self.entity)
        self.entitySet = True
        self.entity = entity

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        self.id = 0
        self.idSet = False

        self.name = 0
        self.nameSet = False

        self.entity = 0
        self.entitySet = False

    def _getSelfKeyPath(self, simulate, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        ancestorVal = Value()
        ancestorVal.setString(simulate)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("simulate",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-alarms",
             "qt-sys-alarms"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("alarms",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-alarms",
             "qt-sys-alarms"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("system",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system",
             "qt-sys"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, simulate, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(simulate, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(simulate, None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, simulate, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(simulate, None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, simulate, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.hasId():
            valId = Value()
            if self.id is not None:
                valId.setString(self.id)
            else:
                valId.setEmpty()
            tagValueList.push((
                "id",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-alarms"
            ), valId)

        if self.hasName():
            valName = Value()
            if self.name is not None:
                valName.setEnum(self.name.getValue())
            else:
                valName.setEmpty()
            tagValueList.push((
                "name",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-alarms"
            ), valName)

        if self.hasEntity():
            valEntity = Value()
            if self.entity is not None:
                valEntity.setString(self.entity)
            else:
                valEntity.setEmpty()
            tagValueList.push((
                "entity",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-alarms"
            ), valEntity)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isIdRequested():
            valId = Value()
            valId.setEmpty()
            tagValueList.push((
                "id",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-alarms"
            ), valId)

        if self.isNameRequested():
            valName = Value()
            valName.setEmpty()
            tagValueList.push((
                "name",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-alarms"
            ), valName)

        if self.isEntityRequested():
            valEntity = Value()
            valEntity.setEmpty()
            tagValueList.push((
                "entity",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-alarms"
            ), valEntity)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isIdRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "id") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-alarms"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-id').errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "id", "id",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-alarms",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-id-bad-value').infoFunc():
                    logFunc('id not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setId(tempVar)
            for logFunc in self._log('read-tag-values-id').debug3Func():
                logFunc('read id. id=%s, tempValue=%s', self.id,
                        tempValue.getType())

        if self.isNameRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "name") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-alarms"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-name').errorFunc(
                        ):
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "name", "name",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-alarms",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-name-bad-value').infoFunc():
                    logFunc('name not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setName(tempVar)
            for logFunc in self._log('read-tag-values-name').debug3Func():
                logFunc('read name. name=%s, tempValue=%s', self.name,
                        tempValue.getType())

        if self.isEntityRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "entity") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-alarms"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-entity'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "entity", "entity",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-alarms",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-entity-bad-value').infoFunc():
                    logFunc('entity not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setEntity(tempVar)
            for logFunc in self._log('read-tag-values-entity').debug3Func():
                logFunc('read entity. entity=%s, tempValue=%s', self.entity,
                        tempValue.getType())

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 36
0
class BlinkyNotificationsMaapi(NotificationsMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-notifications")
        self.domain = None

        
        self.destinationListObj = None
        

        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        
        if not self.destinationListObj:
            self.destinationListObj = self.newDestinationList()
            self.destinationListObj.requestConfigAndOper()
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        
        
        if not self.destinationListObj:
            self.destinationListObj = self.newDestinationList()
            self.destinationListObj.requestConfig()
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        
        if not self.destinationListObj:
            self.destinationListObj = self.newDestinationList()
            self.destinationListObj.requestOper()
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        
        
        if not self.destinationListObj:
            self.destinationListObj = self.newDestinationList()
            self.destinationListObj.clearAllRequested()
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        
        if self.destinationListObj:
            self.destinationListObj.clearAllSet()
        

    def write (self
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(trxContext)

    def read (self
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  True,
                                  trxContext)

    def newDestinationList (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-destinationlist').debug3Func(): logFunc('called.')
        destinationList = BlinkyDestinationMaapiList(self._log)
        destinationList.init(self.domain)
        return destinationList

    def setDestinationListObj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-destinationlist').debug3Func(): logFunc('called. obj=%s', obj)
        self.destinationListObj = obj

    def getDestinationListObj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-destinationlist').debug3Func(): logFunc('called. self.destinationListObj=%s', self.destinationListObj)
        return self.destinationListObj

    def hasDestinationList (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-destinationlist').debug3Func(): logFunc('called. self.destinationListObj=%s', self.destinationListObj)
        if self.destinationListObj:
            return True
        return False




    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        
        if self.destinationListObj:
            self.destinationListObj._clearAllReadData()
        

        

    def _getSelfKeyPath (self
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("notifications", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp", "qt-snmp"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("snmp", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp", "qt-snmp"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        
        if self.destinationListObj:
            res = self.destinationListObj._collectItemsToDelete(
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-destination-failed').errorFunc(): logFunc('destinationListObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        

        
        if self.destinationListObj:
            valBegin = Value()
            (tag, ns, prefix) = ("destination" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp", "qt-snmp")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.destinationListObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-destination-failed').errorFunc(): logFunc('destinationListObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        

        
        if self.destinationListObj:
            valBegin = Value()
            (tag, ns, prefix) = ("destination" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp", "qt-snmp")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.destinationListObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-destination-failed').errorFunc(): logFunc('destinationListObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        

        
        if self.destinationListObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "destination") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "destination", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.destinationListObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-destination-failed').errorFunc(): logFunc('destinationListObj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "destination") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "destination", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 37
0
class BlinkyOutputMaapi(OutputMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-output")
        self.domain = None

        

        
        self.fileBaseNameRequested = False
        self.fileBaseName = None
        self.fileBaseNameSet = False
        
        self.maxFileSizePercentRequested = False
        self.maxFileSizePercent = None
        self.maxFileSizePercentSet = False
        
        self.fileDirectoryRequested = False
        self.fileDirectory = None
        self.fileDirectorySet = False
        
        self.archiveModeRequested = False
        self.archiveMode = None
        self.archiveModeSet = False
        
        self.maxSizeMbRequested = False
        self.maxSizeMb = None
        self.maxSizeMbSet = False
        
        self.writeModeRequested = False
        self.writeMode = None
        self.writeModeSet = False
        
        self.fileRotationIntervalMinutesRequested = False
        self.fileRotationIntervalMinutes = None
        self.fileRotationIntervalMinutesSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestFileBaseName(True)
        
        self.requestMaxFileSizePercent(True)
        
        self.requestFileDirectory(True)
        
        self.requestArchiveMode(True)
        
        self.requestMaxSizeMb(True)
        
        self.requestWriteMode(True)
        
        self.requestFileRotationIntervalMinutes(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestFileBaseName(True)
        
        self.requestMaxFileSizePercent(True)
        
        self.requestFileDirectory(True)
        
        self.requestArchiveMode(True)
        
        self.requestMaxSizeMb(True)
        
        self.requestWriteMode(True)
        
        self.requestFileRotationIntervalMinutes(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestFileBaseName(False)
        
        self.requestMaxFileSizePercent(False)
        
        self.requestFileDirectory(False)
        
        self.requestArchiveMode(False)
        
        self.requestMaxSizeMb(False)
        
        self.requestWriteMode(False)
        
        self.requestFileRotationIntervalMinutes(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestFileBaseName(False)
        
        self.requestMaxFileSizePercent(False)
        
        self.requestFileDirectory(False)
        
        self.requestArchiveMode(False)
        
        self.requestMaxSizeMb(False)
        
        self.requestWriteMode(False)
        
        self.requestFileRotationIntervalMinutes(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setFileBaseName(None)
        self.fileBaseNameSet = False
        
        self.setMaxFileSizePercent(None)
        self.maxFileSizePercentSet = False
        
        self.setFileDirectory(None)
        self.fileDirectorySet = False
        
        self.setArchiveMode(None)
        self.archiveModeSet = False
        
        self.setMaxSizeMb(None)
        self.maxSizeMbSet = False
        
        self.setWriteMode(None)
        self.writeModeSet = False
        
        self.setFileRotationIntervalMinutes(None)
        self.fileRotationIntervalMinutesSet = False
        
        

    def write (self
              , loggerClass
              , instance
              , destination
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(loggerClass, instance, destination, trxContext)

    def read (self
              , loggerClass
              , instance
              , destination
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(loggerClass, instance, destination, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , loggerClass
                       , instance
                       , destination
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(loggerClass, instance, destination, 
                                  True,
                                  trxContext)



    def requestFileBaseName (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-filebasename').debug3Func(): logFunc('called. requested=%s', requested)
        self.fileBaseNameRequested = requested
        self.fileBaseNameSet = False

    def isFileBaseNameRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-filebasename-requested').debug3Func(): logFunc('called. requested=%s', self.fileBaseNameRequested)
        return self.fileBaseNameRequested

    def getFileBaseName (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-filebasename').debug3Func(): logFunc('called. self.fileBaseNameSet=%s, self.fileBaseName=%s', self.fileBaseNameSet, self.fileBaseName)
        if self.fileBaseNameSet:
            return self.fileBaseName
        return None

    def hasFileBaseName (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-filebasename').debug3Func(): logFunc('called. self.fileBaseNameSet=%s, self.fileBaseName=%s', self.fileBaseNameSet, self.fileBaseName)
        if self.fileBaseNameSet:
            return True
        return False

    def setFileBaseName (self, fileBaseName):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-filebasename').debug3Func(): logFunc('called. fileBaseName=%s, old=%s', fileBaseName, self.fileBaseName)
        self.fileBaseNameSet = True
        self.fileBaseName = fileBaseName

    def requestMaxFileSizePercent (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-maxfilesizepercent').debug3Func(): logFunc('called. requested=%s', requested)
        self.maxFileSizePercentRequested = requested
        self.maxFileSizePercentSet = False

    def isMaxFileSizePercentRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-maxfilesizepercent-requested').debug3Func(): logFunc('called. requested=%s', self.maxFileSizePercentRequested)
        return self.maxFileSizePercentRequested

    def getMaxFileSizePercent (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-maxfilesizepercent').debug3Func(): logFunc('called. self.maxFileSizePercentSet=%s, self.maxFileSizePercent=%s', self.maxFileSizePercentSet, self.maxFileSizePercent)
        if self.maxFileSizePercentSet:
            return self.maxFileSizePercent
        return None

    def hasMaxFileSizePercent (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-maxfilesizepercent').debug3Func(): logFunc('called. self.maxFileSizePercentSet=%s, self.maxFileSizePercent=%s', self.maxFileSizePercentSet, self.maxFileSizePercent)
        if self.maxFileSizePercentSet:
            return True
        return False

    def setMaxFileSizePercent (self, maxFileSizePercent):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-maxfilesizepercent').debug3Func(): logFunc('called. maxFileSizePercent=%s, old=%s', maxFileSizePercent, self.maxFileSizePercent)
        self.maxFileSizePercentSet = True
        self.maxFileSizePercent = maxFileSizePercent

    def requestFileDirectory (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-filedirectory').debug3Func(): logFunc('called. requested=%s', requested)
        self.fileDirectoryRequested = requested
        self.fileDirectorySet = False

    def isFileDirectoryRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-filedirectory-requested').debug3Func(): logFunc('called. requested=%s', self.fileDirectoryRequested)
        return self.fileDirectoryRequested

    def getFileDirectory (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-filedirectory').debug3Func(): logFunc('called. self.fileDirectorySet=%s, self.fileDirectory=%s', self.fileDirectorySet, self.fileDirectory)
        if self.fileDirectorySet:
            return self.fileDirectory
        return None

    def hasFileDirectory (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-filedirectory').debug3Func(): logFunc('called. self.fileDirectorySet=%s, self.fileDirectory=%s', self.fileDirectorySet, self.fileDirectory)
        if self.fileDirectorySet:
            return True
        return False

    def setFileDirectory (self, fileDirectory):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-filedirectory').debug3Func(): logFunc('called. fileDirectory=%s, old=%s', fileDirectory, self.fileDirectory)
        self.fileDirectorySet = True
        self.fileDirectory = fileDirectory

    def requestArchiveMode (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-archivemode').debug3Func(): logFunc('called. requested=%s', requested)
        self.archiveModeRequested = requested
        self.archiveModeSet = False

    def isArchiveModeRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-archivemode-requested').debug3Func(): logFunc('called. requested=%s', self.archiveModeRequested)
        return self.archiveModeRequested

    def getArchiveMode (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-archivemode').debug3Func(): logFunc('called. self.archiveModeSet=%s, self.archiveMode=%s', self.archiveModeSet, self.archiveMode)
        if self.archiveModeSet:
            return self.archiveMode
        return None

    def hasArchiveMode (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-archivemode').debug3Func(): logFunc('called. self.archiveModeSet=%s, self.archiveMode=%s', self.archiveModeSet, self.archiveMode)
        if self.archiveModeSet:
            return True
        return False

    def setArchiveMode (self, archiveMode):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-archivemode').debug3Func(): logFunc('called. archiveMode=%s, old=%s', archiveMode, self.archiveMode)
        self.archiveModeSet = True
        self.archiveMode = archiveMode

    def requestMaxSizeMb (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-maxsizemb').debug3Func(): logFunc('called. requested=%s', requested)
        self.maxSizeMbRequested = requested
        self.maxSizeMbSet = False

    def isMaxSizeMbRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-maxsizemb-requested').debug3Func(): logFunc('called. requested=%s', self.maxSizeMbRequested)
        return self.maxSizeMbRequested

    def getMaxSizeMb (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-maxsizemb').debug3Func(): logFunc('called. self.maxSizeMbSet=%s, self.maxSizeMb=%s', self.maxSizeMbSet, self.maxSizeMb)
        if self.maxSizeMbSet:
            return self.maxSizeMb
        return None

    def hasMaxSizeMb (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-maxsizemb').debug3Func(): logFunc('called. self.maxSizeMbSet=%s, self.maxSizeMb=%s', self.maxSizeMbSet, self.maxSizeMb)
        if self.maxSizeMbSet:
            return True
        return False

    def setMaxSizeMb (self, maxSizeMb):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-maxsizemb').debug3Func(): logFunc('called. maxSizeMb=%s, old=%s', maxSizeMb, self.maxSizeMb)
        self.maxSizeMbSet = True
        self.maxSizeMb = maxSizeMb

    def requestWriteMode (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-writemode').debug3Func(): logFunc('called. requested=%s', requested)
        self.writeModeRequested = requested
        self.writeModeSet = False

    def isWriteModeRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-writemode-requested').debug3Func(): logFunc('called. requested=%s', self.writeModeRequested)
        return self.writeModeRequested

    def getWriteMode (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-writemode').debug3Func(): logFunc('called. self.writeModeSet=%s, self.writeMode=%s', self.writeModeSet, self.writeMode)
        if self.writeModeSet:
            return self.writeMode
        return None

    def hasWriteMode (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-writemode').debug3Func(): logFunc('called. self.writeModeSet=%s, self.writeMode=%s', self.writeModeSet, self.writeMode)
        if self.writeModeSet:
            return True
        return False

    def setWriteMode (self, writeMode):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-writemode').debug3Func(): logFunc('called. writeMode=%s, old=%s', writeMode, self.writeMode)
        self.writeModeSet = True
        self.writeMode = writeMode

    def requestFileRotationIntervalMinutes (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-filerotationintervalminutes').debug3Func(): logFunc('called. requested=%s', requested)
        self.fileRotationIntervalMinutesRequested = requested
        self.fileRotationIntervalMinutesSet = False

    def isFileRotationIntervalMinutesRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-filerotationintervalminutes-requested').debug3Func(): logFunc('called. requested=%s', self.fileRotationIntervalMinutesRequested)
        return self.fileRotationIntervalMinutesRequested

    def getFileRotationIntervalMinutes (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-filerotationintervalminutes').debug3Func(): logFunc('called. self.fileRotationIntervalMinutesSet=%s, self.fileRotationIntervalMinutes=%s', self.fileRotationIntervalMinutesSet, self.fileRotationIntervalMinutes)
        if self.fileRotationIntervalMinutesSet:
            return self.fileRotationIntervalMinutes
        return None

    def hasFileRotationIntervalMinutes (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-filerotationintervalminutes').debug3Func(): logFunc('called. self.fileRotationIntervalMinutesSet=%s, self.fileRotationIntervalMinutes=%s', self.fileRotationIntervalMinutesSet, self.fileRotationIntervalMinutes)
        if self.fileRotationIntervalMinutesSet:
            return True
        return False

    def setFileRotationIntervalMinutes (self, fileRotationIntervalMinutes):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-filerotationintervalminutes').debug3Func(): logFunc('called. fileRotationIntervalMinutes=%s, old=%s', fileRotationIntervalMinutes, self.fileRotationIntervalMinutes)
        self.fileRotationIntervalMinutesSet = True
        self.fileRotationIntervalMinutes = fileRotationIntervalMinutes


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.fileBaseName = 0
        self.fileBaseNameSet = False
        
        self.maxFileSizePercent = 0
        self.maxFileSizePercentSet = False
        
        self.fileDirectory = 0
        self.fileDirectorySet = False
        
        self.archiveMode = 0
        self.archiveModeSet = False
        
        self.maxSizeMb = 0
        self.maxSizeMbSet = False
        
        self.writeMode = 0
        self.writeModeSet = False
        
        self.fileRotationIntervalMinutes = 0
        self.fileRotationIntervalMinutesSet = False
        

    def _getSelfKeyPath (self, loggerClass
                         , instance
                         , destination
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("output", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(destination);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("destination", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(instance);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("instance", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(loggerClass);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("logger-class", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", "qt-debug"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        loggerClass, 
                        instance, 
                        destination, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(loggerClass, 
                                         instance, 
                                         destination, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(loggerClass, 
                                       instance, 
                                       destination, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       loggerClass, 
                       instance, 
                       destination, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(loggerClass, 
                                       instance, 
                                       destination, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               loggerClass, 
                               instance, 
                               destination, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasFileBaseName():
            valFileBaseName = Value()
            if self.fileBaseName is not None:
                valFileBaseName.setString(self.fileBaseName)
            else:
                valFileBaseName.setEmpty()
            tagValueList.push(("file-base-name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valFileBaseName)
        
        if self.hasMaxFileSizePercent():
            valMaxFileSizePercent = Value()
            if self.maxFileSizePercent is not None:
                valMaxFileSizePercent.setInt64(self.maxFileSizePercent)
            else:
                valMaxFileSizePercent.setEmpty()
            tagValueList.push(("max-file-size-percent", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valMaxFileSizePercent)
        
        if self.hasFileDirectory():
            valFileDirectory = Value()
            if self.fileDirectory is not None:
                valFileDirectory.setString(self.fileDirectory)
            else:
                valFileDirectory.setEmpty()
            tagValueList.push(("file-directory", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valFileDirectory)
        
        if self.hasArchiveMode():
            valArchiveMode = Value()
            if self.archiveMode is not None:
                valArchiveMode.setEnum(self.archiveMode.getValue())
            else:
                valArchiveMode.setEmpty()
            tagValueList.push(("archive-mode", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valArchiveMode)
        
        if self.hasMaxSizeMb():
            valMaxSizeMb = Value()
            if self.maxSizeMb is not None:
                valMaxSizeMb.setInt64(self.maxSizeMb)
            else:
                valMaxSizeMb.setEmpty()
            tagValueList.push(("max-size-mb", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valMaxSizeMb)
        
        if self.hasWriteMode():
            valWriteMode = Value()
            if self.writeMode is not None:
                valWriteMode.setEnum(self.writeMode.getValue())
            else:
                valWriteMode.setEmpty()
            tagValueList.push(("write-mode", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valWriteMode)
        
        if self.hasFileRotationIntervalMinutes():
            valFileRotationIntervalMinutes = Value()
            if self.fileRotationIntervalMinutes is not None:
                valFileRotationIntervalMinutes.setInt64(self.fileRotationIntervalMinutes)
            else:
                valFileRotationIntervalMinutes.setEmpty()
            tagValueList.push(("file-rotation-interval-minutes", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valFileRotationIntervalMinutes)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isFileBaseNameRequested():
            valFileBaseName = Value()
            valFileBaseName.setEmpty()
            tagValueList.push(("file-base-name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valFileBaseName)
        
        if self.isMaxFileSizePercentRequested():
            valMaxFileSizePercent = Value()
            valMaxFileSizePercent.setEmpty()
            tagValueList.push(("max-file-size-percent", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valMaxFileSizePercent)
        
        if self.isFileDirectoryRequested():
            valFileDirectory = Value()
            valFileDirectory.setEmpty()
            tagValueList.push(("file-directory", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valFileDirectory)
        
        if self.isArchiveModeRequested():
            valArchiveMode = Value()
            valArchiveMode.setEmpty()
            tagValueList.push(("archive-mode", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valArchiveMode)
        
        if self.isMaxSizeMbRequested():
            valMaxSizeMb = Value()
            valMaxSizeMb.setEmpty()
            tagValueList.push(("max-size-mb", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valMaxSizeMb)
        
        if self.isWriteModeRequested():
            valWriteMode = Value()
            valWriteMode.setEmpty()
            tagValueList.push(("write-mode", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valWriteMode)
        
        if self.isFileRotationIntervalMinutesRequested():
            valFileRotationIntervalMinutes = Value()
            valFileRotationIntervalMinutes.setEmpty()
            tagValueList.push(("file-rotation-interval-minutes", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valFileRotationIntervalMinutes)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isFileBaseNameRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "file-base-name") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-filebasename').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "fileBaseName", "file-base-name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-file-base-name-bad-value').infoFunc(): logFunc('fileBaseName not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setFileBaseName(tempVar)
            for logFunc in self._log('read-tag-values-file-base-name').debug3Func(): logFunc('read fileBaseName. fileBaseName=%s, tempValue=%s', self.fileBaseName, tempValue.getType())
        
        if self.isMaxFileSizePercentRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "max-file-size-percent") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-maxfilesizepercent').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "maxFileSizePercent", "max-file-size-percent", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-max-file-size-percent-bad-value').infoFunc(): logFunc('maxFileSizePercent not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setMaxFileSizePercent(tempVar)
            for logFunc in self._log('read-tag-values-max-file-size-percent').debug3Func(): logFunc('read maxFileSizePercent. maxFileSizePercent=%s, tempValue=%s', self.maxFileSizePercent, tempValue.getType())
        
        if self.isFileDirectoryRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "file-directory") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-filedirectory').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "fileDirectory", "file-directory", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-file-directory-bad-value').infoFunc(): logFunc('fileDirectory not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setFileDirectory(tempVar)
            for logFunc in self._log('read-tag-values-file-directory').debug3Func(): logFunc('read fileDirectory. fileDirectory=%s, tempValue=%s', self.fileDirectory, tempValue.getType())
        
        if self.isArchiveModeRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "archive-mode") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-archivemode').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "archiveMode", "archive-mode", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-archive-mode-bad-value').infoFunc(): logFunc('archiveMode not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setArchiveMode(tempVar)
            for logFunc in self._log('read-tag-values-archive-mode').debug3Func(): logFunc('read archiveMode. archiveMode=%s, tempValue=%s', self.archiveMode, tempValue.getType())
        
        if self.isMaxSizeMbRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "max-size-mb") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-maxsizemb').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "maxSizeMb", "max-size-mb", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-max-size-mb-bad-value').infoFunc(): logFunc('maxSizeMb not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setMaxSizeMb(tempVar)
            for logFunc in self._log('read-tag-values-max-size-mb').debug3Func(): logFunc('read maxSizeMb. maxSizeMb=%s, tempValue=%s', self.maxSizeMb, tempValue.getType())
        
        if self.isWriteModeRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "write-mode") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-writemode').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "writeMode", "write-mode", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-write-mode-bad-value').infoFunc(): logFunc('writeMode not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setWriteMode(tempVar)
            for logFunc in self._log('read-tag-values-write-mode').debug3Func(): logFunc('read writeMode. writeMode=%s, tempValue=%s', self.writeMode, tempValue.getType())
        
        if self.isFileRotationIntervalMinutesRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "file-rotation-interval-minutes") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-filerotationintervalminutes').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "fileRotationIntervalMinutes", "file-rotation-interval-minutes", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-file-rotation-interval-minutes-bad-value').infoFunc(): logFunc('fileRotationIntervalMinutes not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setFileRotationIntervalMinutes(tempVar)
            for logFunc in self._log('read-tag-values-file-rotation-interval-minutes').debug3Func(): logFunc('read fileRotationIntervalMinutes. fileRotationIntervalMinutes=%s, tempValue=%s', self.fileRotationIntervalMinutes, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 38
0
class BlinkyOutputMaapi(OutputMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-output")
        self.domain = None

        self.fileBaseNameRequested = False
        self.fileBaseName = None
        self.fileBaseNameSet = False

        self.maxFileSizePercentRequested = False
        self.maxFileSizePercent = None
        self.maxFileSizePercentSet = False

        self.fileDirectoryRequested = False
        self.fileDirectory = None
        self.fileDirectorySet = False

        self.archiveModeRequested = False
        self.archiveMode = None
        self.archiveModeSet = False

        self.maxSizeMbRequested = False
        self.maxSizeMb = None
        self.maxSizeMbSet = False

        self.writeModeRequested = False
        self.writeMode = None
        self.writeModeSet = False

        self.fileRotationIntervalMinutesRequested = False
        self.fileRotationIntervalMinutes = None
        self.fileRotationIntervalMinutesSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestFileBaseName(True)

        self.requestMaxFileSizePercent(True)

        self.requestFileDirectory(True)

        self.requestArchiveMode(True)

        self.requestMaxSizeMb(True)

        self.requestWriteMode(True)

        self.requestFileRotationIntervalMinutes(True)

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestFileBaseName(True)

        self.requestMaxFileSizePercent(True)

        self.requestFileDirectory(True)

        self.requestArchiveMode(True)

        self.requestMaxSizeMb(True)

        self.requestWriteMode(True)

        self.requestFileRotationIntervalMinutes(True)

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestFileBaseName(False)

        self.requestMaxFileSizePercent(False)

        self.requestFileDirectory(False)

        self.requestArchiveMode(False)

        self.requestMaxSizeMb(False)

        self.requestWriteMode(False)

        self.requestFileRotationIntervalMinutes(False)

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestFileBaseName(False)

        self.requestMaxFileSizePercent(False)

        self.requestFileDirectory(False)

        self.requestArchiveMode(False)

        self.requestMaxSizeMb(False)

        self.requestWriteMode(False)

        self.requestFileRotationIntervalMinutes(False)

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

        self.setFileBaseName(None)
        self.fileBaseNameSet = False

        self.setMaxFileSizePercent(None)
        self.maxFileSizePercentSet = False

        self.setFileDirectory(None)
        self.fileDirectorySet = False

        self.setArchiveMode(None)
        self.archiveModeSet = False

        self.setMaxSizeMb(None)
        self.maxSizeMbSet = False

        self.setWriteMode(None)
        self.writeModeSet = False

        self.setFileRotationIntervalMinutes(None)
        self.fileRotationIntervalMinutesSet = False

    def write(self, loggerClass, instance, destination, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(loggerClass, instance, destination,
                                   trxContext)

    def read(self, loggerClass, instance, destination, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(loggerClass, instance, destination, False,
                                  trxContext)

    def readAllOrFail(self,
                      loggerClass,
                      instance,
                      destination,
                      trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(loggerClass, instance, destination, True,
                                  trxContext)

    def requestFileBaseName(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-filebasename').debug3Func():
            logFunc('called. requested=%s', requested)
        self.fileBaseNameRequested = requested
        self.fileBaseNameSet = False

    def isFileBaseNameRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-filebasename-requested').debug3Func():
            logFunc('called. requested=%s', self.fileBaseNameRequested)
        return self.fileBaseNameRequested

    def getFileBaseName(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-filebasename').debug3Func():
            logFunc('called. self.fileBaseNameSet=%s, self.fileBaseName=%s',
                    self.fileBaseNameSet, self.fileBaseName)
        if self.fileBaseNameSet:
            return self.fileBaseName
        return None

    def hasFileBaseName(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-filebasename').debug3Func():
            logFunc('called. self.fileBaseNameSet=%s, self.fileBaseName=%s',
                    self.fileBaseNameSet, self.fileBaseName)
        if self.fileBaseNameSet:
            return True
        return False

    def setFileBaseName(self, fileBaseName):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-filebasename').debug3Func():
            logFunc('called. fileBaseName=%s, old=%s', fileBaseName,
                    self.fileBaseName)
        self.fileBaseNameSet = True
        self.fileBaseName = fileBaseName

    def requestMaxFileSizePercent(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-maxfilesizepercent').debug3Func():
            logFunc('called. requested=%s', requested)
        self.maxFileSizePercentRequested = requested
        self.maxFileSizePercentSet = False

    def isMaxFileSizePercentRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-maxfilesizepercent-requested').debug3Func():
            logFunc('called. requested=%s', self.maxFileSizePercentRequested)
        return self.maxFileSizePercentRequested

    def getMaxFileSizePercent(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-maxfilesizepercent').debug3Func():
            logFunc(
                'called. self.maxFileSizePercentSet=%s, self.maxFileSizePercent=%s',
                self.maxFileSizePercentSet, self.maxFileSizePercent)
        if self.maxFileSizePercentSet:
            return self.maxFileSizePercent
        return None

    def hasMaxFileSizePercent(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-maxfilesizepercent').debug3Func():
            logFunc(
                'called. self.maxFileSizePercentSet=%s, self.maxFileSizePercent=%s',
                self.maxFileSizePercentSet, self.maxFileSizePercent)
        if self.maxFileSizePercentSet:
            return True
        return False

    def setMaxFileSizePercent(self, maxFileSizePercent):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-maxfilesizepercent').debug3Func():
            logFunc('called. maxFileSizePercent=%s, old=%s',
                    maxFileSizePercent, self.maxFileSizePercent)
        self.maxFileSizePercentSet = True
        self.maxFileSizePercent = maxFileSizePercent

    def requestFileDirectory(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-filedirectory').debug3Func():
            logFunc('called. requested=%s', requested)
        self.fileDirectoryRequested = requested
        self.fileDirectorySet = False

    def isFileDirectoryRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-filedirectory-requested').debug3Func():
            logFunc('called. requested=%s', self.fileDirectoryRequested)
        return self.fileDirectoryRequested

    def getFileDirectory(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-filedirectory').debug3Func():
            logFunc('called. self.fileDirectorySet=%s, self.fileDirectory=%s',
                    self.fileDirectorySet, self.fileDirectory)
        if self.fileDirectorySet:
            return self.fileDirectory
        return None

    def hasFileDirectory(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-filedirectory').debug3Func():
            logFunc('called. self.fileDirectorySet=%s, self.fileDirectory=%s',
                    self.fileDirectorySet, self.fileDirectory)
        if self.fileDirectorySet:
            return True
        return False

    def setFileDirectory(self, fileDirectory):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-filedirectory').debug3Func():
            logFunc('called. fileDirectory=%s, old=%s', fileDirectory,
                    self.fileDirectory)
        self.fileDirectorySet = True
        self.fileDirectory = fileDirectory

    def requestArchiveMode(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-archivemode').debug3Func():
            logFunc('called. requested=%s', requested)
        self.archiveModeRequested = requested
        self.archiveModeSet = False

    def isArchiveModeRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-archivemode-requested').debug3Func():
            logFunc('called. requested=%s', self.archiveModeRequested)
        return self.archiveModeRequested

    def getArchiveMode(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-archivemode').debug3Func():
            logFunc('called. self.archiveModeSet=%s, self.archiveMode=%s',
                    self.archiveModeSet, self.archiveMode)
        if self.archiveModeSet:
            return self.archiveMode
        return None

    def hasArchiveMode(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-archivemode').debug3Func():
            logFunc('called. self.archiveModeSet=%s, self.archiveMode=%s',
                    self.archiveModeSet, self.archiveMode)
        if self.archiveModeSet:
            return True
        return False

    def setArchiveMode(self, archiveMode):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-archivemode').debug3Func():
            logFunc('called. archiveMode=%s, old=%s', archiveMode,
                    self.archiveMode)
        self.archiveModeSet = True
        self.archiveMode = archiveMode

    def requestMaxSizeMb(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-maxsizemb').debug3Func():
            logFunc('called. requested=%s', requested)
        self.maxSizeMbRequested = requested
        self.maxSizeMbSet = False

    def isMaxSizeMbRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-maxsizemb-requested').debug3Func():
            logFunc('called. requested=%s', self.maxSizeMbRequested)
        return self.maxSizeMbRequested

    def getMaxSizeMb(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-maxsizemb').debug3Func():
            logFunc('called. self.maxSizeMbSet=%s, self.maxSizeMb=%s',
                    self.maxSizeMbSet, self.maxSizeMb)
        if self.maxSizeMbSet:
            return self.maxSizeMb
        return None

    def hasMaxSizeMb(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-maxsizemb').debug3Func():
            logFunc('called. self.maxSizeMbSet=%s, self.maxSizeMb=%s',
                    self.maxSizeMbSet, self.maxSizeMb)
        if self.maxSizeMbSet:
            return True
        return False

    def setMaxSizeMb(self, maxSizeMb):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-maxsizemb').debug3Func():
            logFunc('called. maxSizeMb=%s, old=%s', maxSizeMb, self.maxSizeMb)
        self.maxSizeMbSet = True
        self.maxSizeMb = maxSizeMb

    def requestWriteMode(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-writemode').debug3Func():
            logFunc('called. requested=%s', requested)
        self.writeModeRequested = requested
        self.writeModeSet = False

    def isWriteModeRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-writemode-requested').debug3Func():
            logFunc('called. requested=%s', self.writeModeRequested)
        return self.writeModeRequested

    def getWriteMode(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-writemode').debug3Func():
            logFunc('called. self.writeModeSet=%s, self.writeMode=%s',
                    self.writeModeSet, self.writeMode)
        if self.writeModeSet:
            return self.writeMode
        return None

    def hasWriteMode(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-writemode').debug3Func():
            logFunc('called. self.writeModeSet=%s, self.writeMode=%s',
                    self.writeModeSet, self.writeMode)
        if self.writeModeSet:
            return True
        return False

    def setWriteMode(self, writeMode):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-writemode').debug3Func():
            logFunc('called. writeMode=%s, old=%s', writeMode, self.writeMode)
        self.writeModeSet = True
        self.writeMode = writeMode

    def requestFileRotationIntervalMinutes(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'request-filerotationintervalminutes').debug3Func():
            logFunc('called. requested=%s', requested)
        self.fileRotationIntervalMinutesRequested = requested
        self.fileRotationIntervalMinutesSet = False

    def isFileRotationIntervalMinutesRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-filerotationintervalminutes-requested').debug3Func():
            logFunc('called. requested=%s',
                    self.fileRotationIntervalMinutesRequested)
        return self.fileRotationIntervalMinutesRequested

    def getFileRotationIntervalMinutes(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'get-filerotationintervalminutes').debug3Func():
            logFunc(
                'called. self.fileRotationIntervalMinutesSet=%s, self.fileRotationIntervalMinutes=%s',
                self.fileRotationIntervalMinutesSet,
                self.fileRotationIntervalMinutes)
        if self.fileRotationIntervalMinutesSet:
            return self.fileRotationIntervalMinutes
        return None

    def hasFileRotationIntervalMinutes(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'has-filerotationintervalminutes').debug3Func():
            logFunc(
                'called. self.fileRotationIntervalMinutesSet=%s, self.fileRotationIntervalMinutes=%s',
                self.fileRotationIntervalMinutesSet,
                self.fileRotationIntervalMinutes)
        if self.fileRotationIntervalMinutesSet:
            return True
        return False

    def setFileRotationIntervalMinutes(self, fileRotationIntervalMinutes):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'set-filerotationintervalminutes').debug3Func():
            logFunc('called. fileRotationIntervalMinutes=%s, old=%s',
                    fileRotationIntervalMinutes,
                    self.fileRotationIntervalMinutes)
        self.fileRotationIntervalMinutesSet = True
        self.fileRotationIntervalMinutes = fileRotationIntervalMinutes

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        self.fileBaseName = 0
        self.fileBaseNameSet = False

        self.maxFileSizePercent = 0
        self.maxFileSizePercentSet = False

        self.fileDirectory = 0
        self.fileDirectorySet = False

        self.archiveMode = 0
        self.archiveModeSet = False

        self.maxSizeMb = 0
        self.maxSizeMbSet = False

        self.writeMode = 0
        self.writeModeSet = False

        self.fileRotationIntervalMinutes = 0
        self.fileRotationIntervalMinutesSet = False

    def _getSelfKeyPath(self, loggerClass, instance, destination,
                        junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("output", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug",
             "qt-debug"))
        keyPath.addKeyPathPrefix(xmlVal)

        ancestorVal = Value()
        ancestorVal.setString(destination)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("destination",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug",
             "qt-debug"))
        keyPath.addKeyPathPrefix(xmlVal)

        ancestorVal = Value()
        ancestorVal.setString(instance)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("instance",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug",
             "qt-debug"))
        keyPath.addKeyPathPrefix(xmlVal)

        ancestorVal = Value()
        ancestorVal.setString(loggerClass)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("logger-class",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug",
             "qt-debug"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, loggerClass, instance, destination, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(loggerClass, instance, destination,
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(loggerClass, instance, destination,
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, loggerClass, instance, destination, readAllOrFail,
                      trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(loggerClass, instance, destination,
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, loggerClass, instance, destination,
                              itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.hasFileBaseName():
            valFileBaseName = Value()
            if self.fileBaseName is not None:
                valFileBaseName.setString(self.fileBaseName)
            else:
                valFileBaseName.setEmpty()
            tagValueList.push(
                ("file-base-name",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"),
                valFileBaseName)

        if self.hasMaxFileSizePercent():
            valMaxFileSizePercent = Value()
            if self.maxFileSizePercent is not None:
                valMaxFileSizePercent.setInt64(self.maxFileSizePercent)
            else:
                valMaxFileSizePercent.setEmpty()
            tagValueList.push(
                ("max-file-size-percent",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"),
                valMaxFileSizePercent)

        if self.hasFileDirectory():
            valFileDirectory = Value()
            if self.fileDirectory is not None:
                valFileDirectory.setString(self.fileDirectory)
            else:
                valFileDirectory.setEmpty()
            tagValueList.push(
                ("file-directory",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"),
                valFileDirectory)

        if self.hasArchiveMode():
            valArchiveMode = Value()
            if self.archiveMode is not None:
                valArchiveMode.setEnum(self.archiveMode.getValue())
            else:
                valArchiveMode.setEmpty()
            tagValueList.push(
                ("archive-mode",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"),
                valArchiveMode)

        if self.hasMaxSizeMb():
            valMaxSizeMb = Value()
            if self.maxSizeMb is not None:
                valMaxSizeMb.setInt64(self.maxSizeMb)
            else:
                valMaxSizeMb.setEmpty()
            tagValueList.push(
                ("max-size-mb",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"),
                valMaxSizeMb)

        if self.hasWriteMode():
            valWriteMode = Value()
            if self.writeMode is not None:
                valWriteMode.setEnum(self.writeMode.getValue())
            else:
                valWriteMode.setEmpty()
            tagValueList.push(
                ("write-mode",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"),
                valWriteMode)

        if self.hasFileRotationIntervalMinutes():
            valFileRotationIntervalMinutes = Value()
            if self.fileRotationIntervalMinutes is not None:
                valFileRotationIntervalMinutes.setInt64(
                    self.fileRotationIntervalMinutes)
            else:
                valFileRotationIntervalMinutes.setEmpty()
            tagValueList.push(
                ("file-rotation-interval-minutes",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"),
                valFileRotationIntervalMinutes)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isFileBaseNameRequested():
            valFileBaseName = Value()
            valFileBaseName.setEmpty()
            tagValueList.push(
                ("file-base-name",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"),
                valFileBaseName)

        if self.isMaxFileSizePercentRequested():
            valMaxFileSizePercent = Value()
            valMaxFileSizePercent.setEmpty()
            tagValueList.push(
                ("max-file-size-percent",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"),
                valMaxFileSizePercent)

        if self.isFileDirectoryRequested():
            valFileDirectory = Value()
            valFileDirectory.setEmpty()
            tagValueList.push(
                ("file-directory",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"),
                valFileDirectory)

        if self.isArchiveModeRequested():
            valArchiveMode = Value()
            valArchiveMode.setEmpty()
            tagValueList.push(
                ("archive-mode",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"),
                valArchiveMode)

        if self.isMaxSizeMbRequested():
            valMaxSizeMb = Value()
            valMaxSizeMb.setEmpty()
            tagValueList.push(
                ("max-size-mb",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"),
                valMaxSizeMb)

        if self.isWriteModeRequested():
            valWriteMode = Value()
            valWriteMode.setEmpty()
            tagValueList.push(
                ("write-mode",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"),
                valWriteMode)

        if self.isFileRotationIntervalMinutesRequested():
            valFileRotationIntervalMinutes = Value()
            valFileRotationIntervalMinutes.setEmpty()
            tagValueList.push(
                ("file-rotation-interval-minutes",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"),
                valFileRotationIntervalMinutes)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isFileBaseNameRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "file-base-name") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-filebasename'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "fileBaseName", "file-base-name",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-file-base-name-bad-value').infoFunc():
                    logFunc('fileBaseName not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setFileBaseName(tempVar)
            for logFunc in self._log(
                    'read-tag-values-file-base-name').debug3Func():
                logFunc('read fileBaseName. fileBaseName=%s, tempValue=%s',
                        self.fileBaseName, tempValue.getType())

        if self.isMaxFileSizePercentRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "max-file-size-percent") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-maxfilesizepercent'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "maxFileSizePercent", "max-file-size-percent",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-max-file-size-percent-bad-value'
                ).infoFunc():
                    logFunc('maxFileSizePercent not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setMaxFileSizePercent(tempVar)
            for logFunc in self._log(
                    'read-tag-values-max-file-size-percent').debug3Func():
                logFunc(
                    'read maxFileSizePercent. maxFileSizePercent=%s, tempValue=%s',
                    self.maxFileSizePercent, tempValue.getType())

        if self.isFileDirectoryRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "file-directory") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-filedirectory'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "fileDirectory", "file-directory",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-file-directory-bad-value').infoFunc():
                    logFunc('fileDirectory not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setFileDirectory(tempVar)
            for logFunc in self._log(
                    'read-tag-values-file-directory').debug3Func():
                logFunc('read fileDirectory. fileDirectory=%s, tempValue=%s',
                        self.fileDirectory, tempValue.getType())

        if self.isArchiveModeRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "archive-mode") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-archivemode'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "archiveMode", "archive-mode",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-archive-mode-bad-value').infoFunc():
                    logFunc('archiveMode not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setArchiveMode(tempVar)
            for logFunc in self._log(
                    'read-tag-values-archive-mode').debug3Func():
                logFunc('read archiveMode. archiveMode=%s, tempValue=%s',
                        self.archiveMode, tempValue.getType())

        if self.isMaxSizeMbRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "max-size-mb") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-maxsizemb'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "maxSizeMb", "max-size-mb",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-max-size-mb-bad-value').infoFunc():
                    logFunc('maxSizeMb not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setMaxSizeMb(tempVar)
            for logFunc in self._log(
                    'read-tag-values-max-size-mb').debug3Func():
                logFunc('read maxSizeMb. maxSizeMb=%s, tempValue=%s',
                        self.maxSizeMb, tempValue.getType())

        if self.isWriteModeRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "write-mode") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-writemode'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "writeMode", "write-mode",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-write-mode-bad-value').infoFunc():
                    logFunc('writeMode not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setWriteMode(tempVar)
            for logFunc in self._log(
                    'read-tag-values-write-mode').debug3Func():
                logFunc('read writeMode. writeMode=%s, tempValue=%s',
                        self.writeMode, tempValue.getType())

        if self.isFileRotationIntervalMinutesRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "file-rotation-interval-minutes") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-filerotationintervalminutes'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "fileRotationIntervalMinutes",
                        "file-rotation-interval-minutes",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-file-rotation-interval-minutes-bad-value'
                ).infoFunc():
                    logFunc('fileRotationIntervalMinutes not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setFileRotationIntervalMinutes(tempVar)
            for logFunc in self._log(
                    'read-tag-values-file-rotation-interval-minutes'
            ).debug3Func():
                logFunc(
                    'read fileRotationIntervalMinutes. fileRotationIntervalMinutes=%s, tempValue=%s',
                    self.fileRotationIntervalMinutes, tempValue.getType())

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 39
0
class BlinkyCountersMaapi(CountersMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-counters")
        self.domain = None

        self.commandWarningTimeoutsRequested = False
        self.commandWarningTimeouts = None
        self.commandWarningTimeoutsSet = False

        self.commandErrorsRequested = False
        self.commandErrors = None
        self.commandErrorsSet = False

        self.fileErrorsRequested = False
        self.fileErrors = None
        self.fileErrorsSet = False

        self.readsRequested = False
        self.reads = None
        self.readsSet = False

        self.parsingErrorsRequested = False
        self.parsingErrors = None
        self.parsingErrorsSet = False

        self.commandTimeoutsRequested = False
        self.commandTimeouts = None
        self.commandTimeoutsSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestCommandWarningTimeouts(True)

        self.requestCommandErrors(True)

        self.requestFileErrors(True)

        self.requestReads(True)

        self.requestParsingErrors(True)

        self.requestCommandTimeouts(True)

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestCommandWarningTimeouts(False)

        self.requestCommandErrors(False)

        self.requestFileErrors(False)

        self.requestReads(False)

        self.requestParsingErrors(False)

        self.requestCommandTimeouts(False)

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestCommandWarningTimeouts(True)

        self.requestCommandErrors(True)

        self.requestFileErrors(True)

        self.requestReads(True)

        self.requestParsingErrors(True)

        self.requestCommandTimeouts(True)

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestCommandWarningTimeouts(False)

        self.requestCommandErrors(False)

        self.requestFileErrors(False)

        self.requestReads(False)

        self.requestParsingErrors(False)

        self.requestCommandTimeouts(False)

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

    def write(self, source, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(source, trxContext)

    def read(self, source, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(source, False, trxContext)

    def readAllOrFail(self, source, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(source, True, trxContext)

    def requestCommandWarningTimeouts(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'request-commandwarningtimeouts').debug3Func():
            logFunc('called. requested=%s', requested)
        self.commandWarningTimeoutsRequested = requested
        self.commandWarningTimeoutsSet = False

    def isCommandWarningTimeoutsRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-commandwarningtimeouts-requested').debug3Func():
            logFunc('called. requested=%s',
                    self.commandWarningTimeoutsRequested)
        return self.commandWarningTimeoutsRequested

    def getCommandWarningTimeouts(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-commandwarningtimeouts').debug3Func():
            logFunc(
                'called. self.commandWarningTimeoutsSet=%s, self.commandWarningTimeouts=%s',
                self.commandWarningTimeoutsSet, self.commandWarningTimeouts)
        if self.commandWarningTimeoutsSet:
            return self.commandWarningTimeouts
        return None

    def hasCommandWarningTimeouts(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-commandwarningtimeouts').debug3Func():
            logFunc(
                'called. self.commandWarningTimeoutsSet=%s, self.commandWarningTimeouts=%s',
                self.commandWarningTimeoutsSet, self.commandWarningTimeouts)
        if self.commandWarningTimeoutsSet:
            return True
        return False

    def setCommandWarningTimeouts(self, commandWarningTimeouts):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-commandwarningtimeouts').debug3Func():
            logFunc('called. commandWarningTimeouts=%s, old=%s',
                    commandWarningTimeouts, self.commandWarningTimeouts)
        self.commandWarningTimeoutsSet = True
        self.commandWarningTimeouts = commandWarningTimeouts

    def requestCommandErrors(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-commanderrors').debug3Func():
            logFunc('called. requested=%s', requested)
        self.commandErrorsRequested = requested
        self.commandErrorsSet = False

    def isCommandErrorsRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-commanderrors-requested').debug3Func():
            logFunc('called. requested=%s', self.commandErrorsRequested)
        return self.commandErrorsRequested

    def getCommandErrors(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-commanderrors').debug3Func():
            logFunc('called. self.commandErrorsSet=%s, self.commandErrors=%s',
                    self.commandErrorsSet, self.commandErrors)
        if self.commandErrorsSet:
            return self.commandErrors
        return None

    def hasCommandErrors(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-commanderrors').debug3Func():
            logFunc('called. self.commandErrorsSet=%s, self.commandErrors=%s',
                    self.commandErrorsSet, self.commandErrors)
        if self.commandErrorsSet:
            return True
        return False

    def setCommandErrors(self, commandErrors):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-commanderrors').debug3Func():
            logFunc('called. commandErrors=%s, old=%s', commandErrors,
                    self.commandErrors)
        self.commandErrorsSet = True
        self.commandErrors = commandErrors

    def requestFileErrors(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-fileerrors').debug3Func():
            logFunc('called. requested=%s', requested)
        self.fileErrorsRequested = requested
        self.fileErrorsSet = False

    def isFileErrorsRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-fileerrors-requested').debug3Func():
            logFunc('called. requested=%s', self.fileErrorsRequested)
        return self.fileErrorsRequested

    def getFileErrors(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-fileerrors').debug3Func():
            logFunc('called. self.fileErrorsSet=%s, self.fileErrors=%s',
                    self.fileErrorsSet, self.fileErrors)
        if self.fileErrorsSet:
            return self.fileErrors
        return None

    def hasFileErrors(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-fileerrors').debug3Func():
            logFunc('called. self.fileErrorsSet=%s, self.fileErrors=%s',
                    self.fileErrorsSet, self.fileErrors)
        if self.fileErrorsSet:
            return True
        return False

    def setFileErrors(self, fileErrors):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-fileerrors').debug3Func():
            logFunc('called. fileErrors=%s, old=%s', fileErrors,
                    self.fileErrors)
        self.fileErrorsSet = True
        self.fileErrors = fileErrors

    def requestReads(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-reads').debug3Func():
            logFunc('called. requested=%s', requested)
        self.readsRequested = requested
        self.readsSet = False

    def isReadsRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-reads-requested').debug3Func():
            logFunc('called. requested=%s', self.readsRequested)
        return self.readsRequested

    def getReads(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-reads').debug3Func():
            logFunc('called. self.readsSet=%s, self.reads=%s', self.readsSet,
                    self.reads)
        if self.readsSet:
            return self.reads
        return None

    def hasReads(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-reads').debug3Func():
            logFunc('called. self.readsSet=%s, self.reads=%s', self.readsSet,
                    self.reads)
        if self.readsSet:
            return True
        return False

    def setReads(self, reads):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-reads').debug3Func():
            logFunc('called. reads=%s, old=%s', reads, self.reads)
        self.readsSet = True
        self.reads = reads

    def requestParsingErrors(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-parsingerrors').debug3Func():
            logFunc('called. requested=%s', requested)
        self.parsingErrorsRequested = requested
        self.parsingErrorsSet = False

    def isParsingErrorsRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-parsingerrors-requested').debug3Func():
            logFunc('called. requested=%s', self.parsingErrorsRequested)
        return self.parsingErrorsRequested

    def getParsingErrors(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-parsingerrors').debug3Func():
            logFunc('called. self.parsingErrorsSet=%s, self.parsingErrors=%s',
                    self.parsingErrorsSet, self.parsingErrors)
        if self.parsingErrorsSet:
            return self.parsingErrors
        return None

    def hasParsingErrors(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-parsingerrors').debug3Func():
            logFunc('called. self.parsingErrorsSet=%s, self.parsingErrors=%s',
                    self.parsingErrorsSet, self.parsingErrors)
        if self.parsingErrorsSet:
            return True
        return False

    def setParsingErrors(self, parsingErrors):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-parsingerrors').debug3Func():
            logFunc('called. parsingErrors=%s, old=%s', parsingErrors,
                    self.parsingErrors)
        self.parsingErrorsSet = True
        self.parsingErrors = parsingErrors

    def requestCommandTimeouts(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-commandtimeouts').debug3Func():
            logFunc('called. requested=%s', requested)
        self.commandTimeoutsRequested = requested
        self.commandTimeoutsSet = False

    def isCommandTimeoutsRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-commandtimeouts-requested').debug3Func():
            logFunc('called. requested=%s', self.commandTimeoutsRequested)
        return self.commandTimeoutsRequested

    def getCommandTimeouts(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-commandtimeouts').debug3Func():
            logFunc(
                'called. self.commandTimeoutsSet=%s, self.commandTimeouts=%s',
                self.commandTimeoutsSet, self.commandTimeouts)
        if self.commandTimeoutsSet:
            return self.commandTimeouts
        return None

    def hasCommandTimeouts(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-commandtimeouts').debug3Func():
            logFunc(
                'called. self.commandTimeoutsSet=%s, self.commandTimeouts=%s',
                self.commandTimeoutsSet, self.commandTimeouts)
        if self.commandTimeoutsSet:
            return True
        return False

    def setCommandTimeouts(self, commandTimeouts):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-commandtimeouts').debug3Func():
            logFunc('called. commandTimeouts=%s, old=%s', commandTimeouts,
                    self.commandTimeouts)
        self.commandTimeoutsSet = True
        self.commandTimeouts = commandTimeouts

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        self.commandWarningTimeouts = 0
        self.commandWarningTimeoutsSet = False

        self.commandErrors = 0
        self.commandErrorsSet = False

        self.fileErrors = 0
        self.fileErrorsSet = False

        self.reads = 0
        self.readsSet = False

        self.parsingErrors = 0
        self.parsingErrorsSet = False

        self.commandTimeouts = 0
        self.commandTimeoutsSet = False

    def _getSelfKeyPath(self, source, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag((
            "counters",
            "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
            "qt-pltf-mngr"))
        keyPath.addKeyPathPrefix(xmlVal)

        ancestorVal = Value()
        ancestorVal.setString(source)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag((
            "source",
            "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
            "qt-pltf-mngr"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag((
            "manager",
            "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
            "qt-pltf-mngr"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("platform",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform",
             "qt-pltf"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, source, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(source, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(source, None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, source, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(source, None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, source, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isCommandWarningTimeoutsRequested():
            valCommandWarningTimeouts = Value()
            valCommandWarningTimeouts.setEmpty()
            tagValueList.push((
                "command-warning-timeouts",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valCommandWarningTimeouts)

        if self.isCommandErrorsRequested():
            valCommandErrors = Value()
            valCommandErrors.setEmpty()
            tagValueList.push((
                "command-errors",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valCommandErrors)

        if self.isFileErrorsRequested():
            valFileErrors = Value()
            valFileErrors.setEmpty()
            tagValueList.push((
                "file-errors",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valFileErrors)

        if self.isReadsRequested():
            valReads = Value()
            valReads.setEmpty()
            tagValueList.push((
                "reads",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valReads)

        if self.isParsingErrorsRequested():
            valParsingErrors = Value()
            valParsingErrors.setEmpty()
            tagValueList.push((
                "parsing-errors",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valParsingErrors)

        if self.isCommandTimeoutsRequested():
            valCommandTimeouts = Value()
            valCommandTimeouts.setEmpty()
            tagValueList.push((
                "command-timeouts",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"
            ), valCommandTimeouts)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isCommandWarningTimeoutsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "command-warning-timeouts") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-commandwarningtimeouts'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "commandWarningTimeouts", "command-warning-timeouts",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-command-warning-timeouts-bad-value'
                ).infoFunc():
                    logFunc('commandWarningTimeouts not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setCommandWarningTimeouts(tempVar)
            for logFunc in self._log(
                    'read-tag-values-command-warning-timeouts').debug3Func():
                logFunc(
                    'read commandWarningTimeouts. commandWarningTimeouts=%s, tempValue=%s',
                    self.commandWarningTimeouts, tempValue.getType())

        if self.isCommandErrorsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "command-errors") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-commanderrors'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "commandErrors", "command-errors",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-command-errors-bad-value').infoFunc():
                    logFunc('commandErrors not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setCommandErrors(tempVar)
            for logFunc in self._log(
                    'read-tag-values-command-errors').debug3Func():
                logFunc('read commandErrors. commandErrors=%s, tempValue=%s',
                        self.commandErrors, tempValue.getType())

        if self.isFileErrorsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "file-errors") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-fileerrors'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "fileErrors", "file-errors",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-file-errors-bad-value').infoFunc():
                    logFunc('fileErrors not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setFileErrors(tempVar)
            for logFunc in self._log(
                    'read-tag-values-file-errors').debug3Func():
                logFunc('read fileErrors. fileErrors=%s, tempValue=%s',
                        self.fileErrors, tempValue.getType())

        if self.isReadsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "reads") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-reads').errorFunc(
                        ):
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "reads", "reads",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-reads-bad-value').infoFunc():
                    logFunc('reads not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setReads(tempVar)
            for logFunc in self._log('read-tag-values-reads').debug3Func():
                logFunc('read reads. reads=%s, tempValue=%s', self.reads,
                        tempValue.getType())

        if self.isParsingErrorsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "parsing-errors") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-parsingerrors'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "parsingErrors", "parsing-errors",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-parsing-errors-bad-value').infoFunc():
                    logFunc('parsingErrors not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setParsingErrors(tempVar)
            for logFunc in self._log(
                    'read-tag-values-parsing-errors').debug3Func():
                logFunc('read parsingErrors. parsingErrors=%s, tempValue=%s',
                        self.parsingErrors, tempValue.getType())

        if self.isCommandTimeoutsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "command-timeouts") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-commandtimeouts'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "commandTimeouts", "command-timeouts",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-command-timeouts-bad-value').infoFunc(
                        ):
                    logFunc('commandTimeouts not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setCommandTimeouts(tempVar)
            for logFunc in self._log(
                    'read-tag-values-command-timeouts').debug3Func():
                logFunc(
                    'read commandTimeouts. commandTimeouts=%s, tempValue=%s',
                    self.commandTimeouts, tempValue.getType())

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 40
0
class BlinkyChairMaapi(ChairMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-chair")
        self.domain = None

        self.statusObj = None

        self.colorRequested = False
        self.color = None
        self.colorSet = False

        self.prettyRequested = False
        self.pretty = None
        self.prettySet = False

        self.numOfLegsRequested = False
        self.numOfLegs = None
        self.numOfLegsSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestColor(True)

        self.requestPretty(True)

        self.requestNumOfLegs(True)

        if not self.statusObj:
            self.statusObj = self.newStatus()
            self.statusObj.requestConfigAndOper()

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestColor(True)

        self.requestPretty(True)

        self.requestNumOfLegs(True)

        if not self.statusObj:
            self.statusObj = self.newStatus()
            self.statusObj.requestConfig()

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestColor(False)

        self.requestPretty(False)

        self.requestNumOfLegs(False)

        if not self.statusObj:
            self.statusObj = self.newStatus()
            self.statusObj.requestOper()

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestColor(False)

        self.requestPretty(False)

        self.requestNumOfLegs(False)

        if not self.statusObj:
            self.statusObj = self.newStatus()
            self.statusObj.clearAllRequested()

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

        self.setColor(None)
        self.colorSet = False

        self.setPretty(None)
        self.prettySet = False

        self.setNumOfLegs(None)
        self.numOfLegsSet = False

        if self.statusObj:
            self.statusObj.clearAllSet()

    def write(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(trxContext)

    def read(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(False, trxContext)

    def readAllOrFail(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(True, trxContext)

    def newStatus(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-status').debug3Func():
            logFunc('called.')
        status = BlinkyStatusMaapi(self._log)
        status.init(self.domain)
        return status

    def setStatusObj(self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-status').debug3Func():
            logFunc('called. obj=%s', obj)
        self.statusObj = obj

    def getStatusObj(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-status').debug3Func():
            logFunc('called. self.statusObj=%s', self.statusObj)
        return self.statusObj

    def hasStatus(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-status').debug3Func():
            logFunc('called. self.statusObj=%s', self.statusObj)
        if self.statusObj:
            return True
        return False

    def requestColor(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-color').debug3Func():
            logFunc('called. requested=%s', requested)
        self.colorRequested = requested
        self.colorSet = False

    def isColorRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-color-requested').debug3Func():
            logFunc('called. requested=%s', self.colorRequested)
        return self.colorRequested

    def getColor(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-color').debug3Func():
            logFunc('called. self.colorSet=%s, self.color=%s', self.colorSet,
                    self.color)
        if self.colorSet:
            return self.color
        return None

    def hasColor(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-color').debug3Func():
            logFunc('called. self.colorSet=%s, self.color=%s', self.colorSet,
                    self.color)
        if self.colorSet:
            return True
        return False

    def setColor(self, color):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-color').debug3Func():
            logFunc('called. color=%s, old=%s', color, self.color)
        self.colorSet = True
        self.color = color

    def requestPretty(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-pretty').debug3Func():
            logFunc('called. requested=%s', requested)
        self.prettyRequested = requested
        self.prettySet = False

    def isPrettyRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-pretty-requested').debug3Func():
            logFunc('called. requested=%s', self.prettyRequested)
        return self.prettyRequested

    def getPretty(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-pretty').debug3Func():
            logFunc('called. self.prettySet=%s, self.pretty=%s',
                    self.prettySet, self.pretty)
        if self.prettySet:
            return self.pretty
        return None

    def hasPretty(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-pretty').debug3Func():
            logFunc('called. self.prettySet=%s, self.pretty=%s',
                    self.prettySet, self.pretty)
        if self.prettySet:
            return True
        return False

    def setPretty(self, pretty):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-pretty').debug3Func():
            logFunc('called. pretty=%s, old=%s', pretty, self.pretty)
        self.prettySet = True
        self.pretty = pretty

    def requestNumOfLegs(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-numoflegs').debug3Func():
            logFunc('called. requested=%s', requested)
        self.numOfLegsRequested = requested
        self.numOfLegsSet = False

    def isNumOfLegsRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-numoflegs-requested').debug3Func():
            logFunc('called. requested=%s', self.numOfLegsRequested)
        return self.numOfLegsRequested

    def getNumOfLegs(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-numoflegs').debug3Func():
            logFunc('called. self.numOfLegsSet=%s, self.numOfLegs=%s',
                    self.numOfLegsSet, self.numOfLegs)
        if self.numOfLegsSet:
            return self.numOfLegs
        return None

    def hasNumOfLegs(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-numoflegs').debug3Func():
            logFunc('called. self.numOfLegsSet=%s, self.numOfLegs=%s',
                    self.numOfLegsSet, self.numOfLegs)
        if self.numOfLegsSet:
            return True
        return False

    def setNumOfLegs(self, numOfLegs):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-numoflegs').debug3Func():
            logFunc('called. numOfLegs=%s, old=%s', numOfLegs, self.numOfLegs)
        self.numOfLegsSet = True
        self.numOfLegs = numOfLegs

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        if self.statusObj:
            self.statusObj._clearAllReadData()

        self.color = 0
        self.colorSet = False

        self.pretty = 0
        self.prettySet = False

        self.numOfLegs = 0
        self.numOfLegsSet = False

    def _getSelfKeyPath(self, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag((
            "chair",
            "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example",
            "se"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        if self.statusObj:
            res = self.statusObj._collectItemsToDelete(itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'collect-items-to-delete-status-failed').errorFunc():
                    logFunc('statusObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.hasColor():
            valColor = Value()
            if self.color is not None:
                valColor.setString(self.color)
            else:
                valColor.setEmpty()
            tagValueList.push((
                "color",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"
            ), valColor)

        if self.hasPretty():
            valPretty = Value()
            if self.pretty is not None:
                valPretty.setBool(self.pretty)
            else:
                valPretty.setEmpty()
            tagValueList.push((
                "pretty",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"
            ), valPretty)

        if self.hasNumOfLegs():
            valNumOfLegs = Value()
            if self.numOfLegs is not None:
                valNumOfLegs.setInt64(self.numOfLegs)
            else:
                valNumOfLegs.setEmpty()
            tagValueList.push((
                "num-of-legs",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"
            ), valNumOfLegs)

        if self.statusObj:
            valBegin = Value()
            (tag, ns, prefix) = (
                "status",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example",
                "se")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.statusObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'fill-write-tag-values-status-failed').errorFunc():
                    logFunc('statusObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isColorRequested():
            valColor = Value()
            valColor.setEmpty()
            tagValueList.push((
                "color",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"
            ), valColor)

        if self.isPrettyRequested():
            valPretty = Value()
            valPretty.setEmpty()
            tagValueList.push((
                "pretty",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"
            ), valPretty)

        if self.isNumOfLegsRequested():
            valNumOfLegs = Value()
            valNumOfLegs.setEmpty()
            tagValueList.push((
                "num-of-legs",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"
            ), valNumOfLegs)

        if self.statusObj:
            valBegin = Value()
            (tag, ns, prefix) = (
                "status",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example",
                "se")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.statusObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'fill-read-tag-values-status-failed').errorFunc():
                    logFunc('statusObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isColorRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "color") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-color').errorFunc(
                        ):
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "color", "color",
                        "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-color-bad-value').infoFunc():
                    logFunc('color not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setColor(tempVar)
            for logFunc in self._log('read-tag-values-color').debug3Func():
                logFunc('read color. color=%s, tempValue=%s', self.color,
                        tempValue.getType())

        if self.isPrettyRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "pretty") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-pretty'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "pretty", "pretty",
                        "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asBool()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-pretty-bad-value').infoFunc():
                    logFunc('pretty not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setPretty(tempVar)
            for logFunc in self._log('read-tag-values-pretty').debug3Func():
                logFunc('read pretty. pretty=%s, tempValue=%s', self.pretty,
                        tempValue.getType())

        if self.isNumOfLegsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "num-of-legs") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-numoflegs'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "numOfLegs", "num-of-legs",
                        "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-num-of-legs-bad-value').infoFunc():
                    logFunc('numOfLegs not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setNumOfLegs(tempVar)
            for logFunc in self._log(
                    'read-tag-values-num-of-legs').debug3Func():
                logFunc('read numOfLegs. numOfLegs=%s, tempValue=%s',
                        self.numOfLegs, tempValue.getType())

        if self.statusObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "status") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-begin').errorFunc():
                    logFunc(
                        'got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                        "status",
                        "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example",
                        Value.kXmlBegin, tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            res = self.statusObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'read-tag-values-status-failed').errorFunc():
                    logFunc(
                        'statusObj._readTagValues() failed. tagValueList=%s',
                        tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "status") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-end').errorFunc():
                    logFunc(
                        'got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                        "status",
                        "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example",
                        Value.kXmlEnd, tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 41
0
class BlinkyOpYMaapi(OpYMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-opY")
        self.domain = None

        

        
        self.valueOpY1Requested = False
        self.valueOpY1 = None
        self.valueOpY1Set = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestValueOpY1(True)
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestValueOpY1(False)
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestValueOpY1(True)
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestValueOpY1(False)
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        

    def write (self
              , opV
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(opV, trxContext)

    def read (self
              , opV
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(opV, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , opV
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(opV, 
                                  True,
                                  trxContext)



    def requestValueOpY1 (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-valueopy1').debug3Func(): logFunc('called. requested=%s', requested)
        self.valueOpY1Requested = requested
        self.valueOpY1Set = False

    def isValueOpY1Requested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-valueopy1-requested').debug3Func(): logFunc('called. requested=%s', self.valueOpY1Requested)
        return self.valueOpY1Requested

    def getValueOpY1 (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-valueopy1').debug3Func(): logFunc('called. self.valueOpY1Set=%s, self.valueOpY1=%s', self.valueOpY1Set, self.valueOpY1)
        if self.valueOpY1Set:
            return self.valueOpY1
        return None

    def hasValueOpY1 (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-valueopy1').debug3Func(): logFunc('called. self.valueOpY1Set=%s, self.valueOpY1=%s', self.valueOpY1Set, self.valueOpY1)
        if self.valueOpY1Set:
            return True
        return False

    def setValueOpY1 (self, valueOpY1):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-valueopy1').debug3Func(): logFunc('called. valueOpY1=%s, old=%s', valueOpY1, self.valueOpY1)
        self.valueOpY1Set = True
        self.valueOpY1 = valueOpY1


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.valueOpY1 = 0
        self.valueOpY1Set = False
        

    def _getSelfKeyPath (self, opV
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("op-y", "http://qwilt.com/model/oper", "oper"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(opV);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("op-v", "http://qwilt.com/model/oper", "oper"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("config-a", "http://qwilt.com/model/oper", "oper"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        opV, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(opV, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(opV, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       opV, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(opV, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               opV, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isValueOpY1Requested():
            valValueOpY1 = Value()
            valValueOpY1.setEmpty()
            tagValueList.push(("value-op-y1", "http://qwilt.com/model/oper"), valValueOpY1)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isValueOpY1Requested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "value-op-y1") or \
                (ns != "http://qwilt.com/model/oper"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-valueopy1').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "valueOpY1", "value-op-y1", "http://qwilt.com/model/oper", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-value-op-y1-bad-value').infoFunc(): logFunc('valueOpY1 not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setValueOpY1(tempVar)
            for logFunc in self._log('read-tag-values-value-op-y1').debug3Func(): logFunc('read valueOpY1. valueOpY1=%s, tempValue=%s', self.valueOpY1, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 42
0
class BlinkyCountersMaapi(CountersMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-counters")
        self.domain = None

        self.silentDroppedPacketsRequested = False
        self.silentDroppedPackets = None
        self.silentDroppedPacketsSet = False

        self.inPacketsRequested = False
        self.inPackets = None
        self.inPacketsSet = False

        self.inBadVersionPacketsRequested = False
        self.inBadVersionPackets = None
        self.inBadVersionPacketsSet = False

        self.inBadCommunityUsePacketsRequested = False
        self.inBadCommunityUsePackets = None
        self.inBadCommunityUsePacketsSet = False

        self.inAsnParseErrorsRequested = False
        self.inAsnParseErrors = None
        self.inAsnParseErrorsSet = False

        self.inBadCommunityPacketsRequested = False
        self.inBadCommunityPackets = None
        self.inBadCommunityPacketsSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestSilentDroppedPackets(True)

        self.requestInPackets(True)

        self.requestInBadVersionPackets(True)

        self.requestInBadCommunityUsePackets(True)

        self.requestInAsnParseErrors(True)

        self.requestInBadCommunityPackets(True)

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestSilentDroppedPackets(False)

        self.requestInPackets(False)

        self.requestInBadVersionPackets(False)

        self.requestInBadCommunityUsePackets(False)

        self.requestInAsnParseErrors(False)

        self.requestInBadCommunityPackets(False)

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestSilentDroppedPackets(True)

        self.requestInPackets(True)

        self.requestInBadVersionPackets(True)

        self.requestInBadCommunityUsePackets(True)

        self.requestInAsnParseErrors(True)

        self.requestInBadCommunityPackets(True)

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestSilentDroppedPackets(False)

        self.requestInPackets(False)

        self.requestInBadVersionPackets(False)

        self.requestInBadCommunityUsePackets(False)

        self.requestInAsnParseErrors(False)

        self.requestInBadCommunityPackets(False)

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

    def write(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(trxContext)

    def read(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(False, trxContext)

    def readAllOrFail(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(True, trxContext)

    def requestSilentDroppedPackets(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-silentdroppedpackets').debug3Func():
            logFunc('called. requested=%s', requested)
        self.silentDroppedPacketsRequested = requested
        self.silentDroppedPacketsSet = False

    def isSilentDroppedPacketsRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-silentdroppedpackets-requested').debug3Func():
            logFunc('called. requested=%s', self.silentDroppedPacketsRequested)
        return self.silentDroppedPacketsRequested

    def getSilentDroppedPackets(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-silentdroppedpackets').debug3Func():
            logFunc(
                'called. self.silentDroppedPacketsSet=%s, self.silentDroppedPackets=%s',
                self.silentDroppedPacketsSet, self.silentDroppedPackets)
        if self.silentDroppedPacketsSet:
            return self.silentDroppedPackets
        return None

    def hasSilentDroppedPackets(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-silentdroppedpackets').debug3Func():
            logFunc(
                'called. self.silentDroppedPacketsSet=%s, self.silentDroppedPackets=%s',
                self.silentDroppedPacketsSet, self.silentDroppedPackets)
        if self.silentDroppedPacketsSet:
            return True
        return False

    def setSilentDroppedPackets(self, silentDroppedPackets):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-silentdroppedpackets').debug3Func():
            logFunc('called. silentDroppedPackets=%s, old=%s',
                    silentDroppedPackets, self.silentDroppedPackets)
        self.silentDroppedPacketsSet = True
        self.silentDroppedPackets = silentDroppedPackets

    def requestInPackets(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-inpackets').debug3Func():
            logFunc('called. requested=%s', requested)
        self.inPacketsRequested = requested
        self.inPacketsSet = False

    def isInPacketsRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-inpackets-requested').debug3Func():
            logFunc('called. requested=%s', self.inPacketsRequested)
        return self.inPacketsRequested

    def getInPackets(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-inpackets').debug3Func():
            logFunc('called. self.inPacketsSet=%s, self.inPackets=%s',
                    self.inPacketsSet, self.inPackets)
        if self.inPacketsSet:
            return self.inPackets
        return None

    def hasInPackets(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-inpackets').debug3Func():
            logFunc('called. self.inPacketsSet=%s, self.inPackets=%s',
                    self.inPacketsSet, self.inPackets)
        if self.inPacketsSet:
            return True
        return False

    def setInPackets(self, inPackets):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-inpackets').debug3Func():
            logFunc('called. inPackets=%s, old=%s', inPackets, self.inPackets)
        self.inPacketsSet = True
        self.inPackets = inPackets

    def requestInBadVersionPackets(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-inbadversionpackets').debug3Func():
            logFunc('called. requested=%s', requested)
        self.inBadVersionPacketsRequested = requested
        self.inBadVersionPacketsSet = False

    def isInBadVersionPacketsRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-inbadversionpackets-requested').debug3Func():
            logFunc('called. requested=%s', self.inBadVersionPacketsRequested)
        return self.inBadVersionPacketsRequested

    def getInBadVersionPackets(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-inbadversionpackets').debug3Func():
            logFunc(
                'called. self.inBadVersionPacketsSet=%s, self.inBadVersionPackets=%s',
                self.inBadVersionPacketsSet, self.inBadVersionPackets)
        if self.inBadVersionPacketsSet:
            return self.inBadVersionPackets
        return None

    def hasInBadVersionPackets(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-inbadversionpackets').debug3Func():
            logFunc(
                'called. self.inBadVersionPacketsSet=%s, self.inBadVersionPackets=%s',
                self.inBadVersionPacketsSet, self.inBadVersionPackets)
        if self.inBadVersionPacketsSet:
            return True
        return False

    def setInBadVersionPackets(self, inBadVersionPackets):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-inbadversionpackets').debug3Func():
            logFunc('called. inBadVersionPackets=%s, old=%s',
                    inBadVersionPackets, self.inBadVersionPackets)
        self.inBadVersionPacketsSet = True
        self.inBadVersionPackets = inBadVersionPackets

    def requestInBadCommunityUsePackets(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'request-inbadcommunityusepackets').debug3Func():
            logFunc('called. requested=%s', requested)
        self.inBadCommunityUsePacketsRequested = requested
        self.inBadCommunityUsePacketsSet = False

    def isInBadCommunityUsePacketsRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-inbadcommunityusepackets-requested').debug3Func():
            logFunc('called. requested=%s',
                    self.inBadCommunityUsePacketsRequested)
        return self.inBadCommunityUsePacketsRequested

    def getInBadCommunityUsePackets(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-inbadcommunityusepackets').debug3Func():
            logFunc(
                'called. self.inBadCommunityUsePacketsSet=%s, self.inBadCommunityUsePackets=%s',
                self.inBadCommunityUsePacketsSet,
                self.inBadCommunityUsePackets)
        if self.inBadCommunityUsePacketsSet:
            return self.inBadCommunityUsePackets
        return None

    def hasInBadCommunityUsePackets(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-inbadcommunityusepackets').debug3Func():
            logFunc(
                'called. self.inBadCommunityUsePacketsSet=%s, self.inBadCommunityUsePackets=%s',
                self.inBadCommunityUsePacketsSet,
                self.inBadCommunityUsePackets)
        if self.inBadCommunityUsePacketsSet:
            return True
        return False

    def setInBadCommunityUsePackets(self, inBadCommunityUsePackets):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-inbadcommunityusepackets').debug3Func():
            logFunc('called. inBadCommunityUsePackets=%s, old=%s',
                    inBadCommunityUsePackets, self.inBadCommunityUsePackets)
        self.inBadCommunityUsePacketsSet = True
        self.inBadCommunityUsePackets = inBadCommunityUsePackets

    def requestInAsnParseErrors(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-inasnparseerrors').debug3Func():
            logFunc('called. requested=%s', requested)
        self.inAsnParseErrorsRequested = requested
        self.inAsnParseErrorsSet = False

    def isInAsnParseErrorsRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-inasnparseerrors-requested').debug3Func():
            logFunc('called. requested=%s', self.inAsnParseErrorsRequested)
        return self.inAsnParseErrorsRequested

    def getInAsnParseErrors(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-inasnparseerrors').debug3Func():
            logFunc(
                'called. self.inAsnParseErrorsSet=%s, self.inAsnParseErrors=%s',
                self.inAsnParseErrorsSet, self.inAsnParseErrors)
        if self.inAsnParseErrorsSet:
            return self.inAsnParseErrors
        return None

    def hasInAsnParseErrors(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-inasnparseerrors').debug3Func():
            logFunc(
                'called. self.inAsnParseErrorsSet=%s, self.inAsnParseErrors=%s',
                self.inAsnParseErrorsSet, self.inAsnParseErrors)
        if self.inAsnParseErrorsSet:
            return True
        return False

    def setInAsnParseErrors(self, inAsnParseErrors):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-inasnparseerrors').debug3Func():
            logFunc('called. inAsnParseErrors=%s, old=%s', inAsnParseErrors,
                    self.inAsnParseErrors)
        self.inAsnParseErrorsSet = True
        self.inAsnParseErrors = inAsnParseErrors

    def requestInBadCommunityPackets(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-inbadcommunitypackets').debug3Func():
            logFunc('called. requested=%s', requested)
        self.inBadCommunityPacketsRequested = requested
        self.inBadCommunityPacketsSet = False

    def isInBadCommunityPacketsRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-inbadcommunitypackets-requested').debug3Func():
            logFunc('called. requested=%s',
                    self.inBadCommunityPacketsRequested)
        return self.inBadCommunityPacketsRequested

    def getInBadCommunityPackets(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-inbadcommunitypackets').debug3Func():
            logFunc(
                'called. self.inBadCommunityPacketsSet=%s, self.inBadCommunityPackets=%s',
                self.inBadCommunityPacketsSet, self.inBadCommunityPackets)
        if self.inBadCommunityPacketsSet:
            return self.inBadCommunityPackets
        return None

    def hasInBadCommunityPackets(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-inbadcommunitypackets').debug3Func():
            logFunc(
                'called. self.inBadCommunityPacketsSet=%s, self.inBadCommunityPackets=%s',
                self.inBadCommunityPacketsSet, self.inBadCommunityPackets)
        if self.inBadCommunityPacketsSet:
            return True
        return False

    def setInBadCommunityPackets(self, inBadCommunityPackets):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-inbadcommunitypackets').debug3Func():
            logFunc('called. inBadCommunityPackets=%s, old=%s',
                    inBadCommunityPackets, self.inBadCommunityPackets)
        self.inBadCommunityPacketsSet = True
        self.inBadCommunityPackets = inBadCommunityPackets

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        self.silentDroppedPackets = 0
        self.silentDroppedPacketsSet = False

        self.inPackets = 0
        self.inPacketsSet = False

        self.inBadVersionPackets = 0
        self.inBadVersionPacketsSet = False

        self.inBadCommunityUsePackets = 0
        self.inBadCommunityUsePacketsSet = False

        self.inAsnParseErrors = 0
        self.inAsnParseErrorsSet = False

        self.inBadCommunityPackets = 0
        self.inBadCommunityPacketsSet = False

    def _getSelfKeyPath(self, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("counters",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp",
             "qt-snmp"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("snmp", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp",
             "qt-snmp"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isSilentDroppedPacketsRequested():
            valSilentDroppedPackets = Value()
            valSilentDroppedPackets.setEmpty()
            tagValueList.push(
                ("silent-dropped-packets",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"),
                valSilentDroppedPackets)

        if self.isInPacketsRequested():
            valInPackets = Value()
            valInPackets.setEmpty()
            tagValueList.push(
                ("in-packets",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"),
                valInPackets)

        if self.isInBadVersionPacketsRequested():
            valInBadVersionPackets = Value()
            valInBadVersionPackets.setEmpty()
            tagValueList.push(
                ("in-bad-version-packets",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"),
                valInBadVersionPackets)

        if self.isInBadCommunityUsePacketsRequested():
            valInBadCommunityUsePackets = Value()
            valInBadCommunityUsePackets.setEmpty()
            tagValueList.push(
                ("in-bad-community-use-packets",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"),
                valInBadCommunityUsePackets)

        if self.isInAsnParseErrorsRequested():
            valInAsnParseErrors = Value()
            valInAsnParseErrors.setEmpty()
            tagValueList.push(
                ("in-asn-parse-errors",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"),
                valInAsnParseErrors)

        if self.isInBadCommunityPacketsRequested():
            valInBadCommunityPackets = Value()
            valInBadCommunityPackets.setEmpty()
            tagValueList.push(
                ("in-bad-community-packets",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"),
                valInBadCommunityPackets)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isSilentDroppedPacketsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "silent-dropped-packets") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-silentdroppedpackets'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "silentDroppedPackets", "silent-dropped-packets",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-silent-dropped-packets-bad-value'
                ).infoFunc():
                    logFunc('silentDroppedPackets not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setSilentDroppedPackets(tempVar)
            for logFunc in self._log(
                    'read-tag-values-silent-dropped-packets').debug3Func():
                logFunc(
                    'read silentDroppedPackets. silentDroppedPackets=%s, tempValue=%s',
                    self.silentDroppedPackets, tempValue.getType())

        if self.isInPacketsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "in-packets") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-inpackets'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "inPackets", "in-packets",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-in-packets-bad-value').infoFunc():
                    logFunc('inPackets not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setInPackets(tempVar)
            for logFunc in self._log(
                    'read-tag-values-in-packets').debug3Func():
                logFunc('read inPackets. inPackets=%s, tempValue=%s',
                        self.inPackets, tempValue.getType())

        if self.isInBadVersionPacketsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "in-bad-version-packets") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-inbadversionpackets'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "inBadVersionPackets", "in-bad-version-packets",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-in-bad-version-packets-bad-value'
                ).infoFunc():
                    logFunc('inBadVersionPackets not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setInBadVersionPackets(tempVar)
            for logFunc in self._log(
                    'read-tag-values-in-bad-version-packets').debug3Func():
                logFunc(
                    'read inBadVersionPackets. inBadVersionPackets=%s, tempValue=%s',
                    self.inBadVersionPackets, tempValue.getType())

        if self.isInBadCommunityUsePacketsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "in-bad-community-use-packets") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-inbadcommunityusepackets'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "inBadCommunityUsePackets",
                        "in-bad-community-use-packets",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-in-bad-community-use-packets-bad-value'
                ).infoFunc():
                    logFunc('inBadCommunityUsePackets not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setInBadCommunityUsePackets(tempVar)
            for logFunc in self._log(
                    'read-tag-values-in-bad-community-use-packets').debug3Func(
                    ):
                logFunc(
                    'read inBadCommunityUsePackets. inBadCommunityUsePackets=%s, tempValue=%s',
                    self.inBadCommunityUsePackets, tempValue.getType())

        if self.isInAsnParseErrorsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "in-asn-parse-errors") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-inasnparseerrors'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "inAsnParseErrors", "in-asn-parse-errors",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-in-asn-parse-errors-bad-value'
                ).infoFunc():
                    logFunc('inAsnParseErrors not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setInAsnParseErrors(tempVar)
            for logFunc in self._log(
                    'read-tag-values-in-asn-parse-errors').debug3Func():
                logFunc(
                    'read inAsnParseErrors. inAsnParseErrors=%s, tempValue=%s',
                    self.inAsnParseErrors, tempValue.getType())

        if self.isInBadCommunityPacketsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "in-bad-community-packets") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-inbadcommunitypackets'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "inBadCommunityPackets", "in-bad-community-packets",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-snmp",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-in-bad-community-packets-bad-value'
                ).infoFunc():
                    logFunc('inBadCommunityPackets not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setInBadCommunityPackets(tempVar)
            for logFunc in self._log(
                    'read-tag-values-in-bad-community-packets').debug3Func():
                logFunc(
                    'read inBadCommunityPackets. inBadCommunityPackets=%s, tempValue=%s',
                    self.inBadCommunityPackets, tempValue.getType())

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 43
0
class BlinkyStatusMaapi(StatusMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-status")
        self.domain = None

        

        
        self.applicationEntryCountRequested = False
        self.applicationEntryCount = None
        self.applicationEntryCountSet = False
        
        self.concurrentRequestsRequested = False
        self.concurrentRequests = None
        self.concurrentRequestsSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestApplicationEntryCount(True)
        
        self.requestConcurrentRequests(True)
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestApplicationEntryCount(False)
        
        self.requestConcurrentRequests(False)
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestApplicationEntryCount(True)
        
        self.requestConcurrentRequests(True)
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestApplicationEntryCount(False)
        
        self.requestConcurrentRequests(False)
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        

    def write (self
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(trxContext)

    def read (self
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  True,
                                  trxContext)



    def requestApplicationEntryCount (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-applicationentrycount').debug3Func(): logFunc('called. requested=%s', requested)
        self.applicationEntryCountRequested = requested
        self.applicationEntryCountSet = False

    def isApplicationEntryCountRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-applicationentrycount-requested').debug3Func(): logFunc('called. requested=%s', self.applicationEntryCountRequested)
        return self.applicationEntryCountRequested

    def getApplicationEntryCount (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-applicationentrycount').debug3Func(): logFunc('called. self.applicationEntryCountSet=%s, self.applicationEntryCount=%s', self.applicationEntryCountSet, self.applicationEntryCount)
        if self.applicationEntryCountSet:
            return self.applicationEntryCount
        return None

    def hasApplicationEntryCount (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-applicationentrycount').debug3Func(): logFunc('called. self.applicationEntryCountSet=%s, self.applicationEntryCount=%s', self.applicationEntryCountSet, self.applicationEntryCount)
        if self.applicationEntryCountSet:
            return True
        return False

    def setApplicationEntryCount (self, applicationEntryCount):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-applicationentrycount').debug3Func(): logFunc('called. applicationEntryCount=%s, old=%s', applicationEntryCount, self.applicationEntryCount)
        self.applicationEntryCountSet = True
        self.applicationEntryCount = applicationEntryCount

    def requestConcurrentRequests (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-concurrentrequests').debug3Func(): logFunc('called. requested=%s', requested)
        self.concurrentRequestsRequested = requested
        self.concurrentRequestsSet = False

    def isConcurrentRequestsRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-concurrentrequests-requested').debug3Func(): logFunc('called. requested=%s', self.concurrentRequestsRequested)
        return self.concurrentRequestsRequested

    def getConcurrentRequests (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-concurrentrequests').debug3Func(): logFunc('called. self.concurrentRequestsSet=%s, self.concurrentRequests=%s', self.concurrentRequestsSet, self.concurrentRequests)
        if self.concurrentRequestsSet:
            return self.concurrentRequests
        return None

    def hasConcurrentRequests (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-concurrentrequests').debug3Func(): logFunc('called. self.concurrentRequestsSet=%s, self.concurrentRequests=%s', self.concurrentRequestsSet, self.concurrentRequests)
        if self.concurrentRequestsSet:
            return True
        return False

    def setConcurrentRequests (self, concurrentRequests):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-concurrentrequests').debug3Func(): logFunc('called. concurrentRequests=%s, old=%s', concurrentRequests, self.concurrentRequests)
        self.concurrentRequestsSet = True
        self.concurrentRequests = concurrentRequests


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.applicationEntryCount = 0
        self.applicationEntryCountSet = False
        
        self.concurrentRequests = 0
        self.concurrentRequestsSet = False
        

    def _getSelfKeyPath (self
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-network-ipv6", "qt-net-ip6"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("application-initiated-discovery", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-network-ipv6", "qt-net-ip6"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("neighbors", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-network-ipv6", "qt-net-ip6"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("ipv6", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-network-ipv6", "qt-net-ip6"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("network", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-network", "qt-net"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isApplicationEntryCountRequested():
            valApplicationEntryCount = Value()
            valApplicationEntryCount.setEmpty()
            tagValueList.push(("application-entry-count", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-network-ipv6"), valApplicationEntryCount)
        
        if self.isConcurrentRequestsRequested():
            valConcurrentRequests = Value()
            valConcurrentRequests.setEmpty()
            tagValueList.push(("concurrent-requests", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-network-ipv6"), valConcurrentRequests)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isApplicationEntryCountRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "application-entry-count") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-network-ipv6"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-applicationentrycount').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "applicationEntryCount", "application-entry-count", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-network-ipv6", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-application-entry-count-bad-value').infoFunc(): logFunc('applicationEntryCount not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setApplicationEntryCount(tempVar)
            for logFunc in self._log('read-tag-values-application-entry-count').debug3Func(): logFunc('read applicationEntryCount. applicationEntryCount=%s, tempValue=%s', self.applicationEntryCount, tempValue.getType())
        
        if self.isConcurrentRequestsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "concurrent-requests") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-network-ipv6"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-concurrentrequests').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "concurrentRequests", "concurrent-requests", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-network-ipv6", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-concurrent-requests-bad-value').infoFunc(): logFunc('concurrentRequests not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setConcurrentRequests(tempVar)
            for logFunc in self._log('read-tag-values-concurrent-requests').debug3Func(): logFunc('read concurrentRequests. concurrentRequests=%s, tempValue=%s', self.concurrentRequests, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 44
0
class BlinkyPersonMaapi(PersonMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-person")
        self.domain = None

        self.employedRequested = False
        self.employed = None
        self.employedSet = False

        self.nameRequested = False
        self.name = None
        self.nameSet = False

        self.heightRequested = False
        self.height = None
        self.heightSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestEmployed(True)

        self.requestName(True)

        self.requestHeight(True)

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestEmployed(True)

        self.requestName(True)

        self.requestHeight(True)

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestEmployed(False)

        self.requestName(False)

        self.requestHeight(False)

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestEmployed(False)

        self.requestName(False)

        self.requestHeight(False)

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

        self.setEmployed(None)
        self.employedSet = False

        self.setName(None)
        self.nameSet = False

        self.setHeight(None)
        self.heightSet = False

    def write(self, person, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(person, trxContext)

    def read(self, person, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(person, False, trxContext)

    def readAllOrFail(self, person, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(person, True, trxContext)

    def requestEmployed(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-employed').debug3Func():
            logFunc('called. requested=%s', requested)
        self.employedRequested = requested
        self.employedSet = False

    def isEmployedRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-employed-requested').debug3Func():
            logFunc('called. requested=%s', self.employedRequested)
        return self.employedRequested

    def getEmployed(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-employed').debug3Func():
            logFunc('called. self.employedSet=%s, self.employed=%s',
                    self.employedSet, self.employed)
        if self.employedSet:
            return self.employed
        return None

    def hasEmployed(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-employed').debug3Func():
            logFunc('called. self.employedSet=%s, self.employed=%s',
                    self.employedSet, self.employed)
        if self.employedSet:
            return True
        return False

    def setEmployed(self, employed):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-employed').debug3Func():
            logFunc('called. employed=%s, old=%s', employed, self.employed)
        self.employedSet = True
        self.employed = employed

    def requestName(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-name').debug3Func():
            logFunc('called. requested=%s', requested)
        self.nameRequested = requested
        self.nameSet = False

    def isNameRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-name-requested').debug3Func():
            logFunc('called. requested=%s', self.nameRequested)
        return self.nameRequested

    def getName(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-name').debug3Func():
            logFunc('called. self.nameSet=%s, self.name=%s', self.nameSet,
                    self.name)
        if self.nameSet:
            return self.name
        return None

    def hasName(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-name').debug3Func():
            logFunc('called. self.nameSet=%s, self.name=%s', self.nameSet,
                    self.name)
        if self.nameSet:
            return True
        return False

    def setName(self, name):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-name').debug3Func():
            logFunc('called. name=%s, old=%s', name, self.name)
        self.nameSet = True
        self.name = name

    def requestHeight(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-height').debug3Func():
            logFunc('called. requested=%s', requested)
        self.heightRequested = requested
        self.heightSet = False

    def isHeightRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-height-requested').debug3Func():
            logFunc('called. requested=%s', self.heightRequested)
        return self.heightRequested

    def getHeight(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-height').debug3Func():
            logFunc('called. self.heightSet=%s, self.height=%s',
                    self.heightSet, self.height)
        if self.heightSet:
            return self.height
        return None

    def hasHeight(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-height').debug3Func():
            logFunc('called. self.heightSet=%s, self.height=%s',
                    self.heightSet, self.height)
        if self.heightSet:
            return True
        return False

    def setHeight(self, height):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-height').debug3Func():
            logFunc('called. height=%s, old=%s', height, self.height)
        self.heightSet = True
        self.height = height

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        self.employed = 0
        self.employedSet = False

        self.name = 0
        self.nameSet = False

        self.height = 0
        self.heightSet = False

    def _getSelfKeyPath(self, person, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        ancestorVal = Value()
        ancestorVal.setString(person)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag((
            "people",
            "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/list-example",
            "le"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, person, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(person, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(person, None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, person, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(person, None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, person, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.hasEmployed():
            valEmployed = Value()
            if self.employed is not None:
                valEmployed.setBool(self.employed)
            else:
                valEmployed.setEmpty()
            tagValueList.push((
                "employed",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/list-example"
            ), valEmployed)

        if self.hasName():
            valName = Value()
            if self.name is not None:
                valName.setString(self.name)
            else:
                valName.setEmpty()
            tagValueList.push((
                "name",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/list-example"
            ), valName)

        if self.hasHeight():
            valHeight = Value()
            if self.height is not None:
                valHeight.setInt64(self.height)
            else:
                valHeight.setEmpty()
            tagValueList.push((
                "height",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/list-example"
            ), valHeight)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isEmployedRequested():
            valEmployed = Value()
            valEmployed.setEmpty()
            tagValueList.push((
                "employed",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/list-example"
            ), valEmployed)

        if self.isNameRequested():
            valName = Value()
            valName.setEmpty()
            tagValueList.push((
                "name",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/list-example"
            ), valName)

        if self.isHeightRequested():
            valHeight = Value()
            valHeight.setEmpty()
            tagValueList.push((
                "height",
                "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/list-example"
            ), valHeight)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isEmployedRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "employed") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/list-example"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-employed'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "employed", "employed",
                        "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/list-example",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asBool()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-employed-bad-value').infoFunc():
                    logFunc('employed not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setEmployed(tempVar)
            for logFunc in self._log('read-tag-values-employed').debug3Func():
                logFunc('read employed. employed=%s, tempValue=%s',
                        self.employed, tempValue.getType())

        if self.isNameRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "name") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/list-example"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-name').errorFunc(
                        ):
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "name", "name",
                        "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/list-example",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-name-bad-value').infoFunc():
                    logFunc('name not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setName(tempVar)
            for logFunc in self._log('read-tag-values-name').debug3Func():
                logFunc('read name. name=%s, tempValue=%s', self.name,
                        tempValue.getType())

        if self.isHeightRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "height") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/list-example"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-height'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "height", "height",
                        "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/list-example",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-height-bad-value').infoFunc():
                    logFunc('height not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setHeight(tempVar)
            for logFunc in self._log('read-tag-values-height').debug3Func():
                logFunc('read height. height=%s, tempValue=%s', self.height,
                        tempValue.getType())

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 45
0
class BlinkyStatusMaapi(StatusMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-status")
        self.domain = None

        

        
        self.versionRequested = False
        self.version = None
        self.versionSet = False
        
        self.healthRequested = False
        self.health = None
        self.healthSet = False
        
        self.numOfCracksRequested = False
        self.numOfCracks = None
        self.numOfCracksSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestVersion(True)
        
        self.requestHealth(True)
        
        self.requestNumOfCracks(True)
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestVersion(False)
        
        self.requestHealth(False)
        
        self.requestNumOfCracks(False)
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestVersion(True)
        
        self.requestHealth(True)
        
        self.requestNumOfCracks(True)
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        
        self.requestVersion(False)
        
        self.requestHealth(False)
        
        self.requestNumOfCracks(False)
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        

    def write (self
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(trxContext)

    def read (self
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  True,
                                  trxContext)



    def requestVersion (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-version').debug3Func(): logFunc('called. requested=%s', requested)
        self.versionRequested = requested
        self.versionSet = False

    def isVersionRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-version-requested').debug3Func(): logFunc('called. requested=%s', self.versionRequested)
        return self.versionRequested

    def getVersion (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-version').debug3Func(): logFunc('called. self.versionSet=%s, self.version=%s', self.versionSet, self.version)
        if self.versionSet:
            return self.version
        return None

    def hasVersion (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-version').debug3Func(): logFunc('called. self.versionSet=%s, self.version=%s', self.versionSet, self.version)
        if self.versionSet:
            return True
        return False

    def setVersion (self, version):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-version').debug3Func(): logFunc('called. version=%s, old=%s', version, self.version)
        self.versionSet = True
        self.version = version

    def requestHealth (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-health').debug3Func(): logFunc('called. requested=%s', requested)
        self.healthRequested = requested
        self.healthSet = False

    def isHealthRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-health-requested').debug3Func(): logFunc('called. requested=%s', self.healthRequested)
        return self.healthRequested

    def getHealth (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-health').debug3Func(): logFunc('called. self.healthSet=%s, self.health=%s', self.healthSet, self.health)
        if self.healthSet:
            return self.health
        return None

    def hasHealth (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-health').debug3Func(): logFunc('called. self.healthSet=%s, self.health=%s', self.healthSet, self.health)
        if self.healthSet:
            return True
        return False

    def setHealth (self, health):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-health').debug3Func(): logFunc('called. health=%s, old=%s', health, self.health)
        self.healthSet = True
        self.health = health

    def requestNumOfCracks (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-numofcracks').debug3Func(): logFunc('called. requested=%s', requested)
        self.numOfCracksRequested = requested
        self.numOfCracksSet = False

    def isNumOfCracksRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-numofcracks-requested').debug3Func(): logFunc('called. requested=%s', self.numOfCracksRequested)
        return self.numOfCracksRequested

    def getNumOfCracks (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-numofcracks').debug3Func(): logFunc('called. self.numOfCracksSet=%s, self.numOfCracks=%s', self.numOfCracksSet, self.numOfCracks)
        if self.numOfCracksSet:
            return self.numOfCracks
        return None

    def hasNumOfCracks (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-numofcracks').debug3Func(): logFunc('called. self.numOfCracksSet=%s, self.numOfCracks=%s', self.numOfCracksSet, self.numOfCracks)
        if self.numOfCracksSet:
            return True
        return False

    def setNumOfCracks (self, numOfCracks):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-numofcracks').debug3Func(): logFunc('called. numOfCracks=%s, old=%s', numOfCracks, self.numOfCracks)
        self.numOfCracksSet = True
        self.numOfCracks = numOfCracks


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.version = 0
        self.versionSet = False
        
        self.health = 0
        self.healthSet = False
        
        self.numOfCracks = 0
        self.numOfCracksSet = False
        

    def _getSelfKeyPath (self
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("status", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example", "se"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("chair", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example", "se"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isVersionRequested():
            valVersion = Value()
            valVersion.setEmpty()
            tagValueList.push(("version", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"), valVersion)
        
        if self.isHealthRequested():
            valHealth = Value()
            valHealth.setEmpty()
            tagValueList.push(("health", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"), valHealth)
        
        if self.isNumOfCracksRequested():
            valNumOfCracks = Value()
            valNumOfCracks.setEmpty()
            tagValueList.push(("num-of-cracks", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"), valNumOfCracks)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isVersionRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "version") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-version').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "version", "version", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-version-bad-value').infoFunc(): logFunc('version not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setVersion(tempVar)
            for logFunc in self._log('read-tag-values-version').debug3Func(): logFunc('read version. version=%s, tempValue=%s', self.version, tempValue.getType())
        
        if self.isHealthRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "health") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-health').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "health", "health", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-health-bad-value').infoFunc(): logFunc('health not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setHealth(tempVar)
            for logFunc in self._log('read-tag-values-health').debug3Func(): logFunc('read health. health=%s, tempValue=%s', self.health, tempValue.getType())
        
        if self.isNumOfCracksRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "num-of-cracks") or \
                (ns != "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-numofcracks').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "numOfCracks", "num-of-cracks", "http://qwilt.com/ns/yang/ut/sys/blinky/example/python/simple-example", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-num-of-cracks-bad-value').infoFunc(): logFunc('numOfCracks not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setNumOfCracks(tempVar)
            for logFunc in self._log('read-tag-values-num-of-cracks').debug3Func(): logFunc('read numOfCracks. numOfCracks=%s, tempValue=%s', self.numOfCracks, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 46
0
class BlinkyThresholdsMaapi(ThresholdsMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-thresholds")
        self.domain = None

        

        
        self.fileArchiveDurationWarningSecondsRequested = False
        self.fileArchiveDurationWarningSeconds = None
        self.fileArchiveDurationWarningSecondsSet = False
        
        self.pendingFileCountWarningRequested = False
        self.pendingFileCountWarning = None
        self.pendingFileCountWarningSet = False
        
        self.overallArchiveDurationWarningSecondsRequested = False
        self.overallArchiveDurationWarningSeconds = None
        self.overallArchiveDurationWarningSecondsSet = False
        
        self.pendingFileCountErrorRequested = False
        self.pendingFileCountError = None
        self.pendingFileCountErrorSet = False
        
        self.fileArchiveDurationErrorSecondsRequested = False
        self.fileArchiveDurationErrorSeconds = None
        self.fileArchiveDurationErrorSecondsSet = False
        
        self.overallArchiveDurationErrorSecondsRequested = False
        self.overallArchiveDurationErrorSeconds = None
        self.overallArchiveDurationErrorSecondsSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestFileArchiveDurationWarningSeconds(True)
        
        self.requestPendingFileCountWarning(True)
        
        self.requestOverallArchiveDurationWarningSeconds(True)
        
        self.requestPendingFileCountError(True)
        
        self.requestFileArchiveDurationErrorSeconds(True)
        
        self.requestOverallArchiveDurationErrorSeconds(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestFileArchiveDurationWarningSeconds(True)
        
        self.requestPendingFileCountWarning(True)
        
        self.requestOverallArchiveDurationWarningSeconds(True)
        
        self.requestPendingFileCountError(True)
        
        self.requestFileArchiveDurationErrorSeconds(True)
        
        self.requestOverallArchiveDurationErrorSeconds(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestFileArchiveDurationWarningSeconds(False)
        
        self.requestPendingFileCountWarning(False)
        
        self.requestOverallArchiveDurationWarningSeconds(False)
        
        self.requestPendingFileCountError(False)
        
        self.requestFileArchiveDurationErrorSeconds(False)
        
        self.requestOverallArchiveDurationErrorSeconds(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestFileArchiveDurationWarningSeconds(False)
        
        self.requestPendingFileCountWarning(False)
        
        self.requestOverallArchiveDurationWarningSeconds(False)
        
        self.requestPendingFileCountError(False)
        
        self.requestFileArchiveDurationErrorSeconds(False)
        
        self.requestOverallArchiveDurationErrorSeconds(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setFileArchiveDurationWarningSeconds(None)
        self.fileArchiveDurationWarningSecondsSet = False
        
        self.setPendingFileCountWarning(None)
        self.pendingFileCountWarningSet = False
        
        self.setOverallArchiveDurationWarningSeconds(None)
        self.overallArchiveDurationWarningSecondsSet = False
        
        self.setPendingFileCountError(None)
        self.pendingFileCountErrorSet = False
        
        self.setFileArchiveDurationErrorSeconds(None)
        self.fileArchiveDurationErrorSecondsSet = False
        
        self.setOverallArchiveDurationErrorSeconds(None)
        self.overallArchiveDurationErrorSecondsSet = False
        
        

    def write (self
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(trxContext)

    def read (self
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(
                                  True,
                                  trxContext)



    def requestFileArchiveDurationWarningSeconds (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-filearchivedurationwarningseconds').debug3Func(): logFunc('called. requested=%s', requested)
        self.fileArchiveDurationWarningSecondsRequested = requested
        self.fileArchiveDurationWarningSecondsSet = False

    def isFileArchiveDurationWarningSecondsRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-filearchivedurationwarningseconds-requested').debug3Func(): logFunc('called. requested=%s', self.fileArchiveDurationWarningSecondsRequested)
        return self.fileArchiveDurationWarningSecondsRequested

    def getFileArchiveDurationWarningSeconds (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-filearchivedurationwarningseconds').debug3Func(): logFunc('called. self.fileArchiveDurationWarningSecondsSet=%s, self.fileArchiveDurationWarningSeconds=%s', self.fileArchiveDurationWarningSecondsSet, self.fileArchiveDurationWarningSeconds)
        if self.fileArchiveDurationWarningSecondsSet:
            return self.fileArchiveDurationWarningSeconds
        return None

    def hasFileArchiveDurationWarningSeconds (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-filearchivedurationwarningseconds').debug3Func(): logFunc('called. self.fileArchiveDurationWarningSecondsSet=%s, self.fileArchiveDurationWarningSeconds=%s', self.fileArchiveDurationWarningSecondsSet, self.fileArchiveDurationWarningSeconds)
        if self.fileArchiveDurationWarningSecondsSet:
            return True
        return False

    def setFileArchiveDurationWarningSeconds (self, fileArchiveDurationWarningSeconds):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-filearchivedurationwarningseconds').debug3Func(): logFunc('called. fileArchiveDurationWarningSeconds=%s, old=%s', fileArchiveDurationWarningSeconds, self.fileArchiveDurationWarningSeconds)
        self.fileArchiveDurationWarningSecondsSet = True
        self.fileArchiveDurationWarningSeconds = fileArchiveDurationWarningSeconds

    def requestPendingFileCountWarning (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-pendingfilecountwarning').debug3Func(): logFunc('called. requested=%s', requested)
        self.pendingFileCountWarningRequested = requested
        self.pendingFileCountWarningSet = False

    def isPendingFileCountWarningRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-pendingfilecountwarning-requested').debug3Func(): logFunc('called. requested=%s', self.pendingFileCountWarningRequested)
        return self.pendingFileCountWarningRequested

    def getPendingFileCountWarning (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-pendingfilecountwarning').debug3Func(): logFunc('called. self.pendingFileCountWarningSet=%s, self.pendingFileCountWarning=%s', self.pendingFileCountWarningSet, self.pendingFileCountWarning)
        if self.pendingFileCountWarningSet:
            return self.pendingFileCountWarning
        return None

    def hasPendingFileCountWarning (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-pendingfilecountwarning').debug3Func(): logFunc('called. self.pendingFileCountWarningSet=%s, self.pendingFileCountWarning=%s', self.pendingFileCountWarningSet, self.pendingFileCountWarning)
        if self.pendingFileCountWarningSet:
            return True
        return False

    def setPendingFileCountWarning (self, pendingFileCountWarning):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-pendingfilecountwarning').debug3Func(): logFunc('called. pendingFileCountWarning=%s, old=%s', pendingFileCountWarning, self.pendingFileCountWarning)
        self.pendingFileCountWarningSet = True
        self.pendingFileCountWarning = pendingFileCountWarning

    def requestOverallArchiveDurationWarningSeconds (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-overallarchivedurationwarningseconds').debug3Func(): logFunc('called. requested=%s', requested)
        self.overallArchiveDurationWarningSecondsRequested = requested
        self.overallArchiveDurationWarningSecondsSet = False

    def isOverallArchiveDurationWarningSecondsRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-overallarchivedurationwarningseconds-requested').debug3Func(): logFunc('called. requested=%s', self.overallArchiveDurationWarningSecondsRequested)
        return self.overallArchiveDurationWarningSecondsRequested

    def getOverallArchiveDurationWarningSeconds (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-overallarchivedurationwarningseconds').debug3Func(): logFunc('called. self.overallArchiveDurationWarningSecondsSet=%s, self.overallArchiveDurationWarningSeconds=%s', self.overallArchiveDurationWarningSecondsSet, self.overallArchiveDurationWarningSeconds)
        if self.overallArchiveDurationWarningSecondsSet:
            return self.overallArchiveDurationWarningSeconds
        return None

    def hasOverallArchiveDurationWarningSeconds (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-overallarchivedurationwarningseconds').debug3Func(): logFunc('called. self.overallArchiveDurationWarningSecondsSet=%s, self.overallArchiveDurationWarningSeconds=%s', self.overallArchiveDurationWarningSecondsSet, self.overallArchiveDurationWarningSeconds)
        if self.overallArchiveDurationWarningSecondsSet:
            return True
        return False

    def setOverallArchiveDurationWarningSeconds (self, overallArchiveDurationWarningSeconds):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-overallarchivedurationwarningseconds').debug3Func(): logFunc('called. overallArchiveDurationWarningSeconds=%s, old=%s', overallArchiveDurationWarningSeconds, self.overallArchiveDurationWarningSeconds)
        self.overallArchiveDurationWarningSecondsSet = True
        self.overallArchiveDurationWarningSeconds = overallArchiveDurationWarningSeconds

    def requestPendingFileCountError (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-pendingfilecounterror').debug3Func(): logFunc('called. requested=%s', requested)
        self.pendingFileCountErrorRequested = requested
        self.pendingFileCountErrorSet = False

    def isPendingFileCountErrorRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-pendingfilecounterror-requested').debug3Func(): logFunc('called. requested=%s', self.pendingFileCountErrorRequested)
        return self.pendingFileCountErrorRequested

    def getPendingFileCountError (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-pendingfilecounterror').debug3Func(): logFunc('called. self.pendingFileCountErrorSet=%s, self.pendingFileCountError=%s', self.pendingFileCountErrorSet, self.pendingFileCountError)
        if self.pendingFileCountErrorSet:
            return self.pendingFileCountError
        return None

    def hasPendingFileCountError (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-pendingfilecounterror').debug3Func(): logFunc('called. self.pendingFileCountErrorSet=%s, self.pendingFileCountError=%s', self.pendingFileCountErrorSet, self.pendingFileCountError)
        if self.pendingFileCountErrorSet:
            return True
        return False

    def setPendingFileCountError (self, pendingFileCountError):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-pendingfilecounterror').debug3Func(): logFunc('called. pendingFileCountError=%s, old=%s', pendingFileCountError, self.pendingFileCountError)
        self.pendingFileCountErrorSet = True
        self.pendingFileCountError = pendingFileCountError

    def requestFileArchiveDurationErrorSeconds (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-filearchivedurationerrorseconds').debug3Func(): logFunc('called. requested=%s', requested)
        self.fileArchiveDurationErrorSecondsRequested = requested
        self.fileArchiveDurationErrorSecondsSet = False

    def isFileArchiveDurationErrorSecondsRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-filearchivedurationerrorseconds-requested').debug3Func(): logFunc('called. requested=%s', self.fileArchiveDurationErrorSecondsRequested)
        return self.fileArchiveDurationErrorSecondsRequested

    def getFileArchiveDurationErrorSeconds (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-filearchivedurationerrorseconds').debug3Func(): logFunc('called. self.fileArchiveDurationErrorSecondsSet=%s, self.fileArchiveDurationErrorSeconds=%s', self.fileArchiveDurationErrorSecondsSet, self.fileArchiveDurationErrorSeconds)
        if self.fileArchiveDurationErrorSecondsSet:
            return self.fileArchiveDurationErrorSeconds
        return None

    def hasFileArchiveDurationErrorSeconds (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-filearchivedurationerrorseconds').debug3Func(): logFunc('called. self.fileArchiveDurationErrorSecondsSet=%s, self.fileArchiveDurationErrorSeconds=%s', self.fileArchiveDurationErrorSecondsSet, self.fileArchiveDurationErrorSeconds)
        if self.fileArchiveDurationErrorSecondsSet:
            return True
        return False

    def setFileArchiveDurationErrorSeconds (self, fileArchiveDurationErrorSeconds):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-filearchivedurationerrorseconds').debug3Func(): logFunc('called. fileArchiveDurationErrorSeconds=%s, old=%s', fileArchiveDurationErrorSeconds, self.fileArchiveDurationErrorSeconds)
        self.fileArchiveDurationErrorSecondsSet = True
        self.fileArchiveDurationErrorSeconds = fileArchiveDurationErrorSeconds

    def requestOverallArchiveDurationErrorSeconds (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-overallarchivedurationerrorseconds').debug3Func(): logFunc('called. requested=%s', requested)
        self.overallArchiveDurationErrorSecondsRequested = requested
        self.overallArchiveDurationErrorSecondsSet = False

    def isOverallArchiveDurationErrorSecondsRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-overallarchivedurationerrorseconds-requested').debug3Func(): logFunc('called. requested=%s', self.overallArchiveDurationErrorSecondsRequested)
        return self.overallArchiveDurationErrorSecondsRequested

    def getOverallArchiveDurationErrorSeconds (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-overallarchivedurationerrorseconds').debug3Func(): logFunc('called. self.overallArchiveDurationErrorSecondsSet=%s, self.overallArchiveDurationErrorSeconds=%s', self.overallArchiveDurationErrorSecondsSet, self.overallArchiveDurationErrorSeconds)
        if self.overallArchiveDurationErrorSecondsSet:
            return self.overallArchiveDurationErrorSeconds
        return None

    def hasOverallArchiveDurationErrorSeconds (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-overallarchivedurationerrorseconds').debug3Func(): logFunc('called. self.overallArchiveDurationErrorSecondsSet=%s, self.overallArchiveDurationErrorSeconds=%s', self.overallArchiveDurationErrorSecondsSet, self.overallArchiveDurationErrorSeconds)
        if self.overallArchiveDurationErrorSecondsSet:
            return True
        return False

    def setOverallArchiveDurationErrorSeconds (self, overallArchiveDurationErrorSeconds):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-overallarchivedurationerrorseconds').debug3Func(): logFunc('called. overallArchiveDurationErrorSeconds=%s, old=%s', overallArchiveDurationErrorSeconds, self.overallArchiveDurationErrorSeconds)
        self.overallArchiveDurationErrorSecondsSet = True
        self.overallArchiveDurationErrorSeconds = overallArchiveDurationErrorSeconds


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.fileArchiveDurationWarningSeconds = 0
        self.fileArchiveDurationWarningSecondsSet = False
        
        self.pendingFileCountWarning = 0
        self.pendingFileCountWarningSet = False
        
        self.overallArchiveDurationWarningSeconds = 0
        self.overallArchiveDurationWarningSecondsSet = False
        
        self.pendingFileCountError = 0
        self.pendingFileCountErrorSet = False
        
        self.fileArchiveDurationErrorSeconds = 0
        self.fileArchiveDurationErrorSecondsSet = False
        
        self.overallArchiveDurationErrorSeconds = 0
        self.overallArchiveDurationErrorSecondsSet = False
        

    def _getSelfKeyPath (self
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("thresholds", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", "qt-log"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("log-archiving", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", "qt-log"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("housekeeper", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", "qt-log"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("system-defaults", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", "qt-log"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("log", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", "qt-log"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasFileArchiveDurationWarningSeconds():
            valFileArchiveDurationWarningSeconds = Value()
            if self.fileArchiveDurationWarningSeconds is not None:
                valFileArchiveDurationWarningSeconds.setInt64(self.fileArchiveDurationWarningSeconds)
            else:
                valFileArchiveDurationWarningSeconds.setEmpty()
            tagValueList.push(("file-archive-duration-warning-seconds", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valFileArchiveDurationWarningSeconds)
        
        if self.hasPendingFileCountWarning():
            valPendingFileCountWarning = Value()
            if self.pendingFileCountWarning is not None:
                valPendingFileCountWarning.setInt64(self.pendingFileCountWarning)
            else:
                valPendingFileCountWarning.setEmpty()
            tagValueList.push(("pending-file-count-warning", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valPendingFileCountWarning)
        
        if self.hasOverallArchiveDurationWarningSeconds():
            valOverallArchiveDurationWarningSeconds = Value()
            if self.overallArchiveDurationWarningSeconds is not None:
                valOverallArchiveDurationWarningSeconds.setInt64(self.overallArchiveDurationWarningSeconds)
            else:
                valOverallArchiveDurationWarningSeconds.setEmpty()
            tagValueList.push(("overall-archive-duration-warning-seconds", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valOverallArchiveDurationWarningSeconds)
        
        if self.hasPendingFileCountError():
            valPendingFileCountError = Value()
            if self.pendingFileCountError is not None:
                valPendingFileCountError.setInt64(self.pendingFileCountError)
            else:
                valPendingFileCountError.setEmpty()
            tagValueList.push(("pending-file-count-error", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valPendingFileCountError)
        
        if self.hasFileArchiveDurationErrorSeconds():
            valFileArchiveDurationErrorSeconds = Value()
            if self.fileArchiveDurationErrorSeconds is not None:
                valFileArchiveDurationErrorSeconds.setInt64(self.fileArchiveDurationErrorSeconds)
            else:
                valFileArchiveDurationErrorSeconds.setEmpty()
            tagValueList.push(("file-archive-duration-error-seconds", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valFileArchiveDurationErrorSeconds)
        
        if self.hasOverallArchiveDurationErrorSeconds():
            valOverallArchiveDurationErrorSeconds = Value()
            if self.overallArchiveDurationErrorSeconds is not None:
                valOverallArchiveDurationErrorSeconds.setInt64(self.overallArchiveDurationErrorSeconds)
            else:
                valOverallArchiveDurationErrorSeconds.setEmpty()
            tagValueList.push(("overall-archive-duration-error-seconds", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valOverallArchiveDurationErrorSeconds)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isFileArchiveDurationWarningSecondsRequested():
            valFileArchiveDurationWarningSeconds = Value()
            valFileArchiveDurationWarningSeconds.setEmpty()
            tagValueList.push(("file-archive-duration-warning-seconds", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valFileArchiveDurationWarningSeconds)
        
        if self.isPendingFileCountWarningRequested():
            valPendingFileCountWarning = Value()
            valPendingFileCountWarning.setEmpty()
            tagValueList.push(("pending-file-count-warning", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valPendingFileCountWarning)
        
        if self.isOverallArchiveDurationWarningSecondsRequested():
            valOverallArchiveDurationWarningSeconds = Value()
            valOverallArchiveDurationWarningSeconds.setEmpty()
            tagValueList.push(("overall-archive-duration-warning-seconds", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valOverallArchiveDurationWarningSeconds)
        
        if self.isPendingFileCountErrorRequested():
            valPendingFileCountError = Value()
            valPendingFileCountError.setEmpty()
            tagValueList.push(("pending-file-count-error", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valPendingFileCountError)
        
        if self.isFileArchiveDurationErrorSecondsRequested():
            valFileArchiveDurationErrorSeconds = Value()
            valFileArchiveDurationErrorSeconds.setEmpty()
            tagValueList.push(("file-archive-duration-error-seconds", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valFileArchiveDurationErrorSeconds)
        
        if self.isOverallArchiveDurationErrorSecondsRequested():
            valOverallArchiveDurationErrorSeconds = Value()
            valOverallArchiveDurationErrorSeconds.setEmpty()
            tagValueList.push(("overall-archive-duration-error-seconds", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"), valOverallArchiveDurationErrorSeconds)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isFileArchiveDurationWarningSecondsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "file-archive-duration-warning-seconds") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-filearchivedurationwarningseconds').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "fileArchiveDurationWarningSeconds", "file-archive-duration-warning-seconds", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-file-archive-duration-warning-seconds-bad-value').infoFunc(): logFunc('fileArchiveDurationWarningSeconds not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setFileArchiveDurationWarningSeconds(tempVar)
            for logFunc in self._log('read-tag-values-file-archive-duration-warning-seconds').debug3Func(): logFunc('read fileArchiveDurationWarningSeconds. fileArchiveDurationWarningSeconds=%s, tempValue=%s', self.fileArchiveDurationWarningSeconds, tempValue.getType())
        
        if self.isPendingFileCountWarningRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "pending-file-count-warning") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-pendingfilecountwarning').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "pendingFileCountWarning", "pending-file-count-warning", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-pending-file-count-warning-bad-value').infoFunc(): logFunc('pendingFileCountWarning not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setPendingFileCountWarning(tempVar)
            for logFunc in self._log('read-tag-values-pending-file-count-warning').debug3Func(): logFunc('read pendingFileCountWarning. pendingFileCountWarning=%s, tempValue=%s', self.pendingFileCountWarning, tempValue.getType())
        
        if self.isOverallArchiveDurationWarningSecondsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "overall-archive-duration-warning-seconds") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-overallarchivedurationwarningseconds').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "overallArchiveDurationWarningSeconds", "overall-archive-duration-warning-seconds", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-overall-archive-duration-warning-seconds-bad-value').infoFunc(): logFunc('overallArchiveDurationWarningSeconds not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setOverallArchiveDurationWarningSeconds(tempVar)
            for logFunc in self._log('read-tag-values-overall-archive-duration-warning-seconds').debug3Func(): logFunc('read overallArchiveDurationWarningSeconds. overallArchiveDurationWarningSeconds=%s, tempValue=%s', self.overallArchiveDurationWarningSeconds, tempValue.getType())
        
        if self.isPendingFileCountErrorRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "pending-file-count-error") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-pendingfilecounterror').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "pendingFileCountError", "pending-file-count-error", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-pending-file-count-error-bad-value').infoFunc(): logFunc('pendingFileCountError not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setPendingFileCountError(tempVar)
            for logFunc in self._log('read-tag-values-pending-file-count-error').debug3Func(): logFunc('read pendingFileCountError. pendingFileCountError=%s, tempValue=%s', self.pendingFileCountError, tempValue.getType())
        
        if self.isFileArchiveDurationErrorSecondsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "file-archive-duration-error-seconds") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-filearchivedurationerrorseconds').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "fileArchiveDurationErrorSeconds", "file-archive-duration-error-seconds", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-file-archive-duration-error-seconds-bad-value').infoFunc(): logFunc('fileArchiveDurationErrorSeconds not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setFileArchiveDurationErrorSeconds(tempVar)
            for logFunc in self._log('read-tag-values-file-archive-duration-error-seconds').debug3Func(): logFunc('read fileArchiveDurationErrorSeconds. fileArchiveDurationErrorSeconds=%s, tempValue=%s', self.fileArchiveDurationErrorSeconds, tempValue.getType())
        
        if self.isOverallArchiveDurationErrorSecondsRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "overall-archive-duration-error-seconds") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-overallarchivedurationerrorseconds').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "overallArchiveDurationErrorSeconds", "overall-archive-duration-error-seconds", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-overall-archive-duration-error-seconds-bad-value').infoFunc(): logFunc('overallArchiveDurationErrorSeconds not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setOverallArchiveDurationErrorSeconds(tempVar)
            for logFunc in self._log('read-tag-values-overall-archive-duration-error-seconds').debug3Func(): logFunc('read overallArchiveDurationErrorSeconds. overallArchiveDurationErrorSeconds=%s, tempValue=%s', self.overallArchiveDurationErrorSeconds, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 47
0
class BlinkyMethodMaapi(MethodMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-method")
        self.domain = None

        self.systemDefaultsObj = None

        self.trimContentItemSizeMbRequested = False
        self.trimContentItemSizeMb = None
        self.trimContentItemSizeMbSet = False

        self.nameRequested = False
        self.name = None
        self.nameSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestTrimContentItemSizeMb(True)

        self.requestName(True)

        if not self.systemDefaultsObj:
            self.systemDefaultsObj = self.newSystemDefaults()
            self.systemDefaultsObj.requestConfigAndOper()

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestTrimContentItemSizeMb(True)

        self.requestName(True)

        if not self.systemDefaultsObj:
            self.systemDefaultsObj = self.newSystemDefaults()
            self.systemDefaultsObj.requestConfig()

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestTrimContentItemSizeMb(False)

        self.requestName(False)

        if not self.systemDefaultsObj:
            self.systemDefaultsObj = self.newSystemDefaults()
            self.systemDefaultsObj.requestOper()

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestTrimContentItemSizeMb(False)

        self.requestName(False)

        if not self.systemDefaultsObj:
            self.systemDefaultsObj = self.newSystemDefaults()
            self.systemDefaultsObj.clearAllRequested()

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

        self.setTrimContentItemSizeMb(None)
        self.trimContentItemSizeMbSet = False

        self.setName(None)
        self.nameSet = False

        if self.systemDefaultsObj:
            self.systemDefaultsObj.clearAllSet()

    def write(self, line, method, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(line, method, trxContext)

    def read(self, line, method, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(line, method, False, trxContext)

    def readAllOrFail(self, line, method, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(line, method, True, trxContext)

    def newSystemDefaults(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-systemdefaults').debug3Func():
            logFunc('called.')
        systemDefaults = BlinkySystemDefaultsMaapi(self._log)
        systemDefaults.init(self.domain)
        return systemDefaults

    def setSystemDefaultsObj(self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-systemdefaults').debug3Func():
            logFunc('called. obj=%s', obj)
        self.systemDefaultsObj = obj

    def getSystemDefaultsObj(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-systemdefaults').debug3Func():
            logFunc('called. self.systemDefaultsObj=%s',
                    self.systemDefaultsObj)
        return self.systemDefaultsObj

    def hasSystemDefaults(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-systemdefaults').debug3Func():
            logFunc('called. self.systemDefaultsObj=%s',
                    self.systemDefaultsObj)
        if self.systemDefaultsObj:
            return True
        return False

    def requestTrimContentItemSizeMb(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-trimcontentitemsizemb').debug3Func():
            logFunc('called. requested=%s', requested)
        self.trimContentItemSizeMbRequested = requested
        self.trimContentItemSizeMbSet = False

    def isTrimContentItemSizeMbRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-trimcontentitemsizemb-requested').debug3Func():
            logFunc('called. requested=%s',
                    self.trimContentItemSizeMbRequested)
        return self.trimContentItemSizeMbRequested

    def getTrimContentItemSizeMb(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-trimcontentitemsizemb').debug3Func():
            logFunc(
                'called. self.trimContentItemSizeMbSet=%s, self.trimContentItemSizeMb=%s',
                self.trimContentItemSizeMbSet, self.trimContentItemSizeMb)
        if self.trimContentItemSizeMbSet:
            return self.trimContentItemSizeMb
        return None

    def hasTrimContentItemSizeMb(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-trimcontentitemsizemb').debug3Func():
            logFunc(
                'called. self.trimContentItemSizeMbSet=%s, self.trimContentItemSizeMb=%s',
                self.trimContentItemSizeMbSet, self.trimContentItemSizeMb)
        if self.trimContentItemSizeMbSet:
            return True
        return False

    def setTrimContentItemSizeMb(self, trimContentItemSizeMb):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-trimcontentitemsizemb').debug3Func():
            logFunc('called. trimContentItemSizeMb=%s, old=%s',
                    trimContentItemSizeMb, self.trimContentItemSizeMb)
        self.trimContentItemSizeMbSet = True
        self.trimContentItemSizeMb = trimContentItemSizeMb

    def requestName(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-name').debug3Func():
            logFunc('called. requested=%s', requested)
        self.nameRequested = requested
        self.nameSet = False

    def isNameRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-name-requested').debug3Func():
            logFunc('called. requested=%s', self.nameRequested)
        return self.nameRequested

    def getName(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-name').debug3Func():
            logFunc('called. self.nameSet=%s, self.name=%s', self.nameSet,
                    self.name)
        if self.nameSet:
            return self.name
        return None

    def hasName(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-name').debug3Func():
            logFunc('called. self.nameSet=%s, self.name=%s', self.nameSet,
                    self.name)
        if self.nameSet:
            return True
        return False

    def setName(self, name):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-name').debug3Func():
            logFunc('called. name=%s, old=%s', name, self.name)
        self.nameSet = True
        self.name = name

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        if self.systemDefaultsObj:
            self.systemDefaultsObj._clearAllReadData()

        self.trimContentItemSizeMb = 0
        self.trimContentItemSizeMbSet = False

        self.name = 0
        self.nameSet = False

    def _getSelfKeyPath(self, line, method, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        ancestorVal = Value()
        ancestorVal.setString(method)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("method",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
             "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("potential",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
             "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("analyzer",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
             "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)

        ancestorVal = Value()
        ancestorVal.setString(line)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("line",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
             "qtc-line"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("content",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", "qtc"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, line, method, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(line, method, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(line, method, None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, line, method, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(line, method, None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, line, method, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        if self.systemDefaultsObj:
            res = self.systemDefaultsObj._collectItemsToDelete(
                line, method, itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'collect-items-to-delete-system-defaults-failed'
                ).errorFunc():
                    logFunc(
                        'systemDefaultsObj._collectItemsToDelete() failed. PARAMS'
                    )
                return ReturnCodes.kGeneralError

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.hasTrimContentItemSizeMb():
            valTrimContentItemSizeMb = Value()
            if self.trimContentItemSizeMb is not None:
                valTrimContentItemSizeMb.setInt64(self.trimContentItemSizeMb)
            else:
                valTrimContentItemSizeMb.setEmpty()
            tagValueList.push(
                ("trim-content-item-size-mb",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"
                 ), valTrimContentItemSizeMb)

        if self.hasName():
            valName = Value()
            if self.name is not None:
                valName.setString(self.name)
            else:
                valName.setEmpty()
            tagValueList.push(
                ("name",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"
                 ), valName)

        if self.systemDefaultsObj:
            valBegin = Value()
            (tag, ns, prefix) = (
                "system-defaults",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
                "qtc-line")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.systemDefaultsObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'fill-write-tag-values-system-defaults-failed'
                ).errorFunc():
                    logFunc(
                        'systemDefaultsObj._fillWriteTagValues() failed. PARAMS'
                    )
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isTrimContentItemSizeMbRequested():
            valTrimContentItemSizeMb = Value()
            valTrimContentItemSizeMb.setEmpty()
            tagValueList.push(
                ("trim-content-item-size-mb",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"
                 ), valTrimContentItemSizeMb)

        if self.isNameRequested():
            valName = Value()
            valName.setEmpty()
            tagValueList.push(
                ("name",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"
                 ), valName)

        if self.systemDefaultsObj:
            valBegin = Value()
            (tag, ns, prefix) = (
                "system-defaults",
                "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
                "qtc-line")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.systemDefaultsObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'fill-read-tag-values-system-defaults-failed'
                ).errorFunc():
                    logFunc(
                        'systemDefaultsObj._fillReadTagValues() failed. PARAMS'
                    )
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isTrimContentItemSizeMbRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "trim-content-item-size-mb") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-trimcontentitemsizemb'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "trimContentItemSizeMb", "trim-content-item-size-mb",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-trim-content-item-size-mb-bad-value'
                ).infoFunc():
                    logFunc('trimContentItemSizeMb not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setTrimContentItemSizeMb(tempVar)
            for logFunc in self._log(
                    'read-tag-values-trim-content-item-size-mb').debug3Func():
                logFunc(
                    'read trimContentItemSizeMb. trimContentItemSizeMb=%s, tempValue=%s',
                    self.trimContentItemSizeMb, tempValue.getType())

        if self.isNameRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "name") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-name').errorFunc(
                        ):
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "name", "name",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-name-bad-value').infoFunc():
                    logFunc('name not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setName(tempVar)
            for logFunc in self._log('read-tag-values-name').debug3Func():
                logFunc('read name. name=%s, tempValue=%s', self.name,
                        tempValue.getType())

        if self.systemDefaultsObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "system-defaults") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-begin').errorFunc():
                    logFunc(
                        'got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                        "system-defaults",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
                        Value.kXmlBegin, tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            res = self.systemDefaultsObj._readTagValues(
                tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'read-tag-values-system-defaults-failed').errorFunc():
                    logFunc(
                        'systemDefaultsObj._readTagValues() failed. tagValueList=%s',
                        tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "system-defaults") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-end').errorFunc():
                    logFunc(
                        'got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                        "system-defaults",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line",
                        Value.kXmlEnd, tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 48
0
class BlinkyTempMemoryMaapi(TempMemoryMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-tempMemory")
        self.domain = None

        self.virtualSizeRequested = False
        self.virtualSize = None
        self.virtualSizeSet = False

        self.rssSizeRequested = False
        self.rssSize = None
        self.rssSizeSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestVirtualSize(True)

        self.requestRssSize(True)

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestVirtualSize(False)

        self.requestRssSize(False)

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestVirtualSize(True)

        self.requestRssSize(True)

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestVirtualSize(False)

        self.requestRssSize(False)

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

    def write(self, process, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(process, trxContext)

    def read(self, process, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(process, False, trxContext)

    def readAllOrFail(self, process, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(process, True, trxContext)

    def requestVirtualSize(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-virtualsize').debug3Func():
            logFunc('called. requested=%s', requested)
        self.virtualSizeRequested = requested
        self.virtualSizeSet = False

    def isVirtualSizeRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-virtualsize-requested').debug3Func():
            logFunc('called. requested=%s', self.virtualSizeRequested)
        return self.virtualSizeRequested

    def getVirtualSize(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-virtualsize').debug3Func():
            logFunc('called. self.virtualSizeSet=%s, self.virtualSize=%s',
                    self.virtualSizeSet, self.virtualSize)
        if self.virtualSizeSet:
            return self.virtualSize
        return None

    def hasVirtualSize(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-virtualsize').debug3Func():
            logFunc('called. self.virtualSizeSet=%s, self.virtualSize=%s',
                    self.virtualSizeSet, self.virtualSize)
        if self.virtualSizeSet:
            return True
        return False

    def setVirtualSize(self, virtualSize):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-virtualsize').debug3Func():
            logFunc('called. virtualSize=%s, old=%s', virtualSize,
                    self.virtualSize)
        self.virtualSizeSet = True
        self.virtualSize = virtualSize

    def requestRssSize(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-rsssize').debug3Func():
            logFunc('called. requested=%s', requested)
        self.rssSizeRequested = requested
        self.rssSizeSet = False

    def isRssSizeRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-rsssize-requested').debug3Func():
            logFunc('called. requested=%s', self.rssSizeRequested)
        return self.rssSizeRequested

    def getRssSize(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-rsssize').debug3Func():
            logFunc('called. self.rssSizeSet=%s, self.rssSize=%s',
                    self.rssSizeSet, self.rssSize)
        if self.rssSizeSet:
            return self.rssSize
        return None

    def hasRssSize(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-rsssize').debug3Func():
            logFunc('called. self.rssSizeSet=%s, self.rssSize=%s',
                    self.rssSizeSet, self.rssSize)
        if self.rssSizeSet:
            return True
        return False

    def setRssSize(self, rssSize):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-rsssize').debug3Func():
            logFunc('called. rssSize=%s, old=%s', rssSize, self.rssSize)
        self.rssSizeSet = True
        self.rssSize = rssSize

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        self.virtualSize = 0
        self.virtualSizeSet = False

        self.rssSize = 0
        self.rssSizeSet = False

    def _getSelfKeyPath(self, process, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("temp-memory",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process",
             "qt-proc"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("status",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process",
             "qt-proc"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("execution",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process",
             "qt-proc"))
        keyPath.addKeyPathPrefix(xmlVal)

        ancestorVal = Value()
        ancestorVal.setString(process)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("process",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process",
             "qt-proc"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, process, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(process, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(process, None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, process, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(process, None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, process, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isVirtualSizeRequested():
            valVirtualSize = Value()
            valVirtualSize.setEmpty()
            tagValueList.push(
                ("virtual-size",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"),
                valVirtualSize)

        if self.isRssSizeRequested():
            valRssSize = Value()
            valRssSize.setEmpty()
            tagValueList.push(
                ("rss-size",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"),
                valRssSize)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isVirtualSizeRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "virtual-size") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-virtualsize'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "virtualSize", "virtual-size",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-virtual-size-bad-value').infoFunc():
                    logFunc('virtualSize not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setVirtualSize(tempVar)
            for logFunc in self._log(
                    'read-tag-values-virtual-size').debug3Func():
                logFunc('read virtualSize. virtualSize=%s, tempValue=%s',
                        self.virtualSize, tempValue.getType())

        if self.isRssSizeRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "rss-size") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-rsssize'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "rssSize", "rss-size",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-rss-size-bad-value').infoFunc():
                    logFunc('rssSize not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setRssSize(tempVar)
            for logFunc in self._log('read-tag-values-rss-size').debug3Func():
                logFunc('read rssSize. rssSize=%s, tempValue=%s', self.rssSize,
                        tempValue.getType())

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
class BlinkySystemDefaultsMaapi(SystemDefaultsMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-systemDefaults")
        self.domain = None

        

        
        self.controllerRequested = False
        self.controller = None
        self.controllerSet = False
        
        self.enabledRequested = False
        self.enabled = None
        self.enabledSet = False
        
        self.descriptionRequested = False
        self.description = None
        self.descriptionSet = False
        
        self.locationTypeRequested = False
        self.locationType = None
        self.locationTypeSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestController(True)
        
        self.requestEnabled(True)
        
        self.requestDescription(True)
        
        self.requestLocationType(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestController(True)
        
        self.requestEnabled(True)
        
        self.requestDescription(True)
        
        self.requestLocationType(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestController(False)
        
        self.requestEnabled(False)
        
        self.requestDescription(False)
        
        self.requestLocationType(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestController(False)
        
        self.requestEnabled(False)
        
        self.requestDescription(False)
        
        self.requestLocationType(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setController(None)
        self.controllerSet = False
        
        self.setEnabled(None)
        self.enabledSet = False
        
        self.setDescription(None)
        self.descriptionSet = False
        
        self.setLocationType(None)
        self.locationTypeSet = False
        
        

    def write (self
              , module
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(module, trxContext)

    def read (self
              , module
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(module, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , module
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(module, 
                                  True,
                                  trxContext)



    def requestController (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-controller').debug3Func(): logFunc('called. requested=%s', requested)
        self.controllerRequested = requested
        self.controllerSet = False

    def isControllerRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-controller-requested').debug3Func(): logFunc('called. requested=%s', self.controllerRequested)
        return self.controllerRequested

    def getController (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-controller').debug3Func(): logFunc('called. self.controllerSet=%s, self.controller=%s', self.controllerSet, self.controller)
        if self.controllerSet:
            return self.controller
        return None

    def hasController (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-controller').debug3Func(): logFunc('called. self.controllerSet=%s, self.controller=%s', self.controllerSet, self.controller)
        if self.controllerSet:
            return True
        return False

    def setController (self, controller):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-controller').debug3Func(): logFunc('called. controller=%s, old=%s', controller, self.controller)
        self.controllerSet = True
        self.controller = controller

    def requestEnabled (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-enabled').debug3Func(): logFunc('called. requested=%s', requested)
        self.enabledRequested = requested
        self.enabledSet = False

    def isEnabledRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-enabled-requested').debug3Func(): logFunc('called. requested=%s', self.enabledRequested)
        return self.enabledRequested

    def getEnabled (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-enabled').debug3Func(): logFunc('called. self.enabledSet=%s, self.enabled=%s', self.enabledSet, self.enabled)
        if self.enabledSet:
            return self.enabled
        return None

    def hasEnabled (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-enabled').debug3Func(): logFunc('called. self.enabledSet=%s, self.enabled=%s', self.enabledSet, self.enabled)
        if self.enabledSet:
            return True
        return False

    def setEnabled (self, enabled):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-enabled').debug3Func(): logFunc('called. enabled=%s, old=%s', enabled, self.enabled)
        self.enabledSet = True
        self.enabled = enabled

    def requestDescription (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-description').debug3Func(): logFunc('called. requested=%s', requested)
        self.descriptionRequested = requested
        self.descriptionSet = False

    def isDescriptionRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-description-requested').debug3Func(): logFunc('called. requested=%s', self.descriptionRequested)
        return self.descriptionRequested

    def getDescription (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-description').debug3Func(): logFunc('called. self.descriptionSet=%s, self.description=%s', self.descriptionSet, self.description)
        if self.descriptionSet:
            return self.description
        return None

    def hasDescription (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-description').debug3Func(): logFunc('called. self.descriptionSet=%s, self.description=%s', self.descriptionSet, self.description)
        if self.descriptionSet:
            return True
        return False

    def setDescription (self, description):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-description').debug3Func(): logFunc('called. description=%s, old=%s', description, self.description)
        self.descriptionSet = True
        self.description = description

    def requestLocationType (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-locationtype').debug3Func(): logFunc('called. requested=%s', requested)
        self.locationTypeRequested = requested
        self.locationTypeSet = False

    def isLocationTypeRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-locationtype-requested').debug3Func(): logFunc('called. requested=%s', self.locationTypeRequested)
        return self.locationTypeRequested

    def getLocationType (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-locationtype').debug3Func(): logFunc('called. self.locationTypeSet=%s, self.locationType=%s', self.locationTypeSet, self.locationType)
        if self.locationTypeSet:
            return self.locationType
        return None

    def hasLocationType (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-locationtype').debug3Func(): logFunc('called. self.locationTypeSet=%s, self.locationType=%s', self.locationTypeSet, self.locationType)
        if self.locationTypeSet:
            return True
        return False

    def setLocationType (self, locationType):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-locationtype').debug3Func(): logFunc('called. locationType=%s, old=%s', locationType, self.locationType)
        self.locationTypeSet = True
        self.locationType = locationType


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.controller = 0
        self.controllerSet = False
        
        self.enabled = 0
        self.enabledSet = False
        
        self.description = 0
        self.descriptionSet = False
        
        self.locationType = 0
        self.locationTypeSet = False
        

    def _getSelfKeyPath (self, module
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("system-defaults", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module", "qt-strg-module"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(module);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("module", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module", "qt-strg-module"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("storage", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage", "qt-strg"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        module, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(module, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(module, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       module, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(module, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               module, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasController():
            valController = Value()
            if self.controller is not None:
                valController.setString(self.controller)
            else:
                valController.setEmpty()
            tagValueList.push(("controller", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module"), valController)
        
        if self.hasEnabled():
            valEnabled = Value()
            if self.enabled is not None:
                valEnabled.setBool(self.enabled)
            else:
                valEnabled.setEmpty()
            tagValueList.push(("enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module"), valEnabled)
        
        if self.hasDescription():
            valDescription = Value()
            if self.description is not None:
                valDescription.setString(self.description)
            else:
                valDescription.setEmpty()
            tagValueList.push(("description", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module"), valDescription)
        
        if self.hasLocationType():
            valLocationType = Value()
            if self.locationType is not None:
                valLocationType.setEnum(self.locationType.getValue())
            else:
                valLocationType.setEmpty()
            tagValueList.push(("location-type", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module"), valLocationType)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isControllerRequested():
            valController = Value()
            valController.setEmpty()
            tagValueList.push(("controller", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module"), valController)
        
        if self.isEnabledRequested():
            valEnabled = Value()
            valEnabled.setEmpty()
            tagValueList.push(("enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module"), valEnabled)
        
        if self.isDescriptionRequested():
            valDescription = Value()
            valDescription.setEmpty()
            tagValueList.push(("description", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module"), valDescription)
        
        if self.isLocationTypeRequested():
            valLocationType = Value()
            valLocationType.setEmpty()
            tagValueList.push(("location-type", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module"), valLocationType)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isControllerRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "controller") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-controller').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "controller", "controller", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-controller-bad-value').infoFunc(): logFunc('controller not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setController(tempVar)
            for logFunc in self._log('read-tag-values-controller').debug3Func(): logFunc('read controller. controller=%s, tempValue=%s', self.controller, tempValue.getType())
        
        if self.isEnabledRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "enabled") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-enabled').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "enabled", "enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asBool()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-enabled-bad-value').infoFunc(): logFunc('enabled not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setEnabled(tempVar)
            for logFunc in self._log('read-tag-values-enabled').debug3Func(): logFunc('read enabled. enabled=%s, tempValue=%s', self.enabled, tempValue.getType())
        
        if self.isDescriptionRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "description") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-description').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "description", "description", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-description-bad-value').infoFunc(): logFunc('description not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setDescription(tempVar)
            for logFunc in self._log('read-tag-values-description').debug3Func(): logFunc('read description. description=%s, tempValue=%s', self.description, tempValue.getType())
        
        if self.isLocationTypeRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "location-type") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-locationtype').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "locationType", "location-type", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-module", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asEnum()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-location-type-bad-value').infoFunc(): logFunc('locationType not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setLocationType(tempVar)
            for logFunc in self._log('read-tag-values-location-type').debug3Func(): logFunc('read locationType. locationType=%s, tempValue=%s', self.locationType, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
class BlinkySystemDefaultsMaapi(SystemDefaultsMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-systemDefaults")
        self.domain = None

        

        
        self.commandWarningTimeoutRequested = False
        self.commandWarningTimeout = None
        self.commandWarningTimeoutSet = False
        
        self.commandTimeoutRequested = False
        self.commandTimeout = None
        self.commandTimeoutSet = False
        
        self.enabledRequested = False
        self.enabled = None
        self.enabledSet = False
        
        self.simulationFileRequested = False
        self.simulationFile = None
        self.simulationFileSet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestCommandWarningTimeout(True)
        
        self.requestCommandTimeout(True)
        
        self.requestEnabled(True)
        
        self.requestSimulationFile(True)
        
        
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestCommandWarningTimeout(True)
        
        self.requestCommandTimeout(True)
        
        self.requestEnabled(True)
        
        self.requestSimulationFile(True)
        
        
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestCommandWarningTimeout(False)
        
        self.requestCommandTimeout(False)
        
        self.requestEnabled(False)
        
        self.requestSimulationFile(False)
        
        
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestCommandWarningTimeout(False)
        
        self.requestCommandTimeout(False)
        
        self.requestEnabled(False)
        
        self.requestSimulationFile(False)
        
        
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setCommandWarningTimeout(None)
        self.commandWarningTimeoutSet = False
        
        self.setCommandTimeout(None)
        self.commandTimeoutSet = False
        
        self.setEnabled(None)
        self.enabledSet = False
        
        self.setSimulationFile(None)
        self.simulationFileSet = False
        
        

    def write (self
              , source
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(source, trxContext)

    def read (self
              , source
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(source, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , source
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(source, 
                                  True,
                                  trxContext)



    def requestCommandWarningTimeout (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-commandwarningtimeout').debug3Func(): logFunc('called. requested=%s', requested)
        self.commandWarningTimeoutRequested = requested
        self.commandWarningTimeoutSet = False

    def isCommandWarningTimeoutRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-commandwarningtimeout-requested').debug3Func(): logFunc('called. requested=%s', self.commandWarningTimeoutRequested)
        return self.commandWarningTimeoutRequested

    def getCommandWarningTimeout (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-commandwarningtimeout').debug3Func(): logFunc('called. self.commandWarningTimeoutSet=%s, self.commandWarningTimeout=%s', self.commandWarningTimeoutSet, self.commandWarningTimeout)
        if self.commandWarningTimeoutSet:
            return self.commandWarningTimeout
        return None

    def hasCommandWarningTimeout (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-commandwarningtimeout').debug3Func(): logFunc('called. self.commandWarningTimeoutSet=%s, self.commandWarningTimeout=%s', self.commandWarningTimeoutSet, self.commandWarningTimeout)
        if self.commandWarningTimeoutSet:
            return True
        return False

    def setCommandWarningTimeout (self, commandWarningTimeout):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-commandwarningtimeout').debug3Func(): logFunc('called. commandWarningTimeout=%s, old=%s', commandWarningTimeout, self.commandWarningTimeout)
        self.commandWarningTimeoutSet = True
        self.commandWarningTimeout = commandWarningTimeout

    def requestCommandTimeout (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-commandtimeout').debug3Func(): logFunc('called. requested=%s', requested)
        self.commandTimeoutRequested = requested
        self.commandTimeoutSet = False

    def isCommandTimeoutRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-commandtimeout-requested').debug3Func(): logFunc('called. requested=%s', self.commandTimeoutRequested)
        return self.commandTimeoutRequested

    def getCommandTimeout (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-commandtimeout').debug3Func(): logFunc('called. self.commandTimeoutSet=%s, self.commandTimeout=%s', self.commandTimeoutSet, self.commandTimeout)
        if self.commandTimeoutSet:
            return self.commandTimeout
        return None

    def hasCommandTimeout (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-commandtimeout').debug3Func(): logFunc('called. self.commandTimeoutSet=%s, self.commandTimeout=%s', self.commandTimeoutSet, self.commandTimeout)
        if self.commandTimeoutSet:
            return True
        return False

    def setCommandTimeout (self, commandTimeout):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-commandtimeout').debug3Func(): logFunc('called. commandTimeout=%s, old=%s', commandTimeout, self.commandTimeout)
        self.commandTimeoutSet = True
        self.commandTimeout = commandTimeout

    def requestEnabled (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-enabled').debug3Func(): logFunc('called. requested=%s', requested)
        self.enabledRequested = requested
        self.enabledSet = False

    def isEnabledRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-enabled-requested').debug3Func(): logFunc('called. requested=%s', self.enabledRequested)
        return self.enabledRequested

    def getEnabled (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-enabled').debug3Func(): logFunc('called. self.enabledSet=%s, self.enabled=%s', self.enabledSet, self.enabled)
        if self.enabledSet:
            return self.enabled
        return None

    def hasEnabled (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-enabled').debug3Func(): logFunc('called. self.enabledSet=%s, self.enabled=%s', self.enabledSet, self.enabled)
        if self.enabledSet:
            return True
        return False

    def setEnabled (self, enabled):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-enabled').debug3Func(): logFunc('called. enabled=%s, old=%s', enabled, self.enabled)
        self.enabledSet = True
        self.enabled = enabled

    def requestSimulationFile (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-simulationfile').debug3Func(): logFunc('called. requested=%s', requested)
        self.simulationFileRequested = requested
        self.simulationFileSet = False

    def isSimulationFileRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-simulationfile-requested').debug3Func(): logFunc('called. requested=%s', self.simulationFileRequested)
        return self.simulationFileRequested

    def getSimulationFile (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-simulationfile').debug3Func(): logFunc('called. self.simulationFileSet=%s, self.simulationFile=%s', self.simulationFileSet, self.simulationFile)
        if self.simulationFileSet:
            return self.simulationFile
        return None

    def hasSimulationFile (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-simulationfile').debug3Func(): logFunc('called. self.simulationFileSet=%s, self.simulationFile=%s', self.simulationFileSet, self.simulationFile)
        if self.simulationFileSet:
            return True
        return False

    def setSimulationFile (self, simulationFile):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-simulationfile').debug3Func(): logFunc('called. simulationFile=%s, old=%s', simulationFile, self.simulationFile)
        self.simulationFileSet = True
        self.simulationFile = simulationFile


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        

        
        self.commandWarningTimeout = 0
        self.commandWarningTimeoutSet = False
        
        self.commandTimeout = 0
        self.commandTimeoutSet = False
        
        self.enabled = 0
        self.enabledSet = False
        
        self.simulationFile = 0
        self.simulationFileSet = False
        

    def _getSelfKeyPath (self, source
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("system-defaults", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager", "qt-pltf-mngr"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(source);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("source", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager", "qt-pltf-mngr"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("manager", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager", "qt-pltf-mngr"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("platform", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform", "qt-pltf"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        source, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(source, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(source, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       source, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(source, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               source, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasCommandWarningTimeout():
            valCommandWarningTimeout = Value()
            if self.commandWarningTimeout is not None:
                valCommandWarningTimeout.setInt64(self.commandWarningTimeout)
            else:
                valCommandWarningTimeout.setEmpty()
            tagValueList.push(("command-warning-timeout", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"), valCommandWarningTimeout)
        
        if self.hasCommandTimeout():
            valCommandTimeout = Value()
            if self.commandTimeout is not None:
                valCommandTimeout.setInt64(self.commandTimeout)
            else:
                valCommandTimeout.setEmpty()
            tagValueList.push(("command-timeout", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"), valCommandTimeout)
        
        if self.hasEnabled():
            valEnabled = Value()
            if self.enabled is not None:
                valEnabled.setBool(self.enabled)
            else:
                valEnabled.setEmpty()
            tagValueList.push(("enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"), valEnabled)
        
        if self.hasSimulationFile():
            valSimulationFile = Value()
            if self.simulationFile is not None:
                valSimulationFile.setString(self.simulationFile)
            else:
                valSimulationFile.setEmpty()
            tagValueList.push(("simulation-file", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"), valSimulationFile)
        

        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isCommandWarningTimeoutRequested():
            valCommandWarningTimeout = Value()
            valCommandWarningTimeout.setEmpty()
            tagValueList.push(("command-warning-timeout", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"), valCommandWarningTimeout)
        
        if self.isCommandTimeoutRequested():
            valCommandTimeout = Value()
            valCommandTimeout.setEmpty()
            tagValueList.push(("command-timeout", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"), valCommandTimeout)
        
        if self.isEnabledRequested():
            valEnabled = Value()
            valEnabled.setEmpty()
            tagValueList.push(("enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"), valEnabled)
        
        if self.isSimulationFileRequested():
            valSimulationFile = Value()
            valSimulationFile.setEmpty()
            tagValueList.push(("simulation-file", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"), valSimulationFile)
        

        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isCommandWarningTimeoutRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "command-warning-timeout") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-commandwarningtimeout').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "commandWarningTimeout", "command-warning-timeout", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-command-warning-timeout-bad-value').infoFunc(): logFunc('commandWarningTimeout not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setCommandWarningTimeout(tempVar)
            for logFunc in self._log('read-tag-values-command-warning-timeout').debug3Func(): logFunc('read commandWarningTimeout. commandWarningTimeout=%s, tempValue=%s', self.commandWarningTimeout, tempValue.getType())
        
        if self.isCommandTimeoutRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "command-timeout") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-commandtimeout').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "commandTimeout", "command-timeout", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-command-timeout-bad-value').infoFunc(): logFunc('commandTimeout not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setCommandTimeout(tempVar)
            for logFunc in self._log('read-tag-values-command-timeout').debug3Func(): logFunc('read commandTimeout. commandTimeout=%s, tempValue=%s', self.commandTimeout, tempValue.getType())
        
        if self.isEnabledRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "enabled") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-enabled').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "enabled", "enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asBool()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-enabled-bad-value').infoFunc(): logFunc('enabled not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setEnabled(tempVar)
            for logFunc in self._log('read-tag-values-enabled').debug3Func(): logFunc('read enabled. enabled=%s, tempValue=%s', self.enabled, tempValue.getType())
        
        if self.isSimulationFileRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "simulation-file") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-simulationfile').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "simulationFile", "simulation-file", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-manager", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-simulation-file-bad-value').infoFunc(): logFunc('simulationFile not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setSimulationFile(tempVar)
            for logFunc in self._log('read-tag-values-simulation-file').debug3Func(): logFunc('read simulationFile. simulationFile=%s, tempValue=%s', self.simulationFile, tempValue.getType())
        

        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 51
0
class BlinkyRefPracticeMaapi(RefPracticeMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-refPractice")
        self.domain = None

        self.someListListObj = None

        self.someLeafRefRequested = False
        self.someLeafRef = None
        self.someLeafRefSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestSomeLeafRef(True)

        if not self.someListListObj:
            self.someListListObj = self.newSomeListList()
            self.someListListObj.requestConfigAndOper()

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestSomeLeafRef(True)

        if not self.someListListObj:
            self.someListListObj = self.newSomeListList()
            self.someListListObj.requestConfig()

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestSomeLeafRef(False)

        if not self.someListListObj:
            self.someListListObj = self.newSomeListList()
            self.someListListObj.requestOper()

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestSomeLeafRef(False)

        if not self.someListListObj:
            self.someListListObj = self.newSomeListList()
            self.someListListObj.clearAllRequested()

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

        self.setSomeLeafRef(None)
        self.someLeafRefSet = False

        if self.someListListObj:
            self.someListListObj.clearAllSet()

    def write(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(trxContext)

    def read(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(False, trxContext)

    def readAllOrFail(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(True, trxContext)

    def newSomeListList(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-somelistlist').debug3Func():
            logFunc('called.')
        someListList = BlinkySomeListMaapiList(self._log)
        someListList.init(self.domain)
        return someListList

    def setSomeListListObj(self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-somelistlist').debug3Func():
            logFunc('called. obj=%s', obj)
        self.someListListObj = obj

    def getSomeListListObj(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-somelistlist').debug3Func():
            logFunc('called. self.someListListObj=%s', self.someListListObj)
        return self.someListListObj

    def hasSomeListList(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-somelistlist').debug3Func():
            logFunc('called. self.someListListObj=%s', self.someListListObj)
        if self.someListListObj:
            return True
        return False

    def requestSomeLeafRef(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-someleafref').debug3Func():
            logFunc('called. requested=%s', requested)
        self.someLeafRefRequested = requested
        self.someLeafRefSet = False

    def isSomeLeafRefRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-someleafref-requested').debug3Func():
            logFunc('called. requested=%s', self.someLeafRefRequested)
        return self.someLeafRefRequested

    def getSomeLeafRef(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-someleafref').debug3Func():
            logFunc('called. self.someLeafRefSet=%s, self.someLeafRef=%s',
                    self.someLeafRefSet, self.someLeafRef)
        if self.someLeafRefSet:
            return self.someLeafRef
        return None

    def hasSomeLeafRef(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-someleafref').debug3Func():
            logFunc('called. self.someLeafRefSet=%s, self.someLeafRef=%s',
                    self.someLeafRefSet, self.someLeafRef)
        if self.someLeafRefSet:
            return True
        return False

    def setSomeLeafRef(self, someLeafRef):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-someleafref').debug3Func():
            logFunc('called. someLeafRef=%s, old=%s', someLeafRef,
                    self.someLeafRef)
        self.someLeafRefSet = True
        self.someLeafRef = someLeafRef

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        if self.someListListObj:
            self.someListListObj._clearAllReadData()

        self.someLeafRef = 0
        self.someLeafRefSet = False

    def _getSelfKeyPath(self, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("ref-practice", "http://qwilt.com/model/lake-example",
             "lake-example"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        if self.someListListObj:
            res = self.someListListObj._collectItemsToDelete(itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'collect-items-to-delete-some-list-failed').errorFunc(
                        ):
                    logFunc(
                        'someListListObj._collectItemsToDelete() failed. PARAMS'
                    )
                return ReturnCodes.kGeneralError

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.hasSomeLeafRef():
            valSomeLeafRef = Value()
            if self.someLeafRef is not None:
                valSomeLeafRef.setString(self.someLeafRef)
            else:
                valSomeLeafRef.setEmpty()
            tagValueList.push(
                ("some-leaf-ref", "http://qwilt.com/model/lake-example"),
                valSomeLeafRef)

        if self.someListListObj:
            valBegin = Value()
            (tag, ns,
             prefix) = ("some-list", "http://qwilt.com/model/lake-example",
                        "lake-example")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.someListListObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'fill-write-tag-values-some-list-failed').errorFunc():
                    logFunc(
                        'someListListObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isSomeLeafRefRequested():
            valSomeLeafRef = Value()
            valSomeLeafRef.setEmpty()
            tagValueList.push(
                ("some-leaf-ref", "http://qwilt.com/model/lake-example"),
                valSomeLeafRef)

        if self.someListListObj:
            valBegin = Value()
            (tag, ns,
             prefix) = ("some-list", "http://qwilt.com/model/lake-example",
                        "lake-example")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.someListListObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'fill-read-tag-values-some-list-failed').errorFunc():
                    logFunc(
                        'someListListObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isSomeLeafRefRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "some-leaf-ref") or \
                (ns != "http://qwilt.com/model/lake-example"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-someleafref'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "someLeafRef", "some-leaf-ref",
                        "http://qwilt.com/model/lake-example", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-some-leaf-ref-bad-value').infoFunc():
                    logFunc('someLeafRef not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setSomeLeafRef(tempVar)
            for logFunc in self._log(
                    'read-tag-values-some-leaf-ref').debug3Func():
                logFunc('read someLeafRef. someLeafRef=%s, tempValue=%s',
                        self.someLeafRef, tempValue.getType())

        if self.someListListObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "some-list") or \
                (ns != "http://qwilt.com/model/lake-example") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-begin').errorFunc():
                    logFunc(
                        'got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                        "some-list", "http://qwilt.com/model/lake-example",
                        Value.kXmlBegin, tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            res = self.someListListObj._readTagValues(tagValueList,
                                                      readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log(
                        'read-tag-values-some-list-failed').errorFunc():
                    logFunc(
                        'someListListObj._readTagValues() failed. tagValueList=%s',
                        tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "some-list") or \
                (ns != "http://qwilt.com/model/lake-example") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-end').errorFunc():
                    logFunc(
                        'got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                        "some-list", "http://qwilt.com/model/lake-example",
                        Value.kXmlEnd, tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 52
0
class BlinkyStatusMaapi(StatusMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-status")
        self.domain = None

        self.tableLastChangeTicksRequested = False
        self.tableLastChangeTicks = None
        self.tableLastChangeTicksSet = False

        self.interfaceNumberRequested = False
        self.interfaceNumber = None
        self.interfaceNumberSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestTableLastChangeTicks(True)

        self.requestInterfaceNumber(True)

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestTableLastChangeTicks(False)

        self.requestInterfaceNumber(False)

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestTableLastChangeTicks(True)

        self.requestInterfaceNumber(True)

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestTableLastChangeTicks(False)

        self.requestInterfaceNumber(False)

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

    def write(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(trxContext)

    def read(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(False, trxContext)

    def readAllOrFail(self, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(True, trxContext)

    def requestTableLastChangeTicks(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-tablelastchangeticks').debug3Func():
            logFunc('called. requested=%s', requested)
        self.tableLastChangeTicksRequested = requested
        self.tableLastChangeTicksSet = False

    def isTableLastChangeTicksRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log(
                'is-tablelastchangeticks-requested').debug3Func():
            logFunc('called. requested=%s', self.tableLastChangeTicksRequested)
        return self.tableLastChangeTicksRequested

    def getTableLastChangeTicks(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-tablelastchangeticks').debug3Func():
            logFunc(
                'called. self.tableLastChangeTicksSet=%s, self.tableLastChangeTicks=%s',
                self.tableLastChangeTicksSet, self.tableLastChangeTicks)
        if self.tableLastChangeTicksSet:
            return self.tableLastChangeTicks
        return None

    def hasTableLastChangeTicks(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-tablelastchangeticks').debug3Func():
            logFunc(
                'called. self.tableLastChangeTicksSet=%s, self.tableLastChangeTicks=%s',
                self.tableLastChangeTicksSet, self.tableLastChangeTicks)
        if self.tableLastChangeTicksSet:
            return True
        return False

    def setTableLastChangeTicks(self, tableLastChangeTicks):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-tablelastchangeticks').debug3Func():
            logFunc('called. tableLastChangeTicks=%s, old=%s',
                    tableLastChangeTicks, self.tableLastChangeTicks)
        self.tableLastChangeTicksSet = True
        self.tableLastChangeTicks = tableLastChangeTicks

    def requestInterfaceNumber(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-interfacenumber').debug3Func():
            logFunc('called. requested=%s', requested)
        self.interfaceNumberRequested = requested
        self.interfaceNumberSet = False

    def isInterfaceNumberRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-interfacenumber-requested').debug3Func():
            logFunc('called. requested=%s', self.interfaceNumberRequested)
        return self.interfaceNumberRequested

    def getInterfaceNumber(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-interfacenumber').debug3Func():
            logFunc(
                'called. self.interfaceNumberSet=%s, self.interfaceNumber=%s',
                self.interfaceNumberSet, self.interfaceNumber)
        if self.interfaceNumberSet:
            return self.interfaceNumber
        return None

    def hasInterfaceNumber(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-interfacenumber').debug3Func():
            logFunc(
                'called. self.interfaceNumberSet=%s, self.interfaceNumber=%s',
                self.interfaceNumberSet, self.interfaceNumber)
        if self.interfaceNumberSet:
            return True
        return False

    def setInterfaceNumber(self, interfaceNumber):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-interfacenumber').debug3Func():
            logFunc('called. interfaceNumber=%s, old=%s', interfaceNumber,
                    self.interfaceNumber)
        self.interfaceNumberSet = True
        self.interfaceNumber = interfaceNumber

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        self.tableLastChangeTicks = 0
        self.tableLastChangeTicksSet = False

        self.interfaceNumber = 0
        self.interfaceNumberSet = False

    def _getSelfKeyPath(self, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("status",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
             "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("interfaces",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
             "qt-if"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isTableLastChangeTicksRequested():
            valTableLastChangeTicks = Value()
            valTableLastChangeTicks.setEmpty()
            tagValueList.push(
                ("table-last-change-ticks",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"),
                valTableLastChangeTicks)

        if self.isInterfaceNumberRequested():
            valInterfaceNumber = Value()
            valInterfaceNumber.setEmpty()
            tagValueList.push(
                ("interface-number",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"),
                valInterfaceNumber)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isTableLastChangeTicksRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "table-last-change-ticks") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-tablelastchangeticks'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "tableLastChangeTicks", "table-last-change-ticks",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asUint32()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-table-last-change-ticks-bad-value'
                ).infoFunc():
                    logFunc('tableLastChangeTicks not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setTableLastChangeTicks(tempVar)
            for logFunc in self._log(
                    'read-tag-values-table-last-change-ticks').debug3Func():
                logFunc(
                    'read tableLastChangeTicks. tableLastChangeTicks=%s, tempValue=%s',
                    self.tableLastChangeTicks, tempValue.getType())

        if self.isInterfaceNumberRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "interface-number") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-interfacenumber'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "interfaceNumber", "interface-number",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt32()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-interface-number-bad-value').infoFunc(
                        ):
                    logFunc('interfaceNumber not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setInterfaceNumber(tempVar)
            for logFunc in self._log(
                    'read-tag-values-interface-number').debug3Func():
                logFunc(
                    'read interfaceNumber. interfaceNumber=%s, tempValue=%s',
                    self.interfaceNumber, tempValue.getType())

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 53
0
class BlinkyTimeoutsMaapi(TimeoutsMaapiBase):
    def __init__(self, logger):
        self.myInitGuard = InitGuard()
        self._log = logger.createLogger("sys-blinky-oper-example",
                                        "blinky-maapi-timeouts")
        self.domain = None

        self.activateRequested = False
        self.activate = None
        self.activateSet = False

        self.getStatusRequested = False
        self.getStatus = None
        self.getStatusSet = False

    def init(self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func():
            logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestActivate(True)

        self.requestGetStatus(True)

    def requestConfig(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func():
            logFunc('called, PARAMS')

        self.requestActivate(True)

        self.requestGetStatus(True)

    def requestOper(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func():
            logFunc('called, PARAMS')

        self.requestActivate(False)

        self.requestGetStatus(False)

    def clearAllRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func():
            logFunc('called, PARAMS')

        self.requestActivate(False)

        self.requestGetStatus(False)

    def clearAllSet(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func():
            logFunc('called, PARAMS')

        self.setActivate(None)
        self.activateSet = False

        self.setGetStatus(None)
        self.getStatusSet = False

    def write(self, disk, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func():
            logFunc('called, PARAMS')
        return self._internalWrite(disk, trxContext)

    def read(self, disk, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(disk, False, trxContext)

    def readAllOrFail(self, disk, trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func():
            logFunc('called, PARAMS')
        return self._internalRead(disk, True, trxContext)

    def requestActivate(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-activate').debug3Func():
            logFunc('called. requested=%s', requested)
        self.activateRequested = requested
        self.activateSet = False

    def isActivateRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-activate-requested').debug3Func():
            logFunc('called. requested=%s', self.activateRequested)
        return self.activateRequested

    def getActivate(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-activate').debug3Func():
            logFunc('called. self.activateSet=%s, self.activate=%s',
                    self.activateSet, self.activate)
        if self.activateSet:
            return self.activate
        return None

    def hasActivate(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-activate').debug3Func():
            logFunc('called. self.activateSet=%s, self.activate=%s',
                    self.activateSet, self.activate)
        if self.activateSet:
            return True
        return False

    def setActivate(self, activate):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-activate').debug3Func():
            logFunc('called. activate=%s, old=%s', activate, self.activate)
        self.activateSet = True
        self.activate = activate

    def requestGetStatus(self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-getstatus').debug3Func():
            logFunc('called. requested=%s', requested)
        self.getStatusRequested = requested
        self.getStatusSet = False

    def isGetStatusRequested(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-getstatus-requested').debug3Func():
            logFunc('called. requested=%s', self.getStatusRequested)
        return self.getStatusRequested

    def getGetStatus(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-getstatus').debug3Func():
            logFunc('called. self.getStatusSet=%s, self.getStatus=%s',
                    self.getStatusSet, self.getStatus)
        if self.getStatusSet:
            return self.getStatus
        return None

    def hasGetStatus(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-getstatus').debug3Func():
            logFunc('called. self.getStatusSet=%s, self.getStatus=%s',
                    self.getStatusSet, self.getStatus)
        if self.getStatusSet:
            return True
        return False

    def setGetStatus(self, getStatus):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-getstatus').debug3Func():
            logFunc('called. getStatus=%s, old=%s', getStatus, self.getStatus)
        self.getStatusSet = True
        self.getStatus = getStatus

    def _clearAllReadData(self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func():
            logFunc('called')

        self.activate = 0
        self.activateSet = False

        self.getStatus = 0
        self.getStatusSet = False

    def _getSelfKeyPath(self, disk, junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func():
            logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("timeouts",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk",
             "qt-strg-dsk"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("file-system",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk",
             "qt-strg-dsk"))
        keyPath.addKeyPathPrefix(xmlVal)

        ancestorVal = Value()
        ancestorVal.setString(disk)
        keyPath.addKeyPathPrefix(ancestorVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("disk",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk",
             "qt-strg-dsk"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("storage",
             "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage",
             "qt-strg"))
        keyPath.addKeyPathPrefix(xmlVal)

        xmlVal = Value()
        xmlVal.setXmlTag(
            ("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)

        for logFunc in self._log('get-self-key-path-done').debug3Func():
            logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite(self, disk, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func():
            logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-fill-write-tag-value-failed').errorFunc():
                logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(disk, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'write-collect-items-to-delete-failed').errorFunc():
                logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(disk, None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext,
                                     itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc():
                logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func():
            logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead(self, disk, readAllOrFail, trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func():
            logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-fill-read-tag-value-failed').errorFunc():
                logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(disk, None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc():
                logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log(
                    'read-read-tag-values-failed').errorFunc():
                logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func():
            logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete(self, disk, itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func():
            logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func():
            logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.hasActivate():
            valActivate = Value()
            if self.activate is not None:
                valActivate.setInt64(self.activate)
            else:
                valActivate.setEmpty()
            tagValueList.push(
                ("activate",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"
                 ), valActivate)

        if self.hasGetStatus():
            valGetStatus = Value()
            if self.getStatus is not None:
                valGetStatus.setInt64(self.getStatus)
            else:
                valGetStatus.setEmpty()
            tagValueList.push(
                ("get-status",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"
                 ), valGetStatus)

        return ReturnCodes.kOk

    def _fillReadTagValues(self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func():
            logFunc('called: tagValueList=%s', tagValueList)

        if self.isActivateRequested():
            valActivate = Value()
            valActivate.setEmpty()
            tagValueList.push(
                ("activate",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"
                 ), valActivate)

        if self.isGetStatusRequested():
            valGetStatus = Value()
            valGetStatus.setEmpty()
            tagValueList.push(
                ("get-status",
                 "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"
                 ), valGetStatus)

        return ReturnCodes.kOk

    def _readTagValues(self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func():
            logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func():
            logFunc('reading leaves. tagValueList=%s', tagValueList)

        if self.isActivateRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "activate") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-activate'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "activate", "activate",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-activate-bad-value').infoFunc():
                    logFunc('activate not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setActivate(tempVar)
            for logFunc in self._log('read-tag-values-activate').debug3Func():
                logFunc('read activate. activate=%s, tempValue=%s',
                        self.activate, tempValue.getType())

        if self.isGetStatusRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "get-status") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"):
                for logFunc in self._log(
                        'reag-tag-values-unexpected-tag-leaf-getstatus'
                ).errorFunc():
                    logFunc(
                        'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                        "getStatus", "get-status",
                        "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk",
                        tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asInt64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log(
                        'read-tag-values-get-status-bad-value').infoFunc():
                    logFunc('getStatus not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setGetStatus(tempVar)
            for logFunc in self._log(
                    'read-tag-values-get-status').debug3Func():
                logFunc('read getStatus. getStatus=%s, tempValue=%s',
                        self.getStatus, tempValue.getType())

        for logFunc in self._log('read-tag-values-done').debug3Func():
            logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail,
                    tagValueList)
        return ReturnCodes.kOk
Ejemplo n.º 54
0
class BlinkyHostMaapiList(HostMaapiListBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-host")
        self.domain = None

        self.hosts = {}
        self.hostKeys = []

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def newHost (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-host').debug3Func(): logFunc('called.')
        host = BlinkyHostMaapi(self._log)
        host.init(self.domain)
        return host

    def setHostObj (self, key, hostObj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-host-obj').debug3Func(): logFunc('called. key=%s, hostObj=%s', key, hostObj)
        if key not in self.hosts:
            self.hostKeys.append(key)
        self.hosts[str(key)] = hostObj

    def getHostObj (self, key):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-host-obj').debug3Func(): logFunc('called. key=%s', key)
        if str(key) in self.hosts.keys():
            for logFunc in self._log('get-host-obj-done').debug3Func(): logFunc('Done. found key=%s, obj=%s', key, self.hosts[str(key)])
            return self.hosts[str(key)]
        for logFunc in self._log('get-host-obj-missing').errorFunc(): logFunc('host %s not in hosts. existing items: %s', key, self.hosts.keys())
        return None

    def deleteHost (self, key):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('delete-host').debug3Func(): logFunc('called. key=%s', key)
        if str(key) not in self.hostKeys:
            for logFunc in self._log('delete-host-not-found').warningFunc(): logFunc('key=%s is missing from the hostKeys list', key)
            if str(key) in self.hosts.keys():
                # internal problem - list & dictionary are not synced
                for logFunc in self._log('delete-host-not-found-but-in-dict').errorFunc(): logFunc('hosts dictionary & hostKeys list are out-of-sync. key %s exists in dict but not in list', key)
            return ReturnCodes.kGeneralError
        if str(key) not in self.hosts.keys():
            # internal problem - list & dictionary are not synced
            for logFunc in self._log('delete-host-not-found-but-in-list').errorFunc(): logFunc('hosts dictionary & hostKeys list are out-of-sync. key %s exists in list but not in dict', key)
            return ReturnCodes.kGeneralError

        self.hostKeys.remove(str(key))
        del self.hosts[str(key)]

    def hasHostObj (self, key):
        self.myInitGuard.isInitOrCrash()
        has = False
        if str(key) in self.hosts.keys():
            if self.hosts[str(key)]:
                has = True
        for logFunc in self._log('has-host-done').debug3Func(): logFunc('done. key=%s exists=%s', key, has)
        return has

    def getListKeys (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-list-keys').debug3Func(): logFunc('called. keys=%s', [str(x) for x in self.hostKeys])
        return self.hostKeys

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called.')
        for host in self.hosts.values():
            host.requestConfigAndOper()

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called.')
        for host in self.hosts.values():
            host.requestConfig()

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called.')
        for host in self.hosts.values():
            host.requestOper()

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called.')
        for host in self.hosts.values():
            host.clearAllRequested()

    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')
        for host in self.hosts.values():
            if host:
                host._clearAllReadData()

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        for key in self.hosts.keys():
            if self.hosts[key]:
                self.hosts[key].clearAllSet()
            else:
                self.hostKeys.remove(str(key))
                del self.hosts[str(key)]

    def _getSelfKeyPath (self, ipv4
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS. junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()

        
        
        
        
        ancestorVal = Value()
        ancestorVal.setString(ipv4);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("ipv4", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system", "qt-sys"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("hosts", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system", "qt-sys"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("static", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system", "qt-sys"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("name-resolution", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system", "qt-sys"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("system", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system", "qt-sys"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def readListKeys (self
                      , ipv4
                      
                      , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-list-keys').debug3Func(): logFunc('called')

        # clear the old map
        self.hosts = {}
        self.hostKeys = []

        keyPath = self._getSelfKeyPath(ipv4, 
                                       
                                       None)

        xmlVal = Value()
        xmlVal.setXmlTag(("host", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system", "qt-sys"))
        keyPath.addKeyPathPostfix(xmlVal)

        keys = []

        res = self.domain.readMaapiKeys(keyPath, keys, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-list-keys-domain-failed').errorFunc(): logFunc('domain.readMaapiKeys() failed')
            return ReturnCodes.kGeneralError

        for key in keys:
            self.hostKeys.append(key.getCannonicalStr())
            self.hosts[key.getCannonicalStr()] = None

        return ReturnCodes.kOk

    def write (self
               , ipv4
               , trxContext=None
               ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(ipv4, 
                                   trxContext)

    def read (self
              , ipv4
              
              , trxContext=None):
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(ipv4, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , ipv4
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(ipv4, 
                                  True,
                                  trxContext)

    def _internalWrite (self, 
                        ipv4, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called.')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('internal-write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(ipv4, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(ipv4, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       ipv4, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('internal-read-fill-read-tag-values-failed').errorFunc(): logFunc('_fillReadTagValues() failed')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(ipv4, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('internal-read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed.')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('internal-read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed.')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               ipv4, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        for key in self.hosts.keys():
            if self.hosts[key]:
                res = self.hosts[key]._collectItemsToDelete(ipv4, 
                                                                     
                                                                     key,
                                                                     itemsToDelete)
                if res != ReturnCodes.kOk:
                    for logFunc in self._log('collect-items-to-delete-host-failed').errorFunc(): logFunc('hostObj._collectItemsToDelete() failed. key=%s. PARAMS', key)
                    return ReturnCodes.kGeneralError

            else:
                keyPath = self._getSelfKeyPath(ipv4, 
                                               
                                               None)
                xmlVal = Value()
                xmlVal.setXmlTag(("host", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system", "qt-sys"))
                keyPath.addKeyPathPostfix(xmlVal)
                valKey = Value()
                valKey.setString(key)
                keyPath.addKeyPathPostfix(valKey)

                itemsToDelete.append(keyPath)

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        for key in self.hosts.keys():
            if self.hosts[key]:
                valBegin = Value()
                (tag, ns, prefix) = ("host", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system", "qt-sys")
                valBegin.setXmlBegin((tag, ns, prefix))
                tagValueList.push((tag, ns), valBegin)

                valKey = Value()
                valKey.setString(key)
                tagValueList.push(("hostname", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system"), valKey)

                tagValueListLen = tagValueList.getLen()

                res = self.hosts[key]._fillWriteTagValues(tagValueList)
                if res != ReturnCodes.kOk:
                    for logFunc in self._log('fill-write-tag-values-host-failed').errorFunc(): logFunc('host._fillWriteTagValues() failed. key=%s', key)
                    return ReturnCodes.kGeneralError

                if tagValueList.getLen() == tagValueListLen:
                    # descendant didn't add anything, no need to read it.
                    tagValueList.pop()
                    tagValueList.pop()
                else:
                    valEnd = Value()
                    valEnd.setXmlEnd((tag, ns, prefix))
                    tagValueList.push((tag, ns), valEnd)

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        for key in self.hosts.keys():
            if self.hosts[key]:
                valBegin = Value()
                (tag, ns, prefix) = ("host", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system", "qt-sys")
                valBegin.setXmlBegin((tag, ns, prefix))
                tagValueList.push((tag, ns), valBegin)

                valKey = Value()
                valKey.setString(key)
                tagValueList.push(("hostname", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system"), valKey)

                tagValueListLen = tagValueList.getLen()

                res = self.hosts[key]._fillReadTagValues(tagValueList)
                if res != ReturnCodes.kOk:
                    for logFunc in self._log('fill-read-tag-values-host-failed').errorFunc(): logFunc('host._fillReadTagValues() failed. key=%s', key)
                    return ReturnCodes.kGeneralError

                if tagValueList.getLen() == tagValueListLen:
                    # descendant didn't add anything, no need to read it.
                    tagValueList.pop()
                    tagValueList.pop()
                else:
                    valEnd = Value()
                    valEnd.setXmlEnd((tag, ns, prefix))
                    tagValueList.push((tag, ns), valEnd)

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. tagValueList=%s, readAllOrFail=%s', tagValueList, readAllOrFail)

        res = ReturnCodes.kOk

        for key in self.hosts.keys():
            if self.hosts[key]:
                ((tag, ns), valBegin) = tagValueList.popFront()
                if (tag != "host") or \
                    (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system") or \
                    (valBegin.getType() != Value.kXmlBegin):
                    for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                            "host", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system", Value.kXmlBegin,
                                                                            tag, ns, valBegin.getType())
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError

                ((tag, ns), valKey) = tagValueList.popFront()
                if (tag != "hostname") or \
                    (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system"):
                    for logFunc in self._log('reag-tag-values-unexpected-tag-key').errorFunc(): logFunc('got unexpected tag-value for key. expected: (%s, %s), got: (%s, %s)',
                                                                          "hostname", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system", tag, ns)
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError

                key = valKey.asString()
                if res != ReturnCodes.kOk:
                    if readAllOrFail:
                        self._clearAllReadData()
                    return ReturnCodes.kGeneralError

                res = self.hosts[key]._readTagValues(tagValueList, readAllOrFail)
                if res != ReturnCodes.kOk:
                    for logFunc in self._log('read-tag-values-host-failed').errorFunc(): logFunc('host._readTagValues() failed. key=%s', key)
                    if readAllOrFail:
                        self._clearAllReadData()
                    return ReturnCodes.kGeneralError

                ((tag, ns), valEnd) = tagValueList.popFront()
                if (tag != "host") or \
                    (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system") or \
                    (valEnd.getType() != Value.kXmlEnd):
                    for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                          "host", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system", Value.kXmlEnd,
                                                                            tag, ns, valEnd.getType())
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. tagValueList=%s, readAllOrFail=%s', tagValueList, readAllOrFail)
        return ReturnCodes.kOk
Ejemplo n.º 55
0
class BlinkyExecutionMaapi(ExecutionMaapiBase):
    def __init__ (self, logger):
        self.myInitGuard = InitGuard()
        self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-execution")
        self.domain = None

        
        self.statusObj = None
        
        self.commandObj = None
        

        
        self.priorityRequested = False
        self.priority = None
        self.prioritySet = False
        
        self.umaskRequested = False
        self.umask = None
        self.umaskSet = False
        
        self.affinityRequested = False
        self.affinity = None
        self.affinitySet = False
        

    def init (self, domain):
        self.myInitGuard.crashIfInitDone()
        for logFunc in self._log('init').debug3Func(): logFunc('called. domain=%s', domain)
        self.domain = domain
        self.myInitGuard.initDone()

    def requestConfigAndOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestPriority(True)
        
        self.requestUmask(True)
        
        self.requestAffinity(True)
        
        
        
        if not self.statusObj:
            self.statusObj = self.newStatus()
            self.statusObj.requestConfigAndOper()
        
        if not self.commandObj:
            self.commandObj = self.newCommand()
            self.commandObj.requestConfigAndOper()
        

    def requestConfig (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS')
        
        self.requestPriority(True)
        
        self.requestUmask(True)
        
        self.requestAffinity(True)
        
        
        
        if not self.statusObj:
            self.statusObj = self.newStatus()
            self.statusObj.requestConfig()
        
        if not self.commandObj:
            self.commandObj = self.newCommand()
            self.commandObj.requestConfig()
        

    def requestOper (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS')
        
        self.requestPriority(False)
        
        self.requestUmask(False)
        
        self.requestAffinity(False)
        
        
        
        if not self.statusObj:
            self.statusObj = self.newStatus()
            self.statusObj.requestOper()
        
        if not self.commandObj:
            self.commandObj = self.newCommand()
            self.commandObj.requestOper()
        

    def clearAllRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS')
        
        self.requestPriority(False)
        
        self.requestUmask(False)
        
        self.requestAffinity(False)
        
        
        
        if not self.statusObj:
            self.statusObj = self.newStatus()
            self.statusObj.clearAllRequested()
        
        if not self.commandObj:
            self.commandObj = self.newCommand()
            self.commandObj.clearAllRequested()
        

    def clearAllSet (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS')
        
        self.setPriority(None)
        self.prioritySet = False
        
        self.setUmask(None)
        self.umaskSet = False
        
        self.setAffinity(None)
        self.affinitySet = False
        
        
        if self.statusObj:
            self.statusObj.clearAllSet()
        
        if self.commandObj:
            self.commandObj.clearAllSet()
        

    def write (self
              , process
              , trxContext=None
              ):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS')
        return self._internalWrite(process, trxContext)

    def read (self
              , process
              
              , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(process, 
                                  False,
                                  trxContext)

    def readAllOrFail (self
                       , process
                       
                       , trxContext=None):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS')
        return self._internalRead(process, 
                                  True,
                                  trxContext)

    def newStatus (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-status').debug3Func(): logFunc('called.')
        status = BlinkyStatusMaapi(self._log)
        status.init(self.domain)
        return status

    def setStatusObj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-status').debug3Func(): logFunc('called. obj=%s', obj)
        self.statusObj = obj

    def getStatusObj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-status').debug3Func(): logFunc('called. self.statusObj=%s', self.statusObj)
        return self.statusObj

    def hasStatus (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-status').debug3Func(): logFunc('called. self.statusObj=%s', self.statusObj)
        if self.statusObj:
            return True
        return False

    def newCommand (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('new-command').debug3Func(): logFunc('called.')
        command = BlinkyCommandMaapi(self._log)
        command.init(self.domain)
        return command

    def setCommandObj (self, obj):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-command').debug3Func(): logFunc('called. obj=%s', obj)
        self.commandObj = obj

    def getCommandObj (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-command').debug3Func(): logFunc('called. self.commandObj=%s', self.commandObj)
        return self.commandObj

    def hasCommand (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-command').debug3Func(): logFunc('called. self.commandObj=%s', self.commandObj)
        if self.commandObj:
            return True
        return False



    def requestPriority (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-priority').debug3Func(): logFunc('called. requested=%s', requested)
        self.priorityRequested = requested
        self.prioritySet = False

    def isPriorityRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-priority-requested').debug3Func(): logFunc('called. requested=%s', self.priorityRequested)
        return self.priorityRequested

    def getPriority (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-priority').debug3Func(): logFunc('called. self.prioritySet=%s, self.priority=%s', self.prioritySet, self.priority)
        if self.prioritySet:
            return self.priority
        return None

    def hasPriority (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-priority').debug3Func(): logFunc('called. self.prioritySet=%s, self.priority=%s', self.prioritySet, self.priority)
        if self.prioritySet:
            return True
        return False

    def setPriority (self, priority):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-priority').debug3Func(): logFunc('called. priority=%s, old=%s', priority, self.priority)
        self.prioritySet = True
        self.priority = priority

    def requestUmask (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-umask').debug3Func(): logFunc('called. requested=%s', requested)
        self.umaskRequested = requested
        self.umaskSet = False

    def isUmaskRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-umask-requested').debug3Func(): logFunc('called. requested=%s', self.umaskRequested)
        return self.umaskRequested

    def getUmask (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-umask').debug3Func(): logFunc('called. self.umaskSet=%s, self.umask=%s', self.umaskSet, self.umask)
        if self.umaskSet:
            return self.umask
        return None

    def hasUmask (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-umask').debug3Func(): logFunc('called. self.umaskSet=%s, self.umask=%s', self.umaskSet, self.umask)
        if self.umaskSet:
            return True
        return False

    def setUmask (self, umask):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-umask').debug3Func(): logFunc('called. umask=%s, old=%s', umask, self.umask)
        self.umaskSet = True
        self.umask = umask

    def requestAffinity (self, requested):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('request-affinity').debug3Func(): logFunc('called. requested=%s', requested)
        self.affinityRequested = requested
        self.affinitySet = False

    def isAffinityRequested (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('is-affinity-requested').debug3Func(): logFunc('called. requested=%s', self.affinityRequested)
        return self.affinityRequested

    def getAffinity (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('get-affinity').debug3Func(): logFunc('called. self.affinitySet=%s, self.affinity=%s', self.affinitySet, self.affinity)
        if self.affinitySet:
            return self.affinity
        return None

    def hasAffinity (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('has-affinity').debug3Func(): logFunc('called. self.affinitySet=%s, self.affinity=%s', self.affinitySet, self.affinity)
        if self.affinitySet:
            return True
        return False

    def setAffinity (self, affinity):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('set-affinity').debug3Func(): logFunc('called. affinity=%s, old=%s', affinity, self.affinity)
        self.affinitySet = True
        self.affinity = affinity


    def _clearAllReadData (self):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called')

        
        if self.statusObj:
            self.statusObj._clearAllReadData()
        
        if self.commandObj:
            self.commandObj._clearAllReadData()
        

        
        self.priority = 0
        self.prioritySet = False
        
        self.umask = 0
        self.umaskSet = False
        
        self.affinity = 0
        self.affinitySet = False
        

    def _getSelfKeyPath (self, process
                         
                         , junkForTemplate):
        for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate)
        keyPath = KeyPath()
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("execution", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process", "qt-proc"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        ancestorVal = Value()
        ancestorVal.setString(process);
        keyPath.addKeyPathPrefix(ancestorVal)
        
        xmlVal = Value()
        xmlVal.setXmlTag(("process", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process", "qt-proc"))
        keyPath.addKeyPathPrefix(xmlVal)
        
        
        xmlVal = Value()
        xmlVal.setXmlTag(("tech", "http://qwilt.com/ns/yang/device/tech/qwilt-tech", "qt"))
        keyPath.addKeyPathPrefix(xmlVal)
        

        for logFunc in self._log('get-self-key-path-done').debug3Func(): logFunc('done. keyPath=%s. PARAMS', keyPath)
        return keyPath

    def _internalWrite (self, 
                        process, 
                        
                        trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-write').debug3Func(): logFunc('called. PARAMS')

        tagValueList = TagValues()

        res = self._fillWriteTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-fill-write-tag-value-failed').errorFunc(): logFunc('_fillWriteTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        itemsToDelete = []
        res = self._collectItemsToDelete(process, 
                                         
                                         itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-collect-items-to-delete-failed').errorFunc(): logFunc('_collectItemsToDelete() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(process, 
                                       
                                       None)

        res = self.domain.writeMaapi(tagValueList, keyPath, trxContext, itemsToDelete)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('write-domain-failed').errorFunc(): logFunc('domain.writeMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-write-done').debug3Func(): logFunc('done. PARAMS')
        return ReturnCodes.kOk

    def _internalRead (self, 
                       process, 
                       
                       readAllOrFail,
                       trxContext):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('internal-read').debug3Func(): logFunc('called. PARAMS, readAllOrFail=%s', readAllOrFail)

        if readAllOrFail:
            self._clearAllReadData()

        tagValueList = TagValues()

        res = self._fillReadTagValues(tagValueList)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-fill-read-tag-value-failed').errorFunc(): logFunc('_fillReadTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        keyPath = self._getSelfKeyPath(process, 
                                       
                                       None)

        res = self.domain.readMaapi(tagValueList, keyPath, trxContext)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-domain-failed').errorFunc(): logFunc('domain.readMaapi() failed. PARAMS')
            return ReturnCodes.kGeneralError

        res = self._readTagValues(tagValueList, readAllOrFail)
        if res != ReturnCodes.kOk:
            for logFunc in self._log('read-read-tag-values-failed').errorFunc(): logFunc('_readTagValues() failed. PARAMS')
            return ReturnCodes.kGeneralError

        for logFunc in self._log('internal-read-done').debug3Func(): logFunc('done. PARAMS, readAllOrFail=%s', readAllOrFail)
        return ReturnCodes.kOk

    def _collectItemsToDelete (self,
                               process, 
                               
                               itemsToDelete):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete)

        
        if self.statusObj:
            res = self.statusObj._collectItemsToDelete(process, 
                                                                          
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-status-failed').errorFunc(): logFunc('statusObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        
        if self.commandObj:
            res = self.commandObj._collectItemsToDelete(process, 
                                                                          
                                                                          itemsToDelete)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('collect-items-to-delete-command-failed').errorFunc(): logFunc('commandObj._collectItemsToDelete() failed. PARAMS')
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('collect-items-to-delete-done').debug3Func(): logFunc('done: itemsToDelete=%s. PARAMS', itemsToDelete)
        return ReturnCodes.kOk

    def _fillWriteTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-write-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.hasPriority():
            valPriority = Value()
            if self.priority is not None:
                valPriority.setString(self.priority)
            else:
                valPriority.setEmpty()
            tagValueList.push(("priority", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"), valPriority)
        
        if self.hasUmask():
            valUmask = Value()
            if self.umask is not None:
                valUmask.setUint64(self.umask)
            else:
                valUmask.setEmpty()
            tagValueList.push(("umask", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"), valUmask)
        
        if self.hasAffinity():
            valAffinity = Value()
            if self.affinity is not None:
                valAffinity.setString(self.affinity)
            else:
                valAffinity.setEmpty()
            tagValueList.push(("affinity", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"), valAffinity)
        

        
        if self.statusObj:
            valBegin = Value()
            (tag, ns, prefix) = ("status" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process", "qt-proc")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.statusObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-status-failed').errorFunc(): logFunc('statusObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.commandObj:
            valBegin = Value()
            (tag, ns, prefix) = ("command" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process", "qt-proc")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.commandObj._fillWriteTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-write-tag-values-command-failed').errorFunc(): logFunc('commandObj._fillWriteTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _fillReadTagValues (self, tagValueList):
        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('fill-read-tag-values').debug3Func(): logFunc('called: tagValueList=%s', tagValueList)

        
        if self.isPriorityRequested():
            valPriority = Value()
            valPriority.setEmpty()
            tagValueList.push(("priority", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"), valPriority)
        
        if self.isUmaskRequested():
            valUmask = Value()
            valUmask.setEmpty()
            tagValueList.push(("umask", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"), valUmask)
        
        if self.isAffinityRequested():
            valAffinity = Value()
            valAffinity.setEmpty()
            tagValueList.push(("affinity", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"), valAffinity)
        

        
        if self.statusObj:
            valBegin = Value()
            (tag, ns, prefix) = ("status" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process", "qt-proc")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.statusObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-status-failed').errorFunc(): logFunc('statusObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        
        if self.commandObj:
            valBegin = Value()
            (tag, ns, prefix) = ("command" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process", "qt-proc")
            valBegin.setXmlBegin((tag, ns, prefix))
            tagValueList.push((tag, ns), valBegin)

            tagValueListLen = tagValueList.getLen()

            res = self.commandObj._fillReadTagValues(tagValueList)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('fill-read-tag-values-command-failed').errorFunc(): logFunc('commandObj._fillReadTagValues() failed. PARAMS')
                return ReturnCodes.kGeneralError

            if tagValueList.getLen() == tagValueListLen:
                # descendant didn't add anything, no need to read it.
                tagValueList.pop()
            else:
                valEnd = Value()
                valEnd.setXmlEnd((tag, ns, prefix))
                tagValueList.push((tag, ns), valEnd)
        

        return ReturnCodes.kOk

    def _readTagValues (self, tagValueList, readAllOrFail):
        __pychecker__ = 'maxlines=300'
        __pychecker__ = 'maxreturns=30'

        self.myInitGuard.isInitOrCrash()
        for logFunc in self._log('read-tag-values').debug3Func(): logFunc('called. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)

        res = ReturnCodes.kOk

        for logFunc in self._log('read-tag-values-leaves').debug3Func(): logFunc('reading leaves. tagValueList=%s', tagValueList)
        
        if self.isPriorityRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "priority") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-priority').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "priority", "priority", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-priority-bad-value').infoFunc(): logFunc('priority not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setPriority(tempVar)
            for logFunc in self._log('read-tag-values-priority').debug3Func(): logFunc('read priority. priority=%s, tempValue=%s', self.priority, tempValue.getType())
        
        if self.isUmaskRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "umask") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-umask').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "umask", "umask", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asUint64()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-umask-bad-value').infoFunc(): logFunc('umask not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setUmask(tempVar)
            for logFunc in self._log('read-tag-values-umask').debug3Func(): logFunc('read umask. umask=%s, tempValue=%s', self.umask, tempValue.getType())
        
        if self.isAffinityRequested():
            ((tag, ns), tempValue) = tagValueList.popFront()
            if (tag != "affinity") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"):
                for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-affinity').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)',
                                                                                                 "affinity", "affinity", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process", tag, ns)
                self._clearAllReadData()
                return ReturnCodes.kGeneralError

            tempVar = None
            tempVar = tempValue.asString()
            if res != ReturnCodes.kOk or tempVar is None:
                for logFunc in self._log('read-tag-values-affinity-bad-value').infoFunc(): logFunc('affinity not read')
                if readAllOrFail:
                    self._clearAllReadData()
                    return ReturnCodes.kGeneralError
            if tempVar is not None:
                self.setAffinity(tempVar)
            for logFunc in self._log('read-tag-values-affinity').debug3Func(): logFunc('read affinity. affinity=%s, tempValue=%s', self.affinity, tempValue.getType())
        

        
        if self.statusObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "status") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.statusObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-status-failed').errorFunc(): logFunc('statusObj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "status") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        
        if self.commandObj:
            ((tag, ns), valBegin) = tagValueList.popFront()
            if (tag != "command") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process") or \
                (valBegin.getType() != Value.kXmlBegin):
                for logFunc in self._log('reag-tag-values-unexpected-tag-begin').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                        "command", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process", Value.kXmlBegin,
                                                                        tag, ns, valBegin.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
            
            res = self.commandObj._readTagValues(tagValueList, readAllOrFail)
            if res != ReturnCodes.kOk:
                for logFunc in self._log('read-tag-values-command-failed').errorFunc(): logFunc('commandObj._readTagValues() failed. tagValueList=%s', tagValueList)
                if readAllOrFail:
                    self._clearAllReadData()
                return ReturnCodes.kGeneralError

            ((tag, ns), valEnd) = tagValueList.popFront()
            if (tag != "command") or \
                (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process") or \
                (valEnd.getType() != Value.kXmlEnd):
                for logFunc in self._log('reag-tag-values-unexpected-tag-end').errorFunc(): logFunc('got unexpected tag-value. expected: (%s, %s, type=%s), got: (%s, %s, type=%s)',
                                                                      "command", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process", Value.kXmlEnd,
                                                                        tag, ns, valEnd.getType())
                self._clearAllReadData()
                return ReturnCodes.kGeneralError
        

        for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList)
        return ReturnCodes.kOk