mcp/user-data: Pin saltstack repo to 2016.11
[fuel.git] / mcp / scripts / lib.sh
index 50f441a..3ec596a 100644 (file)
@@ -4,7 +4,7 @@
 
 generate_ssh_key() {
   [ -f "$SSH_KEY" ] || ssh-keygen -f ${SSH_KEY} -N ''
-  install -o jenkins -m 0600 ${SSH_KEY} /tmp/
+  install -o $USER -m 0600 ${SSH_KEY} /tmp/
 }
 
 get_base_image() {
@@ -18,7 +18,9 @@ cleanup_vms() {
   # clean up existing nodes
   for node in $(virsh list --name | grep -P '\w{3}\d{2}'); do
     virsh destroy $node
-    virsh undefine $node
+  done
+  for node in $(virsh list --name --all | grep -P '\w{3}\d{2}'); do
+    virsh undefine --nvram $node
   done
 }
 
@@ -54,10 +56,11 @@ create_networks() {
 create_vms() {
   local -n vnodes=$1
   local -n vnodes_ram=$2
+  local -n vnodes_vcpus=$3
 
   # create vms with specified options
   for node in "${vnodes[@]}"; do
-    virt-install --name ${node} --ram ${vnodes_ram[$node]} --vcpus=2 --cpu host --accelerate \
+    virt-install --name ${node} --ram ${vnodes_ram[$node]} --vcpus ${vnodes_vcpus[$node]} --cpu host --accelerate \
     --network network:pxe,model=virtio \
     --network network:mgmt,model=virtio \
     --network network:internal,model=virtio \
@@ -65,7 +68,8 @@ create_vms() {
     --disk path=$(pwd)/images/mcp_${node}.qcow2,format=qcow2,bus=virtio,cache=none,io=native \
     --os-type linux --os-variant none \
     --boot hd --vnc --console pty --autostart --noreboot \
-    --disk path=$(pwd)/images/mcp_${node}.iso,device=cdrom
+    --disk path=$(pwd)/images/mcp_${node}.iso,device=cdrom \
+    --noautoconsole
   done
 }
 
@@ -95,7 +99,7 @@ check_connection() {
 
   # wait until ssh on Salt master is available
   while (($attempt <= $total_attempts)); do
-    ssh -i ${SSH_KEY} ubuntu@${SALT_MASTER} uptime
+    ssh ${SSH_OPTS} ubuntu@${SALT_MASTER} uptime
     case $? in
       0) echo "${attempt}> Success"; break ;;
       *) echo "${attempt}/${total_attempts}> ssh server ain't ready yet, waiting for ${sleep_time} seconds ..." ;;