mirror of
https://github.com/vdsm/virtual-dsm.git
synced 2025-06-08 01:18:32 +08:00
Remove vlan code
Remove vlan code
This commit is contained in:
commit
daad343eec
30
run/check.sh
30
run/check.sh
@ -3,19 +3,16 @@ set -u
|
|||||||
|
|
||||||
[ ! -f "/run/qemu.pid" ] && echo "QEMU not running yet.." && exit 0
|
[ ! -f "/run/qemu.pid" ] && echo "QEMU not running yet.." && exit 0
|
||||||
|
|
||||||
# Retrieve IP from guest for Docker healthcheck
|
# Retrieve IP from guest VM for Docker healthcheck
|
||||||
RESPONSE=$(curl -s -m 6 -S http://127.0.0.1:2210/read?command=10 2>&1)
|
RESPONSE=$(curl -s -m 6 -S http://127.0.0.1:2210/read?command=10 2>&1)
|
||||||
|
|
||||||
if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then
|
if [[ ! "${RESPONSE}" =~ "\"success\"" ]] ; then
|
||||||
echo "Failed to connect to guest: $RESPONSE"
|
echo "Failed to connect to guest: $RESPONSE" && exit 1
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Retrieve the HTTP port number
|
# Retrieve the HTTP port number
|
||||||
|
|
||||||
if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then
|
if [[ ! "${RESPONSE}" =~ "\"http_port\"" ]] ; then
|
||||||
echo "Failed to parse response from guest: $RESPONSE"
|
echo "Failed to parse response from guest: $RESPONSE" && exit 1
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rest=${RESPONSE#*http_port}
|
rest=${RESPONSE#*http_port}
|
||||||
@ -23,16 +20,11 @@ rest=${rest#*:}
|
|||||||
rest=${rest%%,*}
|
rest=${rest%%,*}
|
||||||
PORT=${rest%%\"*}
|
PORT=${rest%%\"*}
|
||||||
|
|
||||||
if [ -z "${PORT}" ]; then
|
[ -z "${PORT}" ] && echo "Guest has not set a portnumber yet.." && exit 1
|
||||||
echo "Guest has not set a portnumber yet.."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Retrieve the IP address
|
# Retrieve the IP address
|
||||||
|
|
||||||
if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then
|
if [[ ! "${RESPONSE}" =~ "eth0" ]] ; then
|
||||||
echo "Failed to parse response from guest: $RESPONSE"
|
echo "Failed to parse response from guest: $RESPONSE" && exit 1
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rest=${RESPONSE#*eth0}
|
rest=${RESPONSE#*eth0}
|
||||||
@ -41,15 +33,17 @@ rest=${rest#*:}
|
|||||||
rest=${rest#*\"}
|
rest=${rest#*\"}
|
||||||
IP=${rest%%\"*}
|
IP=${rest%%\"*}
|
||||||
|
|
||||||
if [ -z "${IP}" ]; then
|
[ -z "${IP}" ] && echo "Guest has not received an IP yet.." && exit 1
|
||||||
echo "Guest has not received an IP yet.."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! curl -m 3 -ILfSs "http://${IP}:${PORT}/" > /dev/null; then
|
if ! curl -m 3 -ILfSs "http://${IP}:${PORT}/" > /dev/null; then
|
||||||
echo "Failed to reach ${IP}:${PORT}"
|
echo "Failed to reach ${IP}:${PORT}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Healthcheck OK ($IP)"
|
if [[ "$IP" == "20.20"* ]]; then
|
||||||
|
echo "Healthcheck OK"
|
||||||
|
else
|
||||||
|
echo "Healthcheck OK ( $IP )"
|
||||||
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -3,7 +3,7 @@ set -Eeuo pipefail
|
|||||||
|
|
||||||
# Docker environment variables
|
# Docker environment variables
|
||||||
|
|
||||||
: ${DISK_IO:='native'} # I/O Mode, can be set to 'native', 'threads' or 'io_turing'
|
: ${DISK_IO:='native'} # I/O Mode, can be set to 'native', 'threads' or 'io_turing'
|
||||||
: ${DISK_CACHE:='none'} # Caching mode, can be set to 'writeback' for better performance
|
: ${DISK_CACHE:='none'} # Caching mode, can be set to 'writeback' for better performance
|
||||||
: ${DISK_DISCARD:='on'} # Controls whether unmap (TRIM) commands are passed to the host.
|
: ${DISK_DISCARD:='on'} # Controls whether unmap (TRIM) commands are passed to the host.
|
||||||
: ${DISK_ROTATION:='1'} # Rotation rate, set to 1 for SSD storage and increase for HDD
|
: ${DISK_ROTATION:='1'} # Rotation rate, set to 1 for SSD storage and increase for HDD
|
||||||
|
@ -22,49 +22,23 @@ set -Eeuo pipefail
|
|||||||
|
|
||||||
configureDHCP() {
|
configureDHCP() {
|
||||||
|
|
||||||
VM_NET_VLAN="${VM_NET_TAP}_vlan"
|
|
||||||
GATEWAY=$(ip r | grep default | awk '{print $3}')
|
|
||||||
NETWORK=$(ip -o route | grep "${VM_NET_DEV}" | grep -v default | awk '{print $1}')
|
|
||||||
IP=$(ip address show dev "${VM_NET_DEV}" | grep inet | awk '/inet / { print $2 }' | cut -f1 -d/)
|
|
||||||
|
|
||||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
|
||||||
|
|
||||||
# Create a macvlan network to allow for communication between the host and the VM guest
|
|
||||||
{ ip link add link "${VM_NET_DEV}" "${VM_NET_VLAN}" type macvlan mode bridge ; rc=$?; } || :
|
|
||||||
|
|
||||||
if (( rc != 0 )); then
|
|
||||||
error "Cannot create macvlan interface. Please make sure the network type is 'macvlan' and not 'ipvlan',"
|
|
||||||
error "and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 15
|
|
||||||
fi
|
|
||||||
|
|
||||||
ip address add "${IP}" dev "${VM_NET_VLAN}"
|
|
||||||
ip link set dev "${VM_NET_VLAN}" up
|
|
||||||
|
|
||||||
ip route flush dev "${VM_NET_VLAN}"
|
|
||||||
ip route del "${NETWORK}" dev "${VM_NET_DEV}"
|
|
||||||
ip route add "${NETWORK}" dev "${VM_NET_VLAN}" metric 0
|
|
||||||
|
|
||||||
# Create a macvtap network for the VM guest
|
# Create a macvtap network for the VM guest
|
||||||
{ ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } || :
|
|
||||||
|
|
||||||
|
{ ip link add link "${VM_NET_DEV}" name "${VM_NET_TAP}" address "${VM_NET_MAC}" type macvtap mode bridge ; rc=$?; } || :
|
||||||
|
|
||||||
if (( rc != 0 )); then
|
if (( rc != 0 )); then
|
||||||
error "Capability NET_ADMIN has not been set most likely. Please add the "
|
error "Cannot create macvtap interface. Please make sure the network type is 'macvlan' and not 'ipvlan',"
|
||||||
error "following docker setting to your container: --cap-add NET_ADMIN" && exit 16
|
error "and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 16
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ip link set "${VM_NET_TAP}" up
|
ip link set "${VM_NET_TAP}" up
|
||||||
|
|
||||||
{ set +x; } 2>/dev/null
|
|
||||||
|
|
||||||
TAP_NR=$(</sys/class/net/"${VM_NET_TAP}"/ifindex)
|
TAP_NR=$(</sys/class/net/"${VM_NET_TAP}"/ifindex)
|
||||||
TAP_PATH="/dev/tap${TAP_NR}"
|
TAP_PATH="/dev/tap${TAP_NR}"
|
||||||
|
|
||||||
# Create dev file (there is no udev in container: need to be done manually)
|
# Create dev file (there is no udev in container: need to be done manually)
|
||||||
IFS=: read -r MAJOR MINOR < <(cat /sys/devices/virtual/net/"${VM_NET_TAP}"/tap*/dev)
|
IFS=: read -r MAJOR MINOR < <(cat /sys/devices/virtual/net/"${VM_NET_TAP}"/tap*/dev)
|
||||||
|
(( MAJOR < 1)) && error "Cannot find: sys/devices/virtual/net/${VM_NET_TAP}" && exit 18
|
||||||
if (( MAJOR < 1)); then
|
|
||||||
error "Cannot find: sys/devices/virtual/net/${VM_NET_TAP}" && exit 18
|
|
||||||
fi
|
|
||||||
|
|
||||||
[[ ! -e "${TAP_PATH}" ]] && [[ -e "/dev0/${TAP_PATH##*/}" ]] && ln -s "/dev0/${TAP_PATH##*/}" "${TAP_PATH}"
|
[[ ! -e "${TAP_PATH}" ]] && [[ -e "/dev0/${TAP_PATH##*/}" ]] && ln -s "/dev0/${TAP_PATH##*/}" "${TAP_PATH}"
|
||||||
|
|
||||||
@ -92,10 +66,11 @@ configureDHCP() {
|
|||||||
|
|
||||||
configureNAT () {
|
configureNAT () {
|
||||||
|
|
||||||
|
# Create a bridge with a static IP for the VM guest
|
||||||
|
|
||||||
VM_NET_IP='20.20.20.21'
|
VM_NET_IP='20.20.20.21'
|
||||||
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
[[ "${DEBUG}" == [Yy1]* ]] && set -x
|
||||||
|
|
||||||
# Create bridge with static IP for the VM guest
|
|
||||||
{ ip link add dev dockerbridge type bridge ; rc=$?; } || :
|
{ ip link add dev dockerbridge type bridge ; rc=$?; } || :
|
||||||
|
|
||||||
if (( rc != 0 )); then
|
if (( rc != 0 )); then
|
||||||
@ -178,6 +153,8 @@ configureNAT () {
|
|||||||
$DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}
|
$DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}
|
||||||
|
|
||||||
{ set +x; } 2>/dev/null
|
{ set +x; } 2>/dev/null
|
||||||
|
|
||||||
|
[[ "${DEBUG}" == [Yy1]* ]] && echo
|
||||||
}
|
}
|
||||||
|
|
||||||
# ######################################
|
# ######################################
|
||||||
@ -236,6 +213,4 @@ fi
|
|||||||
|
|
||||||
NET_OPTS="${NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0"
|
NET_OPTS="${NET_OPTS} -device virtio-net-pci,romfile=,netdev=hostnet0,mac=${VM_NET_MAC},id=net0"
|
||||||
|
|
||||||
[[ "${DEBUG}" == [Yy1]* ]] && echo && info "Finished network setup.." && echo
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
@ -78,7 +78,7 @@ _graceful_shutdown() {
|
|||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
echo && info "Quitting..."
|
echo && echo "❯ Quitting..."
|
||||||
echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" >/dev/null 2>&1 || true
|
echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" >/dev/null 2>&1 || true
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -10,11 +10,11 @@ set -Eeuo pipefail
|
|||||||
: ${DISK_SIZE:='16G'} # Initial data disk size
|
: ${DISK_SIZE:='16G'} # Initial data disk size
|
||||||
: ${RAM_SIZE:='512M'} # Maximum RAM amount
|
: ${RAM_SIZE:='512M'} # Maximum RAM amount
|
||||||
|
|
||||||
|
echo "❯ Starting Virtual DSM for Docker v${VERSION}..."
|
||||||
|
|
||||||
info () { echo -e "\E[1;34m❯ \E[1;36m$1\E[0m" ; }
|
info () { echo -e "\E[1;34m❯ \E[1;36m$1\E[0m" ; }
|
||||||
error () { echo -e >&2 "\E[1;31m❯ ERROR: $1\E[0m" ; }
|
error () { echo -e >&2 "\E[1;31m❯ ERROR: $1\E[0m" ; }
|
||||||
|
trap 'error "Status $? while: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR
|
||||||
echo "❯ Starting Virtual DSM for Docker v${VERSION}..."
|
|
||||||
trap 'error "Error status $? for: ${BASH_COMMAND} (line $LINENO/$BASH_LINENO)"' ERR
|
|
||||||
|
|
||||||
[ ! -f "/run/run.sh" ] && error "Script must run inside Docker container!" && exit 11
|
[ ! -f "/run/run.sh" ] && error "Script must run inside Docker container!" && exit 11
|
||||||
[ "$(id -u)" -ne "0" ] && error "Script must be executed with root privileges." && exit 12
|
[ "$(id -u)" -ne "0" ] && error "Script must be executed with root privileges." && exit 12
|
||||||
@ -61,7 +61,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "${KVM_ERR}" ]; then
|
if [ -n "${KVM_ERR}" ]; then
|
||||||
error "KVM acceleration not detected ${KVM_ERR}, please enable it."
|
error "KVM acceleration not detected ${KVM_ERR}, see the FAQ about this."
|
||||||
[[ "${DEBUG}" == [Yy1]* ]] && exit 88
|
[[ "${DEBUG}" == [Yy1]* ]] && exit 88
|
||||||
else
|
else
|
||||||
KVM_OPTS=",accel=kvm -enable-kvm -cpu host"
|
KVM_OPTS=",accel=kvm -enable-kvm -cpu host"
|
||||||
|
@ -13,7 +13,7 @@ trap 'stop' EXIT SIGINT SIGTERM SIGHUP
|
|||||||
|
|
||||||
html()
|
html()
|
||||||
{
|
{
|
||||||
local h="<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE>"
|
local h="<!DOCTYPE html><HTML><HEAD><TITLE>VirtualDSM</TITLE>"
|
||||||
h="${h} <STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,"
|
h="${h} <STYLE>body { color: white; background-color: #125bdb; font-family: Verdana,"
|
||||||
h="${h} Arial,sans-serif; } a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD>"
|
h="${h} Arial,sans-serif; } a, a:hover, a:active, a:visited { color: white; }</STYLE></HEAD>"
|
||||||
h="${h}<BODY><BR><BR><H1><CENTER>$1</CENTER></H1></BODY></HTML>"
|
h="${h}<BODY><BR><BR><H1><CENTER>$1</CENTER></H1></BODY></HTML>"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user