Commit 43b71c4f authored by glucas's avatar glucas

Add enhanced VPN management script.

parent 87ee91d8
#!/bin/bash
# Copyright (C) 2015-2018 Alsace Réseau Neutre
# Copyright (C) 2015-2017 Alsace Réseau Neutre
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -34,7 +34,7 @@ ipv6=
suite='stretch'
sshkey=
iso=
trapcmd=
show_usage() {
echo -e "\nError: $1\n" >&2
......@@ -67,8 +67,7 @@ while getopts "s:n:d:r:4:6:k:i:" opt; do
6) ipv6="$OPTARG" ;;
s) suite=$OPTARG ;;
k) sshkey="$OPTARG" ;;
i) iso="$OPTARG";;
esac
i) iso="$OPTARG";; esac
done
# check inputs
......@@ -93,7 +92,7 @@ gnt-cluster command --failure-only mkdir -p "$VMCONFDIR"
vnc='-H kvm:vnc_bind_address=127.0.0.1'
# Generate VNC password for VPS
if [[ "$name" =~ ^vps- ]]; then
if [[ "$name" =~ ^vps- ]] || [[ "$name" =~ ^vpsto- ]]; then
vncpass=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c 24)
VNCCONF="$VMCONFDIR/vncpwd.conf"
......@@ -126,12 +125,23 @@ set -e
# disable wipe for non-VPS
if ! [[ "$name" =~ ^vps- ]]; then
if ! [[ "$name" =~ ^vps- ]] && ! [[ "$name" =~ ^vpsto- ]] ; then
gnt-cluster modify --prealloc-wipe-disks no > /dev/null
trap "gnt-cluster modify --prealloc-wipe-disks yes > /dev/null" EXIT
trapcmd="gnt-cluster modify --prealloc-wipe-disks yes > /dev/null"
fi
# Change VG for storage VPS
if [[ "$name" =~ vpsto ]]; then
gnt-cluster modify --vg-name vg_vpsstockage -D drbd:metavg=vg_vpsstockage > /dev/null
trapcmd="gnt-cluster modify --vg-name vg0 -D drbd:metavg=vg0 > /dev/null"
fi
# Reset initial VG (SSD) if VPS or reset preallocation wipe if non-VPS
trap "${trapcmd}" EXIT
echo '### Installing instance'
if [ -n "$iso" ]; then
gnt-instance add -t drbd --no-wait-for-sync -s $((disk * 1024)) -B memory=${ram}MB -o debootstrap+"$suite" "${osparam[@]}" --no-install --net 0:ip=10.0.0.42 $vnc --no-start --no-name-check --no-ip-check "$name"
......@@ -174,7 +184,7 @@ if [ -n "$ip" ] && [ -z "$iso" ]; then
fi
if [[ "$name" =~ ^vps- ]]; then
if [[ "$name" =~ ^vps- ]] || [[ "$name" =~ ^vpsto- ]]; then
echo -e "\n### VM summary for subscriber:"
echo -en "\nInfos VPS ARN $name"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment