Laszlo Ersek
2022-Mar-08 14:29 UTC
[Libguestfs] [libguestfs-common PATCH] mlcustomize/firstboot: take an optional priority in "add_firstboot_script"
Enable callers of "add_firstboot_script" to pass an (optional) priority parameter. With this, groups of scripts can be formed with well-defined (lexicographical) ordering between the groups. Within a group, the usual order of registration persists. Suggested-by: Richard W.M. Jones <rjones at redhat.com> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 Signed-off-by: Laszlo Ersek <lersek at redhat.com> --- mlcustomize/firstboot.mli | 16 ++++++++++++---- mlcustomize/firstboot.ml | 9 +++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/mlcustomize/firstboot.mli b/mlcustomize/firstboot.mli index fb30886184cc..e6a0d1f70102 100644 --- a/mlcustomize/firstboot.mli +++ b/mlcustomize/firstboot.mli @@ -16,16 +16,24 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *) -val add_firstboot_script : Guestfs.guestfs -> string -> string -> string -> unit - (** [add_firstboot_script g root name content] adds a firstboot - script called [name] containing [content]. +val default_prio : int + +val add_firstboot_script : Guestfs.guestfs -> string -> ?prio:int -> string -> + string -> unit + (** [add_firstboot_script g root prio name content] adds a firstboot + script called [name] containing [content] with priority [prio]. [content] is the contents of the script, {b not} a filename. The actual name of the script on the guest filesystem is made of [name] with all characters but alphanumeric replaced with dashes. - The scripts are run in the order they are registered. + Within a given priority, the scripts are run in the order they are + registered. A group of scripts with a numerically lower priority is run + before a group with a numerically greater priority. If [prio] is omitted, + it is taken as [default_prio], that is, 5000. If [prio] is smaller than 0 + or greater than 9999, an Assert_failure is raised (the [prio] parameter + is not expected to depend on external data). For Linux guests using SELinux you should make sure the filesystem is relabelled after calling this. *) diff --git a/mlcustomize/firstboot.ml b/mlcustomize/firstboot.ml index c3ebfd910d0b..18dc04efa2e6 100644 --- a/mlcustomize/firstboot.ml +++ b/mlcustomize/firstboot.ml @@ -345,12 +345,17 @@ end let script_count = ref 0 -let add_firstboot_script (g : Guestfs.guestfs) root name content +let default_prio = 5000 + +let add_firstboot_script (g : Guestfs.guestfs) root ?(prio = default_prio) name + content + assert (prio >= 0 && prio <= 9999); let typ = g#inspect_get_type root in let distro = g#inspect_get_distro root in let major = g#inspect_get_major_version root in incr script_count; - let filename = sprintf "%04d-%s" !script_count (sanitize_name name) in + let filename = sprintf "%04d-%04d-%s" prio !script_count + (sanitize_name name) in match typ, distro with | "linux", _ -> Linux.install_service g root distro major; base-commit: 60efc5407552c12688a5e99b7a54d23d5990aa8f -- 2.19.1.3.g30247aa5d201
Laszlo Ersek
2022-Mar-08 14:30 UTC
[Libguestfs] [v2v PATCH 00/12] Windows: set static IP addresses as first thing at first boot
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1788823 This patch set depends on [libguestfs-common PATCH] mlcustomize/firstboot: take an optional priority in "add_firstboot_script" The first 10 patches are meant as refactorings / cleanups, for the sake of easier maintenance / better readability, with no intent to change behavior. From those 10 patches, I ended up regression-testing "configure_qemu_ga" and "configure_wait_pnp" with a real Windows 2019 Server domain; the rest of that section of the series is effectively untested. The last two patches implement the actual goal of this series; I have tested those too, with the same Windows 2019 Server domain. Thanks Laszlo Laszlo Ersek (12): convert_linux: wrap overlong lines convert_windows: wrap overlong lines convert_linux: align shell script indentation with OCaml source code convert_windows: rewrite "configure_qemu_ga" script purely in PowerShell convert_windows: align "reg_restore" batch file commands with OCaml source convert_windows: align "configure_wait_pnp" batch file with OCaml source convert_windows: align "configure_vmdp" batch files with OCaml source convert_windows: align "unconfigure_xenpv" batch file with OCaml source convert_windows: align "unconfigure_prltools" batch file with OCaml source convert_windows: align "unconfigure_vmwaretools" batch file with OCaml src convert/windows: expose "prio" parameter in install_firstboot_powershell convert_windows: install "v2vnetcf.ps1" with prio 2500 convert/convert_linux.ml | 75 +++++--- convert/convert_windows.ml | 193 ++++++++++++-------- convert/windows.ml | 5 +- convert/windows.mli | 6 +- 4 files changed, 170 insertions(+), 109 deletions(-) -- 2.19.1.3.g30247aa5d201
Richard W.M. Jones
2022-Mar-08 16:00 UTC
[Libguestfs] [libguestfs-common PATCH] mlcustomize/firstboot: take an optional priority in "add_firstboot_script"
This patch is fine, thanks ...> + it is taken as [default_prio], that is, 5000. If [prio] is smaller than 0 > + or greater than 9999, an Assert_failure is raised (the [prio] parameter > + is not expected to depend on external data).... but I'm confused by what you meant by "is not expected to depend on external data"? Anyway, ACK Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/