[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] More Generic Config Files
Dear All, I wanted to have a bit more control over the vars I use in my domain config files so that I could achieve more with a single file and just change the var values passed on the command line. A couple of examples: (*)combining a vm 'type' (e.g. www, cvs) and an 'id', checking to see if a disk image for such exists and cloning it from a 'type' master if not. (*)getting a known offset for certain octets in mac addresses dependant on the 'type' so that dhcp allocates predictable results. The first of these was possible using a temp file to hold state, created using inner functions within the check() function for each var. The second appears to be impossible. The attached (and inline) patch creates two new functions that can be called from the config file to register 'postcheck' functions and subsequently call them with the full dictionary of defined vars. Changes made to the vars' values in the postchecks are maintained across calls and are carried into the config proper. My python skills aren't great so any suggestions more than welcome, especially regards to 'hiding' the vars_{ex|im}port functions. I appreciate there are more pressing areas of work but this makes my life easier and may do others' too. If there are sanctioned ways of getting a similar level of functionality please let me know. # HG changeset patch # User dkendall <dan.kendall@xxxxxxxxxx> # Date 1161957184 -3600 # Node ID 6c528a82d57b5fc32c517ebaab5b7c985f2b338c # Parent 4a320d26fc24bc49ae24f31dec2bf006a9ddc7a8 Create postcheck() that calls postcheck routines registered using the new xm_vars.reg_postcheck(). Each of these receives dictionary of the vars and changes made to var values are permanent. Kinda like an all in one check() that knows about all defined vars. Allows for more generic config files. Signed-off-by: dan kendall <dan.kendall@xxxxxxxxxx> diff -r 4a320d26fc24 -r 6c528a82d57b tools/python/xen/xm/help.py --- a/tools/python/xen/xm/help.py Thu Oct 26 16:56:16 2006 +0100 +++ b/tools/python/xen/xm/help.py Fri Oct 27 14:53:04 2006 +0100 @@ -35,6 +35,7 @@ class Vars: self.help = help self.env = env self.vars = [] + self.postchecks = [] def var(self, name, use=None, check=None): """Define a configuration variable. @@ -58,6 +59,34 @@ class Vars: else: for v in self.vars: v.doCheck(self.env) + + def reg_postcheck(self, pcheck): + """Register routine to run after check + """ + self.postchecks.append(pcheck) + + def vars_export_dict(self): + """Export the var list to a dictionary + """ + d = {} + for v in self.vars: + d[v.name] = self.env[v.name] + return d + + def vars_import_dict(self,d): + """Import var list from dictionary + Note we only import already declared vars + """ + for v in self.vars: + self.env[v.name] = d[v.name] + + def postcheck(self): + """Perform any register post check routines + """ + for c in self.postchecks: + d = self.vars_export_dict() + c(d) + self.vars_import_dict(d) def doHelp(self, out=sys.stderr): """Print help for the variables. @@ -86,7 +115,12 @@ class Var: def doCheck(self, env): """Execute the check and set the variable to the new value. """ - if not self.check: return + #ensure variable gets back to config variable 'space' even + #if no check registered + #if not self.check: return + if not self.check: + env[self.name] = '' + return try: env[self.name] = self.check(self.name, env.get(self.name)) except StandardError, ex: **************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the intended recipient of this email and have received it in error you should delete it and notify Centrinet Ltd immediately at email@xxxxxxxxxx This email has been scanned for viruses, but no responsibility is accepted by Centrinet for any loss or damage arising in any way from its receipt or use thereof. The views expressed in this email may not necessarily reflect the views of Centrinet Ltd or any associated company. **************************************************************** Attachment:
help.patch _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |