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
class BlinkyActualMaapi(ActualMaapiBase): def __init__(self, logger): self.myInitGuard = InitGuard() self._log = logger.createLogger("sys-blinky-oper-example", "blinky-maapi-actual") self.domain = None self.priorityRequested = False self.priority = None self.prioritySet = False self.affinityRequested = False self.affinity = None self.affinitySet = False self.commandLineRequested = False self.commandLine = None self.commandLineSet = 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.requestAffinity(True) self.requestCommandLine(True) def requestConfig(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestPriority(False) self.requestAffinity(False) self.requestCommandLine(False) def requestOper(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestPriority(True) self.requestAffinity(True) self.requestCommandLine(True) def clearAllRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestPriority(False) self.requestAffinity(False) self.requestCommandLine(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 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 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 requestCommandLine(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-commandline').debug3Func(): logFunc('called. requested=%s', requested) self.commandLineRequested = requested self.commandLineSet = False def isCommandLineRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-commandline-requested').debug3Func(): logFunc('called. requested=%s', self.commandLineRequested) return self.commandLineRequested def getCommandLine(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-commandline').debug3Func(): logFunc('called. self.commandLineSet=%s, self.commandLine=%s', self.commandLineSet, self.commandLine) if self.commandLineSet: return self.commandLine return None def hasCommandLine(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-commandline').debug3Func(): logFunc('called. self.commandLineSet=%s, self.commandLine=%s', self.commandLineSet, self.commandLine) if self.commandLineSet: return True return False def setCommandLine(self, commandLine): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-commandline').debug3Func(): logFunc('called. commandLine=%s, old=%s', commandLine, self.commandLine) self.commandLineSet = True self.commandLine = commandLine def _clearAllReadData(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.priority = 0 self.prioritySet = False self.affinity = 0 self.affinitySet = False self.commandLine = 0 self.commandLineSet = 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( ("actual", "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.isPriorityRequested(): valPriority = Value() valPriority.setEmpty() tagValueList.push( ("priority", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"), valPriority) if self.isAffinityRequested(): valAffinity = Value() valAffinity.setEmpty() tagValueList.push( ("affinity", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"), valAffinity) if self.isCommandLineRequested(): valCommandLine = Value() valCommandLine.setEmpty() tagValueList.push( ("command-line", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"), valCommandLine) 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.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.isCommandLineRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "command-line") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-process"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-commandline' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "commandLine", "command-line", "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-command-line-bad-value').infoFunc(): logFunc('commandLine not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setCommandLine(tempVar) for logFunc in self._log( 'read-tag-values-command-line').debug3Func(): logFunc('read commandLine. commandLine=%s, tempValue=%s', self.commandLine, tempValue.getType()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
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
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
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
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
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
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
class BlinkyFormatMaapi(FormatMaapiBase): def __init__(self, logger): self.myInitGuard = InitGuard() self._log = logger.createLogger("sys-blinky-oper-example", "blinky-maapi-format") self.domain = None self.messageExtraRequested = False self.messageExtra = None self.messageExtraSet = False self.messageBaseRequested = False self.messageBase = None self.messageBaseSet = False self.payloadRequested = False self.payload = None self.payloadSet = 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.requestMessageExtra(True) self.requestMessageBase(True) self.requestPayload(True) def requestConfig(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestMessageExtra(True) self.requestMessageBase(True) self.requestPayload(True) def requestOper(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestMessageExtra(False) self.requestMessageBase(False) self.requestPayload(False) def clearAllRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestMessageExtra(False) self.requestMessageBase(False) self.requestPayload(False) def clearAllSet(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') self.setMessageExtra(None) self.messageExtraSet = False self.setMessageBase(None) self.messageBaseSet = False self.setPayload(None) self.payloadSet = 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 requestMessageExtra(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-messageextra').debug3Func(): logFunc('called. requested=%s', requested) self.messageExtraRequested = requested self.messageExtraSet = False def isMessageExtraRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-messageextra-requested').debug3Func(): logFunc('called. requested=%s', self.messageExtraRequested) return self.messageExtraRequested def getMessageExtra(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-messageextra').debug3Func(): logFunc('called. self.messageExtraSet=%s, self.messageExtra=%s', self.messageExtraSet, self.messageExtra) if self.messageExtraSet: return self.messageExtra return None def hasMessageExtra(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-messageextra').debug3Func(): logFunc('called. self.messageExtraSet=%s, self.messageExtra=%s', self.messageExtraSet, self.messageExtra) if self.messageExtraSet: return True return False def setMessageExtra(self, messageExtra): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-messageextra').debug3Func(): logFunc('called. messageExtra=%s, old=%s', messageExtra, self.messageExtra) self.messageExtraSet = True self.messageExtra = messageExtra def requestMessageBase(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-messagebase').debug3Func(): logFunc('called. requested=%s', requested) self.messageBaseRequested = requested self.messageBaseSet = False def isMessageBaseRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-messagebase-requested').debug3Func(): logFunc('called. requested=%s', self.messageBaseRequested) return self.messageBaseRequested def getMessageBase(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-messagebase').debug3Func(): logFunc('called. self.messageBaseSet=%s, self.messageBase=%s', self.messageBaseSet, self.messageBase) if self.messageBaseSet: return self.messageBase return None def hasMessageBase(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-messagebase').debug3Func(): logFunc('called. self.messageBaseSet=%s, self.messageBase=%s', self.messageBaseSet, self.messageBase) if self.messageBaseSet: return True return False def setMessageBase(self, messageBase): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-messagebase').debug3Func(): logFunc('called. messageBase=%s, old=%s', messageBase, self.messageBase) self.messageBaseSet = True self.messageBase = messageBase def requestPayload(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-payload').debug3Func(): logFunc('called. requested=%s', requested) self.payloadRequested = requested self.payloadSet = False def isPayloadRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-payload-requested').debug3Func(): logFunc('called. requested=%s', self.payloadRequested) return self.payloadRequested def getPayload(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-payload').debug3Func(): logFunc('called. self.payloadSet=%s, self.payload=%s', self.payloadSet, self.payload) if self.payloadSet: return self.payload return None def hasPayload(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-payload').debug3Func(): logFunc('called. self.payloadSet=%s, self.payload=%s', self.payloadSet, self.payload) if self.payloadSet: return True return False def setPayload(self, payload): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-payload').debug3Func(): logFunc('called. payload=%s, old=%s', payload, self.payload) self.payloadSet = True self.payload = payload def _clearAllReadData(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.messageExtra = 0 self.messageExtraSet = False self.messageBase = 0 self.messageBaseSet = False self.payload = 0 self.payloadSet = 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( ("format", "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.hasMessageExtra(): valMessageExtra = Value() if self.messageExtra is not None: valMessageExtra.setString(self.messageExtra) else: valMessageExtra.setEmpty() tagValueList.push( ("message-extra", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valMessageExtra) if self.hasMessageBase(): valMessageBase = Value() if self.messageBase is not None: valMessageBase.setString(self.messageBase) else: valMessageBase.setEmpty() tagValueList.push( ("message-base", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valMessageBase) if self.hasPayload(): valPayload = Value() if self.payload is not None: valPayload.setString(self.payload) else: valPayload.setEmpty() tagValueList.push( ("payload", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valPayload) 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.isMessageExtraRequested(): valMessageExtra = Value() valMessageExtra.setEmpty() tagValueList.push( ("message-extra", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valMessageExtra) if self.isMessageBaseRequested(): valMessageBase = Value() valMessageBase.setEmpty() tagValueList.push( ("message-base", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valMessageBase) if self.isPayloadRequested(): valPayload = Value() valPayload.setEmpty() tagValueList.push( ("payload", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valPayload) 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.isMessageExtraRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "message-extra") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-messageextra' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "messageExtra", "message-extra", "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-message-extra-bad-value').infoFunc(): logFunc('messageExtra not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setMessageExtra(tempVar) for logFunc in self._log( 'read-tag-values-message-extra').debug3Func(): logFunc('read messageExtra. messageExtra=%s, tempValue=%s', self.messageExtra, tempValue.getType()) if self.isMessageBaseRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "message-base") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-messagebase' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "messageBase", "message-base", "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-message-base-bad-value').infoFunc(): logFunc('messageBase not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setMessageBase(tempVar) for logFunc in self._log( 'read-tag-values-message-base').debug3Func(): logFunc('read messageBase. messageBase=%s, tempValue=%s', self.messageBase, tempValue.getType()) if self.isPayloadRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "payload") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-payload' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "payload", "payload", "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-payload-bad-value').infoFunc(): logFunc('payload not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setPayload(tempVar) for logFunc in self._log('read-tag-values-payload').debug3Func(): logFunc('read payload. payload=%s, tempValue=%s', self.payload, tempValue.getType()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
class BlinkyPhysicalMaapi(PhysicalMaapiBase): def __init__(self, logger): self.myInitGuard = InitGuard() self._log = logger.createLogger("sys-blinky-oper-example", "blinky-maapi-physical") self.domain = None self.implementationRequested = False self.implementation = None self.implementationSet = False self.controllerRequested = False self.controller = None self.controllerSet = False self.idRequested = False self.id = None self.idSet = 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.requestImplementation(True) self.requestController(True) self.requestId(True) def requestConfig(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestImplementation(True) self.requestController(True) self.requestId(True) def requestOper(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestImplementation(False) self.requestController(False) self.requestId(False) def clearAllRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestImplementation(False) self.requestController(False) self.requestId(False) def clearAllSet(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') self.setImplementation(None) self.implementationSet = False self.setController(None) self.controllerSet = False self.setId(None) self.idSet = 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 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 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 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 _clearAllReadData(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.implementation = 0 self.implementationSet = False self.controller = 0 self.controllerSet = False self.id = 0 self.idSet = 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( ("physical", "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.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.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-disk" ), valController) 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-storage-disk" ), valId) 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.isImplementationRequested(): valImplementation = Value() valImplementation.setEmpty() tagValueList.push( ("implementation", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk" ), valImplementation) if self.isControllerRequested(): valController = Value() valController.setEmpty() tagValueList.push( ("controller", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk" ), valController) if self.isIdRequested(): valId = Value() valId.setEmpty() tagValueList.push( ("id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk" ), valId) 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.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.isControllerRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "controller") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"): 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-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-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.isIdRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "id") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk"): 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-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-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()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
class BlinkyAaaMaapi(AaaMaapiBase): def __init__(self, logger): self.myInitGuard = InitGuard() self._log = logger.createLogger("sys-blinky-oper-example", "blinky-maapi-aaa") self.domain = None self.a1int64Requested = False self.a1int64 = None self.a1int64Set = False self.a8strRequested = False self.a8str = None self.a8strSet = False self.a5strRequested = False self.a5str = None self.a5strSet = False self.a3strRequested = False self.a3str = None self.a3strSet = False self.a6strRequested = False self.a6str = None self.a6strSet = False self.a2strRequested = False self.a2str = None self.a2strSet = False self.a4strRequested = False self.a4str = None self.a4strSet = False self.a7strRequested = False self.a7str = None self.a7strSet = False self.a9strRequested = False self.a9str = None self.a9strSet = 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.requestA1int64(True) self.requestA8str(True) self.requestA5str(True) self.requestA3str(True) self.requestA6str(True) self.requestA2str(True) self.requestA4str(True) self.requestA7str(True) self.requestA9str(True) def requestConfig(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestA1int64(True) self.requestA8str(True) self.requestA5str(True) self.requestA3str(True) self.requestA6str(True) self.requestA2str(True) self.requestA4str(True) self.requestA7str(True) self.requestA9str(True) def requestOper(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestA1int64(False) self.requestA8str(False) self.requestA5str(False) self.requestA3str(False) self.requestA6str(False) self.requestA2str(False) self.requestA4str(False) self.requestA7str(False) self.requestA9str(False) def clearAllRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestA1int64(False) self.requestA8str(False) self.requestA5str(False) self.requestA3str(False) self.requestA6str(False) self.requestA2str(False) self.requestA4str(False) self.requestA7str(False) self.requestA9str(False) def clearAllSet(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') self.setA1int64(None) self.a1int64Set = False self.setA8str(None) self.a8strSet = False self.setA5str(None) self.a5strSet = False self.setA3str(None) self.a3strSet = False self.setA6str(None) self.a6strSet = False self.setA2str(None) self.a2strSet = False self.setA4str(None) self.a4strSet = False self.setA7str(None) self.a7strSet = False self.setA9str(None) self.a9strSet = 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 requestA1int64(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-a1int64').debug3Func(): logFunc('called. requested=%s', requested) self.a1int64Requested = requested self.a1int64Set = False def isA1int64Requested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-a1int64-requested').debug3Func(): logFunc('called. requested=%s', self.a1int64Requested) return self.a1int64Requested def getA1int64(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-a1int64').debug3Func(): logFunc('called. self.a1int64Set=%s, self.a1int64=%s', self.a1int64Set, self.a1int64) if self.a1int64Set: return self.a1int64 return None def hasA1int64(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-a1int64').debug3Func(): logFunc('called. self.a1int64Set=%s, self.a1int64=%s', self.a1int64Set, self.a1int64) if self.a1int64Set: return True return False def setA1int64(self, a1int64): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-a1int64').debug3Func(): logFunc('called. a1int64=%s, old=%s', a1int64, self.a1int64) self.a1int64Set = True self.a1int64 = a1int64 def requestA8str(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-a8str').debug3Func(): logFunc('called. requested=%s', requested) self.a8strRequested = requested self.a8strSet = False def isA8strRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-a8str-requested').debug3Func(): logFunc('called. requested=%s', self.a8strRequested) return self.a8strRequested def getA8str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-a8str').debug3Func(): logFunc('called. self.a8strSet=%s, self.a8str=%s', self.a8strSet, self.a8str) if self.a8strSet: return self.a8str return None def hasA8str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-a8str').debug3Func(): logFunc('called. self.a8strSet=%s, self.a8str=%s', self.a8strSet, self.a8str) if self.a8strSet: return True return False def setA8str(self, a8str): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-a8str').debug3Func(): logFunc('called. a8str=%s, old=%s', a8str, self.a8str) self.a8strSet = True self.a8str = a8str def requestA5str(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-a5str').debug3Func(): logFunc('called. requested=%s', requested) self.a5strRequested = requested self.a5strSet = False def isA5strRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-a5str-requested').debug3Func(): logFunc('called. requested=%s', self.a5strRequested) return self.a5strRequested def getA5str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-a5str').debug3Func(): logFunc('called. self.a5strSet=%s, self.a5str=%s', self.a5strSet, self.a5str) if self.a5strSet: return self.a5str return None def hasA5str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-a5str').debug3Func(): logFunc('called. self.a5strSet=%s, self.a5str=%s', self.a5strSet, self.a5str) if self.a5strSet: return True return False def setA5str(self, a5str): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-a5str').debug3Func(): logFunc('called. a5str=%s, old=%s', a5str, self.a5str) self.a5strSet = True self.a5str = a5str def requestA3str(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-a3str').debug3Func(): logFunc('called. requested=%s', requested) self.a3strRequested = requested self.a3strSet = False def isA3strRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-a3str-requested').debug3Func(): logFunc('called. requested=%s', self.a3strRequested) return self.a3strRequested def getA3str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-a3str').debug3Func(): logFunc('called. self.a3strSet=%s, self.a3str=%s', self.a3strSet, self.a3str) if self.a3strSet: return self.a3str return None def hasA3str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-a3str').debug3Func(): logFunc('called. self.a3strSet=%s, self.a3str=%s', self.a3strSet, self.a3str) if self.a3strSet: return True return False def setA3str(self, a3str): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-a3str').debug3Func(): logFunc('called. a3str=%s, old=%s', a3str, self.a3str) self.a3strSet = True self.a3str = a3str def requestA6str(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-a6str').debug3Func(): logFunc('called. requested=%s', requested) self.a6strRequested = requested self.a6strSet = False def isA6strRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-a6str-requested').debug3Func(): logFunc('called. requested=%s', self.a6strRequested) return self.a6strRequested def getA6str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-a6str').debug3Func(): logFunc('called. self.a6strSet=%s, self.a6str=%s', self.a6strSet, self.a6str) if self.a6strSet: return self.a6str return None def hasA6str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-a6str').debug3Func(): logFunc('called. self.a6strSet=%s, self.a6str=%s', self.a6strSet, self.a6str) if self.a6strSet: return True return False def setA6str(self, a6str): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-a6str').debug3Func(): logFunc('called. a6str=%s, old=%s', a6str, self.a6str) self.a6strSet = True self.a6str = a6str def requestA2str(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-a2str').debug3Func(): logFunc('called. requested=%s', requested) self.a2strRequested = requested self.a2strSet = False def isA2strRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-a2str-requested').debug3Func(): logFunc('called. requested=%s', self.a2strRequested) return self.a2strRequested def getA2str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-a2str').debug3Func(): logFunc('called. self.a2strSet=%s, self.a2str=%s', self.a2strSet, self.a2str) if self.a2strSet: return self.a2str return None def hasA2str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-a2str').debug3Func(): logFunc('called. self.a2strSet=%s, self.a2str=%s', self.a2strSet, self.a2str) if self.a2strSet: return True return False def setA2str(self, a2str): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-a2str').debug3Func(): logFunc('called. a2str=%s, old=%s', a2str, self.a2str) self.a2strSet = True self.a2str = a2str def requestA4str(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-a4str').debug3Func(): logFunc('called. requested=%s', requested) self.a4strRequested = requested self.a4strSet = False def isA4strRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-a4str-requested').debug3Func(): logFunc('called. requested=%s', self.a4strRequested) return self.a4strRequested def getA4str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-a4str').debug3Func(): logFunc('called. self.a4strSet=%s, self.a4str=%s', self.a4strSet, self.a4str) if self.a4strSet: return self.a4str return None def hasA4str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-a4str').debug3Func(): logFunc('called. self.a4strSet=%s, self.a4str=%s', self.a4strSet, self.a4str) if self.a4strSet: return True return False def setA4str(self, a4str): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-a4str').debug3Func(): logFunc('called. a4str=%s, old=%s', a4str, self.a4str) self.a4strSet = True self.a4str = a4str def requestA7str(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-a7str').debug3Func(): logFunc('called. requested=%s', requested) self.a7strRequested = requested self.a7strSet = False def isA7strRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-a7str-requested').debug3Func(): logFunc('called. requested=%s', self.a7strRequested) return self.a7strRequested def getA7str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-a7str').debug3Func(): logFunc('called. self.a7strSet=%s, self.a7str=%s', self.a7strSet, self.a7str) if self.a7strSet: return self.a7str return None def hasA7str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-a7str').debug3Func(): logFunc('called. self.a7strSet=%s, self.a7str=%s', self.a7strSet, self.a7str) if self.a7strSet: return True return False def setA7str(self, a7str): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-a7str').debug3Func(): logFunc('called. a7str=%s, old=%s', a7str, self.a7str) self.a7strSet = True self.a7str = a7str def requestA9str(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-a9str').debug3Func(): logFunc('called. requested=%s', requested) self.a9strRequested = requested self.a9strSet = False def isA9strRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-a9str-requested').debug3Func(): logFunc('called. requested=%s', self.a9strRequested) return self.a9strRequested def getA9str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-a9str').debug3Func(): logFunc('called. self.a9strSet=%s, self.a9str=%s', self.a9strSet, self.a9str) if self.a9strSet: return self.a9str return None def hasA9str(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-a9str').debug3Func(): logFunc('called. self.a9strSet=%s, self.a9str=%s', self.a9strSet, self.a9str) if self.a9strSet: return True return False def setA9str(self, a9str): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-a9str').debug3Func(): logFunc('called. a9str=%s, old=%s', a9str, self.a9str) self.a9strSet = True self.a9str = a9str def _clearAllReadData(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.a1int64 = 0 self.a1int64Set = False self.a8str = 0 self.a8strSet = False self.a5str = 0 self.a5strSet = False self.a3str = 0 self.a3strSet = False self.a6str = 0 self.a6strSet = False self.a2str = 0 self.a2strSet = False self.a4str = 0 self.a4strSet = False self.a7str = 0 self.a7strSet = False self.a9str = 0 self.a9strSet = 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(("aaa", "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.hasA1int64(): valA1int64 = Value() if self.a1int64 is not None: valA1int64.setInt64(self.a1int64) else: valA1int64.setEmpty() tagValueList.push(("a1int64", "http://qwilt.com/model/benchmark"), valA1int64) if self.hasA8str(): valA8str = Value() if self.a8str is not None: valA8str.setString(self.a8str) else: valA8str.setEmpty() tagValueList.push(("a8str", "http://qwilt.com/model/benchmark"), valA8str) if self.hasA5str(): valA5str = Value() if self.a5str is not None: valA5str.setString(self.a5str) else: valA5str.setEmpty() tagValueList.push(("a5str", "http://qwilt.com/model/benchmark"), valA5str) if self.hasA3str(): valA3str = Value() if self.a3str is not None: valA3str.setString(self.a3str) else: valA3str.setEmpty() tagValueList.push(("a3str", "http://qwilt.com/model/benchmark"), valA3str) if self.hasA6str(): valA6str = Value() if self.a6str is not None: valA6str.setString(self.a6str) else: valA6str.setEmpty() tagValueList.push(("a6str", "http://qwilt.com/model/benchmark"), valA6str) if self.hasA2str(): valA2str = Value() if self.a2str is not None: valA2str.setString(self.a2str) else: valA2str.setEmpty() tagValueList.push(("a2str", "http://qwilt.com/model/benchmark"), valA2str) if self.hasA4str(): valA4str = Value() if self.a4str is not None: valA4str.setString(self.a4str) else: valA4str.setEmpty() tagValueList.push(("a4str", "http://qwilt.com/model/benchmark"), valA4str) if self.hasA7str(): valA7str = Value() if self.a7str is not None: valA7str.setString(self.a7str) else: valA7str.setEmpty() tagValueList.push(("a7str", "http://qwilt.com/model/benchmark"), valA7str) if self.hasA9str(): valA9str = Value() if self.a9str is not None: valA9str.setString(self.a9str) else: valA9str.setEmpty() tagValueList.push(("a9str", "http://qwilt.com/model/benchmark"), valA9str) 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.isA1int64Requested(): valA1int64 = Value() valA1int64.setEmpty() tagValueList.push(("a1int64", "http://qwilt.com/model/benchmark"), valA1int64) if self.isA8strRequested(): valA8str = Value() valA8str.setEmpty() tagValueList.push(("a8str", "http://qwilt.com/model/benchmark"), valA8str) if self.isA5strRequested(): valA5str = Value() valA5str.setEmpty() tagValueList.push(("a5str", "http://qwilt.com/model/benchmark"), valA5str) if self.isA3strRequested(): valA3str = Value() valA3str.setEmpty() tagValueList.push(("a3str", "http://qwilt.com/model/benchmark"), valA3str) if self.isA6strRequested(): valA6str = Value() valA6str.setEmpty() tagValueList.push(("a6str", "http://qwilt.com/model/benchmark"), valA6str) if self.isA2strRequested(): valA2str = Value() valA2str.setEmpty() tagValueList.push(("a2str", "http://qwilt.com/model/benchmark"), valA2str) if self.isA4strRequested(): valA4str = Value() valA4str.setEmpty() tagValueList.push(("a4str", "http://qwilt.com/model/benchmark"), valA4str) if self.isA7strRequested(): valA7str = Value() valA7str.setEmpty() tagValueList.push(("a7str", "http://qwilt.com/model/benchmark"), valA7str) if self.isA9strRequested(): valA9str = Value() valA9str.setEmpty() tagValueList.push(("a9str", "http://qwilt.com/model/benchmark"), valA9str) 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.isA1int64Requested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "a1int64") or \ (ns != "http://qwilt.com/model/benchmark"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-a1int64' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "a1int64", "a1int64", "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-a1int64-bad-value').infoFunc(): logFunc('a1int64 not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setA1int64(tempVar) for logFunc in self._log('read-tag-values-a1int64').debug3Func(): logFunc('read a1int64. a1int64=%s, tempValue=%s', self.a1int64, tempValue.getType()) if self.isA8strRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "a8str") or \ (ns != "http://qwilt.com/model/benchmark"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-a8str').errorFunc( ): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "a8str", "a8str", "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-a8str-bad-value').infoFunc(): logFunc('a8str not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setA8str(tempVar) for logFunc in self._log('read-tag-values-a8str').debug3Func(): logFunc('read a8str. a8str=%s, tempValue=%s', self.a8str, tempValue.getType()) if self.isA5strRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "a5str") or \ (ns != "http://qwilt.com/model/benchmark"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-a5str').errorFunc( ): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "a5str", "a5str", "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-a5str-bad-value').infoFunc(): logFunc('a5str not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setA5str(tempVar) for logFunc in self._log('read-tag-values-a5str').debug3Func(): logFunc('read a5str. a5str=%s, tempValue=%s', self.a5str, tempValue.getType()) if self.isA3strRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "a3str") or \ (ns != "http://qwilt.com/model/benchmark"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-a3str').errorFunc( ): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "a3str", "a3str", "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-a3str-bad-value').infoFunc(): logFunc('a3str not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setA3str(tempVar) for logFunc in self._log('read-tag-values-a3str').debug3Func(): logFunc('read a3str. a3str=%s, tempValue=%s', self.a3str, tempValue.getType()) if self.isA6strRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "a6str") or \ (ns != "http://qwilt.com/model/benchmark"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-a6str').errorFunc( ): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "a6str", "a6str", "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-a6str-bad-value').infoFunc(): logFunc('a6str not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setA6str(tempVar) for logFunc in self._log('read-tag-values-a6str').debug3Func(): logFunc('read a6str. a6str=%s, tempValue=%s', self.a6str, tempValue.getType()) if self.isA2strRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "a2str") or \ (ns != "http://qwilt.com/model/benchmark"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-a2str').errorFunc( ): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "a2str", "a2str", "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-a2str-bad-value').infoFunc(): logFunc('a2str not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setA2str(tempVar) for logFunc in self._log('read-tag-values-a2str').debug3Func(): logFunc('read a2str. a2str=%s, tempValue=%s', self.a2str, tempValue.getType()) if self.isA4strRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "a4str") or \ (ns != "http://qwilt.com/model/benchmark"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-a4str').errorFunc( ): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "a4str", "a4str", "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-a4str-bad-value').infoFunc(): logFunc('a4str not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setA4str(tempVar) for logFunc in self._log('read-tag-values-a4str').debug3Func(): logFunc('read a4str. a4str=%s, tempValue=%s', self.a4str, tempValue.getType()) if self.isA7strRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "a7str") or \ (ns != "http://qwilt.com/model/benchmark"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-a7str').errorFunc( ): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "a7str", "a7str", "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-a7str-bad-value').infoFunc(): logFunc('a7str not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setA7str(tempVar) for logFunc in self._log('read-tag-values-a7str').debug3Func(): logFunc('read a7str. a7str=%s, tempValue=%s', self.a7str, tempValue.getType()) if self.isA9strRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "a9str") or \ (ns != "http://qwilt.com/model/benchmark"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-a9str').errorFunc( ): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "a9str", "a9str", "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-a9str-bad-value').infoFunc(): logFunc('a9str not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setA9str(tempVar) for logFunc in self._log('read-tag-values-a9str').debug3Func(): logFunc('read a9str. a9str=%s, tempValue=%s', self.a9str, tempValue.getType()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
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.localTimeStringRequested = False self.localTimeString = None self.localTimeStringSet = False self.utcTimeStringRequested = False self.utcTimeString = None self.utcTimeStringSet = False self.daylightSavingTimeRequested = False self.daylightSavingTime = None self.daylightSavingTimeSet = False self.epochRequested = False self.epoch = None self.epochSet = False self.utcOffsetMinutesRequested = False self.utcOffsetMinutes = None self.utcOffsetMinutesSet = 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.requestLocalTimeString(True) self.requestUtcTimeString(True) self.requestDaylightSavingTime(True) self.requestEpoch(True) self.requestUtcOffsetMinutes(True) def requestConfig(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestLocalTimeString(False) self.requestUtcTimeString(False) self.requestDaylightSavingTime(False) self.requestEpoch(False) self.requestUtcOffsetMinutes(False) def requestOper(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestLocalTimeString(True) self.requestUtcTimeString(True) self.requestDaylightSavingTime(True) self.requestEpoch(True) self.requestUtcOffsetMinutes(True) def clearAllRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestLocalTimeString(False) self.requestUtcTimeString(False) self.requestDaylightSavingTime(False) self.requestEpoch(False) self.requestUtcOffsetMinutes(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 requestLocalTimeString(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-localtimestring').debug3Func(): logFunc('called. requested=%s', requested) self.localTimeStringRequested = requested self.localTimeStringSet = False def isLocalTimeStringRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-localtimestring-requested').debug3Func(): logFunc('called. requested=%s', self.localTimeStringRequested) return self.localTimeStringRequested def getLocalTimeString(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-localtimestring').debug3Func(): logFunc( 'called. self.localTimeStringSet=%s, self.localTimeString=%s', self.localTimeStringSet, self.localTimeString) if self.localTimeStringSet: return self.localTimeString return None def hasLocalTimeString(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-localtimestring').debug3Func(): logFunc( 'called. self.localTimeStringSet=%s, self.localTimeString=%s', self.localTimeStringSet, self.localTimeString) if self.localTimeStringSet: return True return False def setLocalTimeString(self, localTimeString): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-localtimestring').debug3Func(): logFunc('called. localTimeString=%s, old=%s', localTimeString, self.localTimeString) self.localTimeStringSet = True self.localTimeString = localTimeString def requestUtcTimeString(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-utctimestring').debug3Func(): logFunc('called. requested=%s', requested) self.utcTimeStringRequested = requested self.utcTimeStringSet = False def isUtcTimeStringRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-utctimestring-requested').debug3Func(): logFunc('called. requested=%s', self.utcTimeStringRequested) return self.utcTimeStringRequested def getUtcTimeString(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-utctimestring').debug3Func(): logFunc('called. self.utcTimeStringSet=%s, self.utcTimeString=%s', self.utcTimeStringSet, self.utcTimeString) if self.utcTimeStringSet: return self.utcTimeString return None def hasUtcTimeString(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-utctimestring').debug3Func(): logFunc('called. self.utcTimeStringSet=%s, self.utcTimeString=%s', self.utcTimeStringSet, self.utcTimeString) if self.utcTimeStringSet: return True return False def setUtcTimeString(self, utcTimeString): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-utctimestring').debug3Func(): logFunc('called. utcTimeString=%s, old=%s', utcTimeString, self.utcTimeString) self.utcTimeStringSet = True self.utcTimeString = utcTimeString def requestDaylightSavingTime(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-daylightsavingtime').debug3Func(): logFunc('called. requested=%s', requested) self.daylightSavingTimeRequested = requested self.daylightSavingTimeSet = False def isDaylightSavingTimeRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log( 'is-daylightsavingtime-requested').debug3Func(): logFunc('called. requested=%s', self.daylightSavingTimeRequested) return self.daylightSavingTimeRequested def getDaylightSavingTime(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-daylightsavingtime').debug3Func(): logFunc( 'called. self.daylightSavingTimeSet=%s, self.daylightSavingTime=%s', self.daylightSavingTimeSet, self.daylightSavingTime) if self.daylightSavingTimeSet: return self.daylightSavingTime return None def hasDaylightSavingTime(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-daylightsavingtime').debug3Func(): logFunc( 'called. self.daylightSavingTimeSet=%s, self.daylightSavingTime=%s', self.daylightSavingTimeSet, self.daylightSavingTime) if self.daylightSavingTimeSet: return True return False def setDaylightSavingTime(self, daylightSavingTime): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-daylightsavingtime').debug3Func(): logFunc('called. daylightSavingTime=%s, old=%s', daylightSavingTime, self.daylightSavingTime) self.daylightSavingTimeSet = True self.daylightSavingTime = daylightSavingTime def requestEpoch(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-epoch').debug3Func(): logFunc('called. requested=%s', requested) self.epochRequested = requested self.epochSet = False def isEpochRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-epoch-requested').debug3Func(): logFunc('called. requested=%s', self.epochRequested) return self.epochRequested def getEpoch(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-epoch').debug3Func(): logFunc('called. self.epochSet=%s, self.epoch=%s', self.epochSet, self.epoch) if self.epochSet: return self.epoch return None def hasEpoch(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-epoch').debug3Func(): logFunc('called. self.epochSet=%s, self.epoch=%s', self.epochSet, self.epoch) if self.epochSet: return True return False def setEpoch(self, epoch): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-epoch').debug3Func(): logFunc('called. epoch=%s, old=%s', epoch, self.epoch) self.epochSet = True self.epoch = epoch def requestUtcOffsetMinutes(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-utcoffsetminutes').debug3Func(): logFunc('called. requested=%s', requested) self.utcOffsetMinutesRequested = requested self.utcOffsetMinutesSet = False def isUtcOffsetMinutesRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-utcoffsetminutes-requested').debug3Func(): logFunc('called. requested=%s', self.utcOffsetMinutesRequested) return self.utcOffsetMinutesRequested def getUtcOffsetMinutes(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-utcoffsetminutes').debug3Func(): logFunc( 'called. self.utcOffsetMinutesSet=%s, self.utcOffsetMinutes=%s', self.utcOffsetMinutesSet, self.utcOffsetMinutes) if self.utcOffsetMinutesSet: return self.utcOffsetMinutes return None def hasUtcOffsetMinutes(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-utcoffsetminutes').debug3Func(): logFunc( 'called. self.utcOffsetMinutesSet=%s, self.utcOffsetMinutes=%s', self.utcOffsetMinutesSet, self.utcOffsetMinutes) if self.utcOffsetMinutesSet: return True return False def setUtcOffsetMinutes(self, utcOffsetMinutes): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-utcoffsetminutes').debug3Func(): logFunc('called. utcOffsetMinutes=%s, old=%s', utcOffsetMinutes, self.utcOffsetMinutes) self.utcOffsetMinutesSet = True self.utcOffsetMinutes = utcOffsetMinutes def _clearAllReadData(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.localTimeString = 0 self.localTimeStringSet = False self.utcTimeString = 0 self.utcTimeStringSet = False self.daylightSavingTime = 0 self.daylightSavingTimeSet = False self.epoch = 0 self.epochSet = False self.utcOffsetMinutes = 0 self.utcOffsetMinutesSet = 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-system-clock", "qt-sys-clock")) keyPath.addKeyPathPrefix(xmlVal) xmlVal = Value() xmlVal.setXmlTag( ("clock", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock", "qt-sys-clock")) 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, 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.isLocalTimeStringRequested(): valLocalTimeString = Value() valLocalTimeString.setEmpty() tagValueList.push( ("local-time-string", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock" ), valLocalTimeString) if self.isUtcTimeStringRequested(): valUtcTimeString = Value() valUtcTimeString.setEmpty() tagValueList.push( ("utc-time-string", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock" ), valUtcTimeString) if self.isDaylightSavingTimeRequested(): valDaylightSavingTime = Value() valDaylightSavingTime.setEmpty() tagValueList.push( ("daylight-saving-time", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock" ), valDaylightSavingTime) if self.isEpochRequested(): valEpoch = Value() valEpoch.setEmpty() tagValueList.push( ("epoch", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock" ), valEpoch) if self.isUtcOffsetMinutesRequested(): valUtcOffsetMinutes = Value() valUtcOffsetMinutes.setEmpty() tagValueList.push( ("utc-offset-minutes", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock" ), valUtcOffsetMinutes) 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.isLocalTimeStringRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "local-time-string") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-localtimestring' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "localTimeString", "local-time-string", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock", 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-local-time-string-bad-value' ).infoFunc(): logFunc('localTimeString not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setLocalTimeString(tempVar) for logFunc in self._log( 'read-tag-values-local-time-string').debug3Func(): logFunc( 'read localTimeString. localTimeString=%s, tempValue=%s', self.localTimeString, tempValue.getType()) if self.isUtcTimeStringRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "utc-time-string") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-utctimestring' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "utcTimeString", "utc-time-string", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock", 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-utc-time-string-bad-value').infoFunc( ): logFunc('utcTimeString not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setUtcTimeString(tempVar) for logFunc in self._log( 'read-tag-values-utc-time-string').debug3Func(): logFunc('read utcTimeString. utcTimeString=%s, tempValue=%s', self.utcTimeString, tempValue.getType()) if self.isDaylightSavingTimeRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "daylight-saving-time") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-daylightsavingtime' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "daylightSavingTime", "daylight-saving-time", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock", 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-daylight-saving-time-bad-value' ).infoFunc(): logFunc('daylightSavingTime not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setDaylightSavingTime(tempVar) for logFunc in self._log( 'read-tag-values-daylight-saving-time').debug3Func(): logFunc( 'read daylightSavingTime. daylightSavingTime=%s, tempValue=%s', self.daylightSavingTime, tempValue.getType()) if self.isEpochRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "epoch") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-epoch').errorFunc( ): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "epoch", "epoch", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock", 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-epoch-bad-value').infoFunc(): logFunc('epoch not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setEpoch(tempVar) for logFunc in self._log('read-tag-values-epoch').debug3Func(): logFunc('read epoch. epoch=%s, tempValue=%s', self.epoch, tempValue.getType()) if self.isUtcOffsetMinutesRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "utc-offset-minutes") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-utcoffsetminutes' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "utcOffsetMinutes", "utc-offset-minutes", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-system-clock", 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-utc-offset-minutes-bad-value' ).infoFunc(): logFunc('utcOffsetMinutes not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setUtcOffsetMinutes(tempVar) for logFunc in self._log( 'read-tag-values-utc-offset-minutes').debug3Func(): logFunc( 'read utcOffsetMinutes. utcOffsetMinutes=%s, tempValue=%s', self.utcOffsetMinutes, tempValue.getType()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
class BlinkyLllMaapi(LllMaapiBase): def __init__ (self, logger): self.myInitGuard = InitGuard() self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-lll") self.domain = None self.aaaObj = None self.cccObj = None self.bbbObj = None self.colorRequested = False self.color = None self.colorSet = 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.requestColor(True) self.requestName(True) if not self.aaaObj: self.aaaObj = self.newAaa() self.aaaObj.requestConfigAndOper() if not self.cccObj: self.cccObj = self.newCcc() self.cccObj.requestConfigAndOper() if not self.bbbObj: self.bbbObj = self.newBbb() self.bbbObj.requestConfigAndOper() def requestConfig (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestColor(True) self.requestName(True) if not self.aaaObj: self.aaaObj = self.newAaa() self.aaaObj.requestConfig() if not self.cccObj: self.cccObj = self.newCcc() self.cccObj.requestConfig() if not self.bbbObj: self.bbbObj = self.newBbb() self.bbbObj.requestConfig() def requestOper (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestColor(False) self.requestName(False) if not self.aaaObj: self.aaaObj = self.newAaa() self.aaaObj.requestOper() if not self.cccObj: self.cccObj = self.newCcc() self.cccObj.requestOper() if not self.bbbObj: self.bbbObj = self.newBbb() self.bbbObj.requestOper() def clearAllRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestColor(False) self.requestName(False) if not self.aaaObj: self.aaaObj = self.newAaa() self.aaaObj.clearAllRequested() if not self.cccObj: self.cccObj = self.newCcc() self.cccObj.clearAllRequested() if not self.bbbObj: self.bbbObj = self.newBbb() self.bbbObj.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.setName(None) self.nameSet = False if self.aaaObj: self.aaaObj.clearAllSet() if self.cccObj: self.cccObj.clearAllSet() if self.bbbObj: self.bbbObj.clearAllSet() 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 newAaa (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('new-aaa').debug3Func(): logFunc('called.') aaa = BlinkyAaaMaapi(self._log) aaa.init(self.domain) return aaa def setAaaObj (self, obj): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-aaa').debug3Func(): logFunc('called. obj=%s', obj) self.aaaObj = obj def getAaaObj (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-aaa').debug3Func(): logFunc('called. self.aaaObj=%s', self.aaaObj) return self.aaaObj def hasAaa (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-aaa').debug3Func(): logFunc('called. self.aaaObj=%s', self.aaaObj) if self.aaaObj: return True return False def newCcc (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('new-ccc').debug3Func(): logFunc('called.') ccc = BlinkyCccMaapi(self._log) ccc.init(self.domain) return ccc def setCccObj (self, obj): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-ccc').debug3Func(): logFunc('called. obj=%s', obj) self.cccObj = obj def getCccObj (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-ccc').debug3Func(): logFunc('called. self.cccObj=%s', self.cccObj) return self.cccObj def hasCcc (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-ccc').debug3Func(): logFunc('called. self.cccObj=%s', self.cccObj) if self.cccObj: return True return False def newBbb (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('new-bbb').debug3Func(): logFunc('called.') bbb = BlinkyBbbMaapi(self._log) bbb.init(self.domain) return bbb def setBbbObj (self, obj): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-bbb').debug3Func(): logFunc('called. obj=%s', obj) self.bbbObj = obj def getBbbObj (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-bbb').debug3Func(): logFunc('called. self.bbbObj=%s', self.bbbObj) return self.bbbObj def hasBbb (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-bbb').debug3Func(): logFunc('called. self.bbbObj=%s', self.bbbObj) if self.bbbObj: 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 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.aaaObj: self.aaaObj._clearAllReadData() if self.cccObj: self.cccObj._clearAllReadData() if self.bbbObj: self.bbbObj._clearAllReadData() self.color = 0 self.colorSet = False self.name = 0 self.nameSet = False def _getSelfKeyPath (self, lll , junkForTemplate): for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate) keyPath = KeyPath() 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) if self.aaaObj: res = self.aaaObj._collectItemsToDelete(lll, itemsToDelete) if res != ReturnCodes.kOk: for logFunc in self._log('collect-items-to-delete-aaa-failed').errorFunc(): logFunc('aaaObj._collectItemsToDelete() failed. PARAMS') return ReturnCodes.kGeneralError if self.cccObj: res = self.cccObj._collectItemsToDelete(lll, itemsToDelete) if res != ReturnCodes.kOk: for logFunc in self._log('collect-items-to-delete-ccc-failed').errorFunc(): logFunc('cccObj._collectItemsToDelete() failed. PARAMS') return ReturnCodes.kGeneralError if self.bbbObj: res = self.bbbObj._collectItemsToDelete(lll, itemsToDelete) if res != ReturnCodes.kOk: for logFunc in self._log('collect-items-to-delete-bbb-failed').errorFunc(): logFunc('bbbObj._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.setEnum(self.color.getValue()) else: valColor.setEmpty() tagValueList.push(("color", "http://qwilt.com/model/benchmark"), valColor) 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/benchmark"), valName) if self.aaaObj: valBegin = Value() (tag, ns, prefix) = ("aaa" , "http://qwilt.com/model/benchmark", "bnch") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) tagValueListLen = tagValueList.getLen() res = self.aaaObj._fillWriteTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log('fill-write-tag-values-aaa-failed').errorFunc(): logFunc('aaaObj._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.cccObj: valBegin = Value() (tag, ns, prefix) = ("ccc" , "http://qwilt.com/model/benchmark", "bnch") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) tagValueListLen = tagValueList.getLen() res = self.cccObj._fillWriteTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log('fill-write-tag-values-ccc-failed').errorFunc(): logFunc('cccObj._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.bbbObj: valBegin = Value() (tag, ns, prefix) = ("bbb" , "http://qwilt.com/model/benchmark", "bnch") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) tagValueListLen = tagValueList.getLen() res = self.bbbObj._fillWriteTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log('fill-write-tag-values-bbb-failed').errorFunc(): logFunc('bbbObj._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/model/benchmark"), valColor) if self.isNameRequested(): valName = Value() valName.setEmpty() tagValueList.push(("name", "http://qwilt.com/model/benchmark"), valName) if self.aaaObj: valBegin = Value() (tag, ns, prefix) = ("aaa" , "http://qwilt.com/model/benchmark", "bnch") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) tagValueListLen = tagValueList.getLen() res = self.aaaObj._fillReadTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log('fill-read-tag-values-aaa-failed').errorFunc(): logFunc('aaaObj._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.cccObj: valBegin = Value() (tag, ns, prefix) = ("ccc" , "http://qwilt.com/model/benchmark", "bnch") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) tagValueListLen = tagValueList.getLen() res = self.cccObj._fillReadTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log('fill-read-tag-values-ccc-failed').errorFunc(): logFunc('cccObj._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.bbbObj: valBegin = Value() (tag, ns, prefix) = ("bbb" , "http://qwilt.com/model/benchmark", "bnch") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) tagValueListLen = tagValueList.getLen() res = self.bbbObj._fillReadTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log('fill-read-tag-values-bbb-failed').errorFunc(): logFunc('bbbObj._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/model/benchmark"): 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/model/benchmark", 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-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.isNameRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "name") or \ (ns != "http://qwilt.com/model/benchmark"): 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/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-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.aaaObj: ((tag, ns), valBegin) = tagValueList.popFront() if (tag != "aaa") or \ (ns != "http://qwilt.com/model/benchmark") 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)', "aaa", "http://qwilt.com/model/benchmark", Value.kXmlBegin, tag, ns, valBegin.getType()) self._clearAllReadData() return ReturnCodes.kGeneralError res = self.aaaObj._readTagValues(tagValueList, readAllOrFail) if res != ReturnCodes.kOk: for logFunc in self._log('read-tag-values-aaa-failed').errorFunc(): logFunc('aaaObj._readTagValues() failed. tagValueList=%s', tagValueList) if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError ((tag, ns), valEnd) = tagValueList.popFront() if (tag != "aaa") or \ (ns != "http://qwilt.com/model/benchmark") 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)', "aaa", "http://qwilt.com/model/benchmark", Value.kXmlEnd, tag, ns, valEnd.getType()) self._clearAllReadData() return ReturnCodes.kGeneralError if self.cccObj: ((tag, ns), valBegin) = tagValueList.popFront() if (tag != "ccc") or \ (ns != "http://qwilt.com/model/benchmark") 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)', "ccc", "http://qwilt.com/model/benchmark", Value.kXmlBegin, tag, ns, valBegin.getType()) self._clearAllReadData() return ReturnCodes.kGeneralError res = self.cccObj._readTagValues(tagValueList, readAllOrFail) if res != ReturnCodes.kOk: for logFunc in self._log('read-tag-values-ccc-failed').errorFunc(): logFunc('cccObj._readTagValues() failed. tagValueList=%s', tagValueList) if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError ((tag, ns), valEnd) = tagValueList.popFront() if (tag != "ccc") or \ (ns != "http://qwilt.com/model/benchmark") 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)', "ccc", "http://qwilt.com/model/benchmark", Value.kXmlEnd, tag, ns, valEnd.getType()) self._clearAllReadData() return ReturnCodes.kGeneralError if self.bbbObj: ((tag, ns), valBegin) = tagValueList.popFront() if (tag != "bbb") or \ (ns != "http://qwilt.com/model/benchmark") 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)', "bbb", "http://qwilt.com/model/benchmark", Value.kXmlBegin, tag, ns, valBegin.getType()) self._clearAllReadData() return ReturnCodes.kGeneralError res = self.bbbObj._readTagValues(tagValueList, readAllOrFail) if res != ReturnCodes.kOk: for logFunc in self._log('read-tag-values-bbb-failed').errorFunc(): logFunc('bbbObj._readTagValues() failed. tagValueList=%s', tagValueList) if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError ((tag, ns), valEnd) = tagValueList.popFront() if (tag != "bbb") or \ (ns != "http://qwilt.com/model/benchmark") 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)', "bbb", "http://qwilt.com/model/benchmark", 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
class BlinkyActionMaapi(ActionMaapiBase): def __init__ (self, logger): self.myInitGuard = InitGuard() self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-action") self.domain = None self.deliveryRequested = False self.delivery = None self.deliverySet = False self.analyticsRequested = False self.analytics = None self.analyticsSet = False self.cachingPotentialRequested = False self.cachingPotential = None self.cachingPotentialSet = False self.acquisitionRequested = False self.acquisition = None self.acquisitionSet = 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.requestDelivery(True) self.requestAnalytics(True) self.requestCachingPotential(True) self.requestAcquisition(True) def requestConfig (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestDelivery(True) self.requestAnalytics(True) self.requestCachingPotential(True) self.requestAcquisition(True) def requestOper (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestDelivery(False) self.requestAnalytics(False) self.requestCachingPotential(False) self.requestAcquisition(False) def clearAllRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestDelivery(False) self.requestAnalytics(False) self.requestCachingPotential(False) self.requestAcquisition(False) def clearAllSet (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') self.setDelivery(None) self.deliverySet = False self.setAnalytics(None) self.analyticsSet = False self.setCachingPotential(None) self.cachingPotentialSet = False self.setAcquisition(None) self.acquisitionSet = False def write (self , rule , trxContext=None ): self.myInitGuard.isInitOrCrash() for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS') return self._internalWrite(rule, trxContext) def read (self , rule , trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS') return self._internalRead(rule, False, trxContext) def readAllOrFail (self , rule , trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS') return self._internalRead(rule, True, trxContext) def requestDelivery (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-delivery').debug3Func(): logFunc('called. requested=%s', requested) self.deliveryRequested = requested self.deliverySet = False def isDeliveryRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-delivery-requested').debug3Func(): logFunc('called. requested=%s', self.deliveryRequested) return self.deliveryRequested def getDelivery (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-delivery').debug3Func(): logFunc('called. self.deliverySet=%s, self.delivery=%s', self.deliverySet, self.delivery) if self.deliverySet: return self.delivery return None def hasDelivery (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-delivery').debug3Func(): logFunc('called. self.deliverySet=%s, self.delivery=%s', self.deliverySet, self.delivery) if self.deliverySet: return True return False def setDelivery (self, delivery): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-delivery').debug3Func(): logFunc('called. delivery=%s, old=%s', delivery, self.delivery) self.deliverySet = True self.delivery = delivery def requestAnalytics (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-analytics').debug3Func(): logFunc('called. requested=%s', requested) self.analyticsRequested = requested self.analyticsSet = False def isAnalyticsRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-analytics-requested').debug3Func(): logFunc('called. requested=%s', self.analyticsRequested) return self.analyticsRequested def getAnalytics (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-analytics').debug3Func(): logFunc('called. self.analyticsSet=%s, self.analytics=%s', self.analyticsSet, self.analytics) if self.analyticsSet: return self.analytics return None def hasAnalytics (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-analytics').debug3Func(): logFunc('called. self.analyticsSet=%s, self.analytics=%s', self.analyticsSet, self.analytics) if self.analyticsSet: return True return False def setAnalytics (self, analytics): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-analytics').debug3Func(): logFunc('called. analytics=%s, old=%s', analytics, self.analytics) self.analyticsSet = True self.analytics = analytics def requestCachingPotential (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-cachingpotential').debug3Func(): logFunc('called. requested=%s', requested) self.cachingPotentialRequested = requested self.cachingPotentialSet = False def isCachingPotentialRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-cachingpotential-requested').debug3Func(): logFunc('called. requested=%s', self.cachingPotentialRequested) return self.cachingPotentialRequested def getCachingPotential (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-cachingpotential').debug3Func(): logFunc('called. self.cachingPotentialSet=%s, self.cachingPotential=%s', self.cachingPotentialSet, self.cachingPotential) if self.cachingPotentialSet: return self.cachingPotential return None def hasCachingPotential (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-cachingpotential').debug3Func(): logFunc('called. self.cachingPotentialSet=%s, self.cachingPotential=%s', self.cachingPotentialSet, self.cachingPotential) if self.cachingPotentialSet: return True return False def setCachingPotential (self, cachingPotential): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-cachingpotential').debug3Func(): logFunc('called. cachingPotential=%s, old=%s', cachingPotential, self.cachingPotential) self.cachingPotentialSet = True self.cachingPotential = cachingPotential def requestAcquisition (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-acquisition').debug3Func(): logFunc('called. requested=%s', requested) self.acquisitionRequested = requested self.acquisitionSet = False def isAcquisitionRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-acquisition-requested').debug3Func(): logFunc('called. requested=%s', self.acquisitionRequested) return self.acquisitionRequested def getAcquisition (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-acquisition').debug3Func(): logFunc('called. self.acquisitionSet=%s, self.acquisition=%s', self.acquisitionSet, self.acquisition) if self.acquisitionSet: return self.acquisition return None def hasAcquisition (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-acquisition').debug3Func(): logFunc('called. self.acquisitionSet=%s, self.acquisition=%s', self.acquisitionSet, self.acquisition) if self.acquisitionSet: return True return False def setAcquisition (self, acquisition): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-acquisition').debug3Func(): logFunc('called. acquisition=%s, old=%s', acquisition, self.acquisition) self.acquisitionSet = True self.acquisition = acquisition def _clearAllReadData (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.delivery = 0 self.deliverySet = False self.analytics = 0 self.analyticsSet = False self.cachingPotential = 0 self.cachingPotentialSet = False self.acquisition = 0 self.acquisitionSet = False def _getSelfKeyPath (self, rule , junkForTemplate): for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate) keyPath = KeyPath() xmlVal = Value() xmlVal.setXmlTag(("action", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", "qtc")) keyPath.addKeyPathPrefix(xmlVal) xmlVal = Value() xmlVal.setXmlTag(("actions", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", "qtc")) 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-content", "qtc")) keyPath.addKeyPathPrefix(xmlVal) xmlVal = Value() xmlVal.setXmlTag(("rules", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", "qtc")) keyPath.addKeyPathPrefix(xmlVal) xmlVal = Value() xmlVal.setXmlTag(("policy", "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 _internalWrite (self, 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(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(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, 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(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, 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.hasDelivery(): valDelivery = Value() if self.delivery is not None: valDelivery.setBool(self.delivery) else: valDelivery.setEmpty() tagValueList.push(("delivery", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"), valDelivery) if self.hasAnalytics(): valAnalytics = Value() if self.analytics is not None: valAnalytics.setBool(self.analytics) else: valAnalytics.setEmpty() tagValueList.push(("analytics", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"), valAnalytics) if self.hasCachingPotential(): valCachingPotential = Value() if self.cachingPotential is not None: valCachingPotential.setBool(self.cachingPotential) else: valCachingPotential.setEmpty() tagValueList.push(("caching-potential", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"), valCachingPotential) if self.hasAcquisition(): valAcquisition = Value() if self.acquisition is not None: valAcquisition.setBool(self.acquisition) else: valAcquisition.setEmpty() tagValueList.push(("acquisition", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"), valAcquisition) 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.isDeliveryRequested(): valDelivery = Value() valDelivery.setEmpty() tagValueList.push(("delivery", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"), valDelivery) if self.isAnalyticsRequested(): valAnalytics = Value() valAnalytics.setEmpty() tagValueList.push(("analytics", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"), valAnalytics) if self.isCachingPotentialRequested(): valCachingPotential = Value() valCachingPotential.setEmpty() tagValueList.push(("caching-potential", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"), valCachingPotential) if self.isAcquisitionRequested(): valAcquisition = Value() valAcquisition.setEmpty() tagValueList.push(("acquisition", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"), valAcquisition) 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.isDeliveryRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "delivery") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-delivery').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "delivery", "delivery", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", 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-delivery-bad-value').infoFunc(): logFunc('delivery not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setDelivery(tempVar) for logFunc in self._log('read-tag-values-delivery').debug3Func(): logFunc('read delivery. delivery=%s, tempValue=%s', self.delivery, tempValue.getType()) if self.isAnalyticsRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "analytics") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-analytics').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "analytics", "analytics", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", 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-analytics-bad-value').infoFunc(): logFunc('analytics not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setAnalytics(tempVar) for logFunc in self._log('read-tag-values-analytics').debug3Func(): logFunc('read analytics. analytics=%s, tempValue=%s', self.analytics, tempValue.getType()) if self.isCachingPotentialRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "caching-potential") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-cachingpotential').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "cachingPotential", "caching-potential", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", 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-caching-potential-bad-value').infoFunc(): logFunc('cachingPotential not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setCachingPotential(tempVar) for logFunc in self._log('read-tag-values-caching-potential').debug3Func(): logFunc('read cachingPotential. cachingPotential=%s, tempValue=%s', self.cachingPotential, tempValue.getType()) if self.isAcquisitionRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "acquisition") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-acquisition').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "acquisition", "acquisition", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", 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-acquisition-bad-value').infoFunc(): logFunc('acquisition not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setAcquisition(tempVar) for logFunc in self._log('read-tag-values-acquisition').debug3Func(): logFunc('read acquisition. acquisition=%s, tempValue=%s', self.acquisition, tempValue.getType()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
class BlinkyOpCMaapi(OpCMaapiBase): def __init__ (self, logger): self.myInitGuard = InitGuard() self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-opC") self.domain = None self.ipValRequested = False self.ipVal = None self.ipValSet = False self.idRequested = False self.id = None self.idSet = False self.valRequested = False self.val = None self.valSet = False self.ipPrefixValRequested = False self.ipPrefixVal = None self.ipPrefixValSet = 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.requestIpVal(True) self.requestId(True) self.requestVal(True) self.requestIpPrefixVal(True) def requestConfig (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestIpVal(False) self.requestId(False) self.requestVal(False) self.requestIpPrefixVal(False) def requestOper (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestIpVal(True) self.requestId(True) self.requestVal(True) self.requestIpPrefixVal(True) def clearAllRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestIpVal(False) self.requestId(False) self.requestVal(False) self.requestIpPrefixVal(False) def clearAllSet (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') def write (self , opC , trxContext=None ): self.myInitGuard.isInitOrCrash() for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS') return self._internalWrite(opC, trxContext) def read (self , opC , trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS') return self._internalRead(opC, False, trxContext) def readAllOrFail (self , opC , trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS') return self._internalRead(opC, True, trxContext) def requestIpVal (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-ipval').debug3Func(): logFunc('called. requested=%s', requested) self.ipValRequested = requested self.ipValSet = False def isIpValRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-ipval-requested').debug3Func(): logFunc('called. requested=%s', self.ipValRequested) return self.ipValRequested def getIpVal (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-ipval').debug3Func(): logFunc('called. self.ipValSet=%s, self.ipVal=%s', self.ipValSet, self.ipVal) if self.ipValSet: return self.ipVal return None def hasIpVal (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-ipval').debug3Func(): logFunc('called. self.ipValSet=%s, self.ipVal=%s', self.ipValSet, self.ipVal) if self.ipValSet: return True return False def setIpVal (self, ipVal): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-ipval').debug3Func(): logFunc('called. ipVal=%s, old=%s', ipVal, self.ipVal) self.ipValSet = True self.ipVal = ipVal 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 requestVal (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-val').debug3Func(): logFunc('called. requested=%s', requested) self.valRequested = requested self.valSet = False def isValRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-val-requested').debug3Func(): logFunc('called. requested=%s', self.valRequested) return self.valRequested def getVal (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-val').debug3Func(): logFunc('called. self.valSet=%s, self.val=%s', self.valSet, self.val) if self.valSet: return self.val return None def hasVal (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-val').debug3Func(): logFunc('called. self.valSet=%s, self.val=%s', self.valSet, self.val) if self.valSet: return True return False def setVal (self, val): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-val').debug3Func(): logFunc('called. val=%s, old=%s', val, self.val) self.valSet = True self.val = val def requestIpPrefixVal (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-ipprefixval').debug3Func(): logFunc('called. requested=%s', requested) self.ipPrefixValRequested = requested self.ipPrefixValSet = False def isIpPrefixValRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-ipprefixval-requested').debug3Func(): logFunc('called. requested=%s', self.ipPrefixValRequested) return self.ipPrefixValRequested def getIpPrefixVal (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-ipprefixval').debug3Func(): logFunc('called. self.ipPrefixValSet=%s, self.ipPrefixVal=%s', self.ipPrefixValSet, self.ipPrefixVal) if self.ipPrefixValSet: return self.ipPrefixVal return None def hasIpPrefixVal (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-ipprefixval').debug3Func(): logFunc('called. self.ipPrefixValSet=%s, self.ipPrefixVal=%s', self.ipPrefixValSet, self.ipPrefixVal) if self.ipPrefixValSet: return True return False def setIpPrefixVal (self, ipPrefixVal): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-ipprefixval').debug3Func(): logFunc('called. ipPrefixVal=%s, old=%s', ipPrefixVal, self.ipPrefixVal) self.ipPrefixValSet = True self.ipPrefixVal = ipPrefixVal def _clearAllReadData (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.ipVal = 0 self.ipValSet = False self.id = 0 self.idSet = False self.val = 0 self.valSet = False self.ipPrefixVal = 0 self.ipPrefixValSet = False def _getSelfKeyPath (self, opC , junkForTemplate): for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate) keyPath = KeyPath() ancestorVal = Value() ancestorVal.setInt64(opC); keyPath.addKeyPathPrefix(ancestorVal) xmlVal = Value() xmlVal.setXmlTag(("op-c", "http://qwilt.com/model/oper", "oper")) keyPath.addKeyPathPrefix(xmlVal) xmlVal = Value() xmlVal.setXmlTag(("op-b", "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, opC, 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(opC, 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(opC, 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, opC, 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(opC, 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, opC, 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.isIpValRequested(): valIpVal = Value() valIpVal.setEmpty() tagValueList.push(("ip-val", "http://qwilt.com/model/oper"), valIpVal) if self.isIdRequested(): valId = Value() valId.setEmpty() tagValueList.push(("id", "http://qwilt.com/model/oper"), valId) if self.isValRequested(): valVal = Value() valVal.setEmpty() tagValueList.push(("val", "http://qwilt.com/model/oper"), valVal) if self.isIpPrefixValRequested(): valIpPrefixVal = Value() valIpPrefixVal.setEmpty() tagValueList.push(("ip-prefix-val", "http://qwilt.com/model/oper"), valIpPrefixVal) 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.isIpValRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "ip-val") or \ (ns != "http://qwilt.com/model/oper"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-ipval').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "ipVal", "ip-val", "http://qwilt.com/model/oper", 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-val-bad-value').infoFunc(): logFunc('ipVal not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setIpVal(tempVar) for logFunc in self._log('read-tag-values-ip-val').debug3Func(): logFunc('read ipVal. ipVal=%s, tempValue=%s', self.ipVal, tempValue.getType()) if self.isIdRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "id") or \ (ns != "http://qwilt.com/model/oper"): 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/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-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.isValRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "val") or \ (ns != "http://qwilt.com/model/oper"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-val').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "val", "val", "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-val-bad-value').infoFunc(): logFunc('val not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setVal(tempVar) for logFunc in self._log('read-tag-values-val').debug3Func(): logFunc('read val. val=%s, tempValue=%s', self.val, tempValue.getType()) if self.isIpPrefixValRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "ip-prefix-val") or \ (ns != "http://qwilt.com/model/oper"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-ipprefixval').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "ipPrefixVal", "ip-prefix-val", "http://qwilt.com/model/oper", tag, ns) self._clearAllReadData() return ReturnCodes.kGeneralError tempVar = None tempVar = (tempValue.asIPv4Prefix()) if res != ReturnCodes.kOk or tempVar is None: for logFunc in self._log('read-tag-values-ip-prefix-val-bad-value').infoFunc(): logFunc('ipPrefixVal not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setIpPrefixVal(tempVar) for logFunc in self._log('read-tag-values-ip-prefix-val').debug3Func(): logFunc('read ipPrefixVal. ipPrefixVal=%s, tempValue=%s', self.ipPrefixVal, tempValue.getType()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
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
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
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.countersObj = 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() 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.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() 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.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() 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.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() 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.setEnabled(None) self.enabledSet = False self.setPollInterval(None) self.pollIntervalSet = False if self.thresholdsObj: self.thresholdsObj.clearAllSet() if self.logArchivingObj: self.logArchivingObj.clearAllSet() if self.countersObj: self.countersObj.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 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 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() if self.countersObj: self.countersObj._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( ("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 if self.countersObj: res = self.countersObj._collectItemsToDelete(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.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) if self.countersObj: valBegin = Value() (tag, ns, prefix) = ("counters", "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.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.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) if self.countersObj: valBegin = Value() (tag, ns, prefix) = ("counters", "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.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.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 if self.countersObj: ((tag, ns), valBegin) = tagValueList.popFront() if (tag != "counters") 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)', "counters", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-log", 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-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)', "counters", "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
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
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(("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
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 BlinkyIpv4Maapi(Ipv4MaapiBase): def __init__ (self, logger): self.myInitGuard = InitGuard() self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-ipv4") self.domain = None self.addressListObj = None self.defaultGatewayRequested = False self.defaultGateway = None self.defaultGatewaySet = 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.requestDefaultGateway(True) if not self.addressListObj: self.addressListObj = self.newAddressList() self.addressListObj.requestConfigAndOper() def requestConfig (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestDefaultGateway(True) if not self.addressListObj: self.addressListObj = self.newAddressList() self.addressListObj.requestConfig() def requestOper (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestDefaultGateway(False) if not self.addressListObj: self.addressListObj = self.newAddressList() self.addressListObj.requestOper() def clearAllRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestDefaultGateway(False) if not self.addressListObj: self.addressListObj = self.newAddressList() self.addressListObj.clearAllRequested() def clearAllSet (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') self.setDefaultGateway(None) self.defaultGatewaySet = False if self.addressListObj: self.addressListObj.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 newAddressList (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('new-addresslist').debug3Func(): logFunc('called.') addressList = BlinkyAddressMaapiList(self._log) addressList.init(self.domain) return addressList def setAddressListObj (self, obj): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-addresslist').debug3Func(): logFunc('called. obj=%s', obj) self.addressListObj = obj def getAddressListObj (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-addresslist').debug3Func(): logFunc('called. self.addressListObj=%s', self.addressListObj) return self.addressListObj def hasAddressList (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-addresslist').debug3Func(): logFunc('called. self.addressListObj=%s', self.addressListObj) if self.addressListObj: return True return False def requestDefaultGateway (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-defaultgateway').debug3Func(): logFunc('called. requested=%s', requested) self.defaultGatewayRequested = requested self.defaultGatewaySet = False def isDefaultGatewayRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-defaultgateway-requested').debug3Func(): logFunc('called. requested=%s', self.defaultGatewayRequested) return self.defaultGatewayRequested def getDefaultGateway (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-defaultgateway').debug3Func(): logFunc('called. self.defaultGatewaySet=%s, self.defaultGateway=%s', self.defaultGatewaySet, self.defaultGateway) if self.defaultGatewaySet: return self.defaultGateway return None def hasDefaultGateway (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-defaultgateway').debug3Func(): logFunc('called. self.defaultGatewaySet=%s, self.defaultGateway=%s', self.defaultGatewaySet, self.defaultGateway) if self.defaultGatewaySet: return True return False def setDefaultGateway (self, defaultGateway): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-defaultgateway').debug3Func(): logFunc('called. defaultGateway=%s, old=%s', defaultGateway, self.defaultGateway) self.defaultGatewaySet = True self.defaultGateway = defaultGateway def _clearAllReadData (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') if self.addressListObj: self.addressListObj._clearAllReadData() self.defaultGateway = 0 self.defaultGatewaySet = 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(("ipv4", "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.addressListObj: res = self.addressListObj._collectItemsToDelete(interface, itemsToDelete) if res != ReturnCodes.kOk: for logFunc in self._log('collect-items-to-delete-address-failed').errorFunc(): logFunc('addressListObj._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.hasDefaultGateway(): valDefaultGateway = Value() if self.defaultGateway is not None: valDefaultGateway.setIPv4(self.defaultGateway) else: valDefaultGateway.setEmpty() tagValueList.push(("default-gateway", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valDefaultGateway) if self.addressListObj: valBegin = Value() (tag, ns, prefix) = ("address" , "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.addressListObj._fillWriteTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log('fill-write-tag-values-address-failed').errorFunc(): logFunc('addressListObj._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.isDefaultGatewayRequested(): valDefaultGateway = Value() valDefaultGateway.setEmpty() tagValueList.push(("default-gateway", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valDefaultGateway) if self.addressListObj: valBegin = Value() (tag, ns, prefix) = ("address" , "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.addressListObj._fillReadTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log('fill-read-tag-values-address-failed').errorFunc(): logFunc('addressListObj._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.isDefaultGatewayRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "default-gateway") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-defaultgateway').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "defaultGateway", "default-gateway", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", 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-default-gateway-bad-value').infoFunc(): logFunc('defaultGateway not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setDefaultGateway(tempVar) for logFunc in self._log('read-tag-values-default-gateway').debug3Func(): logFunc('read defaultGateway. defaultGateway=%s, tempValue=%s', self.defaultGateway, tempValue.getType()) if self.addressListObj: ((tag, ns), valBegin) = tagValueList.popFront() if (tag != "address") 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)', "address", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", Value.kXmlBegin, tag, ns, valBegin.getType()) self._clearAllReadData() return ReturnCodes.kGeneralError res = self.addressListObj._readTagValues(tagValueList, readAllOrFail) if res != ReturnCodes.kOk: for logFunc in self._log('read-tag-values-address-failed').errorFunc(): logFunc('addressListObj._readTagValues() failed. tagValueList=%s', tagValueList) if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError ((tag, ns), valEnd) = tagValueList.popFront() if (tag != "address") 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)', "address", "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
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
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.arpFailuresRequested = False self.arpFailures = None self.arpFailuresSet = False self.arpRequestsSentRequested = False self.arpRequestsSent = None self.arpRequestsSentSet = False self.pingSuccessesRequested = False self.pingSuccesses = None self.pingSuccessesSet = False self.pingRequestsSentRequested = False self.pingRequestsSent = None self.pingRequestsSentSet = False self.arpSuccessesRequested = False self.arpSuccesses = None self.arpSuccessesSet = False self.pingFailuresRequested = False self.pingFailures = None self.pingFailuresSet = False self.arpTimeoutsRequested = False self.arpTimeouts = None self.arpTimeoutsSet = False self.pingTimeoutsRequested = False self.pingTimeouts = None self.pingTimeoutsSet = 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.requestArpFailures(True) self.requestArpRequestsSent(True) self.requestPingSuccesses(True) self.requestPingRequestsSent(True) self.requestArpSuccesses(True) self.requestPingFailures(True) self.requestArpTimeouts(True) self.requestPingTimeouts(True) def requestConfig (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestArpFailures(False) self.requestArpRequestsSent(False) self.requestPingSuccesses(False) self.requestPingRequestsSent(False) self.requestArpSuccesses(False) self.requestPingFailures(False) self.requestArpTimeouts(False) self.requestPingTimeouts(False) def requestOper (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestArpFailures(True) self.requestArpRequestsSent(True) self.requestPingSuccesses(True) self.requestPingRequestsSent(True) self.requestArpSuccesses(True) self.requestPingFailures(True) self.requestArpTimeouts(True) self.requestPingTimeouts(True) def clearAllRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestArpFailures(False) self.requestArpRequestsSent(False) self.requestPingSuccesses(False) self.requestPingRequestsSent(False) self.requestArpSuccesses(False) self.requestPingFailures(False) self.requestArpTimeouts(False) self.requestPingTimeouts(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 requestArpFailures (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-arpfailures').debug3Func(): logFunc('called. requested=%s', requested) self.arpFailuresRequested = requested self.arpFailuresSet = False def isArpFailuresRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-arpfailures-requested').debug3Func(): logFunc('called. requested=%s', self.arpFailuresRequested) return self.arpFailuresRequested def getArpFailures (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-arpfailures').debug3Func(): logFunc('called. self.arpFailuresSet=%s, self.arpFailures=%s', self.arpFailuresSet, self.arpFailures) if self.arpFailuresSet: return self.arpFailures return None def hasArpFailures (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-arpfailures').debug3Func(): logFunc('called. self.arpFailuresSet=%s, self.arpFailures=%s', self.arpFailuresSet, self.arpFailures) if self.arpFailuresSet: return True return False def setArpFailures (self, arpFailures): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-arpfailures').debug3Func(): logFunc('called. arpFailures=%s, old=%s', arpFailures, self.arpFailures) self.arpFailuresSet = True self.arpFailures = arpFailures def requestArpRequestsSent (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-arprequestssent').debug3Func(): logFunc('called. requested=%s', requested) self.arpRequestsSentRequested = requested self.arpRequestsSentSet = False def isArpRequestsSentRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-arprequestssent-requested').debug3Func(): logFunc('called. requested=%s', self.arpRequestsSentRequested) return self.arpRequestsSentRequested def getArpRequestsSent (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-arprequestssent').debug3Func(): logFunc('called. self.arpRequestsSentSet=%s, self.arpRequestsSent=%s', self.arpRequestsSentSet, self.arpRequestsSent) if self.arpRequestsSentSet: return self.arpRequestsSent return None def hasArpRequestsSent (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-arprequestssent').debug3Func(): logFunc('called. self.arpRequestsSentSet=%s, self.arpRequestsSent=%s', self.arpRequestsSentSet, self.arpRequestsSent) if self.arpRequestsSentSet: return True return False def setArpRequestsSent (self, arpRequestsSent): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-arprequestssent').debug3Func(): logFunc('called. arpRequestsSent=%s, old=%s', arpRequestsSent, self.arpRequestsSent) self.arpRequestsSentSet = True self.arpRequestsSent = arpRequestsSent def requestPingSuccesses (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-pingsuccesses').debug3Func(): logFunc('called. requested=%s', requested) self.pingSuccessesRequested = requested self.pingSuccessesSet = False def isPingSuccessesRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-pingsuccesses-requested').debug3Func(): logFunc('called. requested=%s', self.pingSuccessesRequested) return self.pingSuccessesRequested def getPingSuccesses (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-pingsuccesses').debug3Func(): logFunc('called. self.pingSuccessesSet=%s, self.pingSuccesses=%s', self.pingSuccessesSet, self.pingSuccesses) if self.pingSuccessesSet: return self.pingSuccesses return None def hasPingSuccesses (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-pingsuccesses').debug3Func(): logFunc('called. self.pingSuccessesSet=%s, self.pingSuccesses=%s', self.pingSuccessesSet, self.pingSuccesses) if self.pingSuccessesSet: return True return False def setPingSuccesses (self, pingSuccesses): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-pingsuccesses').debug3Func(): logFunc('called. pingSuccesses=%s, old=%s', pingSuccesses, self.pingSuccesses) self.pingSuccessesSet = True self.pingSuccesses = pingSuccesses def requestPingRequestsSent (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-pingrequestssent').debug3Func(): logFunc('called. requested=%s', requested) self.pingRequestsSentRequested = requested self.pingRequestsSentSet = False def isPingRequestsSentRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-pingrequestssent-requested').debug3Func(): logFunc('called. requested=%s', self.pingRequestsSentRequested) return self.pingRequestsSentRequested def getPingRequestsSent (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-pingrequestssent').debug3Func(): logFunc('called. self.pingRequestsSentSet=%s, self.pingRequestsSent=%s', self.pingRequestsSentSet, self.pingRequestsSent) if self.pingRequestsSentSet: return self.pingRequestsSent return None def hasPingRequestsSent (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-pingrequestssent').debug3Func(): logFunc('called. self.pingRequestsSentSet=%s, self.pingRequestsSent=%s', self.pingRequestsSentSet, self.pingRequestsSent) if self.pingRequestsSentSet: return True return False def setPingRequestsSent (self, pingRequestsSent): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-pingrequestssent').debug3Func(): logFunc('called. pingRequestsSent=%s, old=%s', pingRequestsSent, self.pingRequestsSent) self.pingRequestsSentSet = True self.pingRequestsSent = pingRequestsSent def requestArpSuccesses (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-arpsuccesses').debug3Func(): logFunc('called. requested=%s', requested) self.arpSuccessesRequested = requested self.arpSuccessesSet = False def isArpSuccessesRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-arpsuccesses-requested').debug3Func(): logFunc('called. requested=%s', self.arpSuccessesRequested) return self.arpSuccessesRequested def getArpSuccesses (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-arpsuccesses').debug3Func(): logFunc('called. self.arpSuccessesSet=%s, self.arpSuccesses=%s', self.arpSuccessesSet, self.arpSuccesses) if self.arpSuccessesSet: return self.arpSuccesses return None def hasArpSuccesses (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-arpsuccesses').debug3Func(): logFunc('called. self.arpSuccessesSet=%s, self.arpSuccesses=%s', self.arpSuccessesSet, self.arpSuccesses) if self.arpSuccessesSet: return True return False def setArpSuccesses (self, arpSuccesses): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-arpsuccesses').debug3Func(): logFunc('called. arpSuccesses=%s, old=%s', arpSuccesses, self.arpSuccesses) self.arpSuccessesSet = True self.arpSuccesses = arpSuccesses def requestPingFailures (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-pingfailures').debug3Func(): logFunc('called. requested=%s', requested) self.pingFailuresRequested = requested self.pingFailuresSet = False def isPingFailuresRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-pingfailures-requested').debug3Func(): logFunc('called. requested=%s', self.pingFailuresRequested) return self.pingFailuresRequested def getPingFailures (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-pingfailures').debug3Func(): logFunc('called. self.pingFailuresSet=%s, self.pingFailures=%s', self.pingFailuresSet, self.pingFailures) if self.pingFailuresSet: return self.pingFailures return None def hasPingFailures (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-pingfailures').debug3Func(): logFunc('called. self.pingFailuresSet=%s, self.pingFailures=%s', self.pingFailuresSet, self.pingFailures) if self.pingFailuresSet: return True return False def setPingFailures (self, pingFailures): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-pingfailures').debug3Func(): logFunc('called. pingFailures=%s, old=%s', pingFailures, self.pingFailures) self.pingFailuresSet = True self.pingFailures = pingFailures def requestArpTimeouts (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-arptimeouts').debug3Func(): logFunc('called. requested=%s', requested) self.arpTimeoutsRequested = requested self.arpTimeoutsSet = False def isArpTimeoutsRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-arptimeouts-requested').debug3Func(): logFunc('called. requested=%s', self.arpTimeoutsRequested) return self.arpTimeoutsRequested def getArpTimeouts (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-arptimeouts').debug3Func(): logFunc('called. self.arpTimeoutsSet=%s, self.arpTimeouts=%s', self.arpTimeoutsSet, self.arpTimeouts) if self.arpTimeoutsSet: return self.arpTimeouts return None def hasArpTimeouts (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-arptimeouts').debug3Func(): logFunc('called. self.arpTimeoutsSet=%s, self.arpTimeouts=%s', self.arpTimeoutsSet, self.arpTimeouts) if self.arpTimeoutsSet: return True return False def setArpTimeouts (self, arpTimeouts): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-arptimeouts').debug3Func(): logFunc('called. arpTimeouts=%s, old=%s', arpTimeouts, self.arpTimeouts) self.arpTimeoutsSet = True self.arpTimeouts = arpTimeouts def requestPingTimeouts (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-pingtimeouts').debug3Func(): logFunc('called. requested=%s', requested) self.pingTimeoutsRequested = requested self.pingTimeoutsSet = False def isPingTimeoutsRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-pingtimeouts-requested').debug3Func(): logFunc('called. requested=%s', self.pingTimeoutsRequested) return self.pingTimeoutsRequested def getPingTimeouts (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-pingtimeouts').debug3Func(): logFunc('called. self.pingTimeoutsSet=%s, self.pingTimeouts=%s', self.pingTimeoutsSet, self.pingTimeouts) if self.pingTimeoutsSet: return self.pingTimeouts return None def hasPingTimeouts (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-pingtimeouts').debug3Func(): logFunc('called. self.pingTimeoutsSet=%s, self.pingTimeouts=%s', self.pingTimeoutsSet, self.pingTimeouts) if self.pingTimeoutsSet: return True return False def setPingTimeouts (self, pingTimeouts): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-pingtimeouts').debug3Func(): logFunc('called. pingTimeouts=%s, old=%s', pingTimeouts, self.pingTimeouts) self.pingTimeoutsSet = True self.pingTimeouts = pingTimeouts def _clearAllReadData (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.arpFailures = 0 self.arpFailuresSet = False self.arpRequestsSent = 0 self.arpRequestsSentSet = False self.pingSuccesses = 0 self.pingSuccessesSet = False self.pingRequestsSent = 0 self.pingRequestsSentSet = False self.arpSuccesses = 0 self.arpSuccessesSet = False self.pingFailures = 0 self.pingFailuresSet = False self.arpTimeouts = 0 self.arpTimeoutsSet = False self.pingTimeouts = 0 self.pingTimeoutsSet = 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(("counters", "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.isArpFailuresRequested(): valArpFailures = Value() valArpFailures.setEmpty() tagValueList.push(("arp-failures", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valArpFailures) if self.isArpRequestsSentRequested(): valArpRequestsSent = Value() valArpRequestsSent.setEmpty() tagValueList.push(("arp-requests-sent", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valArpRequestsSent) if self.isPingSuccessesRequested(): valPingSuccesses = Value() valPingSuccesses.setEmpty() tagValueList.push(("ping-successes", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valPingSuccesses) if self.isPingRequestsSentRequested(): valPingRequestsSent = Value() valPingRequestsSent.setEmpty() tagValueList.push(("ping-requests-sent", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valPingRequestsSent) if self.isArpSuccessesRequested(): valArpSuccesses = Value() valArpSuccesses.setEmpty() tagValueList.push(("arp-successes", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valArpSuccesses) if self.isPingFailuresRequested(): valPingFailures = Value() valPingFailures.setEmpty() tagValueList.push(("ping-failures", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valPingFailures) if self.isArpTimeoutsRequested(): valArpTimeouts = Value() valArpTimeouts.setEmpty() tagValueList.push(("arp-timeouts", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valArpTimeouts) if self.isPingTimeoutsRequested(): valPingTimeouts = Value() valPingTimeouts.setEmpty() tagValueList.push(("ping-timeouts", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valPingTimeouts) 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.isArpFailuresRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "arp-failures") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-arpfailures').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "arpFailures", "arp-failures", "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-arp-failures-bad-value').infoFunc(): logFunc('arpFailures not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setArpFailures(tempVar) for logFunc in self._log('read-tag-values-arp-failures').debug3Func(): logFunc('read arpFailures. arpFailures=%s, tempValue=%s', self.arpFailures, tempValue.getType()) if self.isArpRequestsSentRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "arp-requests-sent") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-arprequestssent').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "arpRequestsSent", "arp-requests-sent", "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-arp-requests-sent-bad-value').infoFunc(): logFunc('arpRequestsSent not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setArpRequestsSent(tempVar) for logFunc in self._log('read-tag-values-arp-requests-sent').debug3Func(): logFunc('read arpRequestsSent. arpRequestsSent=%s, tempValue=%s', self.arpRequestsSent, tempValue.getType()) if self.isPingSuccessesRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "ping-successes") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-pingsuccesses').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "pingSuccesses", "ping-successes", "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-ping-successes-bad-value').infoFunc(): logFunc('pingSuccesses not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setPingSuccesses(tempVar) for logFunc in self._log('read-tag-values-ping-successes').debug3Func(): logFunc('read pingSuccesses. pingSuccesses=%s, tempValue=%s', self.pingSuccesses, tempValue.getType()) if self.isPingRequestsSentRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "ping-requests-sent") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-pingrequestssent').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "pingRequestsSent", "ping-requests-sent", "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-ping-requests-sent-bad-value').infoFunc(): logFunc('pingRequestsSent not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setPingRequestsSent(tempVar) for logFunc in self._log('read-tag-values-ping-requests-sent').debug3Func(): logFunc('read pingRequestsSent. pingRequestsSent=%s, tempValue=%s', self.pingRequestsSent, tempValue.getType()) if self.isArpSuccessesRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "arp-successes") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-arpsuccesses').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "arpSuccesses", "arp-successes", "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-arp-successes-bad-value').infoFunc(): logFunc('arpSuccesses not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setArpSuccesses(tempVar) for logFunc in self._log('read-tag-values-arp-successes').debug3Func(): logFunc('read arpSuccesses. arpSuccesses=%s, tempValue=%s', self.arpSuccesses, tempValue.getType()) if self.isPingFailuresRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "ping-failures") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-pingfailures').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "pingFailures", "ping-failures", "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-ping-failures-bad-value').infoFunc(): logFunc('pingFailures not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setPingFailures(tempVar) for logFunc in self._log('read-tag-values-ping-failures').debug3Func(): logFunc('read pingFailures. pingFailures=%s, tempValue=%s', self.pingFailures, tempValue.getType()) if self.isArpTimeoutsRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "arp-timeouts") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-arptimeouts').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "arpTimeouts", "arp-timeouts", "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-arp-timeouts-bad-value').infoFunc(): logFunc('arpTimeouts not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setArpTimeouts(tempVar) for logFunc in self._log('read-tag-values-arp-timeouts').debug3Func(): logFunc('read arpTimeouts. arpTimeouts=%s, tempValue=%s', self.arpTimeouts, tempValue.getType()) if self.isPingTimeoutsRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "ping-timeouts") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-pingtimeouts').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "pingTimeouts", "ping-timeouts", "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-ping-timeouts-bad-value').infoFunc(): logFunc('pingTimeouts not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setPingTimeouts(tempVar) for logFunc in self._log('read-tag-values-ping-timeouts').debug3Func(): logFunc('read pingTimeouts. pingTimeouts=%s, tempValue=%s', self.pingTimeouts, tempValue.getType()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
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
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.powerSupplyFailureRequested = False self.powerSupplyFailure = None self.powerSupplyFailureSet = False self.powerSupplyFailureReasonRequested = False self.powerSupplyFailureReason = None self.powerSupplyFailureReasonSet = 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.requestPowerSupplyFailure(True) self.requestPowerSupplyFailureReason(True) def requestConfig (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestPowerSupplyFailure(False) self.requestPowerSupplyFailureReason(False) def requestOper (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestPowerSupplyFailure(True) self.requestPowerSupplyFailureReason(True) def clearAllRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestPowerSupplyFailure(False) self.requestPowerSupplyFailureReason(False) def clearAllSet (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') 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 requestPowerSupplyFailure (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-powersupplyfailure').debug3Func(): logFunc('called. requested=%s', requested) self.powerSupplyFailureRequested = requested self.powerSupplyFailureSet = False def isPowerSupplyFailureRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-powersupplyfailure-requested').debug3Func(): logFunc('called. requested=%s', self.powerSupplyFailureRequested) return self.powerSupplyFailureRequested def getPowerSupplyFailure (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-powersupplyfailure').debug3Func(): logFunc('called. self.powerSupplyFailureSet=%s, self.powerSupplyFailure=%s', self.powerSupplyFailureSet, self.powerSupplyFailure) if self.powerSupplyFailureSet: return self.powerSupplyFailure return None def hasPowerSupplyFailure (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-powersupplyfailure').debug3Func(): logFunc('called. self.powerSupplyFailureSet=%s, self.powerSupplyFailure=%s', self.powerSupplyFailureSet, self.powerSupplyFailure) if self.powerSupplyFailureSet: return True return False def setPowerSupplyFailure (self, powerSupplyFailure): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-powersupplyfailure').debug3Func(): logFunc('called. powerSupplyFailure=%s, old=%s', powerSupplyFailure, self.powerSupplyFailure) self.powerSupplyFailureSet = True self.powerSupplyFailure = powerSupplyFailure def requestPowerSupplyFailureReason (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-powersupplyfailurereason').debug3Func(): logFunc('called. requested=%s', requested) self.powerSupplyFailureReasonRequested = requested self.powerSupplyFailureReasonSet = False def isPowerSupplyFailureReasonRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-powersupplyfailurereason-requested').debug3Func(): logFunc('called. requested=%s', self.powerSupplyFailureReasonRequested) return self.powerSupplyFailureReasonRequested def getPowerSupplyFailureReason (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-powersupplyfailurereason').debug3Func(): logFunc('called. self.powerSupplyFailureReasonSet=%s, self.powerSupplyFailureReason=%s', self.powerSupplyFailureReasonSet, self.powerSupplyFailureReason) if self.powerSupplyFailureReasonSet: return self.powerSupplyFailureReason return None def hasPowerSupplyFailureReason (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-powersupplyfailurereason').debug3Func(): logFunc('called. self.powerSupplyFailureReasonSet=%s, self.powerSupplyFailureReason=%s', self.powerSupplyFailureReasonSet, self.powerSupplyFailureReason) if self.powerSupplyFailureReasonSet: return True return False def setPowerSupplyFailureReason (self, powerSupplyFailureReason): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-powersupplyfailurereason').debug3Func(): logFunc('called. powerSupplyFailureReason=%s, old=%s', powerSupplyFailureReason, self.powerSupplyFailureReason) self.powerSupplyFailureReasonSet = True self.powerSupplyFailureReason = powerSupplyFailureReason def _clearAllReadData (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.powerSupplyFailure = 0 self.powerSupplyFailureSet = False self.powerSupplyFailureReason = 0 self.powerSupplyFailureReasonSet = 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(("alarm", "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) 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.isPowerSupplyFailureRequested(): valPowerSupplyFailure = Value() valPowerSupplyFailure.setEmpty() tagValueList.push(("power-supply-failure", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power"), valPowerSupplyFailure) if self.isPowerSupplyFailureReasonRequested(): valPowerSupplyFailureReason = Value() valPowerSupplyFailureReason.setEmpty() tagValueList.push(("power-supply-failure-reason", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power"), valPowerSupplyFailureReason) 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.isPowerSupplyFailureRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "power-supply-failure") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-powersupplyfailure').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "powerSupplyFailure", "power-supply-failure", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power", 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-power-supply-failure-bad-value').infoFunc(): logFunc('powerSupplyFailure not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setPowerSupplyFailure(tempVar) for logFunc in self._log('read-tag-values-power-supply-failure').debug3Func(): logFunc('read powerSupplyFailure. powerSupplyFailure=%s, tempValue=%s', self.powerSupplyFailure, tempValue.getType()) if self.isPowerSupplyFailureReasonRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "power-supply-failure-reason") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-powersupplyfailurereason').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "powerSupplyFailureReason", "power-supply-failure-reason", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power", 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-power-supply-failure-reason-bad-value').infoFunc(): logFunc('powerSupplyFailureReason not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setPowerSupplyFailureReason(tempVar) for logFunc in self._log('read-tag-values-power-supply-failure-reason').debug3Func(): logFunc('read powerSupplyFailureReason. powerSupplyFailureReason=%s, tempValue=%s', self.powerSupplyFailureReason, tempValue.getType()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
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
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) 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
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
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.timeoutsObj = None self.implementationRequested = False self.implementation = None self.implementationSet = False self.internalIdRequested = False self.internalId = None self.internalIdSet = 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.requestImplementation(True) self.requestInternalId(True) if not self.timeoutsObj: self.timeoutsObj = self.newTimeouts() self.timeoutsObj.requestConfigAndOper() def requestConfig (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestImplementation(True) self.requestInternalId(True) if not self.timeoutsObj: self.timeoutsObj = self.newTimeouts() self.timeoutsObj.requestConfig() def requestOper (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestImplementation(False) self.requestInternalId(False) if not self.timeoutsObj: self.timeoutsObj = self.newTimeouts() self.timeoutsObj.requestOper() def clearAllRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestImplementation(False) self.requestInternalId(False) if not self.timeoutsObj: self.timeoutsObj = self.newTimeouts() self.timeoutsObj.clearAllRequested() def clearAllSet (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') self.setImplementation(None) self.implementationSet = False self.setInternalId(None) self.internalIdSet = False if self.timeoutsObj: self.timeoutsObj.clearAllSet() 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 newTimeouts (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('new-timeouts').debug3Func(): logFunc('called.') timeouts = BlinkyTimeoutsMaapi(self._log) timeouts.init(self.domain) return timeouts def setTimeoutsObj (self, obj): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-timeouts').debug3Func(): logFunc('called. obj=%s', obj) self.timeoutsObj = obj def getTimeoutsObj (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-timeouts').debug3Func(): logFunc('called. self.timeoutsObj=%s', self.timeoutsObj) return self.timeoutsObj def hasTimeouts (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-timeouts').debug3Func(): logFunc('called. self.timeoutsObj=%s', self.timeoutsObj) if self.timeoutsObj: return True return False 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 requestInternalId (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-internalid').debug3Func(): logFunc('called. requested=%s', requested) self.internalIdRequested = requested self.internalIdSet = False def isInternalIdRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-internalid-requested').debug3Func(): logFunc('called. requested=%s', self.internalIdRequested) return self.internalIdRequested def getInternalId (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-internalid').debug3Func(): logFunc('called. self.internalIdSet=%s, self.internalId=%s', self.internalIdSet, self.internalId) if self.internalIdSet: return self.internalId return None def hasInternalId (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-internalid').debug3Func(): logFunc('called. self.internalIdSet=%s, self.internalId=%s', self.internalIdSet, self.internalId) if self.internalIdSet: return True return False def setInternalId (self, internalId): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-internalid').debug3Func(): logFunc('called. internalId=%s, old=%s', internalId, self.internalId) self.internalIdSet = True self.internalId = internalId def _clearAllReadData (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') if self.timeoutsObj: self.timeoutsObj._clearAllReadData() self.implementation = 0 self.implementationSet = False self.internalId = 0 self.internalIdSet = 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(("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) if self.timeoutsObj: res = self.timeoutsObj._collectItemsToDelete(controller, itemsToDelete) if res != ReturnCodes.kOk: for logFunc in self._log('collect-items-to-delete-timeouts-failed').errorFunc(): logFunc('timeoutsObj._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.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-controller"), valImplementation) if self.hasInternalId(): valInternalId = Value() if self.internalId is not None: valInternalId.setString(self.internalId) else: valInternalId.setEmpty() tagValueList.push(("internal-id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller"), valInternalId) if self.timeoutsObj: valBegin = Value() (tag, ns, prefix) = ("timeouts" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller", "qt-strg-ctrl") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) tagValueListLen = tagValueList.getLen() res = self.timeoutsObj._fillWriteTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log('fill-write-tag-values-timeouts-failed').errorFunc(): logFunc('timeoutsObj._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.isImplementationRequested(): valImplementation = Value() valImplementation.setEmpty() tagValueList.push(("implementation", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller"), valImplementation) if self.isInternalIdRequested(): valInternalId = Value() valInternalId.setEmpty() tagValueList.push(("internal-id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller"), valInternalId) if self.timeoutsObj: valBegin = Value() (tag, ns, prefix) = ("timeouts" , "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller", "qt-strg-ctrl") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) tagValueListLen = tagValueList.getLen() res = self.timeoutsObj._fillReadTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log('fill-read-tag-values-timeouts-failed').errorFunc(): logFunc('timeoutsObj._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.isImplementationRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "implementation") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller"): 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-controller", 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.isInternalIdRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "internal-id") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-internalid').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "internalId", "internal-id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller", 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-internal-id-bad-value').infoFunc(): logFunc('internalId not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setInternalId(tempVar) for logFunc in self._log('read-tag-values-internal-id').debug3Func(): logFunc('read internalId. internalId=%s, tempValue=%s', self.internalId, tempValue.getType()) if self.timeoutsObj: ((tag, ns), valBegin) = tagValueList.popFront() if (tag != "timeouts") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller") 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)', "timeouts", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller", Value.kXmlBegin, tag, ns, valBegin.getType()) self._clearAllReadData() return ReturnCodes.kGeneralError res = self.timeoutsObj._readTagValues(tagValueList, readAllOrFail) if res != ReturnCodes.kOk: for logFunc in self._log('read-tag-values-timeouts-failed').errorFunc(): logFunc('timeoutsObj._readTagValues() failed. tagValueList=%s', tagValueList) if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError ((tag, ns), valEnd) = tagValueList.popFront() if (tag != "timeouts") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller") 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)', "timeouts", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-controller", 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
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
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.driverTypeRequested = False self.driverType = None self.driverTypeSet = False self.pciAddressRequested = False self.pciAddress = None self.pciAddressSet = False self.routeTableIdRequested = False self.routeTableId = None self.routeTableIdSet = 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.requestDriverType(True) self.requestPciAddress(True) self.requestRouteTableId(True) def requestConfig(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestDriverType(False) self.requestPciAddress(False) self.requestRouteTableId(False) def requestOper(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestDriverType(True) self.requestPciAddress(True) self.requestRouteTableId(True) def clearAllRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestDriverType(False) self.requestPciAddress(False) self.requestRouteTableId(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 requestDriverType(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-drivertype').debug3Func(): logFunc('called. requested=%s', requested) self.driverTypeRequested = requested self.driverTypeSet = False def isDriverTypeRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-drivertype-requested').debug3Func(): logFunc('called. requested=%s', self.driverTypeRequested) return self.driverTypeRequested def getDriverType(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-drivertype').debug3Func(): logFunc('called. self.driverTypeSet=%s, self.driverType=%s', self.driverTypeSet, self.driverType) if self.driverTypeSet: return self.driverType return None def hasDriverType(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-drivertype').debug3Func(): logFunc('called. self.driverTypeSet=%s, self.driverType=%s', self.driverTypeSet, self.driverType) if self.driverTypeSet: return True return False def setDriverType(self, driverType): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-drivertype').debug3Func(): logFunc('called. driverType=%s, old=%s', driverType, self.driverType) self.driverTypeSet = True self.driverType = driverType def requestPciAddress(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-pciaddress').debug3Func(): logFunc('called. requested=%s', requested) self.pciAddressRequested = requested self.pciAddressSet = False def isPciAddressRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-pciaddress-requested').debug3Func(): logFunc('called. requested=%s', self.pciAddressRequested) return self.pciAddressRequested def getPciAddress(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-pciaddress').debug3Func(): logFunc('called. self.pciAddressSet=%s, self.pciAddress=%s', self.pciAddressSet, self.pciAddress) if self.pciAddressSet: return self.pciAddress return None def hasPciAddress(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-pciaddress').debug3Func(): logFunc('called. self.pciAddressSet=%s, self.pciAddress=%s', self.pciAddressSet, self.pciAddress) if self.pciAddressSet: return True return False def setPciAddress(self, pciAddress): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-pciaddress').debug3Func(): logFunc('called. pciAddress=%s, old=%s', pciAddress, self.pciAddress) self.pciAddressSet = True self.pciAddress = pciAddress def requestRouteTableId(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-routetableid').debug3Func(): logFunc('called. requested=%s', requested) self.routeTableIdRequested = requested self.routeTableIdSet = False def isRouteTableIdRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-routetableid-requested').debug3Func(): logFunc('called. requested=%s', self.routeTableIdRequested) return self.routeTableIdRequested def getRouteTableId(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-routetableid').debug3Func(): logFunc('called. self.routeTableIdSet=%s, self.routeTableId=%s', self.routeTableIdSet, self.routeTableId) if self.routeTableIdSet: return self.routeTableId return None def hasRouteTableId(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-routetableid').debug3Func(): logFunc('called. self.routeTableIdSet=%s, self.routeTableId=%s', self.routeTableIdSet, self.routeTableId) if self.routeTableIdSet: return True return False def setRouteTableId(self, routeTableId): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-routetableid').debug3Func(): logFunc('called. routeTableId=%s, old=%s', routeTableId, self.routeTableId) self.routeTableIdSet = True self.routeTableId = routeTableId def _clearAllReadData(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.driverType = 0 self.driverTypeSet = False self.pciAddress = 0 self.pciAddressSet = False self.routeTableId = 0 self.routeTableIdSet = 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( ("device", "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.isDriverTypeRequested(): valDriverType = Value() valDriverType.setEmpty() tagValueList.push( ("driver-type", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valDriverType) if self.isPciAddressRequested(): valPciAddress = Value() valPciAddress.setEmpty() tagValueList.push( ("pci-address", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valPciAddress) if self.isRouteTableIdRequested(): valRouteTableId = Value() valRouteTableId.setEmpty() tagValueList.push( ("route-table-id", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"), valRouteTableId) 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.isDriverTypeRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "driver-type") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-drivertype' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "driverType", "driver-type", "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-driver-type-bad-value').infoFunc(): logFunc('driverType not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setDriverType(tempVar) for logFunc in self._log( 'read-tag-values-driver-type').debug3Func(): logFunc('read driverType. driverType=%s, tempValue=%s', self.driverType, tempValue.getType()) if self.isPciAddressRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "pci-address") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-pciaddress' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "pciAddress", "pci-address", "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-address-bad-value').infoFunc(): logFunc('pciAddress not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setPciAddress(tempVar) for logFunc in self._log( 'read-tag-values-pci-address').debug3Func(): logFunc('read pciAddress. pciAddress=%s, tempValue=%s', self.pciAddress, tempValue.getType()) if self.isRouteTableIdRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "route-table-id") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-routetableid' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "routeTableId", "route-table-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-route-table-id-bad-value').infoFunc(): logFunc('routeTableId not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setRouteTableId(tempVar) for logFunc in self._log( 'read-tag-values-route-table-id').debug3Func(): logFunc('read routeTableId. routeTableId=%s, tempValue=%s', self.routeTableId, tempValue.getType()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
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
class BlinkyQueueMaapi(QueueMaapiBase): def __init__(self, logger): self.myInitGuard = InitGuard() self._log = logger.createLogger("sys-blinky-oper-example", "blinky-maapi-queue_") self.domain = None self.systemDefaultsObj = None self.queueThresholdLowRequested = False self.queueThresholdLow = None self.queueThresholdLowSet = False self.queueSizeRequested = False self.queueSize = None self.queueSizeSet = False self.queueThresholdHighRequested = False self.queueThresholdHigh = None self.queueThresholdHighSet = 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.requestQueueThresholdLow(True) self.requestQueueSize(True) self.requestQueueThresholdHigh(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.requestQueueThresholdLow(True) self.requestQueueSize(True) self.requestQueueThresholdHigh(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.requestQueueThresholdLow(False) self.requestQueueSize(False) self.requestQueueThresholdHigh(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.requestQueueThresholdLow(False) self.requestQueueSize(False) self.requestQueueThresholdHigh(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.setQueueThresholdLow(None) self.queueThresholdLowSet = False self.setQueueSize(None) self.queueSizeSet = False self.setQueueThresholdHigh(None) self.queueThresholdHighSet = False self.setName(None) self.nameSet = False if self.systemDefaultsObj: self.systemDefaultsObj.clearAllSet() def write(self, line, queueGroup, queue_, trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS') return self._internalWrite(line, queueGroup, queue_, trxContext) def read(self, line, queueGroup, queue_, trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS') return self._internalRead(line, queueGroup, queue_, False, trxContext) def readAllOrFail(self, line, queueGroup, queue_, trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS') return self._internalRead(line, queueGroup, queue_, 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 requestQueueThresholdLow(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-queuethresholdlow').debug3Func(): logFunc('called. requested=%s', requested) self.queueThresholdLowRequested = requested self.queueThresholdLowSet = False def isQueueThresholdLowRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log( 'is-queuethresholdlow-requested').debug3Func(): logFunc('called. requested=%s', self.queueThresholdLowRequested) return self.queueThresholdLowRequested def getQueueThresholdLow(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-queuethresholdlow').debug3Func(): logFunc( 'called. self.queueThresholdLowSet=%s, self.queueThresholdLow=%s', self.queueThresholdLowSet, self.queueThresholdLow) if self.queueThresholdLowSet: return self.queueThresholdLow return None def hasQueueThresholdLow(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-queuethresholdlow').debug3Func(): logFunc( 'called. self.queueThresholdLowSet=%s, self.queueThresholdLow=%s', self.queueThresholdLowSet, self.queueThresholdLow) if self.queueThresholdLowSet: return True return False def setQueueThresholdLow(self, queueThresholdLow): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-queuethresholdlow').debug3Func(): logFunc('called. queueThresholdLow=%s, old=%s', queueThresholdLow, self.queueThresholdLow) self.queueThresholdLowSet = True self.queueThresholdLow = queueThresholdLow def requestQueueSize(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-queuesize').debug3Func(): logFunc('called. requested=%s', requested) self.queueSizeRequested = requested self.queueSizeSet = False def isQueueSizeRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-queuesize-requested').debug3Func(): logFunc('called. requested=%s', self.queueSizeRequested) return self.queueSizeRequested def getQueueSize(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-queuesize').debug3Func(): logFunc('called. self.queueSizeSet=%s, self.queueSize=%s', self.queueSizeSet, self.queueSize) if self.queueSizeSet: return self.queueSize return None def hasQueueSize(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-queuesize').debug3Func(): logFunc('called. self.queueSizeSet=%s, self.queueSize=%s', self.queueSizeSet, self.queueSize) if self.queueSizeSet: return True return False def setQueueSize(self, queueSize): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-queuesize').debug3Func(): logFunc('called. queueSize=%s, old=%s', queueSize, self.queueSize) self.queueSizeSet = True self.queueSize = queueSize def requestQueueThresholdHigh(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-queuethresholdhigh').debug3Func(): logFunc('called. requested=%s', requested) self.queueThresholdHighRequested = requested self.queueThresholdHighSet = False def isQueueThresholdHighRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log( 'is-queuethresholdhigh-requested').debug3Func(): logFunc('called. requested=%s', self.queueThresholdHighRequested) return self.queueThresholdHighRequested def getQueueThresholdHigh(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-queuethresholdhigh').debug3Func(): logFunc( 'called. self.queueThresholdHighSet=%s, self.queueThresholdHigh=%s', self.queueThresholdHighSet, self.queueThresholdHigh) if self.queueThresholdHighSet: return self.queueThresholdHigh return None def hasQueueThresholdHigh(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-queuethresholdhigh').debug3Func(): logFunc( 'called. self.queueThresholdHighSet=%s, self.queueThresholdHigh=%s', self.queueThresholdHighSet, self.queueThresholdHigh) if self.queueThresholdHighSet: return True return False def setQueueThresholdHigh(self, queueThresholdHigh): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-queuethresholdhigh').debug3Func(): logFunc('called. queueThresholdHigh=%s, old=%s', queueThresholdHigh, self.queueThresholdHigh) self.queueThresholdHighSet = True self.queueThresholdHigh = queueThresholdHigh 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.queueThresholdLow = 0 self.queueThresholdLowSet = False self.queueSize = 0 self.queueSizeSet = False self.queueThresholdHigh = 0 self.queueThresholdHighSet = False self.name = 0 self.nameSet = False def _getSelfKeyPath(self, line, queueGroup, queue_, junkForTemplate): for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate) keyPath = KeyPath() ancestorVal = Value() ancestorVal.setString(queue_) keyPath.addKeyPathPrefix(ancestorVal) xmlVal = Value() xmlVal.setXmlTag( ("queue", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", "qtc-line")) keyPath.addKeyPathPrefix(xmlVal) ancestorVal = Value() ancestorVal.setString(queueGroup) keyPath.addKeyPathPrefix(ancestorVal) xmlVal = Value() xmlVal.setXmlTag( ("queue-group", "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, queueGroup, queue_, 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, queueGroup, queue_, 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, queueGroup, queue_, 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, queueGroup, queue_, 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, queueGroup, queue_, 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, queueGroup, queue_, 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, queueGroup, queue_, 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.hasQueueThresholdLow(): valQueueThresholdLow = Value() if self.queueThresholdLow is not None: valQueueThresholdLow.setInt64(self.queueThresholdLow) else: valQueueThresholdLow.setEmpty() tagValueList.push( ("queue-threshold-low", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line" ), valQueueThresholdLow) if self.hasQueueSize(): valQueueSize = Value() if self.queueSize is not None: valQueueSize.setInt64(self.queueSize) else: valQueueSize.setEmpty() tagValueList.push( ("queue-size", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line" ), valQueueSize) if self.hasQueueThresholdHigh(): valQueueThresholdHigh = Value() if self.queueThresholdHigh is not None: valQueueThresholdHigh.setInt64(self.queueThresholdHigh) else: valQueueThresholdHigh.setEmpty() tagValueList.push( ("queue-threshold-high", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line" ), valQueueThresholdHigh) 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.isQueueThresholdLowRequested(): valQueueThresholdLow = Value() valQueueThresholdLow.setEmpty() tagValueList.push( ("queue-threshold-low", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line" ), valQueueThresholdLow) if self.isQueueSizeRequested(): valQueueSize = Value() valQueueSize.setEmpty() tagValueList.push( ("queue-size", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line" ), valQueueSize) if self.isQueueThresholdHighRequested(): valQueueThresholdHigh = Value() valQueueThresholdHigh.setEmpty() tagValueList.push( ("queue-threshold-high", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line" ), valQueueThresholdHigh) 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.isQueueThresholdLowRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "queue-threshold-low") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-queuethresholdlow' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "queueThresholdLow", "queue-threshold-low", "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-queue-threshold-low-bad-value' ).infoFunc(): logFunc('queueThresholdLow not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setQueueThresholdLow(tempVar) for logFunc in self._log( 'read-tag-values-queue-threshold-low').debug3Func(): logFunc( 'read queueThresholdLow. queueThresholdLow=%s, tempValue=%s', self.queueThresholdLow, tempValue.getType()) if self.isQueueSizeRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "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-queuesize' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "queueSize", "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-queue-size-bad-value').infoFunc(): logFunc('queueSize not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setQueueSize(tempVar) for logFunc in self._log( 'read-tag-values-queue-size').debug3Func(): logFunc('read queueSize. queueSize=%s, tempValue=%s', self.queueSize, tempValue.getType()) if self.isQueueThresholdHighRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "queue-threshold-high") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-queuethresholdhigh' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "queueThresholdHigh", "queue-threshold-high", "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-queue-threshold-high-bad-value' ).infoFunc(): logFunc('queueThresholdHigh not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setQueueThresholdHigh(tempVar) for logFunc in self._log( 'read-tag-values-queue-threshold-high').debug3Func(): logFunc( 'read queueThresholdHigh. queueThresholdHigh=%s, tempValue=%s', self.queueThresholdHigh, 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
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
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.statusObj = None self.autoInitRequested = False self.autoInit = None self.autoInitSet = False 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 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.requestAutoInit(True) self.requestOsDevice(True) self.requestImplementation(True) self.requestRaidType(True) self.requestName(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.requestAutoInit(True) self.requestOsDevice(True) self.requestImplementation(True) self.requestRaidType(True) self.requestName(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.requestAutoInit(False) self.requestOsDevice(False) self.requestImplementation(False) self.requestRaidType(False) self.requestName(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.requestAutoInit(False) self.requestOsDevice(False) self.requestImplementation(False) self.requestRaidType(False) self.requestName(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.setAutoInit(None) self.autoInitSet = False self.setOsDevice(None) self.osDeviceSet = False self.setImplementation(None) self.implementationSet = False self.setRaidType(None) self.raidTypeSet = False self.setName(None) self.nameSet = False if self.statusObj: self.statusObj.clearAllSet() 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 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 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 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 _clearAllReadData(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') if self.statusObj: self.statusObj._clearAllReadData() self.autoInit = 0 self.autoInitSet = False self.osDevice = 0 self.osDeviceSet = False self.implementation = 0 self.implementationSet = False self.raidType = 0 self.raidTypeSet = False self.name = 0 self.nameSet = 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) 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) if self.statusObj: res = self.statusObj._collectItemsToDelete(disk, 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.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) 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.statusObj: valBegin = Value() (tag, ns, prefix) = ( "status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk", "qt-strg-dsk") 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.isAutoInitRequested(): valAutoInit = Value() valAutoInit.setEmpty() tagValueList.push( ("auto-init", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk" ), valAutoInit) 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.statusObj: valBegin = Value() (tag, ns, prefix) = ( "status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk", "qt-strg-dsk") 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.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()) 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.statusObj: ((tag, ns), valBegin) = tagValueList.popFront() if (tag != "status") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-storage-disk") 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-storage-disk", 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-storage-disk") 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-storage-disk", 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
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
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) 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.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
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
class BlinkyIpv4Maapi(Ipv4MaapiBase): def __init__(self, logger): self.myInitGuard = InitGuard() self._log = logger.createLogger("sys-blinky-oper-example", "blinky-maapi-ipv4") self.domain = None self.statusObj = None self.arpObj = 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.arpObj: self.arpObj = self.newArp() self.arpObj.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.arpObj: self.arpObj = self.newArp() self.arpObj.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.arpObj: self.arpObj = self.newArp() self.arpObj.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.arpObj: self.arpObj = self.newArp() self.arpObj.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.arpObj: self.arpObj.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 newArp(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('new-arp').debug3Func(): logFunc('called.') arp = BlinkyArpMaapi(self._log) arp.init(self.domain) return arp def setArpObj(self, obj): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-arp').debug3Func(): logFunc('called. obj=%s', obj) self.arpObj = obj def getArpObj(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-arp').debug3Func(): logFunc('called. self.arpObj=%s', self.arpObj) return self.arpObj def hasArp(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-arp').debug3Func(): logFunc('called. self.arpObj=%s', self.arpObj) if self.arpObj: 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.arpObj: self.arpObj._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( ("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) 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.arpObj: res = self.arpObj._collectItemsToDelete(interface, itemsToDelete) if res != ReturnCodes.kOk: for logFunc in self._log( 'collect-items-to-delete-arp-failed').errorFunc(): logFunc('arpObj._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.arpObj: valBegin = Value() (tag, ns, prefix) = ( "arp", "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.arpObj._fillWriteTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log( 'fill-write-tag-values-arp-failed').errorFunc(): logFunc('arpObj._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.arpObj: valBegin = Value() (tag, ns, prefix) = ( "arp", "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.arpObj._fillReadTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log( 'fill-read-tag-values-arp-failed').errorFunc(): logFunc('arpObj._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.arpObj: ((tag, ns), valBegin) = tagValueList.popFront() if (tag != "arp") 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)', "arp", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-interfaces", Value.kXmlBegin, tag, ns, valBegin.getType()) self._clearAllReadData() return ReturnCodes.kGeneralError res = self.arpObj._readTagValues(tagValueList, readAllOrFail) if res != ReturnCodes.kOk: for logFunc in self._log( 'read-tag-values-arp-failed').errorFunc(): logFunc('arpObj._readTagValues() failed. tagValueList=%s', tagValueList) if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError ((tag, ns), valEnd) = tagValueList.popFront() if (tag != "arp") 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)', "arp", "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
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
class BlinkySimulationMaapi(SimulationMaapiBase): def __init__ (self, logger): self.myInitGuard = InitGuard() self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-simulation") self.domain = None self.forceOperationalStatusRequested = False self.forceOperationalStatus = None self.forceOperationalStatusSet = 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.requestForceOperationalStatus(True) def requestConfig (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestForceOperationalStatus(True) def requestOper (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestForceOperationalStatus(False) def clearAllRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestForceOperationalStatus(False) def clearAllSet (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') self.setForceOperationalStatus(None) self.forceOperationalStatusSet = 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 requestForceOperationalStatus (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-forceoperationalstatus').debug3Func(): logFunc('called. requested=%s', requested) self.forceOperationalStatusRequested = requested self.forceOperationalStatusSet = False def isForceOperationalStatusRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-forceoperationalstatus-requested').debug3Func(): logFunc('called. requested=%s', self.forceOperationalStatusRequested) return self.forceOperationalStatusRequested def getForceOperationalStatus (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-forceoperationalstatus').debug3Func(): logFunc('called. self.forceOperationalStatusSet=%s, self.forceOperationalStatus=%s', self.forceOperationalStatusSet, self.forceOperationalStatus) if self.forceOperationalStatusSet: return self.forceOperationalStatus return None def hasForceOperationalStatus (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-forceoperationalstatus').debug3Func(): logFunc('called. self.forceOperationalStatusSet=%s, self.forceOperationalStatus=%s', self.forceOperationalStatusSet, self.forceOperationalStatus) if self.forceOperationalStatusSet: return True return False def setForceOperationalStatus (self, forceOperationalStatus): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-forceoperationalstatus').debug3Func(): logFunc('called. forceOperationalStatus=%s, old=%s', forceOperationalStatus, self.forceOperationalStatus) self.forceOperationalStatusSet = True self.forceOperationalStatus = forceOperationalStatus def _clearAllReadData (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.forceOperationalStatus = 0 self.forceOperationalStatusSet = 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(("simulation", "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) 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, 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.hasForceOperationalStatus(): valForceOperationalStatus = Value() if self.forceOperationalStatus is not None: valForceOperationalStatus.setEnum(self.forceOperationalStatus.getValue()) else: valForceOperationalStatus.setEmpty() tagValueList.push(("force-operational-status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power"), valForceOperationalStatus) 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.isForceOperationalStatusRequested(): valForceOperationalStatus = Value() valForceOperationalStatus.setEmpty() tagValueList.push(("force-operational-status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power"), valForceOperationalStatus) 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.isForceOperationalStatusRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "force-operational-status") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-forceoperationalstatus').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "forceOperationalStatus", "force-operational-status", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-platform-power", 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-force-operational-status-bad-value').infoFunc(): logFunc('forceOperationalStatus not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setForceOperationalStatus(tempVar) for logFunc in self._log('read-tag-values-force-operational-status').debug3Func(): logFunc('read forceOperationalStatus. forceOperationalStatus=%s, tempValue=%s', self.forceOperationalStatus, tempValue.getType()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
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
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.queueUtilizationPercentRequested = False self.queueUtilizationPercent = None self.queueUtilizationPercentSet = 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.requestQueueUtilizationPercent(True) def requestConfig (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestQueueUtilizationPercent(False) def requestOper (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestQueueUtilizationPercent(True) def clearAllRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestQueueUtilizationPercent(False) def clearAllSet (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') def write (self , export_ , trxContext=None ): self.myInitGuard.isInitOrCrash() for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS') return self._internalWrite(export_, trxContext) def read (self , export_ , trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS') return self._internalRead(export_, False, trxContext) def readAllOrFail (self , export_ , trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS') return self._internalRead(export_, True, trxContext) def requestQueueUtilizationPercent (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-queueutilizationpercent').debug3Func(): logFunc('called. requested=%s', requested) self.queueUtilizationPercentRequested = requested self.queueUtilizationPercentSet = False def isQueueUtilizationPercentRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-queueutilizationpercent-requested').debug3Func(): logFunc('called. requested=%s', self.queueUtilizationPercentRequested) return self.queueUtilizationPercentRequested def getQueueUtilizationPercent (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-queueutilizationpercent').debug3Func(): logFunc('called. self.queueUtilizationPercentSet=%s, self.queueUtilizationPercent=%s', self.queueUtilizationPercentSet, self.queueUtilizationPercent) if self.queueUtilizationPercentSet: return self.queueUtilizationPercent return None def hasQueueUtilizationPercent (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-queueutilizationpercent').debug3Func(): logFunc('called. self.queueUtilizationPercentSet=%s, self.queueUtilizationPercent=%s', self.queueUtilizationPercentSet, self.queueUtilizationPercent) if self.queueUtilizationPercentSet: return True return False def setQueueUtilizationPercent (self, queueUtilizationPercent): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-queueutilizationpercent').debug3Func(): logFunc('called. queueUtilizationPercent=%s, old=%s', queueUtilizationPercent, self.queueUtilizationPercent) self.queueUtilizationPercentSet = True self.queueUtilizationPercent = queueUtilizationPercent def _clearAllReadData (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.queueUtilizationPercent = 0 self.queueUtilizationPercentSet = False def _getSelfKeyPath (self, export_ , 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-content-reporting", "qtc-report")) keyPath.addKeyPathPrefix(xmlVal) ancestorVal = Value() ancestorVal.setString(export_); keyPath.addKeyPathPrefix(ancestorVal) xmlVal = Value() xmlVal.setXmlTag(("export", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-reporting", "qtc-report")) keyPath.addKeyPathPrefix(xmlVal) xmlVal = Value() xmlVal.setXmlTag(("reporting", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-reporting", "qtc-report")) 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, export_, 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(export_, 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(export_, 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, export_, 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(export_, 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, export_, 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.isQueueUtilizationPercentRequested(): valQueueUtilizationPercent = Value() valQueueUtilizationPercent.setEmpty() tagValueList.push(("queue-utilization-percent", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-reporting"), valQueueUtilizationPercent) 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.isQueueUtilizationPercentRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "queue-utilization-percent") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-reporting"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-queueutilizationpercent').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "queueUtilizationPercent", "queue-utilization-percent", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-reporting", 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-queue-utilization-percent-bad-value').infoFunc(): logFunc('queueUtilizationPercent not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setQueueUtilizationPercent(tempVar) for logFunc in self._log('read-tag-values-queue-utilization-percent').debug3Func(): logFunc('read queueUtilizationPercent. queueUtilizationPercent=%s, tempValue=%s', self.queueUtilizationPercent, tempValue.getType()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
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
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.type_Requested = False self.type_ = None self.type_Set = False self.enabledRequested = False self.enabled = None self.enabledSet = 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.requestType_(True) self.requestEnabled(True) def requestConfig (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestType_(True) self.requestEnabled(True) def requestOper (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestType_(False) self.requestEnabled(False) def clearAllRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestType_(False) self.requestEnabled(False) def clearAllSet (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') self.setType_(None) self.type_Set = False self.setEnabled(None) self.enabledSet = False def write (self , line , interface , trxContext=None ): self.myInitGuard.isInitOrCrash() for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS') return self._internalWrite(line, interface, trxContext) def read (self , line , interface , trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS') return self._internalRead(line, interface, False, trxContext) def readAllOrFail (self , line , interface , trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS') return self._internalRead(line, interface, True, trxContext) def requestType_ (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-type_').debug3Func(): logFunc('called. requested=%s', requested) self.type_Requested = requested self.type_Set = False def isType_Requested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-type_-requested').debug3Func(): logFunc('called. requested=%s', self.type_Requested) return self.type_Requested def getType_ (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-type_').debug3Func(): logFunc('called. self.type_Set=%s, self.type_=%s', self.type_Set, self.type_) if self.type_Set: return self.type_ return None def hasType_ (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-type_').debug3Func(): logFunc('called. self.type_Set=%s, self.type_=%s', self.type_Set, self.type_) if self.type_Set: return True return False def setType_ (self, type_): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-type_').debug3Func(): logFunc('called. type_=%s, old=%s', type_, self.type_) self.type_Set = True self.type_ = type_ 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 _clearAllReadData (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.type_ = 0 self.type_Set = False self.enabled = 0 self.enabledSet = False def _getSelfKeyPath (self, line , interface , 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-content-line", "qtc-line")) 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-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, 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(line, 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(line, 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, line, 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(line, 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, line, 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.hasType_(): valType_ = Value() if self.type_ is not None: valType_.setEnum(self.type_.getValue()) else: valType_.setEmpty() tagValueList.push(("type", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valType_) 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) 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.isType_Requested(): valType_ = Value() valType_.setEmpty() tagValueList.push(("type", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valType_) if self.isEnabledRequested(): valEnabled = Value() valEnabled.setEmpty() tagValueList.push(("enabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"), valEnabled) 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.isType_Requested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "type") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-type_').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "type_", "type", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content-line", 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-type-bad-value').infoFunc(): logFunc('type_ not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setType_(tempVar) for logFunc in self._log('read-tag-values-type').debug3Func(): logFunc('read type_. type_=%s, tempValue=%s', self.type_, 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()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
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
class BlinkyConnectivityCheckMaapi(ConnectivityCheckMaapiBase): def __init__ (self, logger): self.myInitGuard = InitGuard() self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-connectivityCheck") self.domain = None self.ipv4Obj = None self.ipv6Obj = 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.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') 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') 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') 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') 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 _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() 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(("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.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.ipv4Obj: valBegin = Value() (tag, ns, prefix) = ("ipv4" , "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.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-interfaces", "qt-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.ipv4Obj: valBegin = Value() (tag, ns, prefix) = ("ipv4" , "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.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-interfaces", "qt-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.ipv4Obj: ((tag, ns), valBegin) = tagValueList.popFront() if (tag != "ipv4") 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)', "ipv4", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-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-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-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-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-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-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-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
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
class BlinkyDesignMaapi(DesignMaapiBase): def __init__ (self, logger): self.myInitGuard = InitGuard() self._log=logger.createLogger("sys-blinky-oper-example","blinky-maapi-design") self.domain = None self.colorRequested = False self.color = None self.colorSet = False self.patternRequested = False self.pattern = None self.patternSet = False self.macAddressRequested = False self.macAddress = None self.macAddressSet = False self.lineWidthRequested = False self.lineWidth = None self.lineWidthSet = 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.requestPattern(True) self.requestMacAddress(True) self.requestLineWidth(True) def requestConfig (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestColor(False) self.requestPattern(False) self.requestMacAddress(False) self.requestLineWidth(False) def requestOper (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestColor(True) self.requestPattern(True) self.requestMacAddress(True) self.requestLineWidth(True) def clearAllRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestColor(False) self.requestPattern(False) self.requestMacAddress(False) self.requestLineWidth(False) def clearAllSet (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') def write (self , lake , fish_ , trxContext=None ): self.myInitGuard.isInitOrCrash() for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS') return self._internalWrite(lake, fish_, trxContext) def read (self , lake , fish_ , trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS') return self._internalRead(lake, fish_, False, trxContext) def readAllOrFail (self , lake , fish_ , trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS') return self._internalRead(lake, fish_, True, trxContext) 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 requestPattern (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-pattern').debug3Func(): logFunc('called. requested=%s', requested) self.patternRequested = requested self.patternSet = False def isPatternRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-pattern-requested').debug3Func(): logFunc('called. requested=%s', self.patternRequested) return self.patternRequested def getPattern (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-pattern').debug3Func(): logFunc('called. self.patternSet=%s, self.pattern=%s', self.patternSet, self.pattern) if self.patternSet: return self.pattern return None def hasPattern (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-pattern').debug3Func(): logFunc('called. self.patternSet=%s, self.pattern=%s', self.patternSet, self.pattern) if self.patternSet: return True return False def setPattern (self, pattern): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-pattern').debug3Func(): logFunc('called. pattern=%s, old=%s', pattern, self.pattern) self.patternSet = True self.pattern = pattern def requestMacAddress (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-macaddress').debug3Func(): logFunc('called. requested=%s', requested) self.macAddressRequested = requested self.macAddressSet = False def isMacAddressRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-macaddress-requested').debug3Func(): logFunc('called. requested=%s', self.macAddressRequested) return self.macAddressRequested def getMacAddress (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-macaddress').debug3Func(): logFunc('called. self.macAddressSet=%s, self.macAddress=%s', self.macAddressSet, self.macAddress) if self.macAddressSet: return self.macAddress return None def hasMacAddress (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-macaddress').debug3Func(): logFunc('called. self.macAddressSet=%s, self.macAddress=%s', self.macAddressSet, self.macAddress) if self.macAddressSet: return True return False def setMacAddress (self, macAddress): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-macaddress').debug3Func(): logFunc('called. macAddress=%s, old=%s', macAddress, self.macAddress) self.macAddressSet = True self.macAddress = macAddress def requestLineWidth (self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-linewidth').debug3Func(): logFunc('called. requested=%s', requested) self.lineWidthRequested = requested self.lineWidthSet = False def isLineWidthRequested (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-linewidth-requested').debug3Func(): logFunc('called. requested=%s', self.lineWidthRequested) return self.lineWidthRequested def getLineWidth (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-linewidth').debug3Func(): logFunc('called. self.lineWidthSet=%s, self.lineWidth=%s', self.lineWidthSet, self.lineWidth) if self.lineWidthSet: return self.lineWidth return None def hasLineWidth (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-linewidth').debug3Func(): logFunc('called. self.lineWidthSet=%s, self.lineWidth=%s', self.lineWidthSet, self.lineWidth) if self.lineWidthSet: return True return False def setLineWidth (self, lineWidth): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-linewidth').debug3Func(): logFunc('called. lineWidth=%s, old=%s', lineWidth, self.lineWidth) self.lineWidthSet = True self.lineWidth = lineWidth def _clearAllReadData (self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.color = 0 self.colorSet = False self.pattern = 0 self.patternSet = False self.macAddress = 0 self.macAddressSet = False self.lineWidth = 0 self.lineWidthSet = False def _getSelfKeyPath (self, lake , fish_ , junkForTemplate): for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate) keyPath = KeyPath() xmlVal = Value() xmlVal.setXmlTag(("design", "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_, 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_, 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_, 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_, 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_, 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_, 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.isColorRequested(): valColor = Value() valColor.setEmpty() tagValueList.push(("color", "http://qwilt.com/model/lake-example"), valColor) if self.isPatternRequested(): valPattern = Value() valPattern.setEmpty() tagValueList.push(("pattern", "http://qwilt.com/model/lake-example"), valPattern) if self.isMacAddressRequested(): valMacAddress = Value() valMacAddress.setEmpty() tagValueList.push(("mac-address", "http://qwilt.com/model/lake-example"), valMacAddress) if self.isLineWidthRequested(): valLineWidth = Value() valLineWidth.setEmpty() tagValueList.push(("line-width", "http://qwilt.com/model/lake-example"), valLineWidth) 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/model/lake-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/model/lake-example", 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-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.isPatternRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "pattern") or \ (ns != "http://qwilt.com/model/lake-example"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-pattern').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "pattern", "pattern", "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-bad-value').infoFunc(): logFunc('pattern not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setPattern(tempVar) for logFunc in self._log('read-tag-values-pattern').debug3Func(): logFunc('read pattern. pattern=%s, tempValue=%s', self.pattern, tempValue.getType()) if self.isMacAddressRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "mac-address") or \ (ns != "http://qwilt.com/model/lake-example"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-macaddress').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "macAddress", "mac-address", "http://qwilt.com/model/lake-example", tag, ns) self._clearAllReadData() return ReturnCodes.kGeneralError tempVar = None tempVar = MacAddress('\0'*6) tempVar = MacAddress(tempValue.asBinary()) if res != ReturnCodes.kOk or tempVar is None: for logFunc in self._log('read-tag-values-mac-address-bad-value').infoFunc(): logFunc('macAddress not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setMacAddress(tempVar) for logFunc in self._log('read-tag-values-mac-address').debug3Func(): logFunc('read macAddress. macAddress=%s, tempValue=%s', self.macAddress, tempValue.getType()) if self.isLineWidthRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "line-width") or \ (ns != "http://qwilt.com/model/lake-example"): for logFunc in self._log('reag-tag-values-unexpected-tag-leaf-linewidth').errorFunc(): logFunc('got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "lineWidth", "line-width", "http://qwilt.com/model/lake-example", tag, ns) self._clearAllReadData() return ReturnCodes.kGeneralError tempVar = None tempVar = tempValue.asInt8() if res != ReturnCodes.kOk or tempVar is None: for logFunc in self._log('read-tag-values-line-width-bad-value').infoFunc(): logFunc('lineWidth not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setLineWidth(tempVar) for logFunc in self._log('read-tag-values-line-width').debug3Func(): logFunc('read lineWidth. lineWidth=%s, tempValue=%s', self.lineWidth, tempValue.getType()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
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
class BlinkyPrefixMaapi(PrefixMaapiBase): def __init__(self, logger): self.myInitGuard = InitGuard() self._log = logger.createLogger("sys-blinky-oper-example", "blinky-maapi-prefix") self.domain = None self.prefixRequested = False self.prefix = None self.prefixSet = 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.requestPrefix(True) def requestConfig(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestPrefix(True) def requestOper(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestPrefix(False) def clearAllRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestPrefix(False) def clearAllSet(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') self.setPrefix(None) self.prefixSet = False def write(self, zone, prefix, trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS') return self._internalWrite(zone, prefix, trxContext) def read(self, zone, prefix, trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS') return self._internalRead(zone, prefix, False, trxContext) def readAllOrFail(self, zone, prefix, trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS') return self._internalRead(zone, prefix, True, trxContext) def requestPrefix(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-prefix').debug3Func(): logFunc('called. requested=%s', requested) self.prefixRequested = requested self.prefixSet = False def isPrefixRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-prefix-requested').debug3Func(): logFunc('called. requested=%s', self.prefixRequested) return self.prefixRequested def getPrefix(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-prefix').debug3Func(): logFunc('called. self.prefixSet=%s, self.prefix=%s', self.prefixSet, self.prefix) if self.prefixSet: return self.prefix return None def hasPrefix(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-prefix').debug3Func(): logFunc('called. self.prefixSet=%s, self.prefix=%s', self.prefixSet, self.prefix) if self.prefixSet: return True return False def setPrefix(self, prefix): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-prefix').debug3Func(): logFunc('called. prefix=%s, old=%s', prefix, self.prefix) self.prefixSet = True self.prefix = prefix def _clearAllReadData(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.prefix = 0 self.prefixSet = False def _getSelfKeyPath(self, zone, prefix, junkForTemplate): for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate) keyPath = KeyPath() ancestorVal = Value() ancestorVal.setString(prefix) keyPath.addKeyPathPrefix(ancestorVal) xmlVal = Value() xmlVal.setXmlTag( ("prefix", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", "qtc")) keyPath.addKeyPathPrefix(xmlVal) 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 _internalWrite(self, zone, prefix, 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(zone, prefix, 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, prefix, 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, prefix, 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(zone, prefix, 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, zone, prefix, 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.hasPrefix(): valPrefix = Value() if self.prefix is not None: valPrefix.setIPv6Prefix(self.prefix) else: valPrefix.setEmpty() tagValueList.push( ("prefix", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"), valPrefix) 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.isPrefixRequested(): valPrefix = Value() valPrefix.setEmpty() tagValueList.push( ("prefix", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content"), valPrefix) 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.isPrefixRequested(): ((tag, ns), tempValue) = 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-leaf-prefix' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "prefix", "prefix", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-content", tag, ns) self._clearAllReadData() return ReturnCodes.kGeneralError tempVar = None tempVar = (tempValue.asIPv6Prefix()) if res != ReturnCodes.kOk or tempVar is None: for logFunc in self._log( 'read-tag-values-prefix-bad-value').infoFunc(): logFunc('prefix not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setPrefix(tempVar) for logFunc in self._log('read-tag-values-prefix').debug3Func(): logFunc('read prefix. prefix=%s, tempValue=%s', self.prefix, tempValue.getType()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
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
class BlinkyVariableMaapiList(VariableMaapiListBase): def __init__(self, logger): self.myInitGuard = InitGuard() self._log = logger.createLogger("sys-blinky-oper-example", "blinky-maapi-variable") self.domain = None self.variables = {} self.variableKeys = [] 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 newVariable(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('new-variable').debug3Func(): logFunc('called.') variable = BlinkyVariableMaapi(self._log) variable.init(self.domain) return variable def setVariableObj(self, key, variableObj): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-variable-obj').debug3Func(): logFunc('called. key=%s, variableObj=%s', key, variableObj) if key not in self.variables: self.variableKeys.append(key) self.variables[str(key)] = variableObj def getVariableObj(self, key): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-variable-obj').debug3Func(): logFunc('called. key=%s', key) if str(key) in self.variables.keys(): for logFunc in self._log('get-variable-obj-done').debug3Func(): logFunc('Done. found key=%s, obj=%s', key, self.variables[str(key)]) return self.variables[str(key)] for logFunc in self._log('get-variable-obj-missing').errorFunc(): logFunc('variable %s not in variables. existing items: %s', key, self.variables.keys()) return None def deleteVariable(self, key): self.myInitGuard.isInitOrCrash() for logFunc in self._log('delete-variable').debug3Func(): logFunc('called. key=%s', key) if str(key) not in self.variableKeys: for logFunc in self._log( 'delete-variable-not-found').warningFunc(): logFunc('key=%s is missing from the variableKeys list', key) if str(key) in self.variables.keys(): # internal problem - list & dictionary are not synced for logFunc in self._log( 'delete-variable-not-found-but-in-dict').errorFunc(): logFunc( 'variables dictionary & variableKeys list are out-of-sync. key %s exists in dict but not in list', key) return ReturnCodes.kGeneralError if str(key) not in self.variables.keys(): # internal problem - list & dictionary are not synced for logFunc in self._log( 'delete-variable-not-found-but-in-list').errorFunc(): logFunc( 'variables dictionary & variableKeys list are out-of-sync. key %s exists in list but not in dict', key) return ReturnCodes.kGeneralError self.variableKeys.remove(str(key)) del self.variables[str(key)] def hasVariableObj(self, key): self.myInitGuard.isInitOrCrash() has = False if str(key) in self.variables.keys(): if self.variables[str(key)]: has = True for logFunc in self._log('has-variable-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.variableKeys]) return self.variableKeys def requestConfigAndOper(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config-and-oper').debug3Func(): logFunc('called.') for variable in self.variables.values(): variable.requestConfigAndOper() def requestConfig(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called.') for variable in self.variables.values(): variable.requestConfig() def requestOper(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called.') for variable in self.variables.values(): variable.requestOper() def clearAllRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called.') for variable in self.variables.values(): variable.clearAllRequested() def _clearAllReadData(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') for variable in self.variables.values(): if variable: variable._clearAllReadData() def clearAllSet(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') for key in self.variables.keys(): if self.variables[key]: self.variables[key].clearAllSet() else: self.variableKeys.remove(str(key)) del self.variables[str(key)] def _getSelfKeyPath(self, linux_, variableCollection, junkForTemplate): for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS. junkForTemplate=%s', junkForTemplate) keyPath = KeyPath() ancestorVal = Value() ancestorVal.setString(variableCollection) keyPath.addKeyPathPrefix(ancestorVal) xmlVal = Value() xmlVal.setXmlTag( ("variable-collection", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-linux-variables", "qt-lnx-variables")) keyPath.addKeyPathPrefix(xmlVal) ancestorVal = Value() ancestorVal.setString(linux_) keyPath.addKeyPathPrefix(ancestorVal) xmlVal = Value() xmlVal.setXmlTag( ("linux", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-linux", "qt-lnx")) 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, linux_, variableCollection, trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read-list-keys').debug3Func(): logFunc('called') # clear the old map self.variables = {} self.variableKeys = [] keyPath = self._getSelfKeyPath(linux_, variableCollection, None) xmlVal = Value() xmlVal.setXmlTag( ("variable", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-linux-variables", "qt-lnx-variables")) 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.variableKeys.append(key.getCannonicalStr()) self.variables[key.getCannonicalStr()] = None return ReturnCodes.kOk def write(self, linux_, variableCollection, trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS') return self._internalWrite(linux_, variableCollection, trxContext) def read(self, linux_, variableCollection, trxContext=None): for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS') return self._internalRead(linux_, variableCollection, False, trxContext) def readAllOrFail(self, linux_, variableCollection, trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS') return self._internalRead(linux_, variableCollection, True, trxContext) def _internalWrite(self, linux_, variableCollection, 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(linux_, variableCollection, 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(linux_, variableCollection, 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, linux_, variableCollection, 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(linux_, variableCollection, 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, linux_, variableCollection, itemsToDelete): self.myInitGuard.isInitOrCrash() for logFunc in self._log('collect-items-to-delete').debug3Func(): logFunc('called: itemsToDelete=%s. PARAMS', itemsToDelete) for key in self.variables.keys(): if self.variables[key]: res = self.variables[key]._collectItemsToDelete( linux_, variableCollection, key, itemsToDelete) if res != ReturnCodes.kOk: for logFunc in self._log( 'collect-items-to-delete-variable-failed' ).errorFunc(): logFunc( 'variableObj._collectItemsToDelete() failed. key=%s. PARAMS', key) return ReturnCodes.kGeneralError else: keyPath = self._getSelfKeyPath(linux_, variableCollection, None) xmlVal = Value() xmlVal.setXmlTag(( "variable", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-linux-variables", "qt-lnx-variables")) 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.variables.keys(): if self.variables[key]: valBegin = Value() (tag, ns, prefix) = ( "variable", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-linux-variables", "qt-lnx-variables") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) valKey = Value() valKey.setString(key) tagValueList.push(( "name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-linux-variables" ), valKey) tagValueListLen = tagValueList.getLen() res = self.variables[key]._fillWriteTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log( 'fill-write-tag-values-variable-failed').errorFunc( ): logFunc( 'variable._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.variables.keys(): if self.variables[key]: valBegin = Value() (tag, ns, prefix) = ( "variable", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-linux-variables", "qt-lnx-variables") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) valKey = Value() valKey.setString(key) tagValueList.push(( "name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-linux-variables" ), valKey) tagValueListLen = tagValueList.getLen() res = self.variables[key]._fillReadTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log( 'fill-read-tag-values-variable-failed').errorFunc( ): logFunc('variable._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.variables.keys(): if self.variables[key]: ((tag, ns), valBegin) = tagValueList.popFront() if (tag != "variable") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-linux-variables") 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)', "variable", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-linux-variables", Value.kXmlBegin, tag, ns, valBegin.getType()) self._clearAllReadData() return ReturnCodes.kGeneralError ((tag, ns), valKey) = tagValueList.popFront() if (tag != "name") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-linux-variables"): 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)', "name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-linux-variables", tag, ns) self._clearAllReadData() return ReturnCodes.kGeneralError key = valKey.asString() if res != ReturnCodes.kOk: if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError res = self.variables[key]._readTagValues( tagValueList, readAllOrFail) if res != ReturnCodes.kOk: for logFunc in self._log( 'read-tag-values-variable-failed').errorFunc(): logFunc('variable._readTagValues() failed. key=%s', key) if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError ((tag, ns), valEnd) = tagValueList.popFront() if (tag != "variable") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-linux-variables") 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)', "variable", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-linux-variables", 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
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
class BlinkyRuleMaapi(RuleMaapiBase): def __init__(self, logger): self.myInitGuard = InitGuard() self._log = logger.createLogger("sys-blinky-oper-example", "blinky-maapi-rule") self.domain = None self.decisionObj = None self.matchObj = None self.disabledRequested = False self.disabled = None self.disabledSet = False self.nameRequested = False self.name = None self.nameSet = False self.descriptionRequested = False self.description = None self.descriptionSet = 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.requestDisabled(True) self.requestName(True) self.requestDescription(True) if not self.decisionObj: self.decisionObj = self.newDecision() self.decisionObj.requestConfigAndOper() if not self.matchObj: self.matchObj = self.newMatch() self.matchObj.requestConfigAndOper() def requestConfig(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestDisabled(True) self.requestName(True) self.requestDescription(True) if not self.decisionObj: self.decisionObj = self.newDecision() self.decisionObj.requestConfig() if not self.matchObj: self.matchObj = self.newMatch() self.matchObj.requestConfig() def requestOper(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestDisabled(False) self.requestName(False) self.requestDescription(False) if not self.decisionObj: self.decisionObj = self.newDecision() self.decisionObj.requestOper() if not self.matchObj: self.matchObj = self.newMatch() self.matchObj.requestOper() def clearAllRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestDisabled(False) self.requestName(False) self.requestDescription(False) if not self.decisionObj: self.decisionObj = self.newDecision() self.decisionObj.clearAllRequested() if not self.matchObj: self.matchObj = self.newMatch() self.matchObj.clearAllRequested() def clearAllSet(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') self.setDisabled(None) self.disabledSet = False self.setName(None) self.nameSet = False self.setDescription(None) self.descriptionSet = False if self.decisionObj: self.decisionObj.clearAllSet() if self.matchObj: self.matchObj.clearAllSet() 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 newDecision(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('new-decision').debug3Func(): logFunc('called.') decision = BlinkyDecisionMaapi(self._log) decision.init(self.domain) return decision def setDecisionObj(self, obj): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-decision').debug3Func(): logFunc('called. obj=%s', obj) self.decisionObj = obj def getDecisionObj(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-decision').debug3Func(): logFunc('called. self.decisionObj=%s', self.decisionObj) return self.decisionObj def hasDecision(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-decision').debug3Func(): logFunc('called. self.decisionObj=%s', self.decisionObj) if self.decisionObj: return True return False def newMatch(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('new-match').debug3Func(): logFunc('called.') match = BlinkyMatchMaapi(self._log) match.init(self.domain) return match def setMatchObj(self, obj): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-match').debug3Func(): logFunc('called. obj=%s', obj) self.matchObj = obj def getMatchObj(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-match').debug3Func(): logFunc('called. self.matchObj=%s', self.matchObj) return self.matchObj def hasMatch(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-match').debug3Func(): logFunc('called. self.matchObj=%s', self.matchObj) if self.matchObj: return True return False def requestDisabled(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-disabled').debug3Func(): logFunc('called. requested=%s', requested) self.disabledRequested = requested self.disabledSet = False def isDisabledRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-disabled-requested').debug3Func(): logFunc('called. requested=%s', self.disabledRequested) return self.disabledRequested def getDisabled(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-disabled').debug3Func(): logFunc('called. self.disabledSet=%s, self.disabled=%s', self.disabledSet, self.disabled) if self.disabledSet: return self.disabled return None def hasDisabled(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-disabled').debug3Func(): logFunc('called. self.disabledSet=%s, self.disabled=%s', self.disabledSet, self.disabled) if self.disabledSet: return True return False def setDisabled(self, disabled): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-disabled').debug3Func(): logFunc('called. disabled=%s, old=%s', disabled, self.disabled) self.disabledSet = True self.disabled = disabled 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 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 _clearAllReadData(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') if self.decisionObj: self.decisionObj._clearAllReadData() if self.matchObj: self.matchObj._clearAllReadData() self.disabled = 0 self.disabledSet = False self.name = 0 self.nameSet = False self.description = 0 self.descriptionSet = 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() 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) if self.decisionObj: res = self.decisionObj._collectItemsToDelete( loggerClass, instance, rule, itemsToDelete) if res != ReturnCodes.kOk: for logFunc in self._log( 'collect-items-to-delete-decision-failed').errorFunc(): logFunc( 'decisionObj._collectItemsToDelete() failed. PARAMS') return ReturnCodes.kGeneralError if self.matchObj: res = self.matchObj._collectItemsToDelete(loggerClass, instance, rule, itemsToDelete) if res != ReturnCodes.kOk: for logFunc in self._log( 'collect-items-to-delete-match-failed').errorFunc(): logFunc('matchObj._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.hasDisabled(): valDisabled = Value() if self.disabled is not None: valDisabled.setBool(self.disabled) else: valDisabled.setEmpty() tagValueList.push( ("disabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valDisabled) 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.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-debug"), valDescription) if self.decisionObj: valBegin = Value() (tag, ns, prefix) = ( "decision", "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.decisionObj._fillWriteTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log( 'fill-write-tag-values-decision-failed').errorFunc(): logFunc('decisionObj._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.matchObj: valBegin = Value() (tag, ns, prefix) = ( "match", "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.matchObj._fillWriteTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log( 'fill-write-tag-values-match-failed').errorFunc(): logFunc('matchObj._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.isDisabledRequested(): valDisabled = Value() valDisabled.setEmpty() tagValueList.push( ("disabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valDisabled) if self.isNameRequested(): valName = Value() valName.setEmpty() tagValueList.push( ("name", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valName) if self.isDescriptionRequested(): valDescription = Value() valDescription.setEmpty() tagValueList.push( ("description", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"), valDescription) if self.decisionObj: valBegin = Value() (tag, ns, prefix) = ( "decision", "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.decisionObj._fillReadTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log( 'fill-read-tag-values-decision-failed').errorFunc(): logFunc('decisionObj._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.matchObj: valBegin = Value() (tag, ns, prefix) = ( "match", "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.matchObj._fillReadTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log( 'fill-read-tag-values-match-failed').errorFunc(): logFunc('matchObj._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.isDisabledRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "disabled") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-disabled' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "disabled", "disabled", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", 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-disabled-bad-value').infoFunc(): logFunc('disabled not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setDisabled(tempVar) for logFunc in self._log('read-tag-values-disabled').debug3Func(): logFunc('read disabled. disabled=%s, tempValue=%s', self.disabled, tempValue.getType()) 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.isDescriptionRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "description") or \ (ns != "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug"): 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-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-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.decisionObj: ((tag, ns), valBegin) = tagValueList.popFront() if (tag != "decision") 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)', "decision", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", Value.kXmlBegin, tag, ns, valBegin.getType()) self._clearAllReadData() return ReturnCodes.kGeneralError res = self.decisionObj._readTagValues(tagValueList, readAllOrFail) if res != ReturnCodes.kOk: for logFunc in self._log( 'read-tag-values-decision-failed').errorFunc(): logFunc( 'decisionObj._readTagValues() failed. tagValueList=%s', tagValueList) if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError ((tag, ns), valEnd) = tagValueList.popFront() if (tag != "decision") 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)', "decision", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", Value.kXmlEnd, tag, ns, valEnd.getType()) self._clearAllReadData() return ReturnCodes.kGeneralError if self.matchObj: ((tag, ns), valBegin) = tagValueList.popFront() if (tag != "match") 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)', "match", "http://qwilt.com/ns/yang/device/tech/qwilt-tech-debug", Value.kXmlBegin, tag, ns, valBegin.getType()) self._clearAllReadData() return ReturnCodes.kGeneralError res = self.matchObj._readTagValues(tagValueList, readAllOrFail) if res != ReturnCodes.kOk: for logFunc in self._log( 'read-tag-values-match-failed').errorFunc(): logFunc( 'matchObj._readTagValues() failed. tagValueList=%s', tagValueList) if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError ((tag, ns), valEnd) = tagValueList.popFront() if (tag != "match") 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)', "match", "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
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
class BlinkyConfigUMaapi(ConfigUMaapiBase): def __init__(self, logger): self.myInitGuard = InitGuard() self._log = logger.createLogger("sys-blinky-oper-example", "blinky-maapi-configU") self.domain = None self.valueConfigU1Requested = False self.valueConfigU1 = None self.valueConfigU1Set = 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.requestValueConfigU1(True) def requestConfig(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestValueConfigU1(True) def requestOper(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestValueConfigU1(False) def clearAllRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestValueConfigU1(False) def clearAllSet(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') self.setValueConfigU1(None) self.valueConfigU1Set = False def write(self, configU, trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('write').debug3Func(): logFunc('called, PARAMS') return self._internalWrite(configU, trxContext) def read(self, configU, trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read').debug3Func(): logFunc('called, PARAMS') return self._internalRead(configU, False, trxContext) def readAllOrFail(self, configU, trxContext=None): self.myInitGuard.isInitOrCrash() for logFunc in self._log('read-all-or-fail').debug3Func(): logFunc('called, PARAMS') return self._internalRead(configU, True, trxContext) def requestValueConfigU1(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-valueconfigu1').debug3Func(): logFunc('called. requested=%s', requested) self.valueConfigU1Requested = requested self.valueConfigU1Set = False def isValueConfigU1Requested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-valueconfigu1-requested').debug3Func(): logFunc('called. requested=%s', self.valueConfigU1Requested) return self.valueConfigU1Requested def getValueConfigU1(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-valueconfigu1').debug3Func(): logFunc('called. self.valueConfigU1Set=%s, self.valueConfigU1=%s', self.valueConfigU1Set, self.valueConfigU1) if self.valueConfigU1Set: return self.valueConfigU1 return None def hasValueConfigU1(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-valueconfigu1').debug3Func(): logFunc('called. self.valueConfigU1Set=%s, self.valueConfigU1=%s', self.valueConfigU1Set, self.valueConfigU1) if self.valueConfigU1Set: return True return False def setValueConfigU1(self, valueConfigU1): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-valueconfigu1').debug3Func(): logFunc('called. valueConfigU1=%s, old=%s', valueConfigU1, self.valueConfigU1) self.valueConfigU1Set = True self.valueConfigU1 = valueConfigU1 def _clearAllReadData(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') self.valueConfigU1 = 0 self.valueConfigU1Set = False def _getSelfKeyPath(self, configU, junkForTemplate): for logFunc in self._log('get-self-key-path').debug3Func(): logFunc('called. PARAMS, junkForTemplate=%s', junkForTemplate) keyPath = KeyPath() ancestorVal = Value() ancestorVal.setString(configU) keyPath.addKeyPathPrefix(ancestorVal) xmlVal = Value() xmlVal.setXmlTag(("config-u", "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, configU, 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(configU, 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(configU, 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, configU, 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(configU, 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, configU, 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.hasValueConfigU1(): valValueConfigU1 = Value() if self.valueConfigU1 is not None: valValueConfigU1.setString(self.valueConfigU1) else: valValueConfigU1.setEmpty() tagValueList.push( ("value-config-u1", "http://qwilt.com/model/oper"), valValueConfigU1) 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.isValueConfigU1Requested(): valValueConfigU1 = Value() valValueConfigU1.setEmpty() tagValueList.push( ("value-config-u1", "http://qwilt.com/model/oper"), valValueConfigU1) 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.isValueConfigU1Requested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "value-config-u1") or \ (ns != "http://qwilt.com/model/oper"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-valueconfigu1' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "valueConfigU1", "value-config-u1", "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-config-u1-bad-value').infoFunc( ): logFunc('valueConfigU1 not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setValueConfigU1(tempVar) for logFunc in self._log( 'read-tag-values-value-config-u1').debug3Func(): logFunc('read valueConfigU1. valueConfigU1=%s, tempValue=%s', self.valueConfigU1, tempValue.getType()) for logFunc in self._log('read-tag-values-done').debug3Func(): logFunc('done. readAllOrFail=%s, tagValueList=%s', readAllOrFail, tagValueList) return ReturnCodes.kOk
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
class BlinkyOpBMaapi(OpBMaapiBase): def __init__(self, logger): self.myInitGuard = InitGuard() self._log = logger.createLogger("sys-blinky-oper-example", "blinky-maapi-opB") self.domain = None self.opCListObj = None self.opDObj = None self.opValueBRequested = False self.opValueB = None self.opValueBSet = 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.requestOpValueB(True) if not self.opCListObj: self.opCListObj = self.newOpCList() self.opCListObj.requestConfigAndOper() if not self.opDObj: self.opDObj = self.newOpD() self.opDObj.requestConfigAndOper() def requestConfig(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-config').debug3Func(): logFunc('called, PARAMS') self.requestOpValueB(False) if not self.opCListObj: self.opCListObj = self.newOpCList() self.opCListObj.requestConfig() if not self.opDObj: self.opDObj = self.newOpD() self.opDObj.requestConfig() def requestOper(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-oper').debug3Func(): logFunc('called, PARAMS') self.requestOpValueB(True) if not self.opCListObj: self.opCListObj = self.newOpCList() self.opCListObj.requestOper() if not self.opDObj: self.opDObj = self.newOpD() self.opDObj.requestOper() def clearAllRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-requested').debug3Func(): logFunc('called, PARAMS') self.requestOpValueB(False) if not self.opCListObj: self.opCListObj = self.newOpCList() self.opCListObj.clearAllRequested() if not self.opDObj: self.opDObj = self.newOpD() self.opDObj.clearAllRequested() def clearAllSet(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-set').debug3Func(): logFunc('called, PARAMS') if self.opCListObj: self.opCListObj.clearAllSet() if self.opDObj: self.opDObj.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 newOpCList(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('new-opclist').debug3Func(): logFunc('called.') opCList = BlinkyOpCMaapiList(self._log) opCList.init(self.domain) return opCList def setOpCListObj(self, obj): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-opclist').debug3Func(): logFunc('called. obj=%s', obj) self.opCListObj = obj def getOpCListObj(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-opclist').debug3Func(): logFunc('called. self.opCListObj=%s', self.opCListObj) return self.opCListObj def hasOpCList(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-opclist').debug3Func(): logFunc('called. self.opCListObj=%s', self.opCListObj) if self.opCListObj: return True return False def newOpD(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('new-opd').debug3Func(): logFunc('called.') opD = BlinkyOpDMaapi(self._log) opD.init(self.domain) return opD def setOpDObj(self, obj): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-opd').debug3Func(): logFunc('called. obj=%s', obj) self.opDObj = obj def getOpDObj(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-opd').debug3Func(): logFunc('called. self.opDObj=%s', self.opDObj) return self.opDObj def hasOpD(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-opd').debug3Func(): logFunc('called. self.opDObj=%s', self.opDObj) if self.opDObj: return True return False def requestOpValueB(self, requested): self.myInitGuard.isInitOrCrash() for logFunc in self._log('request-opvalueb').debug3Func(): logFunc('called. requested=%s', requested) self.opValueBRequested = requested self.opValueBSet = False def isOpValueBRequested(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('is-opvalueb-requested').debug3Func(): logFunc('called. requested=%s', self.opValueBRequested) return self.opValueBRequested def getOpValueB(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('get-opvalueb').debug3Func(): logFunc('called. self.opValueBSet=%s, self.opValueB=%s', self.opValueBSet, self.opValueB) if self.opValueBSet: return self.opValueB return None def hasOpValueB(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('has-opvalueb').debug3Func(): logFunc('called. self.opValueBSet=%s, self.opValueB=%s', self.opValueBSet, self.opValueB) if self.opValueBSet: return True return False def setOpValueB(self, opValueB): self.myInitGuard.isInitOrCrash() for logFunc in self._log('set-opvalueb').debug3Func(): logFunc('called. opValueB=%s, old=%s', opValueB, self.opValueB) self.opValueBSet = True self.opValueB = opValueB def _clearAllReadData(self): self.myInitGuard.isInitOrCrash() for logFunc in self._log('clear-all-read-data').debug3Func(): logFunc('called') if self.opCListObj: self.opCListObj._clearAllReadData() if self.opDObj: self.opDObj._clearAllReadData() self.opValueB = 0 self.opValueBSet = 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-b", "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) if self.opCListObj: res = self.opCListObj._collectItemsToDelete(itemsToDelete) if res != ReturnCodes.kOk: for logFunc in self._log( 'collect-items-to-delete-op-c-failed').errorFunc(): logFunc( 'opCListObj._collectItemsToDelete() failed. PARAMS') return ReturnCodes.kGeneralError if self.opDObj: res = self.opDObj._collectItemsToDelete(itemsToDelete) if res != ReturnCodes.kOk: for logFunc in self._log( 'collect-items-to-delete-op-d-failed').errorFunc(): logFunc('opDObj._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.opCListObj: valBegin = Value() (tag, ns, prefix) = ("op-c", "http://qwilt.com/model/oper", "oper") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) tagValueListLen = tagValueList.getLen() res = self.opCListObj._fillWriteTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log( 'fill-write-tag-values-op-c-failed').errorFunc(): logFunc('opCListObj._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.opDObj: valBegin = Value() (tag, ns, prefix) = ("op-d", "http://qwilt.com/model/oper", "oper") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) tagValueListLen = tagValueList.getLen() res = self.opDObj._fillWriteTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log( 'fill-write-tag-values-op-d-failed').errorFunc(): logFunc('opDObj._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.isOpValueBRequested(): valOpValueB = Value() valOpValueB.setEmpty() tagValueList.push(("op-value-b", "http://qwilt.com/model/oper"), valOpValueB) if self.opCListObj: valBegin = Value() (tag, ns, prefix) = ("op-c", "http://qwilt.com/model/oper", "oper") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) tagValueListLen = tagValueList.getLen() res = self.opCListObj._fillReadTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log( 'fill-read-tag-values-op-c-failed').errorFunc(): logFunc('opCListObj._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.opDObj: valBegin = Value() (tag, ns, prefix) = ("op-d", "http://qwilt.com/model/oper", "oper") valBegin.setXmlBegin((tag, ns, prefix)) tagValueList.push((tag, ns), valBegin) tagValueListLen = tagValueList.getLen() res = self.opDObj._fillReadTagValues(tagValueList) if res != ReturnCodes.kOk: for logFunc in self._log( 'fill-read-tag-values-op-d-failed').errorFunc(): logFunc('opDObj._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.isOpValueBRequested(): ((tag, ns), tempValue) = tagValueList.popFront() if (tag != "op-value-b") or \ (ns != "http://qwilt.com/model/oper"): for logFunc in self._log( 'reag-tag-values-unexpected-tag-leaf-opvalueb' ).errorFunc(): logFunc( 'got unexpected tag-value for leaf: %s. expected: (%s, %s), got: (%s, %s)', "opValueB", "op-value-b", "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-op-value-b-bad-value').infoFunc(): logFunc('opValueB not read') if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError if tempVar is not None: self.setOpValueB(tempVar) for logFunc in self._log( 'read-tag-values-op-value-b').debug3Func(): logFunc('read opValueB. opValueB=%s, tempValue=%s', self.opValueB, tempValue.getType()) if self.opCListObj: ((tag, ns), valBegin) = tagValueList.popFront() if (tag != "op-c") or \ (ns != "http://qwilt.com/model/oper") 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)', "op-c", "http://qwilt.com/model/oper", Value.kXmlBegin, tag, ns, valBegin.getType()) self._clearAllReadData() return ReturnCodes.kGeneralError res = self.opCListObj._readTagValues(tagValueList, readAllOrFail) if res != ReturnCodes.kOk: for logFunc in self._log( 'read-tag-values-op-c-failed').errorFunc(): logFunc( 'opCListObj._readTagValues() failed. tagValueList=%s', tagValueList) if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError ((tag, ns), valEnd) = tagValueList.popFront() if (tag != "op-c") or \ (ns != "http://qwilt.com/model/oper") 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)', "op-c", "http://qwilt.com/model/oper", Value.kXmlEnd, tag, ns, valEnd.getType()) self._clearAllReadData() return ReturnCodes.kGeneralError if self.opDObj: ((tag, ns), valBegin) = tagValueList.popFront() if (tag != "op-d") or \ (ns != "http://qwilt.com/model/oper") 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)', "op-d", "http://qwilt.com/model/oper", Value.kXmlBegin, tag, ns, valBegin.getType()) self._clearAllReadData() return ReturnCodes.kGeneralError res = self.opDObj._readTagValues(tagValueList, readAllOrFail) if res != ReturnCodes.kOk: for logFunc in self._log( 'read-tag-values-op-d-failed').errorFunc(): logFunc('opDObj._readTagValues() failed. tagValueList=%s', tagValueList) if readAllOrFail: self._clearAllReadData() return ReturnCodes.kGeneralError ((tag, ns), valEnd) = tagValueList.popFront() if (tag != "op-d") or \ (ns != "http://qwilt.com/model/oper") 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)', "op-d", "http://qwilt.com/model/oper", 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