本文整理汇总了Python中dao.Dao.getObjectById方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.getObjectById方法的具体用法?Python Dao.getObjectById怎么用?Python Dao.getObjectById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.getObjectById方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: L3ClosMediation
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import getObjectById [as 别名]
#.........这里部分代码省略.........
if dirty == True:
# update pod itself
pod.update(pod.id, pod.name, **podDict)
pod.inventoryData = base64.b64encode(zlib.compress(json.dumps(inventoryData)))
# clear existing inventory because user wants to rebuild inventory
self.dao.deleteObjects(pod.devices)
# 1. Build inventory
self.createSpineIFDs(pod, inventoryData['spines'])
self.createLeafIFDs(pod, inventoryData['leafs'])
# 2. Create inter-connect
self.createLinkBetweenIfds(pod)
# 3. allocate resource, ip-blocks, ASN
self.allocateResource(pod)
# update status
pod.state = 'updated'
self.dao.updateObjects([pod])
# TODO move the backup operation to CLI
# backup current database
util.backupDatabase(self.conf)
def updatePod(self, podId, podDict, inventoryDict = None):
'''
Modify an existing POD. As a sanity check, if we don't find the POD
by UUID, a ValueException is thrown
'''
if podId is not None:
try:
pod = self.dao.getObjectById(Pod, podId)
except (exc.NoResultFound) as e:
raise ValueError("Pod[id='%s']: not found" % (podId))
else:
# update other fields
self.updatePodData(pod, podDict, inventoryDict)
logger.info("Pod[id='%s', name='%s']: updated" % (pod.id, pod.name))
else:
raise ValueError("Pod id can't be None")
return pod
def deletePod(self, podId):
'''
Delete an existing POD. As a sanity check, if we don't find the POD
by UUID, a ValueException is thrown
'''
if podId is not None:
try:
pod = self.dao.getObjectById(Pod, podId)
except (exc.NoResultFound) as e:
raise ValueError("Pod[id='%s']: not found" % (podId))
else:
logger.info("Pod[id='%s', name='%s']: deleted" % (pod.id, pod.name))
self.dao.deleteObject(pod)
else:
raise ValueError("Pod id can't be None")
def createCablingPlan(self, podId):
'''
Finds Pod object by id and create cabling plan
It also creates the output folders for pod
'''
示例2: __init__
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import getObjectById [as 别名]
class ResourceAllocationReport:
def __init__(self, conf = {}, dao = None):
if any(conf) == False:
self.conf = util.loadConfig()
logger.setLevel(logging.getLevelName(self.conf['logLevel'][moduleName]))
else:
self.conf = conf
if dao is None:
self.dao = Dao(self.conf)
else:
self.dao = dao
def getPods(self):
podObject = self.dao.getAll(Pod)
pods = []
for i in range(len(podObject)):
pod = {}
pod['id'] = podObject[i].id
pod['name'] = podObject[i].name
pod['spineDeviceType'] = podObject[i].spineDeviceType
pod['spineCount'] = podObject[i].spineCount
pod['leafDeviceType'] = podObject[i].leafDeviceType
pod['leafCount'] = podObject[i].leafCount
pod['topologyType'] = podObject[i].topologyType
pods.append(pod)
return pods
def getPod(self, podName):
try:
return self.dao.getUniqueObjectByName(Pod, podName)
except (exc.NoResultFound) as e:
logger.debug("No Pod found with pod name: '%s', exc.NoResultFound: %s" % (podName, e.message))
def getIpFabric(self, ipFabricId):
try:
return self.dao.getObjectById(Pod, ipFabricId)
except (exc.NoResultFound) as e:
logger.debug("No IpFabric found with Id: '%s', exc.NoResultFound: %s" % (ipFabricId, e.message))
def getInterconnectAllocation(self, podName):
pod = self.getPod(podName)
if pod is None: return {}
interconnectAllocation = {}
interconnectAllocation['block'] = pod.interConnectPrefix
interconnectAllocation['allocated'] = pod.allocatedInterConnectBlock
return interconnectAllocation
def getLoopbackAllocation(self, podName):
pod = self.getPod(podName)
if pod is None: return {}
loopbackAllocation = {}
loopbackAllocation['block'] = pod.loopbackPrefix
loopbackAllocation['allocated'] = pod.allocatedLoopbackBlock
return loopbackAllocation
def getIrbAllocation(self, podName):
pod = self.getPod(podName)
if pod is None: return {}
irbAllocation = {}
irbAllocation['block'] = pod.vlanPrefix
irbAllocation['allocated'] = pod.allocatedIrbBlock
return irbAllocation
def getAsnAllocation(self, podName):
pod = self.getPod(podName)
if pod is None: return {}
asnAllocation = {}
asnAllocation['spineBlockStart'] = pod.spineAS
asnAllocation['spineBlockEnd'] = pod.leafAS - 1
asnAllocation['leafBlockStart'] = pod.leafAS
asnAllocation['leafBlockEnd'] = 65535
asnAllocation['spineAllocatedStart'] = pod.spineAS
asnAllocation['spineAllocatedEnd'] = pod.allocatedSpineAS
asnAllocation['leafAllocatedStart'] = pod.leafAS
asnAllocation['leafAllocatedEnd'] = pod.allocatefLeafAS
return asnAllocation