예제 #1
0
파일: report.py 프로젝트: codyrat/OpenClos
 def generateReport(self, podId, cachedData = True, writeToFile = False):
     with self._dao.getReadSession() as session:
         pod = self.getIpFabric(session, podId)
         if pod is None: 
             logger.error('No pod found for podId: %s' % (podId))
             raise ValueError('No pod found for podId: %s' % (podId)) 
         
         if cachedData == False:
             logger.info('Generating L2Report from real data')
             
             # reset all spines l2 status
             self.resetSpineL2Status(pod.devices)
             
             futureList = []
             for device in pod.devices:
                 if device.role == 'leaf':
                     l2DataCollector = L2DataCollector(device.id, self._conf, self._dao) 
                     futureList.append(self.executor.submit(l2DataCollector.startL2Report))
             logger.info('Submitted processing all devices')
             concurrent.futures.wait(futureList)
             # At this point multiple threads, ie multiple db sessions
             # have updated device, so we need to refresh pod data. 
             # Rather than refresh, better option is expire, which
             # would trigger lazy load.
             session.expire(pod)
             logger.info('Done processing all devices')
         else:
             logger.info('Generating L2Report from cached data')
         cablingPlanWriter = CablingPlanWriter(self._conf, pod, self._dao)
         if writeToFile:
             return cablingPlanWriter.writeThreeStageL2ReportJson()
         else:
             return cablingPlanWriter.getThreeStageL2ReportJson()
예제 #2
0
파일: l3Clos.py 프로젝트: Juniper/OpenClos
    def createCablingPlan(self, podId):
        '''
        Finds Pod object by id and create cabling plan
        It also creates the output folders for pod
        '''
        if podId is None: 
            raise InvalidRequest("Pod id cannot be None")

        with self._dao.getReadWriteSession() as session:        
            try:
                pod = self._dao.getObjectById(session, Pod, podId)
            except (exc.NoResultFound):
                raise PodNotFound(podId, exc) 
 
            if len(pod.devices) > 0:
                cablingPlanWriter = CablingPlanWriter(self._conf, pod, self._dao)
                # create cabling plan in JSON format
                cablingPlanJson = cablingPlanWriter.writeJSON()
                pod.cablingPlan = CablingPlan(pod.id, cablingPlanJson)
                # create cabling plan in DOT format
                cablingPlanWriter.writeDOT()
                self._dao.updateObjects(session, [pod])
                
                return True
            else:
                logger.warning("Pod[id='%s', name='%s']: inventory is empty" % (pod.id, pod.name)) 
                return False
예제 #3
0
파일: l3Clos.py 프로젝트: sysbot/OpenClos
    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)

            return True
        else:
            raise ValueError("No topology found for pod name: '%s'", (podName))
    def createCablingPlan(self, podId):
        '''
        Finds Pod object by id and create cabling plan
        It also creates the output folders for pod
        '''
        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)) 
 
            if len(pod.devices) > 0:
                cablingPlanWriter = CablingPlanWriter(self.conf, pod, self.dao)
                # create cabling plan in JSON format
                cablingPlanWriter.writeJSON()
                # create cabling plan in DOT format
                cablingPlanWriter.writeDOT()
                
                # update status
                pod.state = 'cablingDone'
                self.dao.updateObjects([pod])
    
                return True
            else:
                raise ValueError("Pod[id='%s', name='%s']: inventory is empty" % (pod.id, pod.name)) 
            
        else:
            raise ValueError("Pod id can't be None") 
예제 #5
0
파일: l3Clos.py 프로젝트: rgiyer/OpenClos
    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);
            
            return True
        else:
            raise ValueError("No topology found for pod name: '%s'", (podName))