2 * Copyright (C) 2014-2015 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 (* Parsing /etc/mclu.conf *)
25 let rex = Pcre.regexp "^\\s*$" in
30 let rex = Pcre.regexp "^\\s*#" in
35 let rex = Pcre.regexp "^\\s*\\[(\\w+)\\]\\s*$" in
38 let subs = Pcre.exec ~rex line in
39 Some (Pcre.get_substring subs 1)
43 let ws_rex = Pcre.regexp "\\s+"
48 mac_addr : string option;
51 let _nodes : node list ref = ref []
53 let load_configuration config_file =
55 try open_in config_file
57 eprintf "mclu: %s: cannot open configuration file: %s\n" config_file msg;
59 let rec loop section =
60 let line = input_line chan in
61 if is_blank_line line || is_comment line then
64 match is_header line with
68 (* Ignore unknown sections and keep going. *)
69 printf "mclu: %s: warning: ignoring unknown section [%s]\n"
73 (* How we parse lines within sections depends on the header. *)
76 (* If we're in the [nodes] section, parse "hostname [key=value].." *)
77 (match Pcre.split ~rex:ws_rex line with
82 libvirt_uri = sprintf "qemu+ssh://root@%s/system" hostname;
85 let node = List.fold_left (
87 match Pcre.split ~pat:"=" ~max:2 def with
88 | ["mac"; value] -> { node with mac_addr = Some value }
89 | ["uri"; value] -> { node with libvirt_uri = value }
90 | [_] -> node (* key with no value - ignore *)
91 | [_; _] -> node (* unknown key=value - ignore *)
94 _nodes := node :: !_nodes;
99 (* Ignore the line. *)
100 printf "mclu: %s: warning: ignoring `%s'\n" config_file line;
106 with End_of_file -> ()
110 _nodes := List.rev !_nodes
112 (* Get list of nodes. *)
113 let nodes () = !_nodes