Parses disk_config files for FAI
Author: Raphael Pinson rap@gmai l.com hink
http://wiki.fai-project.org
The Test_FAI_DiskConfig file contains various examples and tests.
let mount_options = [ label "mount_options" . counter "mount_option" . Build.opt_list mount_option Sep.comma ]
An array of mount_options
let fs_options =
An array of fs_options
let partition = [ label "partition" . Util.del_str "." . store /[0-9]+/ ]
An optional partition number for disk
let vg_option = [ key "pvcreateopts" . Util.del_str "=\"" . store /[^"\n]*/ . Util.del_str "\"" ]
An option for volume_vg
let disk_with_opt = [ label "disk" . store /[^:., \t\n]+/ . partition? . spare_missing* ]
A disk with a spare/missing option for raids
let disk_list = Build.opt_list disk_with_opt Sep.comma
A list of disk_with_opts
let disk_config = let excludes = "lvm" | "raid" | "end" | /disk[0-9]+/ | "cryptsetup" | "tmpfs" in let other_label = Rx.fspath - excludes in disk_config_entry "lvm" lvmoption volume_lvm | disk_config_entry "raid" raidoption volume_raid | disk_config_entry "tmpfs" option volume_tmpfs | disk_config_entry "end" option volume (* there shouldn't be an option here *) | disk_config_entry /disk[0-9]+/ option volume | disk_config_entry "cryptsetup" cryptoption volume_cryptsetup | disk_config_entry other_label option volume
let eol = Util.eol
let space = Sep.space
let empty = Util.empty
let comment = Util.comment
A generic tag beginning with a colon
let tag (re:regexp) = [ Util.del_str ":" . key re ]
A generic key/value option
let generic_opt (type:string) (kw:regexp) = [ key type . Util.del_str ":" . store kw ]
A generic key/list option
let generic_opt_list (type:string) (kw:regexp) = [ key type . Util.del_str ":" . counter "locallist" . Build.opt_list [seq "locallist" . store kw] Sep.comma ]
let mountpoint_kw = "-" (* do not mount *) | "swap" (* swap space *)
encrypt tag
let encrypt = tag "encrypt"
resize tag
let resize = tag "resize"
Regexps for size
let size_kw = /[0-9]+[kMGTP%]?(-([0-9]+[kMGTP%]?)?)?/ | /-[0-9]+[kMGTP%]?/
let size = [ label "size" . store size_kw . resize? ]
Regexps for filesystem
let filesystem_kw = "-" | "swap"
let filesystem = [ label "filesystem" . store filesystem_kw ]
let mount_option_value = [ label "value" . Util.del_str "=" . store /[^,= \t\n]+/ ]
Counting options
let mount_option = [ seq "mount_option" . store /[^,= \t\n]+/ . mount_option_value? ]
An array of mount_options
let mount_options = [ label "mount_options" . counter "mount_option" . Build.opt_list mount_option Sep.comma ]
let fs_option = [ key /createopts|tuneopts/ . Util.del_str "=\"" . store /[^"\n]*/ . Util.del_str "\"" ]
An array of fs_options
let fs_options =
let volume_full (type:lens) (third_field:lens) =
LVM volume group name
let name = [ label "name" . store /[^\/ \t\n]+/ ]
An optional partition number for disk
let partition = [ label "partition" . Util.del_str "." . store /[0-9]+/ ]
let disk = [ label "disk" . store /[^., \t\n]+/ . partition? ]
An option for volume_vg
let vg_option = [ key "pvcreateopts" . Util.del_str "=\"" . store /[^"\n]*/ . Util.del_str "\"" ]
let volume_vg = [ key "vg" . space . name . space . disk . (space . vg_option)? . eol ]
let spare_missing = tag /spare|missing/
A disk with a spare/missing option for raids
let disk_with_opt = [ label "disk" . store /[^:., \t\n]+/ . partition? . spare_missing* ]
A list of disk_with_opts
let disk_list = Build.opt_list disk_with_opt Sep.comma
let type_label_lv = label "lv" . [ label "vg" . store (/[^# \t\n-]+/ - "raw") ] . Util.del_str "-" . [ label "name" . store /[^ \t\n]+/ ]
let volume_tmpfs = [ key "tmpfs" . space . mountpoint .space . size . space . mount_options . (space . fs_options)? . eol ]
let volume_lvm = volume_full type_label_lv size (* lvm logical volume: vg name and lv name *) | volume_vg
let volume_raid = volume_full (key /raid[0156]/) disk_list (* raid level *)
let device = [ label "device" . store Rx.fspath ]
let volume_cryptsetup = volume_full (key ("swap"|"tmp"|"luks")) device
let volume = volume_full (key "primary") size (* for physical disks only *) | volume_full (key "logical") size (* for physical disks only *) | volume_full (key "raw-disk") size
A succesion of volumes and comments
let volume_or_comment (vol:lens) = (vol|empty|comment)* . vol
let disk_config_entry (kw:regexp) (opt:lens) (vol:lens) = [ key "disk_config" . space . store kw . (space . opt)* . eol . (volume_or_comment vol)? ]
let lvmoption =
let raidoption =
let option =
let disk_config = let excludes = "lvm" | "raid" | "end" | /disk[0-9]+/ | "cryptsetup" | "tmpfs" in let other_label = Rx.fspath - excludes in disk_config_entry "lvm" lvmoption volume_lvm | disk_config_entry "raid" raidoption volume_raid | disk_config_entry "tmpfs" option volume_tmpfs | disk_config_entry "end" option volume (* there shouldn't be an option here *) | disk_config_entry /disk[0-9]+/ option volume | disk_config_entry "cryptsetup" cryptoption volume_cryptsetup | disk_config_entry other_label option volume
The disk_config lens
let lns = (disk_config|comment|empty)*