def handle_deploy_ztp_config(self, pod_id): ## Find the Pod Object report = ResourceAllocationReport() with report._dao.getReadSession() as session: pod_object = report._dao.getObjectById(session, Pod, pod_id) podDirectoryName = "%s-%s" % (pod_id, pod_object.name) installedDhcpConf = "/etc/dhcp/dhcpd.conf" ## Generate the path to the dhcp conf generatedDhcpConf = os.path.join( os.path.dirname(os.path.abspath(__file__)), "out", podDirectoryName, "dhcpd.conf" ) if not os.path.isfile(generatedDhcpConf): print "DHCP configuration file has not been generated for Pod %s yet, will generate it first" % pod_id ztpServer = ZtpServer() ztpServer.createPodSpecificDhcpConfFile(session, pod_id) if util.isPlatformUbuntu(): os.system("sudo cp " + generatedDhcpConf + " " + installedDhcpConf) print "New configuration file copied to %s " % installedDhcpConf os.system("/etc/init.d/isc-dhcp-server restart") elif util.isPlatformCentos(): os.system("sudo cp " + generatedDhcpConf + " " + installedDhcpConf) print "New configuration file copied to %s " % installedDhcpConf os.system("/etc/rc.d/init.d/dhcpd restart")
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 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 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')
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 generateSingleDhcpConf(self): if util.isPlatformUbuntu(): ztp = self.populateDhcpGlobalSettings() dhcpTemplate = self.templateEnv.get_template('dhcp.conf.ubuntu') return dhcpTemplate.render( ztp=self.populateDhcpDeviceSpecificSettingForAllPods(ztp))