mclu: boot: Allow template to specify a minimum disk size.
authorRichard W.M. Jones <rjones@redhat.com>
Mon, 30 Mar 2015 12:40:43 +0000 (13:40 +0100)
committerRichard W.M. Jones <rjones@redhat.com>
Mon, 30 Mar 2015 12:40:43 +0000 (13:40 +0100)
mclu_boot.ml
template.ml
template.mli

index 5bf742f..451beb8 100644 (file)
@@ -71,6 +71,18 @@ Try `mclu list --templates' to list all known templates.\n" template;
   (* Probe the template for various features. *)
   let template_info = Template.probe ~verbose template_filename in
 
   (* Probe the template for various features. *)
   let template_info = Template.probe ~verbose template_filename in
 
+  (* Check --size is not too small. *)
+  let size =
+    match !size, template_info.Template.minimum_size with
+    | 0L, None -> 0L               (* virt-builder default *)
+    | 0L, Some min_size ->         (* go with template minimum size *)
+      min_size
+    | size, Some min_size when size < min_size ->
+      eprintf "mclu: --size parameter is smaller than the minimum specified by the template (%s).\n"
+        (human_size min_size);
+      exit 1
+    | size, _ -> size in           (* go with user-specified size *)
+
   (* Decide how much RAM we will give the guest.  This affects our
    * choice of node, so do it early.
    *)
   (* Decide how much RAM we will give the guest.  This affects our
    * choice of node, so do it early.
    *)
@@ -267,7 +279,7 @@ Try: `mclu on %s'\n" hostname hostname;
     fpf "export format=%s\n" (quote format);
     fpf "export name=%s\n" (quote name);
     fpf "export output=%s\n" (quote remote_image);
     fpf "export format=%s\n" (quote format);
     fpf "export name=%s\n" (quote name);
     fpf "export output=%s\n" (quote remote_image);
-    (match !size with
+    (match size with
     | 0L -> ()
     | size -> fpf "export size=%s\n" (quote (sprintf "--size %Ldb" size))
     );
     | 0L -> ()
     | size -> fpf "export size=%s\n" (quote (sprintf "--size %Ldb" size))
     );
index dfeae3f..29af293 100644 (file)
@@ -75,6 +75,7 @@ type template_info = {
   base_image : string;
   minimum_memory : int64 option;
   recommended_memory : int64 option;
   base_image : string;
   minimum_memory : int64 option;
   recommended_memory : int64 option;
+  minimum_size : int64 option;
   disk_bus : string option;
   network_model : string option;
 }
   disk_bus : string option;
   network_model : string option;
 }
@@ -115,6 +116,16 @@ let probe ?(verbose = false) filename =
          exit 1
       );
     | _ -> None in
          exit 1
       );
     | _ -> None in
+  let minimum_size =
+    match run_template ~verbose filename "minimum-size" [] with
+    | Some [size] ->
+      (try Some (bytes_of_human_size size)
+       with Not_found ->
+         eprintf "mclu: cannot parse output of '%s minimum-size'\n"
+           filename;
+         exit 1
+      );
+    | _ -> None in
   let disk_bus =
     match run_template ~verbose filename "disk-bus" [] with
     | Some [answer] -> Some answer
   let disk_bus =
     match run_template ~verbose filename "disk-bus" [] with
     | Some [answer] -> Some answer
@@ -127,5 +138,6 @@ let probe ?(verbose = false) filename =
   { base_image = base_image;
     minimum_memory = minimum_memory;
     recommended_memory = recommended_memory;
   { base_image = base_image;
     minimum_memory = minimum_memory;
     recommended_memory = recommended_memory;
+    minimum_size = minimum_size;
     disk_bus = disk_bus;
     network_model = network_model }
     disk_bus = disk_bus;
     network_model = network_model }
index 748abbc..635ca55 100644 (file)
@@ -28,6 +28,7 @@ type template_info = {
   base_image : string;
   minimum_memory : int64 option;
   recommended_memory : int64 option;
   base_image : string;
   minimum_memory : int64 option;
   recommended_memory : int64 option;
+  minimum_size : int64 option;
   disk_bus : string option;
   network_model : string option;
 }
   disk_bus : string option;
   network_model : string option;
 }