[Pkg-libvirt-commits] [libguestfs] 86/165: builder: support aliases for images (RHBZ#1098718).
Hilko Bengen
bengen at moszumanska.debian.org
Sat Aug 30 08:24:52 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch experimental
in repository libguestfs.
commit e4005bd530aab62a8d86cfc7cb5db1c69ae873dd
Author: Pino Toscano <ptoscano at redhat.com>
Date: Tue May 27 10:57:13 2014 +0200
builder: support aliases for images (RHBZ#1098718).
---
builder/builder.ml | 12 ++++++++++++
builder/index_parser.ml | 14 ++++++++++++++
builder/index_parser.mli | 1 +
builder/list_entries.ml | 17 +++++++++++++++++
builder/virt-builder.pod | 8 ++++++++
5 files changed, 52 insertions(+)
diff --git a/builder/builder.ml b/builder/builder.ml
index e7be901..2884cf6 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..7ccbece 100644
--- a/builder/index_parser.ml
+++ b/builder/index_parser.ml
@@ -38,6 +38,7 @@ and entry = {
lvexpand : string option;
notes : (string * string) list;
hidden : bool;
+ aliases : string list option;
sigchecker : Sigchecker.t;
proxy : Downloader.proxy_mode;
@@ -56,6 +57,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 +103,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 " " l)
+ );
if hidden then fp "hidden=true\n"
let get_index ~prog ~debug ~downloader ~sigchecker ~proxy source =
@@ -245,6 +251,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.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 +273,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..ccf38e8 100644
--- a/builder/index_parser.mli
+++ b/builder/index_parser.mli
@@ -32,6 +32,7 @@ and entry = {
lvexpand : string option;
notes : (string * string) list;
hidden : bool;
+ aliases : string list option;
sigchecker : Sigchecker.t;
proxy : Downloader.proxy_mode;
diff --git a/builder/list_entries.ml b/builder/list_entries.ml
index 505a1b9..1891679 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 " " 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
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list