---
builder/builder.ml | 12 ++++++++++++
builder/index_parser.ml | 16 ++++++++++++++++
builder/index_parser.mli | 4 ++++
builder/list_entries.ml | 17 +++++++++++++++++
builder/virt-builder.pod | 8 ++++++++
5 files changed, 57 insertions(+)
diff --git a/builder/builder.ml b/builder/builder.ml
index a0ef6d7..c317816 100644
--- a/builder/builder.ml
+++ b/builder/builder.ml
@@ -192,6 +192,18 @@ let main () =
| (`Install|`Notes) as mode -> mode in
(* Which os-version (ie. index entry)? *)
+ let arg =
+ (* Try to resolve the alias. *)
+ try
+ let item =
+ List.find (
+ fun (name, { Index_parser.aliases = aliases }) ->
+ match aliases with
+ | None -> false
+ | Some l -> List.mem arg l
+ ) index in
+ fst item
+ with Not_found -> arg in
let item =
try List.find (
fun (name, { Index_parser.arch = a }) ->
diff --git a/builder/index_parser.ml b/builder/index_parser.ml
index 40b2116..0040bf9 100644
--- a/builder/index_parser.ml
+++ b/builder/index_parser.ml
@@ -38,11 +38,14 @@ and entry = {
lvexpand : string option;
notes : (string * string) list;
hidden : bool;
+ aliases : string list option;
sigchecker : Sigchecker.t;
proxy : Downloader.proxy_mode;
}
+let list_separator = " "
+
let print_entry chan (name, { printable_name = printable_name;
file_uri = file_uri;
arch = arch;
@@ -56,6 +59,7 @@ let print_entry chan (name, { printable_name = printable_name;
expand = expand;
lvexpand = lvexpand;
notes = notes;
+ aliases = aliases;
hidden = hidden }) =
let fp fs = fprintf chan fs in
fp "[%s]\n" name;
@@ -101,6 +105,10 @@ let print_entry chan (name, { printable_name = printable_name;
| "" -> fp "notes=%s\n" notes
| lang -> fp "notes[%s]=%s\n" lang notes
) notes;
+ (match aliases with
+ | None -> ()
+ | Some l -> fp "aliases=%s\n" (String.concat list_separator l)
+ );
if hidden then fp "hidden=true\n"
let get_index ~prog ~debug ~downloader ~sigchecker ~proxy source =
@@ -245,6 +253,13 @@ let get_index ~prog ~debug ~downloader ~sigchecker ~proxy source =
eprintf (f_"virt-builder: cannot parse 'hidden' field for
'%s'\n")
n;
corrupt_file () in
+ let aliases =
+ let l =
+ try string_nsplit list_separator (List.assoc ("aliases", None)
fields)
+ with Not_found -> [] in
+ match l with
+ | [] -> None
+ | l -> Some l in
let entry = { printable_name = printable_name;
osinfo = osinfo;
@@ -260,6 +275,7 @@ let get_index ~prog ~debug ~downloader ~sigchecker ~proxy source =
lvexpand = lvexpand;
notes = notes;
hidden = hidden;
+ aliases = aliases;
proxy = proxy;
sigchecker = sigchecker } in
n, entry
diff --git a/builder/index_parser.mli b/builder/index_parser.mli
index a714d05..97f8c40 100644
--- a/builder/index_parser.mli
+++ b/builder/index_parser.mli
@@ -32,9 +32,13 @@ and entry = {
lvexpand : string option;
notes : (string * string) list;
hidden : bool;
+ aliases : string list option;
sigchecker : Sigchecker.t;
proxy : Downloader.proxy_mode;
}
val get_index : prog:string -> debug:bool -> downloader:Downloader.t ->
sigchecker:Sigchecker.t -> proxy:Downloader.proxy_mode -> string -> index
+
+(* The separator string for elements in values of type list. *)
+val list_separator : string
diff --git a/builder/list_entries.ml b/builder/list_entries.ml
index 505a1b9..9264cfc 100644
--- a/builder/list_entries.ml
+++ b/builder/list_entries.ml
@@ -65,6 +65,7 @@ and list_entries_long ~sources index =
size = size;
compressed_size = compressed_size;
notes = notes;
+ aliases = aliases;
hidden = hidden }) ->
if not hidden then (
printf "%-24s %s\n" "os-version:" name;
@@ -79,6 +80,11 @@ and list_entries_long ~sources index =
| Some size ->
printf "%-24s %s\n" (s_"Download size:") (human_size
size);
);
+ (match aliases with
+ | None -> ()
+ | Some l -> printf "%-24s %s\n" (s_"Aliases:")
+ (String.concat Index_parser.list_separator l);
+ );
let notes = Languages.find_notes langs notes in
(match notes with
| notes :: _ ->
@@ -116,6 +122,15 @@ and list_entries_json ~sources index =
| None -> ()
| Some n ->
printf " \"%s\": \"%Ld\",\n" key n in
+ let json_optional_printf_stringlist key = function
+ | None -> ()
+ | Some l ->
+ printf " \"%s\": [" key;
+ iteri (
+ fun i alias ->
+ printf " \"%s\"%s" alias (trailing_comma i (List.length
l))
+ ) l;
+ printf " ],\n" in
let print_notes = function
| [] -> ()
| notes ->
@@ -156,6 +171,7 @@ and list_entries_json ~sources index =
size = size;
compressed_size = compressed_size;
notes = notes;
+ aliases = aliases;
hidden = hidden }) ->
printf " {\n";
printf " \"os-version\": \"%s\",\n" name;
@@ -164,6 +180,7 @@ and list_entries_json ~sources index =
printf " \"size\": %Ld,\n" size;
json_optional_printf_int64 "compressed-size" compressed_size;
print_notes notes;
+ json_optional_printf_stringlist "aliases" aliases;
printf " \"hidden\": %s\n" (json_string_of_bool hidden);
printf " }%s\n" (trailing_comma i (List.length index))
) index;
diff --git a/builder/virt-builder.pod b/builder/virt-builder.pod
index 5c531de..a70767f 100644
--- a/builder/virt-builder.pod
+++ b/builder/virt-builder.pod
@@ -1288,6 +1288,14 @@ Using the hidden flag prevents the template from being listed by
the
I<--list> option (but it is still installable). This is used for test
images.
+=item C<aliases=ALIAS1 ALIAS2 ...>
+
+This optional field specifies a list of aliases, separated by spaces,
+for the image. For example, an alias could be used to always point
+to the latest version of a certain image, leaving the old versions
+available in the index instead of updating the same image (see the
+C<revision> field).
+
=back
=head3 Running virt-builder against multiple sources
--
1.9.3