4 SALT_MASTER=192.168.10.100
5 BASE_IMAGE=https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img
6 declare -A NODES=( [cfg01]=4096 [ctl01]=6144 [ctl02]=6144 [ctl03]=6144 [gtw01]=2048 [cmp01]=2048 )
8 # get required packages
9 apt-get install -y mkisofs curl virtinst cpu-checker qemu-kvm
12 [ -f $SSH_KEY ] || ssh-keygen -f $SSH_KEY -N ''
18 for node in "${!NODES[@]}"; do
19 # clean up existing nodes
20 if [ "$(virsh domstate $node 2>/dev/null)" == 'running' ]; then
25 # create/prepare images
26 [ -f images/mcp_${node}.iso ] || ./create-config-drive.sh -k ${SSH_KEY}.pub -u user-data.sh -h ${node} images/mcp_${node}.iso
27 cp ${BASE_IMAGE/*\/} images/mcp_${node}.qcow2
28 qemu-img resize images/mcp_${node}.qcow2 100G
31 # create required networks
32 for net in pxe mgmt internal public; do
33 if virsh net-info $net >/dev/null 2>&1; then
34 virsh net-destroy ${net}
35 virsh net-undefine ${net}
37 virsh net-define net_${net}.xml
38 virsh net-autostart ${net}
39 virsh net-start ${net}
42 # create vms with specified options
43 for node in "${!NODES[@]}"; do
44 virt-install --name ${node} --ram ${NODES[$node]} --vcpus=2 --cpu host --accelerate \
45 --network network:pxe,model=virtio \
46 --network network:mgmt,model=virtio \
47 --network network:internal,model=virtio \
48 --network network:public,model=virtio \
49 --disk path=$(pwd)/images/mcp_${node}.qcow2,format=qcow2,bus=virtio,cache=none,io=native \
50 --boot hd --vnc --console pty --autostart --noreboot \
51 --disk path=$(pwd)/images/mcp_${node}.iso,device=cdrom
54 # set static ip address for salt master node
55 virsh net-update pxe add ip-dhcp-host \
56 "<host mac='$(virsh domiflist cfg01 | awk '/pxe/ {print $5}')' name='cfg01' ip='$SALT_MASTER'/>" --live
59 for node in "${!NODES[@]}"; do
64 CONNECTION_ATTEMPTS=20
67 # refresh salt master host key
68 ssh-keygen -R $SALT_MASTER
70 # wait until ssh on Salt master is available
71 echo "Attempting to ssh to Salt master ..."
74 while (($ATTEMPT <= $CONNECTION_ATTEMPTS)); do
75 ssh -i ${SSH_KEY} ubuntu@$SALT_MASTER uptime
77 (0) echo "${ATTEMPT}> Success"; break ;;
78 (*) echo "${ATTEMPT}/${CONNECTION_ATTEMPTS}> ssh server ain't ready yet, waiting for ${SLEEP} seconds ..." ;;
81 ssh-keyscan -t ecdsa $SALT_MASTER >> ~/.ssh/known_hosts