Add reties when pulling images

Related-Prod: DEVCLOUD-820
Change-Id: If2d38da3d564ce3614f39143f1da0fd4ab9f169a
diff --git a/de/heat-templates/scripts/instance_boot.sh b/de/heat-templates/scripts/instance_boot.sh
index 4186b29..be5adea 100644
--- a/de/heat-templates/scripts/instance_boot.sh
+++ b/de/heat-templates/scripts/instance_boot.sh
@@ -159,20 +159,27 @@
 
 }
 
+function pull_image {
+    local image="$1"
+    function pull_image_retry {
+        docker pull ${image}
+    }
+    retry 10 "Can't pool docker image $image" pull_image_retry
+}
+
 function cache_images {
 
-    function cache_images_retry {
-        local image_prefix=${DOCKER_UCP_IMAGE%/*}
-        local image_name=${DOCKER_UCP_IMAGE##*/}
-        if [[ "$image_name" =~ .*-tp[0-9]+ ]]; then
-            for image in $(docker container run --rm --name ucp -v /var/run/docker.sock:/var/run/docker.sock ${DOCKER_UCP_IMAGE} images --list); do
-                docker pull ${image_prefix}/${image##*/};
-                docker tag ${image_prefix}/${image##*/} ${image}
-            done
-        fi
-    }
+    # Cache UCP image with retries
+    pull_image "${DOCKER_UCP_IMAGE}"
 
-    retry 10 "Can't cache docker images" cache_images_retry
+    local image_prefix=${DOCKER_UCP_IMAGE%/*}
+    local image_name=${DOCKER_UCP_IMAGE##*/}
+    if [[ "$image_name" =~ .*-tp[0-9]+ ]]; then
+        for image in $(docker container run --rm --name ucp -v /var/run/docker.sock:/var/run/docker.sock ${DOCKER_UCP_IMAGE} images --list); do
+            pull_image "${image_prefix}/${image##*/}"
+            docker tag ${image_prefix}/${image##*/} ${image}
+        done
+    fi
 }
 
 function install_ucp {