+ xml
+
+ and generate_custom_xml () =
+ (* Generate a wrapper script to make passing the variables
+ * to the template easier.
+ *)
+ let () =
+ let chan = open_out xml_template_wrapper in
+ let fpf fs = fprintf chan fs in
+ fpf "#!/bin/sh\n";
+ fpf "export format=%s\n" (quote format);
+ fpf "export mac_addr=%s\n" (quote mac_addr);
+ fpf "export memory_kb=%Ld\n" (memory /^ 1024L);
+ fpf "export name=%s\n" (quote name);
+ fpf "export output=%s\n" (quote remote_image);
+ fpf "export vcpus=%d\n" vcpus;
+ fpf "%s xml\n" template_filename;
+ close_out chan;
+ Unix.chmod xml_template_wrapper 0o755 in
+
+ if verbose then printf "%s\n%!" xml_template_wrapper;
+ let chan = Unix.open_process_in xml_template_wrapper in
+ let lines = ref [] in
+ (try while true do lines := input_line chan :: !lines done
+ with End_of_file -> ());
+ let stat = Unix.close_process_in chan in
+ (match stat with
+ | Unix.WEXITED 0 -> ()
+ | Unix.WEXITED i ->
+ eprintf "mclu: template '%s' subcmd xml exited with error %d\n"
+ template_filename i;
+ exit 1
+ | Unix.WSIGNALED i ->
+ eprintf "mclu: template '%s' subcmd xml killed by signal %d\n"
+ template_filename i;
+ exit 1
+ | Unix.WSTOPPED i ->
+ eprintf "mclu: template '%s' subcmd xml stopped by signal %d\n"
+ template_filename i;
+ exit 1
+ );
+ let xml = String.concat "\n" (List.rev !lines) in
+ xml
+ in
+
+ let xml =
+ if not template_info.Template.has_xml_target then
+ generate_standard_xml ()
+ else
+ generate_custom_xml () in