From f5ae46dca79511cf2d4762ca4ef07b59bd647309 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 30 Nov 2012 12:32:30 +0000 Subject: inspection, virt-sysprep: Use /etc/hostname on F18+, RHEL7+ (RHBZ#881953, RHBZ#858696). --- src/inspect-fs-unix.c | 15 ++++++++------- sysprep/sysprep_operation_hostname.ml | 26 ++++++++++++++++---------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/inspect-fs-unix.c b/src/inspect-fs-unix.c index a48d1768..8d3e6b08 100644 --- a/src/inspect-fs-unix.c +++ b/src/inspect-fs-unix.c @@ -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) diff --git a/sysprep/sysprep_operation_hostname.ml b/sysprep/sysprep_operation_hostname.ml index a1dd15a8..33e3b0ae 100644 --- a/sysprep/sysprep_operation_hostname.ml +++ b/sysprep/sysprep_operation_hostname.ml @@ -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 = { -- cgit