diff options
author | Michael Polenchuk <mpolenchuk@mirantis.com> | 2017-05-24 13:52:02 +0400 |
---|---|---|
committer | Michael Polenchuk <mpolenchuk@mirantis.com> | 2017-05-25 14:38:56 +0400 |
commit | 27d968bc35ef4f622acd171ada778a4e0f4c76fb (patch) | |
tree | 5f780e69aa1969ac499e5442162629984521ca1d /mcp/reclass/scripts/infra.sh | |
parent | a6daf4ece3f05600ad66fea55c5220d07a71cef1 (diff) |
[mcp] Bring in deployment scripts
Change-Id: I7d2af958e447a5892f7cd1f6c6fb8616951e2ff3
Signed-off-by: Michael Polenchuk <mpolenchuk@mirantis.com>
Diffstat (limited to 'mcp/reclass/scripts/infra.sh')
-rwxr-xr-x | mcp/reclass/scripts/infra.sh | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/mcp/reclass/scripts/infra.sh b/mcp/reclass/scripts/infra.sh new file mode 100755 index 000000000..182d90692 --- /dev/null +++ b/mcp/reclass/scripts/infra.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +SSH_KEY=mcp.rsa +SALT_MASTER=192.168.10.100 +BASE_IMAGE=https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img +declare -A NODES=( [cfg01]=4096 [ctl01]=6144 [ctl02]=6144 [ctl03]=6144 [gtw01]=2048 [cmp01]=2048 ) + +[ -f $SSH_KEY ] || ssh-keygen -f $SSH_KEY -N '' + +# get base image +mkdir -p images +wget -nc $BASE_IMAGE + +for node in "${!NODES[@]}"; do + # clean up existing nodes + if [ "$(virsh domstate $node 2>/dev/null)" == 'running' ]; then + virsh destroy $node + virsh undefine $node + fi + + # create/prepare images + [ -f images/mcp_${node}.iso ] || ./create-config-drive.sh -k ${SSH_KEY}.pub -u user-data.sh -h ${node} images/mcp_${node}.iso + cp ${BASE_IMAGE/*\/} images/mcp_${node}.qcow2 + qemu-img resize images/mcp_${node}.qcow2 100G +done + +# create required networks +for net in pxe mgmt internal public; do + if virsh net-info $net >/dev/null 2>&1; then + virsh net-destroy ${net} + virsh net-undefine ${net} + fi + virsh net-define net_${net}.xml + virsh net-autostart ${net} + virsh net-start ${net} +done + +# create vms with specified options +for node in "${!NODES[@]}"; do + virt-install --name ${node} --ram ${NODES[$node]} --vcpus=2 --cpu host --accelerate \ + --network network:pxe,model=virtio \ + --network network:mgmt,model=virtio \ + --network network:internal,model=virtio \ + --network network:public,model=virtio \ + --disk path=$(pwd)/images/mcp_${node}.qcow2,format=qcow2,bus=virtio,cache=none,io=native \ + --boot hd --vnc --console pty --autostart --noreboot \ + --disk path=$(pwd)/images/mcp_${node}.iso,device=cdrom +done + +# set static ip address for salt master node +virsh net-update pxe add ip-dhcp-host \ +"<host mac='$(virsh domiflist cfg01 | awk '/pxe/ {print $5}')' name='cfg01' ip='$SALT_MASTER'/>" --live + +# start vms +for node in "${!NODES[@]}"; do + virsh start ${node} + sleep $[RANDOM%5+1] +done + +CONNECTION_ATTEMPTS=20 +SLEEP=15 + +# wait until ssh on Salt master is available +echo "Attempting to ssh to Salt master ..." +ATTEMPT=1 + +while (($ATTEMPT <= $CONNECTION_ATTEMPTS)); do + ssh -i ${SSH_KEY} ubuntu@$SALT_MASTER uptime + case $? in + (0) echo "${ATTEMPT}> Success"; break ;; + (*) echo "${ATTEMPT}/${CONNECTION_ATTEMPTS}> ssh server ain't ready yet, waiting for ${SLEEP} seconds ..." ;; + esac + sleep $SLEEP + ((ATTEMPT+=1)) +done |