当前位置: 首页>>代码示例>>Python>>正文


Python Dao.getUniqueObjectByName方法代码示例

本文整理汇总了Python中dao.Dao.getUniqueObjectByName方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.getUniqueObjectByName方法的具体用法?Python Dao.getUniqueObjectByName怎么用?Python Dao.getUniqueObjectByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dao.Dao的用法示例。


在下文中一共展示了Dao.getUniqueObjectByName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import getUniqueObjectByName [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
开发者ID:bgp44,项目名称:juniper,代码行数:85,代码来源:report.py

示例2: ZtpServer

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import getUniqueObjectByName [as 别名]
class ZtpServer():
    def __init__(self, conf = {}, templateEnv = None):
        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)

        if templateEnv is None:
            self.templateEnv = Environment(loader=PackageLoader('jnpr.openclos', ztpTemplateLocation))

    
    def dcpServerReloadConfig(self):
        #TODO: sudo service isc-dhcp-server force-reload
        # Not needed as of now
        pass
    
    ''' TODO: for 2.0, Not needed as of now
    def createSingleDhcpConfFile(self):
        pods = self.dao.getAll(Pod)

        if len(pods) > 0:
            confWriter = DhcpConfWriter(self.conf, pods[0], self.dao)
            confWriter.writeSingle(self.generateSingleDhcpConf())
    '''
   
    def generateSingleDhcpConf(self):
        if util.isPlatformUbuntu():
            ztp = self.populateDhcpGlobalSettings()
            dhcpTemplate = self.templateEnv.get_template('dhcp.conf.ubuntu')
            return dhcpTemplate.render(ztp = self.populateDhcpDeviceSpecificSettingForAllPods(ztp))

    def createPodSpecificDhcpConfFile(self, podName):
        pod = self.dao.getUniqueObjectByName(Pod, podName)

        confWriter = DhcpConfWriter(self.conf, pod, self.dao)
        confWriter.write(self.generatePodSpecificDhcpConf(pod.name))

    def generatePodSpecificDhcpConf(self, podName):
        ztp = self.populateDhcpGlobalSettings()
        conf = None
        if util.isPlatformUbuntu():
            dhcpTemplate = self.templateEnv.get_template('dhcp.conf.ubuntu')
            ztp = self.populateDhcpDeviceSpecificSetting(podName, ztp)
            conf = dhcpTemplate.render(ztp = ztp)
        elif util.isPlatformCentos():
            dhcpTemplate = self.templateEnv.get_template('dhcp.conf.centos')
            ztp = self.populateDhcpDeviceSpecificSetting(podName, ztp)
            conf = dhcpTemplate.render(ztp = ztp)
            
        logger.debug('dhcpd.conf\n%s' % (conf))
        return conf

    def populateDhcpGlobalSettings(self):
        ztp = {}
        ztpGlobalSettings = util.loadClosDefinition()['ztp']
        subnet = ztpGlobalSettings['dhcpSubnet']
        dhcpBlock = IPNetwork(subnet)
        ipList = list(dhcpBlock.iter_hosts())
        ztp['network'] = str(dhcpBlock.network)
        ztp['netmask'] = str(dhcpBlock.netmask)

        ztp['defaultRoute'] = ztpGlobalSettings.get('dhcpOptionRoute')
        if  ztp['defaultRoute'] is None or ztp['defaultRoute'] == '': 
            ztp['defaultRoute'] = str(ipList[0])

        ztp['rangeStart'] = ztpGlobalSettings.get('dhcpOptionRangeStart')
        if  ztp['rangeStart'] is None or ztp['rangeStart'] == '': 
            ztp['rangeStart'] = str(ipList[1])

        ztp['rangeEnd'] = ztpGlobalSettings.get('dhcpOptionRangeEnd')
        if  ztp['rangeEnd'] is None or ztp['rangeEnd'] == '': 
            ztp['rangeEnd'] = str(ipList[-1])

        ztp['broadcast'] = str(dhcpBlock.broadcast)
        ztp['httpServerIp'] = self.conf['httpServer']['ipAddr']
        ztp['imageUrl'] = ztpGlobalSettings.get('junosImage')

        return ztp
    
    def populateDhcpDeviceSpecificSettingForAllPods(self, ztp = {}):
        pods = self.dao.getAll(Pod)
        for pod in pods:
            ztp = self.populateDhcpDeviceSpecificSetting(pod.name, ztp)
        return ztp

    def populateDhcpDeviceSpecificSetting(self, podName, ztp = {}):
        
        if ztp.get('devices') is None:
            ztp['devices'] = []
        
        pod = self.dao.getUniqueObjectByName(Pod, podName)
        for device in pod.devices:
            if device.role == 'spine':
                image = pod.spineJunosImage
            elif device.role == 'leaf':
                image = pod.leafJunosImage
            else:
#.........这里部分代码省略.........
开发者ID:rgiyer,项目名称:OpenClos,代码行数:103,代码来源:ztp.py

示例3: L3ClosMediation

# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import getUniqueObjectByName [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);
#.........这里部分代码省略.........
开发者ID:rgiyer,项目名称:OpenClos,代码行数:103,代码来源:l3Clos.py


注:本文中的dao.Dao.getUniqueObjectByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。