[Libguestfs] [PATCH] sysprep: add feature of removing specified paths

Wanlong Gao gaowanlong at cn.fujitsu.com
Tue Oct 22 08:17:25 UTC 2013


Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com>
---
 po/POTFILES-ml                           |  1 +
 sysprep/Makefile.am                      |  1 +
 sysprep/sysprep_operation_remove_path.ml | 53 ++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+)
 create mode 100644 sysprep/sysprep_operation_remove_path.ml

diff --git a/po/POTFILES-ml b/po/POTFILES-ml
index 509e786..0e25e95 100644
--- a/po/POTFILES-ml
+++ b/po/POTFILES-ml
@@ -50,6 +50,7 @@ sysprep/sysprep_operation_pam_data.ml
 sysprep/sysprep_operation_password.ml
 sysprep/sysprep_operation_puppet_data_log.ml
 sysprep/sysprep_operation_random_seed.ml
+sysprep/sysprep_operation_remove_path.ml
 sysprep/sysprep_operation_rhn_systemid.ml
 sysprep/sysprep_operation_rpm_db.ml
 sysprep/sysprep_operation_samba_db_log.ml
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
index c5be5ba..cb95cea 100644
--- a/sysprep/Makefile.am
+++ b/sysprep/Makefile.am
@@ -57,6 +57,7 @@ operations = \
 	password \
 	puppet_data_log \
 	random_seed \
+	remove_path \
 	rhn_systemid \
 	rpm_db \
 	samba_db_log \
diff --git a/sysprep/sysprep_operation_remove_path.ml b/sysprep/sysprep_operation_remove_path.ml
new file mode 100644
index 0000000..d307373
--- /dev/null
+++ b/sysprep/sysprep_operation_remove_path.ml
@@ -0,0 +1,53 @@
+(* virt-sysprep
+ * Copyright (C) 2013 Fujitsu Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+open Common_utils
+open Sysprep_operation
+open Common_gettext.Gettext
+
+module G = Guestfs
+
+let paths= ref []
+let add_paths path= paths := path :: !paths
+
+let path_perform g root =
+  let paths = List.rev !paths in
+  if paths <> [] then (
+    List.iter (fun glob -> Array.iter g#rm_rf (g#glob_expand glob)) paths
+  );
+  []
+
+let op = {
+  defaults with
+    name = "remove-path";
+    enabled_by_default = true;
+    heading = s_"Remove specified paths";
+    pod_description = Some (s_"\
+Remove specified files or directories.
+
+Use the I<--remove-path> option to specify a path to remove.");
+    extra_args = [
+      ("--remove-path", Arg.String add_paths, s_"path" ^ " " ^ s_"Files or directories to be removed on guest"),
+      s_"\
+Remove the specified path C<file> on guest.";
+    ];
+
+    perform_on_filesystems = Some path_perform;
+}
+
+let () = register_operation op
-- 
1.8.4.474.g128a96c




More information about the Libguestfs mailing list