mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2026-08-28 20:06:05 +00:00
feat: Show additional guest info in debug mode (#1216)
This commit is contained in:
+81
-8
@@ -1228,22 +1228,93 @@ configureMAC() {
|
||||
return 0
|
||||
}
|
||||
|
||||
printNetworkDebug() {
|
||||
formatAddress() {
|
||||
|
||||
local line=""
|
||||
local ip="${1:-}"
|
||||
local prefix="${2:-}"
|
||||
local result="$ip"
|
||||
|
||||
[ -z "$result" ] && return 1
|
||||
|
||||
if [ -n "$prefix" ] && [[ "$prefix" != "24" ]]; then
|
||||
result+="/$prefix"
|
||||
fi
|
||||
|
||||
echo "$result"
|
||||
return 0
|
||||
}
|
||||
|
||||
showHostInfo() {
|
||||
|
||||
local mtu=""
|
||||
local host=""
|
||||
local nameservers=""
|
||||
local uplink=""
|
||||
|
||||
enabled "$DEBUG" || return 0
|
||||
|
||||
host=$(containerID)
|
||||
local line="Host: $host"
|
||||
|
||||
local iface="$DEV"
|
||||
if [ -n "$NIC" ] && [[ "${NIC,,}" != "veth" ]]; then
|
||||
iface+="/$NIC"
|
||||
fi
|
||||
|
||||
[ -z "$iface" ] && iface="(none)"
|
||||
line+=" Interface: $iface"
|
||||
|
||||
uplink=$(formatAddress "$UPLINK" "$PREFIX" || true)
|
||||
[ -z "$uplink" ] && uplink="(none)"
|
||||
line+=" IP: $uplink"
|
||||
|
||||
local gateway="${GATEWAY:-}"
|
||||
[ -z "$gateway" ] && gateway="(none)"
|
||||
line+=" Gateway: $gateway"
|
||||
|
||||
mtu=$(getMTU "$DEV")
|
||||
if [ -n "$mtu" ] && [[ "$mtu" != "0" && "$mtu" != "1500" ]]; then
|
||||
line+=" MTU: $mtu"
|
||||
fi
|
||||
|
||||
line="Host: $host IP: $UPLINK Gateway: $GATEWAY Interface: $DEV MAC: $MAC MTU: $MTU Mask: $MASK/$PREFIX"
|
||||
info "$line"
|
||||
return 0
|
||||
}
|
||||
|
||||
if [ -f /etc/resolv.conf ]; then
|
||||
nameservers=$(grep '^nameserver ' /etc/resolv.conf | sed 's/^nameserver //' | paste -sd ',' | sed 's/,/, /g')
|
||||
[ -n "$nameservers" ] && info "Nameservers: $nameservers"
|
||||
showGuestInfo() {
|
||||
|
||||
local ip="${IP:-}"
|
||||
local nameservers=""
|
||||
|
||||
enabled "$DEBUG" || return 0
|
||||
|
||||
local mode="${NETWORK,,}"
|
||||
isNAT && mode="NAT"
|
||||
[ -z "$mode" ] && mode="(none)"
|
||||
local line="Network mode: $mode"
|
||||
|
||||
[ -n "$ip" ] && ip=$(formatAddress "$ip" "$PREFIX" || true)
|
||||
[ -z "$ip" ] && ip="DHCP"
|
||||
line+=" Guest: $ip"
|
||||
|
||||
[ -n "$MAC" ] && line+=" ($MAC)"
|
||||
|
||||
local count="0"
|
||||
local file="/etc/resolv.dnsmasq"
|
||||
[ ! -f "$file" ] && file="/etc/resolv.conf"
|
||||
|
||||
if [ -f "$file" ]; then
|
||||
count=$(grep -c '^nameserver ' "$file" || true)
|
||||
nameservers=$(grep '^nameserver ' "$file" | sed 's/^nameserver //' | paste -sd ',' | sed 's/,/, /g')
|
||||
fi
|
||||
|
||||
[ -z "$nameservers" ] && nameservers="(none)"
|
||||
|
||||
if (( count <= 1 )); then
|
||||
line+=" Nameserver: $nameservers"
|
||||
info "$line"
|
||||
else
|
||||
info "$line"
|
||||
info "Nameservers: $nameservers"
|
||||
fi
|
||||
|
||||
echo
|
||||
@@ -1266,7 +1337,7 @@ prepareNetwork() {
|
||||
configureMTU
|
||||
configureMAC
|
||||
|
||||
printNetworkDebug
|
||||
showHostInfo
|
||||
|
||||
return 0
|
||||
}
|
||||
@@ -1363,6 +1434,8 @@ else
|
||||
|
||||
fi
|
||||
|
||||
showGuestInfo
|
||||
|
||||
NET_OPTS+=" -device $ADAPTER,id=net0,netdev=hostnet0,romfile=,mac=$MAC"
|
||||
|
||||
if [[ "$GUEST_MTU" != "0" && "$GUEST_MTU" != "1500" ]]; then
|
||||
|
||||
Reference in New Issue
Block a user