Browse code

xenapi - use management network to reach OS VM

Devstack used the HOST_IP_IFACE to reach the OpenStack VM through ssh.
This patch changes this behavior, so that the IP address of the
interface connected to the management network will be used.

Related to blueprint xenapi-devstack-cleanup

Change-Id: I7f34d973870792d60a33ea512901d9b0d422150b

Mate Lakat authored on 2013/05/13 02:34:29
Showing 2 changed files
... ...
@@ -65,3 +65,31 @@ function get_local_sr {
65 65
 function get_local_sr_path {
66 66
     echo "/var/run/sr-mount/$(get_local_sr)"
67 67
 }
68
+
69
+function find_ip_by_name() {
70
+    local guest_name="$1"
71
+    local interface="$2"
72
+
73
+    local period=10
74
+    local max_tries=10
75
+    local i=0
76
+
77
+    while true; do
78
+        if [ $i -ge $max_tries ]; then
79
+            echo "Timeout: ip address for interface $interface of $guest_name"
80
+            exit 11
81
+        fi
82
+
83
+        ipaddress=$(xe vm-list --minimal \
84
+                    name-label=$guest_name \
85
+                    params=networks | sed -ne "s,^.*${interface}/ip: \([0-9.]*\).*\$,\1,p")
86
+
87
+        if [ -z "$ipaddress" ]; then
88
+            sleep $period
89
+            ((i++))
90
+        else
91
+            echo $ipaddress
92
+            break
93
+        fi
94
+    done
95
+}
... ...
@@ -313,53 +313,26 @@ xe vm-snapshot vm="$GUEST_NAME" new-name-label="$SNAME_FIRST_BOOT"
313 313
 #
314 314
 xe vm-start vm="$GUEST_NAME"
315 315
 
316
-
317
-#
318
-# Find IP and optionally wait for stack.sh to complete
319
-#
320
-
321
-function find_ip_by_name() {
322
-  local guest_name="$1"
323
-  local interface="$2"
324
-  local period=10
325
-  max_tries=10
326
-  i=0
327
-  while true
328
-  do
329
-    if [ $i -ge $max_tries ]; then
330
-      echo "Timed out waiting for devstack ip address"
331
-      exit 11
332
-    fi
333
-
334
-    devstackip=$(xe vm-list --minimal \
335
-                 name-label=$guest_name \
336
-                 params=networks | sed -ne "s,^.*${interface}/ip: \([0-9.]*\).*\$,\1,p")
337
-    if [ -z "$devstackip" ]
338
-    then
339
-      sleep $period
340
-      ((i++))
341
-    else
342
-      echo $devstackip
343
-      break
344
-    fi
345
-  done
346
-}
347
-
348 316
 function ssh_no_check() {
349 317
     ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$@"
350 318
 }
351 319
 
352
-# Note the XenServer needs to be on the chosen
353
-# network, so XenServer can access Glance API
320
+# Get hold of the Management IP of OpenStack VM
321
+OS_VM_MANAGEMENT_ADDRESS=$MGT_IP
322
+if [ $OS_VM_MANAGEMENT_ADDRESS == "dhcp" ]; then
323
+    OS_VM_MANAGEMENT_ADDRESS=$(find_ip_by_name $GUEST_NAME 2)
324
+fi
325
+
326
+# Get hold of the Service IP of OpenStack VM
354 327
 if [ $HOST_IP_IFACE == "eth2" ]; then
355
-    DOMU_IP=$MGT_IP
328
+    OS_VM_SERVICES_ADDRESS=$MGT_IP
356 329
     if [ $MGT_IP == "dhcp" ]; then
357
-        DOMU_IP=$(find_ip_by_name $GUEST_NAME 2)
330
+        OS_VM_SERVICES_ADDRESS=$(find_ip_by_name $GUEST_NAME 2)
358 331
     fi
359 332
 else
360
-    DOMU_IP=$PUB_IP
333
+    OS_VM_SERVICES_ADDRESS=$PUB_IP
361 334
     if [ $PUB_IP == "dhcp" ]; then
362
-        DOMU_IP=$(find_ip_by_name $GUEST_NAME 3)
335
+        OS_VM_SERVICES_ADDRESS=$(find_ip_by_name $GUEST_NAME 3)
363 336
     fi
364 337
 fi
365 338
 
... ...
@@ -371,11 +344,11 @@ if [ "$WAIT_TILL_LAUNCH" = "1" ]  && [ -e ~/.ssh/id_rsa.pub  ] && [ "$COPYENV" =
371 371
 
372 372
     echo "VM Launched - Waiting for startup script"
373 373
     # wait for log to appear
374
-    while ! ssh_no_check -q stack@$DOMU_IP "[ -e run.sh.log ]"; do
374
+    while ! ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "[ -e run.sh.log ]"; do
375 375
         sleep 10
376 376
     done
377 377
     echo -n "Running"
378
-    while [ `ssh_no_check -q stack@$DOMU_IP pgrep -c run.sh` -ge 1 ]
378
+    while [ `ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS pgrep -c run.sh` -ge 1 ]
379 379
     do
380 380
         sleep 10
381 381
         echo -n "."
... ...
@@ -384,17 +357,17 @@ if [ "$WAIT_TILL_LAUNCH" = "1" ]  && [ -e ~/.ssh/id_rsa.pub  ] && [ "$COPYENV" =
384 384
     set -x
385 385
 
386 386
     # output the run.sh.log
387
-    ssh_no_check -q stack@$DOMU_IP 'cat run.sh.log'
387
+    ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS 'cat run.sh.log'
388 388
 
389 389
     # Fail if the expected text is not found
390
-    ssh_no_check -q stack@$DOMU_IP 'cat run.sh.log' | grep -q 'stack.sh completed in'
390
+    ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS 'cat run.sh.log' | grep -q 'stack.sh completed in'
391 391
 
392 392
     set +x
393 393
     echo "################################################################################"
394 394
     echo ""
395 395
     echo "All Finished!"
396 396
     echo "You can visit the OpenStack Dashboard"
397
-    echo "at http://$DOMU_IP, and contact other services at the usual ports."
397
+    echo "at http://$OS_VM_SERVICES_ADDRESS, and contact other services at the usual ports."
398 398
 else
399 399
     set +x
400 400
     echo "################################################################################"
... ...
@@ -403,9 +376,9 @@ else
403 403
     echo "Now, you can monitor the progress of the stack.sh installation by "
404 404
     echo "tailing /opt/stack/run.sh.log from within your domU."
405 405
     echo ""
406
-    echo "ssh into your domU now: 'ssh stack@$DOMU_IP' using your password"
406
+    echo "ssh into your domU now: 'ssh stack@$OS_VM_MANAGEMENT_ADDRESS' using your password"
407 407
     echo "and then do: 'tail -f /opt/stack/run.sh.log'"
408 408
     echo ""
409 409
     echo "When the script completes, you can then visit the OpenStack Dashboard"
410
-    echo "at http://$DOMU_IP, and contact other services at the usual ports."
410
+    echo "at http://$OS_VM_SERVICES_ADDRESS, and contact other services at the usual ports."
411 411
 fi