inspection, virt-sysprep: Use /etc/hostname on F18+, RHEL7+ (RHBZ#881953, RHBZ#858696).

This commit is contained in:
Richard W.M. Jones
2012-11-30 12:32:30 +00:00
parent fe4cdb2a47
commit f5ae46dca7
2 changed files with 24 additions and 17 deletions

View File

@@ -748,11 +748,11 @@ check_hostname_unix (guestfs_h *g, struct inspect_fs *fs)
switch (fs->type) {
case OS_TYPE_LINUX:
case OS_TYPE_HURD:
/* Red Hat-derived would be in /etc/sysconfig/network, and
* Debian-derived in the file /etc/hostname. Very old Debian and
* SUSE use /etc/HOSTNAME. It's best to just look for each of
* these files in turn, rather than try anything clever based on
* distro.
/* Red Hat-derived would be in /etc/sysconfig/network or
* /etc/hostname (RHEL 7+, F18+). Debian-derived in the file
* /etc/hostname. Very old Debian and SUSE use /etc/HOSTNAME.
* It's best to just look for each of these files in turn, rather
* than try anything clever based on distro.
*/
if (guestfs_is_file (g, "/etc/HOSTNAME")) {
fs->hostname = guestfs___first_line_of_file (g, "/etc/HOSTNAME");
@@ -803,8 +803,9 @@ check_hostname_unix (guestfs_h *g, struct inspect_fs *fs)
return 0;
}
/* Parse the hostname from /etc/sysconfig/network. This must be called
* from the inspect_with_augeas wrapper.
/* Parse the hostname from /etc/sysconfig/network. This must be
* called from the inspect_with_augeas wrapper. Note that F18+ and
* RHEL7+ use /etc/hostname just like Debian.
*/
static int
check_hostname_redhat (guestfs_h *g, struct inspect_fs *fs)

View File

@@ -29,12 +29,22 @@ let hostname = ref "localhost.localdomain"
let hostname_perform g root =
let typ = g#inspect_get_type root in
let distro = g#inspect_get_distro root in
match typ, distro with
| "linux", ("fedora"|"rhel"|"centos"|"scientificlinux"|"redhat-based") ->
(* Fedora 18 anaconda can create guests without
* /etc/sysconfig/network file. If this happens then we may need
* to create this file (RHBZ#858696).
let major_version = g#inspect_get_major_version root in
let update_etc_hostname () =
g#write "/etc/hostname" !hostname;
[ `Created_files ]
in
match typ, distro, major_version with
(* Fedora 18 (hence RHEL 7+) changed to using /etc/hostname
* (RHBZ#881953, RHBZ#858696).
*)
| "linux", "fedora", v when v >= 18 -> update_etc_hostname ()
| "linux", "rhel", v when v >= 7 -> update_etc_hostname ()
| "linux", ("debian"|"ubuntu"), _ -> update_etc_hostname ()
| "linux", ("fedora"|"rhel"|"centos"|"scientificlinux"|"redhat-based"), _ ->
let filename = "/etc/sysconfig/network" in
if g#is_file filename then (
(* Replace HOSTNAME=... entry. The code assumes it's a small,
@@ -54,14 +64,10 @@ let hostname_perform g root =
);
[ `Created_files ]
| "linux", ("opensuse"|"sles"|"suse-based") ->
| "linux", ("opensuse"|"sles"|"suse-based"), _ ->
g#write "/etc/HOSTNAME" !hostname;
[ `Created_files ]
| "linux", ("debian"|"ubuntu") ->
g#write "/etc/hostname" !hostname;
[ `Created_files ]
| _ -> []
let hostname_op = {