# npackage example https://svn.lliurex.net/pandora/n4d-ldap/trunk # jinja2 http://jinja.pocoo.org/docs/templates from jinja2 import Environment from jinja2.loaders import FileSystemLoader from jinja2 import Template import tempfile import shutil import os import subprocess class NetinstallManager: def __init__(self): #Load template file self.tpl_env = Environment(loader=FileSystemLoader('/usr/share/n4d/templates/netinstall')) pass #def init def startup(self,options): # executed when launching n4d pass #def startup def apt(self): # executed after apt operations pass #def apt # service test and backup functions # def test(self): pass #def test def backup(self): pass #def test def restore(self): pass #def test def load_exports(self): #Get template template_cname = self.tpl_env.get_template("cname") list_variables = {} ########################### #Getting VARS ########################### #Obtains INTERNAL_DOMAIN list_variables['INTERNAL_DOMAIN'] = objects['VariablesManager'].get_variable('INTERNAL_DOMAIN') #If INTERNAL_DOMAIN is not defined returns an error if list_variables['INTERNAL_DOMAIN'] == None: return {'status':False,'msg':'Variable INTERNAL_DOMAIN not defined'} #Obtains HOSTNAME list_variables['HOSTNAME'] = objects['VariablesManager'].get_variable('HOSTNAME') #If variable SRV_IP is not defined returns an error if list_variables['HOSTNAME'] == None: return {'status':False,'msg':'Variable HOSTNAME not defined'} #Encode vars to UTF-8 string_template = template_cname.render(list_variables).encode('UTF-8') #Open template file fd, tmpfilepath = tempfile.mkstemp() new_export_file = open(tmpfilepath,'w') new_export_file.write(string_template) new_export_file.close() os.close(fd) #Write template values n4d_mv(tmpfilepath,'/var/lib/dnsmasq/config/cname-preseed',True,'root','root','0644',True ) subprocess.Popen(['/etc/init.d/dnsmasq','restart'],stdout=subprocess.PIPE).communicate() return {'status':True,'msg':'Exports written'} #def load_exports # ######################### # #class N4dProxy