本文整理汇总了Python中dao.Dao.deleteObject方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.deleteObject方法的具体用法?Python Dao.deleteObject怎么用?Python Dao.deleteObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.deleteObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: L3ClosMediation
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import deleteObject [as 别名]
#.........这里部分代码省略.........
dirty = True
logger.info("Pod[id='%s', name='%s']: spineDeviceType changed" % (pod.id, pod.name))
if 'leafDeviceType' in podDict and pod.leafDeviceType != podDict['leafDeviceType']:
dirty = True
logger.info("Pod[id='%s', name='%s']: leafDeviceType changed" % (pod.id, pod.name))
if 'interConnectPrefix' in podDict and pod.interConnectPrefix != podDict['interConnectPrefix']:
dirty = True
logger.info("Pod[id='%s', name='%s']: interConnectPrefix changed" % (pod.id, pod.name))
if 'vlanPrefix' in podDict and pod.vlanPrefix != podDict['vlanPrefix']:
dirty = True
logger.info("Pod[id='%s', name='%s']: vlanPrefix changed" % (pod.id, pod.name))
if 'loopbackPrefix' in podDict and pod.loopbackPrefix != podDict['loopbackPrefix']:
dirty = True
logger.info("Pod[id='%s', name='%s']: loopbackPrefix changed" % (pod.id, pod.name))
if 'spineAS' in podDict and pod.spineAS != podDict['spineAS']:
dirty = True
logger.info("Pod[id='%s', name='%s']: spineAS changed" % (pod.id, pod.name))
if 'leafAS' in podDict and pod.leafAS != podDict['leafAS']:
dirty = True
logger.info("Pod[id='%s', name='%s']: leafAS changed" % (pod.id, pod.name))
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)
示例2: L3ClosMediation
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import deleteObject [as 别名]
class L3ClosMediation():
def __init__(self, conf = {}):
if any(conf) == False:
self.conf = util.loadConfig()
logger.setLevel(logging.getLevelName(self.conf['logLevel'][moduleName]))
else:
self.conf = conf
self.dao = Dao(self.conf)
self.templateEnv = Environment(loader=PackageLoader('jnpr.openclos', junosTemplateLocation))
self.templateEnv.keep_trailing_newline = True
def loadClosDefinition(self, closDefination = os.path.join(util.configLocation, 'closTemplate.yaml')):
'''
Loads clos definition from yaml file and creates pod object
'''
try:
stream = open(closDefination, 'r')
yamlStream = yaml.load(stream)
return yamlStream['pods']
except (OSError, IOError) as e:
print "File error:", e
except (yaml.scanner.ScannerError) as e:
print "YAML error:", e
stream.close()
finally:
pass
def isRecreateFabric(self, podInDb, podDict):
'''
If any device type/family, ASN range or IP block changed, that would require
re-generation of the fabric, causing new set of IP and ASN assignment per device
'''
if (podInDb.spineDeviceType != podDict['spineDeviceType'] or \
podInDb.leafDeviceType != podDict['leafDeviceType'] or \
podInDb.interConnectPrefix != podDict['interConnectPrefix'] or \
podInDb.vlanPrefix != podDict['vlanPrefix'] or \
podInDb.loopbackPrefix != podDict['loopbackPrefix'] or \
podInDb.spineAS != podDict['spineAS'] or \
podInDb.leafAS != podDict['leafAS']):
return True
return False
def processFabric(self, podName, pod, reCreateFabric = False):
# REVISIT use of reCreateFabric
try:
podInDb = 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))
else:
logger.debug("Deleted existing pod name: '%s'" % (podName))
self.dao.deleteObject(podInDb)
podInDb = Pod(podName, **pod)
podInDb.validate()
self.dao.createObjects([podInDb])
logger.info("Created pod name: '%s'" % (podName))
self.processTopology(podName, reCreateFabric)
# backup current database
util.backupDatabase(self.conf)
return podInDb
def processTopology(self, podName, reCreateFabric = False):
'''
Finds Pod object by name and process topology
It also creates the output folders for pod
'''
try:
pod = self.dao.getUniqueObjectByName(Pod, podName)
except (exc.NoResultFound) as e:
raise ValueError("No Pod found with pod name: '%s', exc.NoResultFound: %s" % (podName, e.message))
except (exc.MultipleResultsFound) as e:
raise ValueError("Multiple Pods found with pod name: '%s', exc.MultipleResultsFound: %s" % (podName, e.message))
if pod.inventory is not None:
# topology handling is divided into 3 steps:
# 1. load inventory
# 2. create cabling plan
# 3. create configuration files
# 1. load inventory
json_inventory = open(os.path.join(util.configLocation, pod.inventory))
inventory = json.load(json_inventory)
json_inventory.close()
self.createSpineIFDs(pod, inventory['spines'])
self.createLeafIFDs(pod, inventory['leafs'])
# 2. create cabling plan in JSON format
cablingPlanWriter = CablingPlanWriter(self.conf, pod, self.dao)
cablingPlanJSON = cablingPlanWriter.writeJSON()
self.createLinkBetweenIFDs(pod, cablingPlanJSON['links'])
# create cabling plan in DOT format
cablingPlanWriter.writeDOT()
# 3. allocate resource and create configuration files
self.allocateResource(pod)
self.generateConfig(pod);
#.........这里部分代码省略.........