def writeJSONThreeStage(self): deviceDict = {} deviceDict['leaves'] = [] deviceDict['spines'] = [] for device in self.pod.devices: if (device.role == 'leaf'): deviceDict['leaves'].append(device.name) elif (device.role == 'spine'): deviceDict['spines'].append(device.name) spinePortNames = util.getPortNamesForDeviceFamily(self.pod.spineDeviceType, self.conf['deviceFamily']) leafPortNames = util.getPortNamesForDeviceFamily(self.pod.leafDeviceType, self.conf['deviceFamily']) # rendering cabling plan requires 4 parameters: # 1. list of spines # 2. list of spine ports (Note spine does not have any uplink/downlink marked, it is just ports) # 3. list of leaves # 4. list of leaf ports (Note leaf uses uplink to connect to spine) cablingPlanJSON = self.template.render(spines=deviceDict['spines'], spinePorts=spinePortNames['ports'], leaves=deviceDict['leaves'], leafPorts=leafPortNames['uplinkPorts']) path = os.path.join(self.outputDir, 'cablingPlan.json') logger.info('Writing cabling plan: %s' % (path)) with open(path, 'w') as f: f.write(cablingPlanJSON) # load cabling plan return json.loads(cablingPlanJSON)
def getOpenClosConfigParams(self, dbSession): supportedDevices = [] for device in self.__conf['deviceFamily']: port = util.getPortNamesForDeviceFamily(device, self.__conf['deviceFamily']) deviceDetail = {} if len(port['uplinkPorts']) > 0: deviceDetail['family'] = device deviceDetail['uplinkStart'] = port['uplinkPorts'][0] deviceDetail['uplinkEnd'] = port['uplinkPorts'][len(port['uplinkPorts'])-1] deviceDetail['role'] = 'leaf' if len(port['downlinkPorts']) > 0: deviceDetail['downlinkStart'] = port['uplinkPorts'][0] deviceDetail['downlinkEnd'] = port['uplinkPorts'][len(port['uplinkPorts'])-1] deviceDetail['role'] = 'leaf' if len(port['uplinkPorts'])==0 and len(port['downlinkPorts']) == 0: if device == 'qfx5100-24q-2p': deviceDetail['role'] = 'spine' deviceDetail['family'] = device deviceDetail['downlinkStart'] = port['ports'][0] deviceDetail['downlinkEnd'] = port['ports'][len(port['ports'])-1] deviceDetail['uplinkStart'] = '' deviceDetail['uplinkEnd'] = '' supportedDevices.append(deviceDetail) confValues = {} confValues.update({'dbUrl': self.__conf['dbUrl']}) confValues.update({'supportedDevices' : supportedDevices }) confValues.update({'dotColors': self.__conf['DOT']['colors'] }) confValues.update({'httpServer' : self.__conf['httpServer']}) confValues.update({'snmpTrap' : self.__conf['snmpTrap']}) return {'OpenClosConf' : confValues }
def filterUplinkAppendRemotePortIfd(self, lldpData, deviceFamily): ''' On local device find uplink port names, filter only uplink ports, get remote ports that has Device + IFD configured in the DB :returns list of dict: lldpData for uplinks only deivce1: local device (on which lldp was run) port1: local interface (on device1) device2: remote device port2: remote interface ifd2: remote IFD from db ''' if not lldpData: logger.debug('NO LLDP data found for device: %s' % (self.deviceIp)) return lldpData uplinkNames = util.getPortNamesForDeviceFamily(deviceFamily, self._conf['deviceFamily'])['uplinkPorts'] upLinks = [] for link in lldpData.values(): if link['port1'] in uplinkNames: ifd2 = self._dao.getIfdByDeviceNamePortName(self._session, link['device2'], link['port2']) if ifd2 is not None: link['ifd2'] = ifd2 upLinks.append(link) logger.debug('Found IFD deviceName: %s, portName: %s' % (link['device2'], link['port2'])) logger.debug('Number of uplink IFDs found from LLDP data is %d' % (len(upLinks))) return upLinks
def _createLeafGenericConfigsFor2Stage(self, session, pod): ''' :param Pod: pod :returns list: list of PodConfigs ''' leafTemplate = self._templateEnv.get_template('leafGenericTemplate.txt') leafSettings = {} for leafSetting in pod.leafSettings: leafSettings[leafSetting.deviceFamily] = leafSetting trapGroups = self._getLeafTrapGroupSettings(session, True) outOfBandNetworkParams = self._getParamsForOutOfBandNetwork(session, pod) for deviceFamily in leafSettings.keys(): if deviceFamily == 'qfx5100-24q-2p': continue ifdNames = [] for ifdName in util.getPortNamesForDeviceFamily(deviceFamily, self._conf['deviceFamily'])['downlinkPorts']: ifdNames.append(ifdName) leafSettings[deviceFamily].config = leafTemplate.render(deviceFamily = deviceFamily, oob = outOfBandNetworkParams, trapGroups = trapGroups, hashedPassword=pod.getHashPassword(), ifdNames=ifdNames) return leafSettings.values()
def _createAccessPortInterfaces(self, deviceFamily): accessInterface = self._templateEnv.get_template('accessInterface.txt') ifdNames = [] for ifdName in util.getPortNamesForDeviceFamily(deviceFamily, self._conf['deviceFamily'])['downlinkPorts']: ifdNames.append(ifdName) return accessInterface.render(ifdNames=ifdNames)
def createSpineIFDs(self, pod, spines): devices = [] interfaces = [] for spine in spines: user = spine.get('user') password = spine.get('pass') device = Device(spine['name'], pod.spineDeviceType, user, password, 'spine', spine['mac_address'], spine['mgmt_ip'], pod) devices.append(device) portNames = util.getPortNamesForDeviceFamily(device.family, self.conf['deviceFamily']) for name in portNames['ports']: # spine does not have any uplink/downlink marked, it is just ports ifd = InterfaceDefinition(name, device, 'downlink') interfaces.append(ifd) self.dao.createObjects(devices) self.dao.createObjects(interfaces)
def fixUplinkPorts(self, device, lldpUplinksWithIfd): ''' :param dict lldpUplinksWithIfd: lldp links for uplink deivce1: local device (on which lldp was run) port1: local interface (on device1) device2: remote device port2: remote interface ifd2: remote IFD from db ''' if lldpUplinksWithIfd is None or len(lldpUplinksWithIfd) == 0: logger.warn('NO LLDP lldpUplinksWithIfd, skipping fixUplinkPorts') return updateList = [] uplinkNamesBasedOnDeviceFamily = util.getPortNamesForDeviceFamily(device.family, self._conf['deviceFamily'])['uplinkPorts'] # hack :( needed to keep the sequence proper in case2, if device changed from ex to qfx self.markAllUplinkIfdsToUplink_x(device) # case1: fix IFDs based on lldp data fixedIfdIds = {} for link in lldpUplinksWithIfd: spineIfd = link['ifd2'] peerLeafIfd = spineIfd.peer # sanity check against links that are not according to the cabling plan if peerLeafIfd is None: continue updateList += self.fixIfdIflName(peerLeafIfd, link['port1']) fixedIfdIds[peerLeafIfd.id] = True uplinkNamesBasedOnDeviceFamily.remove(peerLeafIfd.name) # case2: fix remaining IFDs based on device family allocatedUplinkIfds = self._session.query(InterfaceDefinition).filter(InterfaceDefinition.device_id == device.id).\ filter(InterfaceDefinition.role == 'uplink').filter(InterfaceDefinition.peer is not None).order_by(InterfaceDefinition.sequenceNum).all() listIndex = 0 for allocatedIfd in allocatedUplinkIfds: if not fixedIfdIds.get(allocatedIfd.id): if uplinkNamesBasedOnDeviceFamily: updateList += self.fixIfdIflName(allocatedIfd, uplinkNamesBasedOnDeviceFamily.pop(0)) else: updateList += self.fixIfdIflName(allocatedIfd, 'uplink-' + str(listIndex)) listIndex += 1 logger.debug('Number of uplink IFD + IFL fixed: %d' % (len(updateList))) self._dao.updateObjectsAndCommitNow(self._session, updateList)
def _createSpineIfds(self, session, pod, spines): devices = [] interfaces = [] for spine in spines: username = spine.get('username') #default is 'root' set on DB password = spine.get('password') macAddress = spine.get('macAddress') deployStatus = spine.get('deployStatus') #default is 'provision' set on DB serialNumber = spine.get('serialNumber') device = Device(spine['name'], pod.spineDeviceType, username, password, 'spine', macAddress, None, pod, deployStatus, serialNumber) devices.append(device) portNames = util.getPortNamesForDeviceFamily(device.family, self._conf['deviceFamily']) for name in portNames['ports']: # spine does not have any uplink/downlink marked, it is just ports ifd = InterfaceDefinition(name, device, 'downlink') interfaces.append(ifd) self._dao.createObjects(session, devices) self._dao.createObjects(session, interfaces)
def createLeafIFDs(self, pod, leafs): devices = [] interfaces = [] for leaf in leafs: user = leaf.get('user') password = leaf.get('pass') device = Device(leaf['name'], pod.leafDeviceType, user, password, 'leaf', leaf['mac_address'], leaf['mgmt_ip'], pod) devices.append(device) portNames = util.getPortNamesForDeviceFamily(device.family, self.conf['deviceFamily']) for name in portNames['uplinkPorts']: # all uplink IFDs towards spine ifd = InterfaceDefinition(name, device, 'uplink') interfaces.append(ifd) for name in portNames['downlinkPorts']: # all downlink IFDs towards Access/Server ifd = InterfaceDefinition(name, device, 'downlink') interfaces.append(ifd) self.dao.createObjects(devices) self.dao.createObjects(interfaces)
def filterUplinkFromLldpData(self, lldpData, deviceFamily): ''' On local device find uplink port names, filter only uplink ports, :param dict lldpData: deivce1: local device (on which lldp was run) port1: local interface (on device1) device2: remote device port2: remote interface :param str deviceFamily: deviceFamily (qfx5100-96s-8q) ''' if not lldpData: return lldpData uplinkNames = util.getPortNamesForDeviceFamily(deviceFamily, self._conf['deviceFamily'])['uplinkPorts'] filteredNames = set(uplinkNames).intersection(set(lldpData.keys())) filteredUplinks = {name:lldpData[name] for name in filteredNames} logger.debug('Number of uplink IFDs found from LLDP data is %d' % (len(filteredUplinks))) return filteredUplinks
def _createLeafIfds(self, session, pod, leaves): devices = [] interfaces = [] for leaf in leaves: username = leaf.get('username') password = leaf.get('password') #default is Pod level pass, set on constructor macAddress = leaf.get('macAddress') family = leaf.get('family') #default is 'unknown' set on DB deployStatus = leaf.get('deployStatus') #default is 'provision' set on DB serialNumber = leaf.get('serialNumber') device = Device(leaf['name'], family, username, password, 'leaf', macAddress, None, pod, deployStatus, serialNumber) devices.append(device) if family is None or family == 'unknown': # temporary uplink ports, names will get fixed after 2-stage ztp for i in xrange(0, pod.spineCount): interfaces.append(InterfaceDefinition('uplink-' + str(i), device, 'uplink')) else: portNames = util.getPortNamesForDeviceFamily(device.family, self._conf['deviceFamily']) interfaceCount = 0 for name in portNames['uplinkPorts']: # all uplink IFDs towards spine interfaces.append(InterfaceDefinition(name, device, 'uplink')) interfaceCount += 1 # Hack plugNPlay-mixedLeaf: Create additional uplinks when spine count is more than available uplink ports # example: spine count=5, device=ex4300-24p while interfaceCount < pod.spineCount: interfaces.append(InterfaceDefinition('uplink-' + str(interfaceCount), device, 'uplink')) interfaceCount += 1 # leaf access/downlink ports are not used in app so far, no need to create them #for name in portNames['downlinkPorts']: # all downlink IFDs towards Access/Server # interfaces.append(InterfaceDefinition(name, device, 'downlink')) self._dao.createObjects(session, devices) self._dao.createObjects(session, interfaces)