mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
sysprep: Change perform callback to perform_on_filesystems and perform_on_devices.
Operations that need to work directly on guest block devices will fail because the block devices are busy. Therefore add a phase with the filesystems unmounted, and allow operations to specify that they need to work in this phase.
This commit is contained in:
@@ -207,9 +207,10 @@ let () =
|
||||
with Guestfs.Error msg -> eprintf (f_"%s (ignored)\n") msg
|
||||
) mps;
|
||||
|
||||
(* Perform the operations. *)
|
||||
(* Perform the filesystem operations. *)
|
||||
let flags =
|
||||
Sysprep_operation.perform_operations ?operations ~quiet g root in
|
||||
Sysprep_operation.perform_operations_on_filesystems
|
||||
?operations ~quiet g root in
|
||||
|
||||
(* Parse flags. *)
|
||||
let relabel = ref false in
|
||||
@@ -234,7 +235,15 @@ let () =
|
||||
);
|
||||
|
||||
(* Unmount everything in this guest. *)
|
||||
g#umount_all ()
|
||||
g#umount_all ();
|
||||
|
||||
(* Perform the block device operations. *)
|
||||
let flags =
|
||||
Sysprep_operation.perform_operations_on_devices
|
||||
?operations ~quiet g root in
|
||||
|
||||
(* At present we don't support any flags from perform_on_devices. *)
|
||||
assert (flags = [])
|
||||
) roots
|
||||
|
||||
(* Finished. *)
|
||||
|
||||
@@ -24,13 +24,16 @@ open Sysprep_gettext.Gettext
|
||||
|
||||
type flag = [ `Created_files ]
|
||||
|
||||
type callback = Guestfs.guestfs -> string -> flag list
|
||||
|
||||
type operation = {
|
||||
name : string;
|
||||
enabled_by_default : bool;
|
||||
heading : string;
|
||||
pod_description : string option;
|
||||
extra_args : ((Arg.key * Arg.spec * Arg.doc) * string) list;
|
||||
perform : Guestfs.guestfs -> string -> flag list;
|
||||
perform_on_filesystems : callback option;
|
||||
perform_on_devices : callback option;
|
||||
}
|
||||
|
||||
let all_operations = ref []
|
||||
@@ -189,7 +192,7 @@ let list_operations () =
|
||||
op.heading
|
||||
) !all_operations
|
||||
|
||||
let perform_operations ?operations ?(quiet = false) g root =
|
||||
let perform_operations_on_filesystems ?operations ?(quiet = false) g root =
|
||||
assert !baked;
|
||||
|
||||
let ops =
|
||||
@@ -200,10 +203,33 @@ let perform_operations ?operations ?(quiet = false) g root =
|
||||
|
||||
let flags =
|
||||
List.map (
|
||||
fun op ->
|
||||
function
|
||||
| { name = name; perform_on_filesystems = Some fn } ->
|
||||
if not quiet then
|
||||
printf "Performing %S ...\n%!" op.name;
|
||||
op.perform g root
|
||||
printf "Performing %S ...\n%!" name;
|
||||
fn g root
|
||||
| { perform_on_filesystems = None } -> []
|
||||
) ops in
|
||||
|
||||
List.flatten flags
|
||||
|
||||
let perform_operations_on_devices ?operations ?(quiet = false) g root =
|
||||
assert !baked;
|
||||
|
||||
let ops =
|
||||
match operations with
|
||||
| None -> !enabled_by_default_operations
|
||||
| Some opset -> (* just the operation names listed *)
|
||||
OperationSet.elements opset in
|
||||
|
||||
let flags =
|
||||
List.map (
|
||||
function
|
||||
| { name = name; perform_on_devices = Some fn } ->
|
||||
if not quiet then
|
||||
printf "Performing %S ...\n%!" name;
|
||||
fn g root
|
||||
| { perform_on_devices = None } -> []
|
||||
) ops in
|
||||
|
||||
List.flatten flags
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
|
||||
type flag = [ `Created_files ]
|
||||
|
||||
type callback = Guestfs.guestfs -> string -> flag list
|
||||
|
||||
type operation = {
|
||||
name : string;
|
||||
(** Operation name, also used to enable the operation on the command
|
||||
@@ -46,7 +48,7 @@ type operation = {
|
||||
You can decide the types of the arguments, whether they are
|
||||
mandatory etc. *)
|
||||
|
||||
perform : Guestfs.guestfs -> string -> flag list;
|
||||
perform_on_filesystems : callback option;
|
||||
(** The function which is called to perform this operation, when
|
||||
enabled.
|
||||
|
||||
@@ -66,6 +68,11 @@ type operation = {
|
||||
On error the function should raise an exception. The function
|
||||
also needs to be careful to {i suppress} exceptions for things
|
||||
which are not errors, eg. deleting non-existent files. *)
|
||||
|
||||
perform_on_devices : callback option;
|
||||
(** This is the same as {!perform_on_filesystems} except that
|
||||
the guest filesystem(s) are {i not} mounted. This allows the
|
||||
operation to work directly on block devices, LVs etc. *)
|
||||
}
|
||||
|
||||
val register_operation : operation -> unit
|
||||
@@ -102,5 +109,8 @@ val add_to_set : string -> set -> set
|
||||
Note that this will raise [Not_found] if [name] is not
|
||||
a valid operation name. *)
|
||||
|
||||
val perform_operations : ?operations:set -> ?quiet:bool -> Guestfs.guestfs -> string -> flag list
|
||||
val perform_operations_on_filesystems : ?operations:set -> ?quiet:bool -> Guestfs.guestfs -> string -> flag list
|
||||
(** Perform all operations, or the subset listed in the [operations] set. *)
|
||||
|
||||
val perform_operations_on_devices : ?operations:set -> ?quiet:bool -> Guestfs.guestfs -> string -> flag list
|
||||
(** Perform all operations, or the subset listed in the [operations] set. *)
|
||||
|
||||
@@ -40,7 +40,8 @@ let abrt_data_op = {
|
||||
Remove the automatically generated ABRT crash data in
|
||||
C</var/spool/abrt/>.");
|
||||
extra_args = [];
|
||||
perform = abrt_data_perform;
|
||||
perform_on_filesystems = Some abrt_data_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation abrt_data_op
|
||||
|
||||
@@ -41,7 +41,8 @@ let bash_history_op = {
|
||||
Remove the bash history of user \"root\" and any other users
|
||||
who have a C<.bash_history> file in their home directory.");
|
||||
extra_args = [];
|
||||
perform = bash_history_perform;
|
||||
perform_on_filesystems = Some bash_history_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation bash_history_op
|
||||
|
||||
@@ -49,7 +49,8 @@ let blkid_tab_op = {
|
||||
heading = s_"Remove blkid tab in the guest";
|
||||
pod_description = None;
|
||||
extra_args = [];
|
||||
perform = blkid_tab_perform;
|
||||
perform_on_filesystems = Some blkid_tab_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation blkid_tab_op
|
||||
|
||||
@@ -53,7 +53,8 @@ let ca_certificates_op = {
|
||||
heading = s_"Remove CA certificates in the guest";
|
||||
pod_description = None;
|
||||
extra_args = [];
|
||||
perform = ca_certificates_perform;
|
||||
perform_on_filesystems = Some ca_certificates_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation ca_certificates_op
|
||||
|
||||
@@ -31,7 +31,8 @@ let cron_spool_op = {
|
||||
heading = s_"Remove user at-jobs and cron-jobs";
|
||||
pod_description = None;
|
||||
extra_args = [];
|
||||
perform = cron_spool_perform;
|
||||
perform_on_filesystems = Some cron_spool_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation cron_spool_op
|
||||
|
||||
@@ -36,7 +36,8 @@ let dhcp_client_state_op = {
|
||||
heading = s_"Remove DHCP client leases";
|
||||
pod_description = None;
|
||||
extra_args = [];
|
||||
perform = dhcp_client_state_perform;
|
||||
perform_on_filesystems = Some dhcp_client_state_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation dhcp_client_state_op
|
||||
|
||||
@@ -31,7 +31,8 @@ let dhcp_server_state_op = {
|
||||
heading = s_"Remove DHCP server leases";
|
||||
pod_description = None;
|
||||
extra_args = [];
|
||||
perform = dhcp_server_state_perform;
|
||||
perform_on_filesystems = Some dhcp_server_state_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation dhcp_server_state_op
|
||||
|
||||
@@ -38,7 +38,8 @@ let dovecot_data_op = {
|
||||
heading = s_"Remove Dovecot (mail server) data";
|
||||
pod_description = None;
|
||||
extra_args = [];
|
||||
perform = dovecot_data_perform;
|
||||
perform_on_filesystems = Some dovecot_data_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation dovecot_data_op
|
||||
|
||||
@@ -37,7 +37,8 @@ let flag_reconfiguration_op = {
|
||||
Note that this may require user intervention when the
|
||||
guest is booted.");
|
||||
extra_args = [];
|
||||
perform = flag_reconfiguration;
|
||||
perform_on_filesystems = Some flag_reconfiguration;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation flag_reconfiguration_op;
|
||||
|
||||
@@ -66,7 +66,8 @@ to C<localhost.localdomain>.");
|
||||
s_"\
|
||||
Change the hostname. If not given, defaults to C<localhost.localdomain>."
|
||||
];
|
||||
perform = hostname_perform;
|
||||
perform_on_filesystems = Some hostname_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation hostname_op
|
||||
|
||||
@@ -46,7 +46,8 @@ let kerberos_data_op = {
|
||||
heading = s_"Remove Kerberos data in the guest";
|
||||
pod_description = None;
|
||||
extra_args = [];
|
||||
perform = kerberos_data_perform;
|
||||
perform_on_filesystems = Some kerberos_data_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation kerberos_data_op
|
||||
|
||||
@@ -89,7 +89,8 @@ On Linux the following files are removed:
|
||||
|
||||
%s") globs_as_pod);
|
||||
extra_args = [];
|
||||
perform = logfiles_perform;
|
||||
perform_on_filesystems = Some logfiles_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation logfiles_op
|
||||
|
||||
@@ -41,7 +41,8 @@ installation and stays constant for all subsequent boots. Optionally,
|
||||
for stateless systems it is generated during runtime at boot if it is
|
||||
found to be empty.");
|
||||
extra_args = [];
|
||||
perform = machine_id_perform;
|
||||
perform_on_filesystems = Some machine_id_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation machine_id_op
|
||||
|
||||
@@ -36,7 +36,8 @@ let mail_spool_op = {
|
||||
heading = s_"Remove email from the local mail spool directory";
|
||||
pod_description = None;
|
||||
extra_args = [];
|
||||
perform = mail_spool_perform;
|
||||
perform_on_filesystems = Some mail_spool_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation mail_spool_op
|
||||
|
||||
@@ -51,7 +51,8 @@ let net_hwaddr_op = {
|
||||
For Fedora and Red Hat Enterprise Linux,
|
||||
this is removed from C<ifcfg-*> files.");
|
||||
extra_args = [];
|
||||
perform = net_hwaddr_perform;
|
||||
perform_on_filesystems = Some net_hwaddr_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation net_hwaddr_op
|
||||
|
||||
@@ -40,7 +40,8 @@ let package_manager_cache_op = {
|
||||
heading = s_"Remove package manager cache";
|
||||
pod_description = None;
|
||||
extra_args = [];
|
||||
perform = package_manager_cache_perform;
|
||||
perform_on_filesystems = Some package_manager_cache_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation package_manager_cache_op
|
||||
|
||||
@@ -46,7 +46,8 @@ let pam_data_op = {
|
||||
heading = s_"Remove the PAM data in the guest";
|
||||
pod_description = None;
|
||||
extra_args = [];
|
||||
perform = pam_data_perform;
|
||||
perform_on_filesystems = Some pam_data_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation pam_data_op
|
||||
|
||||
@@ -46,7 +46,8 @@ let puppet_data_log_op = {
|
||||
heading = s_"Remove the data and log files of puppet";
|
||||
pod_description = None;
|
||||
extra_args = [];
|
||||
perform = puppet_data_log_perform;
|
||||
perform_on_filesystems = Some puppet_data_log_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation puppet_data_log_op
|
||||
|
||||
@@ -54,7 +54,8 @@ guest.
|
||||
|
||||
See L</RANDOM SEED> below.");
|
||||
extra_args = [];
|
||||
perform = random_seed_perform;
|
||||
perform_on_filesystems = Some random_seed_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation random_seed_op
|
||||
|
||||
@@ -37,7 +37,8 @@ let rhn_systemid_op = {
|
||||
heading = s_"Remove the RHN system ID";
|
||||
pod_description = None;
|
||||
extra_args = [];
|
||||
perform = rhn_systemid_perform;
|
||||
perform_on_filesystems = Some rhn_systemid_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation rhn_systemid_op
|
||||
|
||||
@@ -47,7 +47,8 @@ let samba_db_log_op = {
|
||||
heading = s_"Remove the database and log files of Samba";
|
||||
pod_description = None;
|
||||
extra_args = [];
|
||||
perform = samba_db_log_perform;
|
||||
perform_on_filesystems = Some samba_db_log_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation samba_db_log_op
|
||||
|
||||
@@ -155,7 +155,8 @@ current directory will be the guest's root directory.
|
||||
B<Note:> If the script is not on the $PATH, then you must give
|
||||
the full absolute path to the script.";
|
||||
];
|
||||
perform = script_perform;
|
||||
perform_on_filesystems = Some script_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation script_op
|
||||
|
||||
@@ -41,7 +41,8 @@ let smolt_uuid_op = {
|
||||
heading = s_"Remove the Smolt hardware UUID";
|
||||
pod_description = None;
|
||||
extra_args = [];
|
||||
perform = smolt_uuid_perform;
|
||||
perform_on_filesystems = Some smolt_uuid_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation smolt_uuid_op
|
||||
|
||||
@@ -46,7 +46,8 @@ you a stark warning about the host key changing:
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!");
|
||||
extra_args = [];
|
||||
perform = ssh_hostkeys_perform;
|
||||
perform_on_filesystems = Some ssh_hostkeys_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation ssh_hostkeys_op
|
||||
|
||||
@@ -41,7 +41,8 @@ let ssh_userdir_op = {
|
||||
Remove the C<.ssh> directory of user \"root\" and any other
|
||||
users who have a C<.ssh> directory in their home directory.");
|
||||
extra_args = [];
|
||||
perform = ssh_userdir_perform;
|
||||
perform_on_filesystems = Some ssh_userdir_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation ssh_userdir_op
|
||||
|
||||
@@ -45,7 +45,8 @@ let sssd_db_log_op = {
|
||||
heading = s_"Remove the database and log files of sssd";
|
||||
pod_description = None;
|
||||
extra_args = [];
|
||||
perform = sssd_db_log_perform;
|
||||
perform_on_filesystems = Some sssd_db_log_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation sssd_db_log_op
|
||||
|
||||
@@ -43,7 +43,8 @@ old MAC address occupies the old name (eg. eth0), this means the fresh
|
||||
MAC address is assigned to a new name (eg. eth1) and this is usually
|
||||
undesirable. Erasing the udev persistent net rules avoids this.");
|
||||
extra_args = [];
|
||||
perform = udev_persistent_net_perform;
|
||||
perform_on_filesystems = Some udev_persistent_net_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation udev_persistent_net_op
|
||||
|
||||
@@ -66,7 +66,8 @@ let user_account_op = {
|
||||
Remove all the user accounts and their home directories.
|
||||
The \"root\" account is not removed.");
|
||||
extra_args = [];
|
||||
perform = user_account_perform;
|
||||
perform_on_filesystems = Some user_account_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation user_account_op
|
||||
|
||||
@@ -38,7 +38,8 @@ This file records who is currently logged in on a machine. In modern
|
||||
Linux distros it is stored in a ramdisk and hence not part of the
|
||||
virtual machine's disk, but it was stored on disk in older distros.");
|
||||
extra_args = [];
|
||||
perform = utmp_perform;
|
||||
perform_on_filesystems = Some utmp_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation utmp_op
|
||||
|
||||
@@ -37,7 +37,8 @@ let yum_uuid_op = {
|
||||
Yum creates a fresh UUID the next time it runs when it notices that the
|
||||
original UUID has been erased.");
|
||||
extra_args = [];
|
||||
perform = yum_uuid_perform;
|
||||
perform_on_filesystems = Some yum_uuid_perform;
|
||||
perform_on_devices = None;
|
||||
}
|
||||
|
||||
let () = register_operation yum_uuid_op
|
||||
|
||||
Reference in New Issue
Block a user