Esempio n. 1
0
    def __init__(self, conf = {}, daoClass = Dao):
        if any(conf) == False:
            self._conf = OpenClosProperty(appName = moduleName).getProperties()
        else:
            self._conf = conf

        self._dao = daoClass.getInstance()

        self._templateEnv = Environment(loader=PackageLoader(junosTemplatePackage, junosTemplateLocation))
        self._templateEnv.keep_trailing_newline = True
        self.isZtpStaged = util.isZtpStaged(self._conf)
        self.deviceSku = DeviceSku()
Esempio n. 2
0
    def __init__(self, conf = {}, daoClass = Dao):
        global logger
        if any(conf) == False:
            self._conf = util.loadConfig(appName = moduleName)
        else:
            self._conf = conf

        logger = logging.getLogger(moduleName)
        self._dao = daoClass.getInstance()

        self._templateEnv = Environment(loader=PackageLoader('jnpr.openclos', junosTemplateLocation))
        self._templateEnv.keep_trailing_newline = True
        self.isZtpStaged = util.isZtpStaged(self._conf)
Esempio n. 3
0
 def getTemplate(self):
     ''' 
     Finds template based on o/s on which OpenClos is running
     and 1stage/2stage ZTP process
     returns: jinja2 template 
     '''
     if util.isPlatformUbuntu():
         if util.isZtpStaged(self.__conf):
             return self.templateEnv.get_template('ubuntu.2stage.dhcp.conf')
         else:
             return self.templateEnv.get_template('ubuntu.1stage.dhcp.conf')
     elif util.isPlatformCentos():
         if util.isZtpStaged(self.__conf):
             return self.templateEnv.get_template('centos.2stage.dhcp.conf')
         else:
             return self.templateEnv.get_template('centos.1stage.dhcp.conf')
     elif util.isPlatformWindows():
         ''' 
         this code is for testing only, generated dhcpd.conf would not work on windows  
         '''
         if util.isZtpStaged(self.__conf):
             return self.templateEnv.get_template('ubuntu.2stage.dhcp.conf')
         else:
             return self.templateEnv.get_template('ubuntu.1stage.dhcp.conf')
Esempio n. 4
0
 def getTemplate(self):
     ''' 
     Finds template based on o/s on which OpenClos is running
     and 1stage/2stage ZTP process
     returns: jinja2 template 
     '''
     if util.isPlatformUbuntu():
         if util.isZtpStaged(self.__conf):
             return self.templateEnv.get_template('ubuntu.2stage.dhcp.conf')
         else:
             return self.templateEnv.get_template('ubuntu.1stage.dhcp.conf')
     elif util.isPlatformCentos():
         if util.isZtpStaged(self.__conf):
             return self.templateEnv.get_template('centos.2stage.dhcp.conf')
         else:
             return self.templateEnv.get_template('centos.1stage.dhcp.conf')
     elif util.isPlatformWindows():
         ''' 
         this code is for testing only, generated dhcpd.conf would not work on windows  
         '''
         if util.isZtpStaged(self.__conf):
             return self.templateEnv.get_template('ubuntu.2stage.dhcp.conf')
         else:
             return self.templateEnv.get_template('ubuntu.1stage.dhcp.conf')
Esempio n. 5
0
    def populateDhcpDeviceSpecificSetting(self, session, podId, ztp={}):
        '''
        don't start any url as /openclos/... first / causes ZTP problem
        '''
        imageUrlPrefix = 'openclos/images/'

        if ztp.get('devices') is None:
            ztp['devices'] = []

        pod = self._dao.getObjectById(session, Pod, podId)
        for device in pod.devices:
            if device.family == 'unknown':
                continue

            if device.role == 'spine':
                imageName = util.getImageNameForDevice(pod, device)
                if imageName is not None:
                    imageUrl = imageUrlPrefix + imageName
                else:
                    imageUrl = None
            elif device.role == 'leaf':
                if util.isZtpStaged(self.__conf):
                    continue
                imageName = util.getImageNameForDevice(pod, device)
                if imageName is not None:
                    imageUrl = imageUrlPrefix + imageName
                else:
                    imageUrl = None
            else:
                logger.error(
                    'PodId: %s, Pod: %s, Device: %s with unknown role: %s' %
                    (pod.id, pod.name, device.name, device.role))
                continue

            deviceMgmtIp = str(IPNetwork(device.managementIp).ip)
            if device.macAddress:
                ztp['devices'].append({
                    'name':
                    device.name,
                    'mac':
                    device.macAddress,
                    # don't start url as /openclos/pods, first / causes ZTP problem
                    'configUrl':
                    'openclos/pods/' + pod.id + '/devices/' + device.id +
                    '/config',
                    'imageUrl':
                    imageUrl,
                    'mgmtIp':
                    deviceMgmtIp
                })
                logger.info('Device: %s, %s used MAC to map in dhcpd.conf' %
                            (device.name, deviceMgmtIp))
            elif device.serialNumber:
                ztp['devices'].append({
                    'name':
                    device.name,
                    'serial':
                    device.serialNumber,
                    # don't start url as /openclos/pods, first / causes ZTP problem
                    'configUrl':
                    'openclos/pods/' + pod.id + '/devices/' + device.id +
                    '/config',
                    'imageUrl':
                    imageUrl,
                    'mgmtIp':
                    deviceMgmtIp
                })
                logger.info('Device: %s, %s used Serial to map in dhcpd.conf' %
                            (device.name, deviceMgmtIp))
            else:
                logger.error(
                    'Device: %s, %s does not have MAC or SerialNumber, not added in dhcpd.conf'
                    % (device.name, deviceMgmtIp))

        if util.isZtpStaged(self.__conf):
            ztp['leafs'] = []
            for leafSetting in pod.leafSettings:
                setting = {}
                setting['leafDeviceFamily'] = leafSetting.deviceFamily
                if leafSetting.junosImage is not None:
                    setting[
                        'leafImageUrl'] = imageUrlPrefix + leafSetting.junosImage
                else:
                    setting['leafImageUrl'] = None
                # don't start url as /openclos/pods/..., first / causes ZTP problem
                setting[
                    'leafGenericConfigUrl'] = 'openclos/pods/' + pod.id + '/leaf-generic-configurations/' + leafSetting.deviceFamily
                '''
                setting['substringLength'] is the last argument of substring on dhcpd.conf, 
                should not be hardcoded, as it would change based on device family
                match if substring (option vendor-class-identifier, 0,21) = "Juniper-qfx5100-48s-6q"
    
                '''
                setting['substringLength'] = len('Juniper-' +
                                                 leafSetting.deviceFamily)
                ztp['leafs'].append(setting)

        return ztp
Esempio n. 6
0
 def populateDhcpDeviceSpecificSetting(self, session, podId, ztp = {}):
     '''
     don't start any url as /openclos/... first / causes ZTP problem
     '''
     imageUrlPrefix =  'openclos/images/'       
     
     if ztp.get('devices') is None:
         ztp['devices'] = []
     
     pod = self._dao.getObjectById(session, Pod, podId)
     for device in pod.devices:
         if device.family == 'unknown':
             continue
         
         if device.role == 'spine':
             imageName = util.getImageNameForDevice(pod, device)
             if imageName is not None:
                 imageUrl = imageUrlPrefix + imageName
             else:
                 imageUrl = None
         elif device.role == 'leaf':
             if util.isZtpStaged(self.__conf):
                 continue
             imageName = util.getImageNameForDevice(pod, device)
             if imageName is not None:
                 imageUrl = imageUrlPrefix + imageName
             else:
                 imageUrl = None
         else:
             logger.error('PodId: %s, Pod: %s, Device: %s with unknown role: %s' % (pod.id, pod.name, device.name, device.role))
             continue
         
         deviceMgmtIp = str(IPNetwork(device.managementIp).ip)
         if device.macAddress :
             ztp['devices'].append({'name': device.name, 'mac': device.macAddress,
             # don't start url as /openclos/ip-fabrics, first / causes ZTP problem
             'configUrl': 'openclos/ip-fabrics/' + pod.id + '/devices/' + device.id + '/config',
             'imageUrl': imageUrl, 'mgmtIp': deviceMgmtIp})
             logger.info('Device: %s, %s used MAC to map in dhcpd.conf' % (device.name, deviceMgmtIp))
         elif device.serialNumber:
             ztp['devices'].append({'name': device.name, 'serial': device.serialNumber,
             # don't start url as /openclos/ip-fabrics, first / causes ZTP problem
             'configUrl': 'openclos/ip-fabrics/' + pod.id + '/devices/' + device.id + '/config',
             'imageUrl': imageUrl, 'mgmtIp': deviceMgmtIp})
             logger.info('Device: %s, %s used Serial to map in dhcpd.conf' % (device.name, deviceMgmtIp))
         else:
             logger.error('Device: %s, %s does not have MAC or SerialNumber, not added in dhcpd.conf' % (device.name, deviceMgmtIp))
             
     if util.isZtpStaged(self.__conf):
         ztp['leafs'] = []
         for leafSetting in pod.leafSettings:
             setting = {}
             setting['leafDeviceFamily'] = leafSetting.deviceFamily
             if leafSetting.junosImage is not None:
                 setting['leafImageUrl'] = imageUrlPrefix + leafSetting.junosImage
             else:
                 setting['leafImageUrl'] = None
             # don't start url as /openclos/ip-fabrics/..., first / causes ZTP problem
             setting['leafGenericConfigUrl'] = 'openclos/ip-fabrics/' + pod.id + '/leaf-generic-configurations/' + leafSetting.deviceFamily
             '''
             setting['substringLength'] is the last argument of substring on dhcpd.conf, 
             should not be hardcoded, as it would change based on device family
             match if substring (option vendor-class-identifier, 0,21) = "Juniper-qfx5100-48s-6q"
 
             '''
             setting['substringLength'] = len('Juniper-' + leafSetting.deviceFamily)
             ztp['leafs'].append(setting)
             
     return ztp