[explorer/machine_type] Print top most machine layer as first line (fallback to physical)

This commit is contained in:
Dennis Camera 2021-07-31 19:29:41 +02:00
parent edcac70b2a
commit abc6d009b2

View file

@ -26,17 +26,19 @@
# VERB does not have a special meaning, it is just for better readability. # VERB does not have a special meaning, it is just for better readability.
# #
# e.g. # e.g.
# container
# container on lxc # container on lxc
# virtual by kvm-spapr # virtual by kvm-spapr
# #
# The third word of each line can be composed of different parts concatenated with a `-' # The third word of each line (except the first) can be composed of different
# (minus) character, with each component being a specification of the previous, # parts concatenated with a `-' (minus) character, with each component being
# e.g.: # a specification of the previous, e.g.:
# - lxc-libvirt (LXC container, managed by libvirt) # - lxc-libvirt (LXC container, managed by libvirt)
# - lpar-s390 / lpar-power (LPAR running on IBM S/390 or POWER, respectively) # - lpar-s390 / lpar-power (LPAR running on IBM S/390 or POWER, respectively)
# - xen-hvm / xen-pv (Xen HVM vs para-virtualization) # - xen-hvm / xen-pv (Xen HVM vs para-virtualization)
# #
# If this explorer cannot determine any information it will print nothing. # If this explorer cannot collect enough information about virtualization it
# will fall back to 'physical'.
# #
# Add /sbin and /usr/sbin to the path so we can find system # Add /sbin and /usr/sbin to the path so we can find system
@ -121,6 +123,10 @@ get_sysctl() {
is_command sysctl && sysctl -n "$1" 2>/dev/null is_command sysctl && sysctl -n "$1" 2>/dev/null
} }
detected_layer() {
test -n "${_toplayer:-}" || echo "${_toplayer:=${1:?}}"
}
# Check for container # Check for container
@ -895,6 +901,7 @@ for stage in \
pid_1 cgroup files os_specific pid_1 cgroup files os_specific
do do
ctengine=$(run_stage ct ${stage}) || continue ctengine=$(run_stage ct ${stage}) || continue
detected_layer 'container'
is_contained=true is_contained=true
if test -n "${ctengine}" if test -n "${ctengine}"
then then
@ -916,6 +923,7 @@ for stage in \
os_specific hyp_specific sys_hypervisor dt dmi cpuinfo arch_specific os_specific hyp_specific sys_hypervisor dt dmi cpuinfo arch_specific
do do
hypervisor=$(run_stage vm ${stage}) || continue hypervisor=$(run_stage vm ${stage}) || continue
detected_layer 'virtual machine'
is_virtual=true is_virtual=true
if test -n "${hypervisor}" if test -n "${hypervisor}"
then then
@ -929,3 +937,8 @@ then
# we are virtual. # we are virtual.
echo virtual echo virtual
fi fi
# Fallback
detected_layer physical