[PATCH] sysprep: remove the cache of package manager
by Wanlong Gao
Remove the cache of package manager like yum and apt.
Signed-off-by: Wanlong Gao <gaowanlong(a)cn.fujitsu.com>
---
sysprep/Makefile.am | 2 +
sysprep/sysprep_operation_package_manager_cache.ml | 49 ++++++++++++++++++++
2 files changed, 51 insertions(+)
create mode 100644 sysprep/sysprep_operation_package_manager_cache.ml
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
index e4b7f7b..78b1fa1 100644
--- a/sysprep/Makefile.am
+++ b/sysprep/Makefile.am
@@ -42,6 +42,7 @@ SOURCES = \
sysprep_operation_logfiles.ml \
sysprep_operation_mail_spool.ml \
sysprep_operation_net_hwaddr.ml \
+ sysprep_operation_package_manager_cache.ml \
sysprep_operation_random_seed.ml \
sysprep_operation_rhn_systemid.ml \
sysprep_operation_script.ml \
@@ -69,6 +70,7 @@ OBJECTS = \
sysprep_operation_logfiles.cmx \
sysprep_operation_mail_spool.cmx \
sysprep_operation_net_hwaddr.cmx \
+ sysprep_operation_package_manager_cache.ml \
sysprep_operation_random_seed.cmx \
sysprep_operation_rhn_systemid.cmx \
sysprep_operation_script.cmx \
diff --git a/sysprep/sysprep_operation_package_manager_cache.ml b/sysprep/sysprep_operation_package_manager_cache.ml
new file mode 100644
index 0000000..f70f310
--- /dev/null
+++ b/sysprep/sysprep_operation_package_manager_cache.ml
@@ -0,0 +1,49 @@
+(* virt-sysprep
+ * Copyright (C) 2012 FUJITSU LIMITED
+ *
+ * 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 Sysprep_operation
+
+module G = Guestfs
+
+let package_manager_cache_perform g root =
+ let packager = g#inspect_get_package_management root in
+ match packager with
+ | "yum" ->
+ let cache = g#glob_expand "/var/cache/yum/*" in
+ Array.iter (
+ fun dir ->
+ g#rm_rf dir
+ ) cache; []
+ | "apt" ->
+ let cache = g#glob_expand "/var/cache/apt/archives/*" in
+ Array.iter (
+ fun dir ->
+ g#rm_rf dir
+ ) cache; []
+ | _ -> (); []
+
+let package_manager_cache_op = {
+ name = "package-manager-cache";
+ enabled_by_default = true;
+ heading = "Remove the cache of package manager";
+ pod_description = None;
+ extra_args = [];
+ perform = package_manager_cache_perform;
+}
+
+let () = register_operation package_manager_cache_op
--
1.7.10
12 years, 8 months
[PATCH] sysprep: flag the system for reconfiguration
by Wanlong Gao
Flag the system for reconfiguration by touching /.unconfigured .
Signed-off-by: Wanlong Gao <gaowanlong(a)cn.fujitsu.com>
---
TODO | 2 -
sysprep/Makefile.am | 2 +
sysprep/sysprep_operation_flag_reconfiguration.ml | 42 +++++++++++++++++++++
3 files changed, 44 insertions(+), 2 deletions(-)
create mode 100644 sysprep/sysprep_operation_flag_reconfiguration.ml
diff --git a/TODO b/TODO
index 426d9ff..8cc0543 100644
--- a/TODO
+++ b/TODO
@@ -373,11 +373,9 @@ Return libosinfo mappings from inspection API.
virt-sysprep ideas
------------------
- - touch /.unconfigured ?
- other Spacewalk / RHN IDs (?)
- Kerberos keys
- Puppet registration
- - user accounts
- Windows sysprep
(see: https://github.com/clalancette/oz/blob/e74ce83283d468fd987583d6837b441608... )
- blue skies: change the background image
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
index f51fc07..71669b2 100644
--- a/sysprep/Makefile.am
+++ b/sysprep/Makefile.am
@@ -37,6 +37,7 @@ SOURCES = \
sysprep_operation_cron_spool.ml \
sysprep_operation_dhcp_client_state.ml \
sysprep_operation_dhcp_server_state.ml \
+ sysprep_operation_flag_reconfiguration.ml \
sysprep_operation_hostname.ml \
sysprep_operation_logfiles.ml \
sysprep_operation_mail_spool.ml \
@@ -62,6 +63,7 @@ OBJECTS = \
sysprep_operation_cron_spool.cmx \
sysprep_operation_dhcp_client_state.cmx \
sysprep_operation_dhcp_server_state.cmx \
+ sysprep_operation_flag_reconfiguration.ml \
sysprep_operation_hostname.cmx \
sysprep_operation_logfiles.cmx \
sysprep_operation_mail_spool.cmx \
diff --git a/sysprep/sysprep_operation_flag_reconfiguration.ml b/sysprep/sysprep_operation_flag_reconfiguration.ml
new file mode 100644
index 0000000..2a26c21
--- /dev/null
+++ b/sysprep/sysprep_operation_flag_reconfiguration.ml
@@ -0,0 +1,42 @@
+(* virt-sysprep
+ * Copyright (C) 2012 FUJITSU LIMITED
+ *
+ * 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 Sysprep_operation
+
+module G = Guestfs
+
+let flag_reconfiguration g root =
+ let typ = g#inspect_get_type root in
+ if typ <> "windows" then (
+ g#touch "/.unconfigured";
+ [ `Created_files ]
+ )
+ else []
+
+let flag_reconfiguration_op = {
+ name = "flag-reconfiguration";
+ enabled_by_default = true;
+ heading = "Flag the system for reconfiguration";
+ pod_description = Some "\
+Flag the system for reconfiguration by touching a file
+\"/.unconfigured\".";
+ extra_args = [];
+ perform = flag_reconfiguration;
+}
+
+let () = register_operation flag_reconfiguration_op;
--
1.7.10
12 years, 8 months
[PATCH RFC] sysprep: remove user accounts
by Wanlong Gao
Hi Rich,
This patch attends to remove the user accounts in the guest,
I send this out to request your comments, if the concept
is correct and you can point out some syntax error for me.
Thanks a lot,
Wanlong Gao
Remove user accounts except the root user.
Signed-off-by: Wanlong Gao <gaowanlong(a)cn.fujitsu.com>
---
sysprep/Makefile.am | 2 +
sysprep/sysprep_operation_user_account.ml | 82 +++++++++++++++++++++++++++++
2 files changed, 84 insertions(+)
create mode 100644 sysprep/sysprep_operation_user_account.ml
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
index f51fc07..9b06804 100644
--- a/sysprep/Makefile.am
+++ b/sysprep/Makefile.am
@@ -48,6 +48,7 @@ SOURCES = \
sysprep_operation_ssh_hostkeys.ml \
sysprep_operation_ssh_userdir.ml \
sysprep_operation_udev_persistent_net.ml \
+ sysprep_operation_user_account.ml \
sysprep_operation_utmp.ml \
sysprep_operation_yum_uuid.ml \
utils.ml
@@ -73,6 +74,7 @@ OBJECTS = \
sysprep_operation_ssh_hostkeys.cmx \
sysprep_operation_ssh_userdir.cmx \
sysprep_operation_udev_persistent_net.cmx \
+ sysprep_operation_user_account.ml \
sysprep_operation_utmp.cmx \
sysprep_operation_yum_uuid.cmx \
main.cmx
diff --git a/sysprep/sysprep_operation_user_account.ml b/sysprep/sysprep_operation_user_account.ml
new file mode 100644
index 0000000..ac07c6d
--- /dev/null
+++ b/sysprep/sysprep_operation_user_account.ml
@@ -0,0 +1,82 @@
+(* virt-sysprep
+ * Copyright (C) 2012 FUJITSU LIMITED
+ *
+ * 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 Sysprep_operation
+
+module G = Guestfs
+
+let user_account_perform g root =
+ let typ = g#inspect_get_type root in
+ if typ <> "windows" then (
+ let login_def = "/etc/login.defs" in
+ let lines = Array.to_list (g#read_lines login_def) in
+ let line_min = Array.filter (
+ fun line -> (string_prefix line "UID_MIN")
+ ) lines in
+ let _,min_uid = sscanf line_min "%s %d" (fun a b -> a,b) in
+ let line_max = Array.filter (
+ fun line -> (string_prefix line "UID_MAX")
+ ) lines in
+ let _,max_uid = sscanf line_max "%s %d" (fun a b -> a,b) in
+ let passwd = "/etc/passwd" in
+ let shadow = "/etc/shadow" in
+ let group = "/etc/group" in
+ let lines = Array.to_list (g#read_lines passwd) in
+ let lines_passwd = Array.to_list (g#read_lines passwd) in
+ let lines_shadow = Array.to_list (g#read_lines shadow) in
+ let lines_group = Array.to_list (g#read_lines group) in
+ List.iter (
+ fun line ->
+ let user_line = string_split ":" line in
+ let user_line = Array.of_list user_line in
+ if user_line.(2) >= min_uid and user_line.(2) <= max_uid then (
+ let user = user_line(0) in
+ let lines_passwd = List.filter (
+ fun line -> not (string_prefix line user)
+ ) lines_passwd in
+ let lines_shadow = List.filter (
+ fun line -> not (string_prefix line user)
+ ) lines_shadow in
+ let lines_group = List.filter (
+ fun line -> not (string_prefix line user)
+ ) lines_group in
+ let dir = String.concat "/home/" user in
+ g#rm_rf dir
+ )
+ ) lines in
+ let file = String.concat "\n" lines_passwd ^ "\n" in
+ g#write passwd file in
+ let file = String.concat "\n" lines_shadow ^ "\n" in
+ g#write shadow file in
+ let file = String.concat "\n" lines_group ^ "\n" in
+ g#write group file
+ )
+ else []
+
+let user_account_op = {
+ name = "user-account";
+ pod_description = "\
+Remove the user accounts except \"root\" in the guest.
+
+Remove the user accounts and their home directory except
+the \"root\" account.";
+ extra_args = [];
+ perform = user_account_perform;
+}
+
+let () = register_operation bash_history_op
--
1.7.10
12 years, 8 months
Cannot login after modification shadow file with guestmount
by Daneel Yaitskov
Hi.
I have a VM with CentOs6.2 on KVM. I mount an image of the VM when it's
not working with guestmount:
root@diehard:~# guestmount -a named-centos.img -i tmp
vi /etc/shadow
insert comment line into the file (esc yy p 0 i # esc :wq!), save changes,
unmount the image, turn on the VM, and I cannot login.
I cannot login even if I recover the shadow file.
root@diehard:~# guestmount --version
guestmount 1.16.15
--
Яицков Даниил Сергеевич
Daneel S. Yaitskov
skype: daneel_s_yaitskov
google talks: rtfm.rtfm.rtfm(a)gmail.com
email: dy(a)hivext.net
12 years, 8 months
[PATCH libguestfs] maint: fix doc typos
by Jim Meyering
Hi Rich,
I ran this command to spot a few typos:
git ls-files|misspellings -f -|grep -v '^po'
Here are fixes:
>From ec62fad96cc2884c8fd43ecb550a8bcac317cca0 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering(a)redhat.com>
Date: Wed, 18 Apr 2012 11:15:57 +0200
Subject: [PATCH libguestfs] maint: fix doc typos
Fix typos spotted by http://github.com/lyda/misspell-check.
* configure.ac: As above.
* ocaml/examples/guestfs-ocaml.pod: Likewise.
* fish/guestfish.pod: Likewise.
---
configure.ac | 2 +-
fish/guestfish.pod | 6 +++---
ocaml/examples/guestfs-ocaml.pod | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/configure.ac b/configure.ac
index c62bf9a..eb5f363 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1254,7 +1254,7 @@ echo -n "gobject introspection ............... "
if test "x$HAVE_INTROSPECTION_TRUE" = "x"; then echo "yes"; else echo "no"; fi
echo
echo "If any optional component is configured 'no' when you expected 'yes'"
-echo "then you should check the preceeding messages."
+echo "then you should check the preceding messages."
echo
echo "Please report bugs back to the mailing list:"
echo "http://www.redhat.com/mailman/listinfo/libguestfs"
diff --git a/fish/guestfish.pod b/fish/guestfish.pod
index c0827c7..a45af00 100644
--- a/fish/guestfish.pod
+++ b/fish/guestfish.pod
@@ -698,7 +698,7 @@ the Unix L<chmod(1)> program):
Commands that return numbers usually print them in decimal, but
some commands print numbers in other radices (eg. C<umask> prints
-the mode in octal, preceeded by C<0>).
+the mode in octal, preceded by C<0>).
=head1 WILDCARDS AND GLOBBING
@@ -730,7 +730,7 @@ will perform a Cartesian product.
=head1 COMMENTS
Any line which starts with a I<#> character is treated as a comment
-and ignored. The I<#> can optionally be preceeded by whitespace,
+and ignored. The I<#> can optionally be preceded by whitespace,
but B<not> by a command. For example:
# this is a comment
@@ -904,7 +904,7 @@ some arbitrary end marker:
END
Any string of characters can be used instead of C<END>. The end
-marker must appear on a line of its own, without any preceeding or
+marker must appear on a line of its own, without any preceding or
following characters (not even spaces).
Note that the C<-E<lt>E<lt>> syntax only applies to parameters used to
diff --git a/ocaml/examples/guestfs-ocaml.pod b/ocaml/examples/guestfs-ocaml.pod
index 7d0c041..139997b 100644
--- a/ocaml/examples/guestfs-ocaml.pod
+++ b/ocaml/examples/guestfs-ocaml.pod
@@ -47,7 +47,7 @@ on the class C<Guestfs.guestfs>:
method set_verbose : bool -> unit
The object-oriented style is usually briefer, and the minor performance
-penalty isn't noticable in the general overhead of performing
+penalty isn't noticeable in the general overhead of performing
libguestfs functions.
=head2 CLOSING THE HANDLE
--
1.7.10.208.gb4267
12 years, 8 months
error: expected declaration specifiers or '...' before 'virDomainPtr'
by Thomas Jung
hi there
got a problem with the installation of libguestfs 1.16.19 on ubuntu....
./configure --disable-appliance --disable-daemon runs just fine, but make
crashes with
In file included from virt.c:38:0:
guestfs.h:2160:70: error: expected declaration specifiers or '...' before
'virDomainPtr'
make[3]: *** [libguestfs_la-virt.lo] Error 1
make[3]: Leaving directory `/home/projekt/libguestfs-1.16.19/src'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/home/projekt/libguestfs-1.16.19/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/projekt/libguestfs-1.16.19'
make: *** [all] Error 2
any idea?
Swoop
12 years, 8 months
[PATCH] Don't abort inspection if mdadm.conf ARRAY doesn't have a uuid
by Matthew Booth
---
src/inspect_fs_unix.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/inspect_fs_unix.c b/src/inspect_fs_unix.c
index 1ef4ca4..5695adc 100644
--- a/src/inspect_fs_unix.c
+++ b/src/inspect_fs_unix.c
@@ -1113,7 +1113,7 @@ map_md_devices(guestfs_h *g, Hash_table **map)
free(uuid_path);
if (!uuid) {
free(dev);
- goto error;
+ continue;
}
/* Parse the uuid into an md_uuid structure so we can look it up in the
--
1.7.10
12 years, 8 months
Re: [Libguestfs] [libvirt] [test-API 2/3] Add the better copyright statements in scripts
by Richard W.M. Jones
On Tue, Apr 17, 2012 at 07:22:48PM +0800, Osier Yang wrote:
> [ CC to Rich ]
>
> On 2012年04月17日 19:18, Osier Yang wrote:
> >On 2012年04月17日 19:13, Daniel P. Berrange wrote:
> >>On Tue, Apr 17, 2012 at 07:09:36PM +0800, Osier Yang wrote:
> >>>On 2012年04月17日 19:04, Daniel P. Berrange wrote:
> >>>>On Tue, Apr 17, 2012 at 06:59:24PM +0800, Osier Yang wrote:
> >>>>>The new copyright statements is:
> >>>>>
> >>>>><copyright>
> >>>>>Copyright (C) 2010-2012 Red Hat, Inc.
> >>>>>
> >>>>>libvirt-test-API 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 warranties of
> >>>>>TITLE, NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR
> >>>>>PURPOSE.
> >>>>>
> >>>>>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., 675 Mass Ave, Cambridge, MA 02139, USA.
> >>>>></copyright>
> >>>>
> >>>>I'm fairly sure that address is outdated - everywhere in libvirt
> >>>>code uses
> >>>>
> >>>>* You should have received a copy of the GNU Lesser General Public
> >>>>* License along with this library; if not, write to the Free Software
> >>>>* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
> >>>>02111-1307 USA
> >>>>
> >>>
> >>>Thanks for the reminding, will post a v2, then think we need to
> >>>update the address in libvirt codes too?
> >>
> >>Hmm, I wonder if we are better off just removing the address
> >>completely. There are no end of bug reports in Fedora reviews
> >>about outdated addresses and the FSF have moved locations
> >>multiple times. I see GNULIB now just writes:
> >>
> >>* You should have received a copy of the GNU Lesser General Public
> >>License
> >>* along with this program. If not, see<http://www.gnu.org/licenses/>.
> >>
> >
> >I found this when checking the GNU website mins ago. Yeah, it's better
> >, per they moves from time to time, ;-)
> >
>
> @Rich, I had to say: I copied the last 3 sentences (the address part)
> from libguestfs. Perhaps it needs the updating too.
They've moved again?!
We are currently using:
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301 USA
and went through a big process of fixing every file to use this
address a little while back.
commit 04ea1375c55aa67df4e7fc61dbb534111767f3b6
Author: Matthew Booth <mbooth(a)redhat.com>
Date: Tue Nov 8 14:27:49 2011 +0000
Update FSF address.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
12 years, 8 months
Notes on libguestfs with Ubuntu 12.04 (Precise)
by Richard W.M. Jones
Ubuntu are now supplying a libguestfs package (or to be more accurate,
they are just copying the Debian package) but it doesn't work out of the box.
There is a bug in apt which we worked around in febootstrap 3.14, but
the supplied version of febootstap is only 3.12. Hence you will get
errors like this during installation:
febootstrap: aptitude: error: no file was downloaded corresponding to package <some package name>
and you'll get the same error if you try to build from source.
The solution is to build febootstrap 3.14:
cd /tmp
sudo apt-get build-dep febootstrap
sudo apt-get install devscripts
apt-get source febootstrap
wget http://people.redhat.com/~rjones/febootstrap/files/febootstrap-3.14.tar.gz
tar zxf febootstrap-3.14.tar.gz
cd febootstrap-3.14
rm -rf debian
cp -a ../febootstrap-3.12/debian .
vi debian/changelog
# change the first line: 3.12 -> 3.14
debuild -i -uc -us -b
That will create an febootstrap 3.14 .deb file in /tmp which you can
install:
sudo dpkg -i ../febootstrap_3.14-1_amd64.deb
Then you can go ahead and use the libguestfs package:
sudo update-guestfs-appliance
or compile libguestfs from source.
There is another problem which you may hit, if you add a completely
blank disk to libguestfs (this also affects libguestfs-test-tool):
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/931371
https://bugzilla.kernel.org/show_bug.cgi?id=42778
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/
12 years, 8 months