22
Dec
09

Cobbler Settings Lens for Augeas

After much help from David Lutterkort, I have a first cut of an Augeas lens for Cobbler . The settings file is basically a single YAML document, so this lens could be used to do generic yaml processing, but I would assume it would need some tweaks before then.

I figure it is best to get the first cut out there though. So here it is.

(*
	Parse the /etc/cobbler/settings file  which is in
	YAML 1.0 format.

	The lens can handle the following contructs
	* key: value
	* key: "value"
	* key: 'value'
	* key: [value1, value2]
	* key:
	   - value1
	   - value2
	* key:
	   key2: value1
	   key3: value2 

	Author: Bryan Kearney

	About: License
	  This file is licensed under the LGPLv2+, like the rest of Augeas.
*)
module CobblerSettings =
	autoload xfm

	let kw = /[a-zA-Z0-9_]+/
	(* TODO Would be better if this stripped off the " and ' chracters *)
	let kv = /([^]['", \t\n#:@-]+|"[^"\n]*"|'[^'\n]*')/ 

	let lbr = del /\[/ "["
	let rbr = del /\]/ "]"
	let colon = del /:[ \t]*/ ": "
	let dash = del /-[ \t]*/ "- "
	(* let comma = del /,[ \t]*(\n[ \t]+)?/ ", " *)
	let comma = del /[ \t]*,[ \t]*/ ", "

	let eol_only = del /\n/ "\n"

	(* TODO Would be better to make items a child of a document *)
	let docmarker = /-{3}/

	let eol   = Util.eol
	let comment = Util.comment
	let empty   = Util.empty
	let indent = del /[ \t]+/ "\t"
	let ws = del /[ \t]*/ " "

	let value_list = Build.opt_list [label "item" . store kv] comma
	let setting = [key kw . colon . store kv] . eol
	let simple_setting_suffix = store kv . eol
	let setting_list_suffix =  [label "sequence" . lbr . ws . (value_list . ws)? . rbr ] . eol
	let indendented_setting_list_suffix =  eol_only . (indent . setting)+
    let indented_list_suffix =  [label "list" . eol_only . ([ label "value" . indent . dash  . store kv] . eol)+]

    (* Break out setting because of a current bug in augeas *)
	let nested_setting = [key kw . colon . (
											(* simple_setting_suffix | *)
											setting_list_suffix |
											indendented_setting_list_suffix |
											indented_list_suffix
											)
						]

	let document = [label "---" . store docmarker] . eol    

	let lns = (document | comment | empty | setting | nested_setting )*
    (* let lns = (setting)* *)

	let xfm = transform lns (incl "/etc/cobbler/settings") 

	(*
	test lns  get "" = ?
	test lns  get "Simple_Setting: Value \n" = ?
	test lns  get "Simple_Setting2: 'Value2@acme.com' \n" = ?
	test lns  get "Simple_Setting3: ''\n" = ?
	test lns  get "Simple_Setting4: \"\"\n" = ?
	test lns  get "Setting_List:[Value1, Value2, Value3]\n" = ?
	test lns  get "Empty_Setting_List: []\n" = ?
	test lns  get "# Commented_Out_Setting: 'some value'\n" = ?
	test lns  get "---\n" = ?
	test lns  get "Nested_Setting:\n Test: Value\n" = ?
	test lns  get "Nested_Setting:\n - Test \n" = ?
	let  cset = Sys.read_file "/etc/cobbler/settings"
	test lns  get cset = ?
    *)
(* Local Variables: *)
(* mode: caml *)
(* End: *)

My next steps will be to clean this up, and to submit it along with some tests.


2 Responses to “Cobbler Settings Lens for Augeas”


  1. December 22, 2009 at 1:15 am

    YAML supports, among other things, nasty things such as anchors (which I explicitly disabled in Cobbler because they are confusing to everyone who asks what they are) and Flow styles, which looks like embedded JSON.

    Cobbler will accept certainly accept YAML in flow styles. It might accept anchors (and just not render them), I forget.

    • 2 bryankearney
      December 22, 2009 at 2:16 am

      Yeah.. I bet that all YAML would not be parsed by this. I know, for example, that there is no concept of nesting the document. But.. this lens does get the file which is delivered with the fedora RPM… which is good.


Leave a Reply




bk on Identi.ca (via twitter)