1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-26 00:38:10 +00:00

Add option --without-kvm

Some cloud providers (example, AWS EC2 for non-metal instances) do not
support nested virtualization, as well as some hypervisors (example,
VirtualBox prior to 6.x, Hyper-V on AMD). Option `--without-kvm` can
be used to disable hardware acceleration in these scenarios. Otherwise,
user will receive error when trying to start Qemu-based devices.

Commit also: replace `enable_kvm` and `require_kvm` with newer config
options (`enable_hardware_acceleration` and
`require_hardware_acceleration`); and do some code refactors.

One can argue that, instead of prividing option `--without-kvm`, we
should check if system supports KVM and enable/disable hardware
acceleration accordingly. However, there is the case when the
hypervisor supports nested virtualization, but feature is just disabled.
The chosen approach for this case is to keep KVM enabled and let user
known (user will eventually receive an error) so user can fix it.
Otherwise, user might never know and suffer from performance
degradation.
This commit is contained in:
Rarylson Freitas 2021-08-01 16:03:48 -03:00
parent d2534d6fa0
commit d926a713b9

View File

@ -23,9 +23,10 @@
function help { function help {
echo "Usage:" >&2 echo "Usage:" >&2
echo "--with-openvpn: Install Open VPN" >&2 echo "--with-openvpn: Install OpenVPN" >&2
echo "--with-iou: Install IOU" >&2 echo "--with-iou: Install IOU" >&2
echo "--with-i386-repository: Add the i386 repositories required by IOU if they are not already available on the system. Warning: this will replace your source.list in order to use the official Ubuntu mirror" >&2 echo "--with-i386-repository: Add the i386 repositories required by IOU if they are not already available on the system. Warning: this will replace your source.list in order to use the official Ubuntu mirror" >&2
echo "--without-kvm: Disable KVM, required if system do not support it (limitation in some hypervisors and cloud providers). Warning: only disable KVM if strictly necessary as this will degrade performance" >&2
echo "--unstable: Use the GNS3 unstable repository" echo "--unstable: Use the GNS3 unstable repository"
echo "--help: This help" >&2 echo "--help: This help" >&2
} }
@ -45,9 +46,10 @@ fi
USE_VPN=0 USE_VPN=0
USE_IOU=0 USE_IOU=0
I386_REPO=0 I386_REPO=0
DISABLE_KVM=0
UNSTABLE=0 UNSTABLE=0
TEMP=`getopt -o h --long with-openvpn,with-iou,with-i386-repository,unstable,help -n 'gns3-remote-install.sh' -- "$@"` TEMP=`getopt -o h --long with-openvpn,with-iou,with-i386-repository,without-kvm,unstable,help -n 'gns3-remote-install.sh' -- "$@"`
if [ $? != 0 ] if [ $? != 0 ]
then then
help help
@ -70,6 +72,10 @@ while true ; do
I386_REPO=1 I386_REPO=1
shift shift
;; ;;
--without-kvm)
DISABLE_KVM=1
shift
;;
--unstable) --unstable)
UNSTABLE=1 UNSTABLE=1
shift shift
@ -147,7 +153,7 @@ apt-get update
log "Upgrade packages" log "Upgrade packages"
apt-get upgrade --yes --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" apt-get upgrade --yes --force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"
log " Install GNS3 packages" log "Install GNS3 packages"
apt-get install -y gns3-server apt-get install -y gns3-server
log "Create user GNS3 with /opt/gns3 as home directory" log "Create user GNS3 with /opt/gns3 as home directory"
@ -171,7 +177,7 @@ usermod -aG docker gns3
if [ $USE_IOU == 1 ] if [ $USE_IOU == 1 ]
then then
log "IOU setup" log "Setup IOU"
dpkg --add-architecture i386 dpkg --add-architecture i386
apt-get update apt-get update
@ -204,10 +210,16 @@ configs_path = /opt/gns3/configs
report_errors = True report_errors = True
[Qemu] [Qemu]
enable_kvm = True enable_hardware_acceleration = True
require_kvm = True require_hardware_acceleration = True
EOFC EOFC
if [ $DISABLE_KVM == 1 ]
then
log "Disable KVM support"
sed -i 's/hardware_acceleration = True/hardware_acceleration = False/g' /etc/gns3/gns3_server.conf
fi
chown -R gns3:gns3 /etc/gns3 chown -R gns3:gns3 /etc/gns3
chmod -R 700 /etc/gns3 chmod -R 700 /etc/gns3
@ -286,20 +298,11 @@ if [ $USE_VPN == 1 ]
then then
log "Setup VPN" log "Setup VPN"
cat <<EOFSERVER > /etc/gns3/gns3_server.conf log "Change GNS3 to listen on VPN interface"
[Server]
host = 172.16.253.1
port = 3080
images_path = /opt/gns3/images
projects_path = /opt/gns3/projects
report_errors = True
[Qemu] sed -i 's/host = 0.0.0.0/host = 172.16.253.1/' /etc/gns3/gns3_server.conf
enable_kvm = True
require_kvm = True
EOFSERVER
log "Install packages for Open VPN" log "Install packages for OpenVPN"
apt-get install -y \ apt-get install -y \
openvpn \ openvpn \
@ -329,7 +332,6 @@ echo "And remove this file with rm /etc/update-motd.d/70-openvpn"
EOFMOTD EOFMOTD
chmod 755 /etc/update-motd.d/70-openvpn chmod 755 /etc/update-motd.d/70-openvpn
mkdir -p /etc/openvpn/ mkdir -p /etc/openvpn/
[ -d /dev/net ] || mkdir -p /dev/net [ -d /dev/net ] || mkdir -p /dev/net
@ -385,7 +387,7 @@ status openvpn-status-1194.log
log-append /var/log/openvpn-udp1194.log log-append /var/log/openvpn-udp1194.log
EOFUDP EOFUDP
echo "Setup HTTP server for serving client certificate" log "Setup HTTP server for serving client certificate"
mkdir -p /usr/share/nginx/openvpn/$UUID mkdir -p /usr/share/nginx/openvpn/$UUID
cp /root/client.ovpn /usr/share/nginx/openvpn/$UUID/$HOSTNAME.ovpn cp /root/client.ovpn /usr/share/nginx/openvpn/$UUID/$HOSTNAME.ovpn
touch /usr/share/nginx/openvpn/$UUID/index.html touch /usr/share/nginx/openvpn/$UUID/index.html
@ -402,11 +404,13 @@ EOFNGINX
service nginx stop service nginx stop
service nginx start service nginx start
log "Restart OpenVPN" log "Restart OpenVPN and GNS3"
set +e set +e
service openvpn stop service openvpn stop
service openvpn start service openvpn start
service gns3 stop
service gns3 start
log "Download http://$MY_IP_ADDR:8003/$UUID/$HOSTNAME.ovpn to setup your OpenVPN client after rebooting the server" log "Download http://$MY_IP_ADDR:8003/$UUID/$HOSTNAME.ovpn to setup your OpenVPN client after rebooting the server"