############################# ON ERL3 ############################# # First SSH to the ELR3 then edit the configuration configure # drops you into the configuration terminal # Set the boot file. set service dhcp-server shared-network-name LAN1 subnet 172.16.24.0/22 bootfile-name pxelinux.0 # Set the boot server. set service dhcp-server shared-network-name LAN1 subnet 172.16.24.0/22 bootfile-server 172.16.24.90 # Set the TFTP server to the same as the bootfile-server (assuming they're the same in your case) set service dhcp-server shared-network-name LAN1 subnet 172.16.24.0/22 tftp-server-name 172.16.24.90 # Now commit the changes and save commit save # Exit the configuration terminal exit # Log out of the ERL3 exit ############################# ON ERL3 ############################# ############################# ON PXE SERVER ############################# set -eouv export tftpboot_dir="/var/lib/tftpboot" export tftp_server="172.16.24.90" export tftp_ssh_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvCFVPmVN37Ti2ypHal3k23rSi3/FMhSGoHruyOSRCEobnWl/y86QA8D8I2GgwWi4z1qNv62KQyYGLDW6gHoBdx+X/jktu6DbyejY3h55T3fxo0gUPkQnBVGvg6KmtHNGMLzv+GExMuYnp2hSJ5ATgvh2edlYEqMIdAnMazecQ3Ia86qPiYcuB75V7t65NsDa5Io1iIiqLOaHXH//MXXXlfKr+RGnvv9VuhTy+dErYPa1Bl/mPvlist7zw860Wb3aQyFTObomIPbJIojpw/AKXKT4lyDRmdsqj8qKcCEIXW9zgFMUqbdF+lBtmOI05FU9csVrMTDrsz+jIQSIYbcGX cloudnull@Kevins-MacBook-Pro.local" export image_url="http://releases.ubuntu.com/16.04.2/ubuntu-16.04.2-server-amd64.iso" export image_name="$(basename ${image_url})" export image_short_name="$(basename -s .iso ${image_name})" # Web server setup apt install -y tftpd-hpa inetutils-inetd nginx p7zip-full p7zip-rar cat > /etc/nginx/sites-enabled/default < /etc/default/tftpd-hpa < /etc/inetd.conf < ${tftpboot_dir}/pxelinux.cfg/default < ${tftpboot_dir}/boot-screens/menu.cfg < "${tftpboot_dir}/pxelinux.cfg/01-52-54-00-bd-80-$(printf "%02d" ${count})" < ${tftpboot_dir}/preseed/ubuntu-16.04-vm-preseed.cfg <> /target/root/.ssh/authorized_keys; \ in-target bash -c "wget http://${tftp_server}/networking/\$(hostname)-bridges.cfg -O /etc/network/interfaces.d/vm-bridges.cfg"; \ in-target bash -c "wget http://${tftp_server}/networking/basic-interface.cfg -O /etc/network/interfaces" # Finish # Reboot after the install is finished. finish-install finish-install/reboot_in_progress note EOF cat > ${tftpboot_dir}/preseed/ubuntu-16.04-mnaio-preseed.cfg <> /target/root/.ssh/authorized_keys; \ in-target bash -c "wget http://${tftp_server}/networking/mnaio-bridges.cfg -O /etc/network/interfaces.d/mnaio-bridges.cfg"; \ in-target bash -c "wget http://${tftp_server}/networking/basic-interface.cfg -O /etc/network/interfaces" # Finish # Reboot after the install is finished. finish-install finish-install/reboot_in_progress note EOF cat > /var/www/pxe/networking/vm-bridges.cfg < /var/www/pxe/networking/mnaio-bridges.cfg < /var/www/pxe/networking/basic-interface.cfg < /var/www/pxe/networking/${VM_NAME}-bridges.cfg count=$((count + 1)) done # Fix perms if needed find "${tftpboot_dir}" -type d -exec chmod 0755 {} \; find "${tftpboot_dir}" -type f -exec chmod 0644 {} \; ############################# ON PXE SERVER ############################# ############################# ON BOOTED VM HOST ############################# # on the mnaio host this is used to setup the libvirt network default configs mkdir -p /opt/mnaio/templates cat > /opt/mnaio/templates/libvirt-network-template.xml < __NETWORK__ EOF # Remove the original virsh network, we will not need this, then create the integration bridges mkdir -p /opt/mnaio/scripts cat > /opt/mnaio/scripts/libvirt-networking.sh < /etc/libvirt/qemu/networks/\${network}.xml virsh net-define --file /etc/libvirt/qemu/networks/\${network}.xml virsh net-create --file /etc/libvirt/qemu/networks/\${network}.xml virsh net-autostart \${network} fi done EOF # Create the volume group vg01 on our space disk vgcreate vg01 /dev/sdc1 # Create a storage pool on our volume group so that VMs can use it virsh pool-create-as vg01 logical virsh pool-dumpxml vg01 > /etc/libvirt/storage/vg01.xml virsh pool-define /etc/libvirt/storage/vg01.xml virsh pool-autostart vg01 ############################# ON BOOTED VM HOST ############################# ############################# CREATE VM ############################# count=1 for i in infra1 infra2 infra3 compute1 swift1 cinder1; do VM_NAME="${i}" VM_SIZE=$((${#VM_NAME} * 16)) echo y | lvcreate -n ${VM_NAME} -L ${VM_SIZE}G vg01 sed "s|__name__|${VM_NAME}|g" /opt/mnaio/templates/vm.xml > /etc/libvirt/qemu/${VM_NAME}.xml sed -i "s|__mac__|$(printf "%02d" ${count})|g" /etc/libvirt/qemu/${VM_NAME}.xml virsh define /etc/libvirt/qemu/${VM_NAME}.xml virsh create /etc/libvirt/qemu/${VM_NAME}.xml virsh start ${VM_NAME} || true count=$((count + 1)) done ############################# CREATE VM ############################# ############################# DELETE VM ############################# for i in infra1 infra2 infra3 compute1 swift1 cinder1; do VM_NAME="${i}" virsh destroy ${VM_NAME} || true virsh undefine ${VM_NAME} echo y | lvremove /dev/mapper/vg01-${VM_NAME} rm /etc/libvirt/qemu/${VM_NAME}.xml done ############################# DELETE VM #############################