Add DNS params

This commit is contained in:
nemo 2019-09-09 14:28:22 +02:00
parent 9e4c3b2644
commit bf65a99ebf
3 changed files with 27 additions and 22 deletions

View file

@ -1,10 +1,17 @@
# URL of the API
URL="https://ipam.example.conf/api/${USER_IPAM}"
# Bridge used by VMs
VM_BRIDGE_DEV="vmbr99"
# IPv6 gateway for the VM
IPV6_GATEWAY="fe80::123:123:123:123"
# ID of the ranges, you can put multiple ranges per AFI
# If multiple DNS nameservers, seperate each of them vy a space
DNS_NAMESERVERS_IPV4='1.2.3.4 2.3.4.5'
DNS_NAMESERVERS_IPV6='1111:2222::3333 2222:3333::4444'
# ID of the ranges, you can put multiple ranges per AFI, these values will be use to check if the new VM_ID is already registered or not in IPAM
ID_RANGES_V4='123 234'
ID_RANGES_V6='345'
@ -12,11 +19,14 @@ ID_RANGES_V6='345'
ID_RANGE_V4_TO_CREATE_VM='123'
ID_RANGE_V6_TO_CREATE_VM='345'
# Set the limit for possible disk size (Giga)
VM_DISK_MIN=32
VM_DISK_MAX=64
# Set the limit for possible vCPU number
VM_CPU_MIN=1
VM_CPU_MAX=4
# Set the limit for possible RAM size (Mega)
VM_RAM_MIN=512
VM_RAM_MAX=2048

View file

@ -29,7 +29,7 @@ if [ $1 ]; then
usage
exit 1
else
# Verification of the presence of VM conf file
# Check the presence of VM conf file
if [ -f "$1" ]; then
VM_CONF_FILE=$1
. ${VM_CONF_FILE}
@ -348,14 +348,9 @@ echo "INFO : Get the FE80 IPv6 of the new VM..."
VM_MAC=$(grep net0 /etc/pve/qemu-server/${VM_ID}.conf | cut -d '=' -f 2 | cut -d ',' -f 1)
VM_FE80=$(ipv6calc --action prefixmac2ipv6 --in prefix+mac --out ipv6addr fe80:: $VM_MAC)
VM_BRIDGE_DEV="vmbr1"
# Define SSH host
SSH_HOST="root@${VM_FE80}%${VM_BRIDGE_DEV}"
echo "INFO : wait 2 minutes to be sure that ssh service is started"
sleep 180
# Create network configuration file for new VM
echo "INFO : Create network configuration file for new VM..."
echo "# This file describes the network interfaces available on your system
@ -373,11 +368,12 @@ allow-hotplug ens18
iface ens18 inet static
address ${VM_IPV4_NEW}/${VM_IPV4_NEW_SUBNET_MASK}
gateway ${VM_IPV4_NEW_SUBNET_GW}
dns-nameservers 89.234.186.5 89.234.186.4
dns-nameservers ${DNS_NAMESERVERS_IPV4}
iface ens18 inet6 static
address ${RANGE_IPV6_NEW_WITHOUT_MASK}1/${RANGE_IPV6_NEW_MASK}
gateway ${IPV6_GATEWAY}" > /tmp/interfaces_vm${VM_ID}
gateway ${IPV6_GATEWAY}
dns-nameservers ${DNS_NAMESERVERS_IPV6}" > /tmp/interfaces_vm${VM_ID}
# Replace network configuration file on new VM
echo "INFO : Replace network configuration file on new VM... (VM NETWORK CONF UPDATE)"
@ -405,12 +401,12 @@ if [ $? -ne 0 ]; then
fi
# Regenerate SSH host keys for the VM and restart SSHD
#echo "INFO : Regenerate SSH host keys for the VM and restart SSHD..."
#ssh ${SSH_OPT} ${SSH_HOST} "/bin/rm -v /etc/ssh/ssh_host_* && dpkg-reconfigure openssh-server && systemctl restart ssh" &> /dev/null
#if [ $? -ne 0 ]; then
# echo 'ERROR : problem during regenerate SSH host keys for the VM, please finish manually the deploy OR delete VM and IPAM information'
# exit 1
#fi
echo "INFO : Regenerate SSH host keys for the VM and restart SSHD..."
ssh ${SSH_OPT} ${SSH_HOST} "/bin/rm -v /etc/ssh/ssh_host_* && dpkg-reconfigure openssh-server && systemctl restart ssh" &> /dev/null
if [ $? -ne 0 ]; then
echo 'ERROR : problem during regenerate SSH host keys for the VM, please finish manually the deploy OR delete VM and IPAM information'
exit 1
fi
# Get FingerPrint
echo "INFO : Get SSH FingerPrint of the new VM..."
@ -439,7 +435,6 @@ if [ "${VM_DISK_EXTEND}" -ne 0 ]; then
# Wait for system reboot
sleep 20
echo "INFO : wait 3 minutes to be sure that ssh service is started"
sleep 180
echo "INFO : Create new PV... (pvcreate /dev/vda3)"
@ -455,7 +450,7 @@ sleep 180
if [ $? -ne 0 ]; then
echo 'ERROR : problem during get the name of the default VG'
exit 1
fi
fi
echo "INFO : Add new PV to VG ${DEFAULT_VG}... (vgextend ${DEFAULT_VG} /dev/vda3)"
@ -468,12 +463,12 @@ sleep 180
echo "INFO : Resize LV on disk... (RESIZE VM LV)"
DEFAULT_LV_ROOT=$(find /dev/mapper -name '*root*')
DEFAULT_LV_ROOT=$(find /dev/mapper -name '*root*')
if [ $? -ne 0 ]; then
echo 'ERROR : problem during get the name of the default root LV'
exit 1
fi
fi
ssh ${SSH_OPT} ${SSH_HOST} "lvextend -l +100%FREE ${DEFAULT_LV_ROOT}" &> /dev/null

View file

@ -8,14 +8,14 @@ USER_MAIL="user@example.net"
# WARNING, if this value is incorrect, nobody could connect the deployed VM...
USER_SSH_PUB_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCZWqqdey/B95uiSAXJUFo56UHCsk5b3AxRw+SfnuOGyP15tGwOT4AhCyx2XXcxAlnuTNYhONfHg82wVN581suF3w2wnWkJdYqlwmCB20CQENuFXIIcw1ZYTyVcLfdSNhMAO1VuvkvyTEDac2Mh9epMe3lcgYpM/+YZiRfuInDYzixOJOuSz+NFMCm9XHhQDZ3CxZSMjKCV3+yW6vcQ/QfWs749C1JwdTiEMSrwpMm+IwtVnO5Tv4EA/jUs6a+CVo4GtfwIVWH5CGtrc4SYfbfFwoITS3UKDUGgx1YKU81bXrzldlofPxAAAAAAAAAA6n6orTu81pKRiok3oN/Vhuhb john@host"
# Disk size in GB (ex : 32)
# Disk size in Giga (ex : 32)
VM_DISK=32
# vCPU number (ex : 1)
VM_CPU=1
# RAM size in MB (ex : 512)
# RAM size in Mega (ex : 512)
VM_RAM=512
# VM Proxmox ID of template (ex : 123)
# VM Proxmox ID of template to use to create the new VM (ex : 123)
VM_TEMPLATE_ID=123