Browse code

Merge "upload_image.sh should handle file URLs"

Jenkins authored on 2013/11/22 12:02:08
Showing 1 changed files
... ...
@@ -1338,11 +1338,24 @@ function upload_image() {
1338 1338
     # Create a directory for the downloaded image tarballs.
1339 1339
     mkdir -p $FILES/images
1340 1340
 
1341
-    # Downloads the image (uec ami+aki style), then extracts it.
1342
-    IMAGE_FNAME=`basename "$image_url"`
1343
-    if [[ ! -f $FILES/$IMAGE_FNAME || "$(stat -c "%s" $FILES/$IMAGE_FNAME)" = "0" ]]; then
1344
-        wget -c $image_url -O $FILES/$IMAGE_FNAME
1345
-        if [[ $? -ne 0 ]]; then
1341
+    if [[ $image_url != file* ]]; then
1342
+        # Downloads the image (uec ami+aki style), then extracts it.
1343
+        IMAGE_FNAME=`basename "$image_url"`
1344
+        if [[ ! -f $FILES/$IMAGE_FNAME || "$(stat -c "%s" $FILES/$IMAGE_FNAME)" = "0" ]]; then
1345
+             wget -c $image_url -O $FILES/$IMAGE_FNAME
1346
+             if [[ $? -ne 0 ]]; then
1347
+                 echo "Not found: $image_url"
1348
+                 return
1349
+             fi
1350
+        fi
1351
+        IMAGE="$FILES/${IMAGE_FNAME}"
1352
+    else
1353
+        # File based URL (RFC 1738): file://host/path
1354
+        # Remote files are not considered here.
1355
+        # *nix: file:///home/user/path/file
1356
+        # windows: file:///C:/Documents%20and%20Settings/user/path/file
1357
+        IMAGE=$(echo $image_url | sed "s/^file:\/\///g")
1358
+        if [[ ! -f $IMAGE || "$(stat -c "%s" $IMAGE)" == "0" ]]; then
1346 1359
             echo "Not found: $image_url"
1347 1360
             return
1348 1361
         fi
... ...
@@ -1350,7 +1363,6 @@ function upload_image() {
1350 1350
 
1351 1351
     # OpenVZ-format images are provided as .tar.gz, but not decompressed prior to loading
1352 1352
     if [[ "$image_url" =~ 'openvz' ]]; then
1353
-        IMAGE="$FILES/${IMAGE_FNAME}"
1354 1353
         IMAGE_NAME="${IMAGE_FNAME%.tar.gz}"
1355 1354
         glance --os-auth-token $token --os-image-url http://$GLANCE_HOSTPORT image-create --name "$IMAGE_NAME" --is-public=True --container-format ami --disk-format ami < "${IMAGE}"
1356 1355
         return
... ...
@@ -1358,7 +1370,6 @@ function upload_image() {
1358 1358
 
1359 1359
     # vmdk format images
1360 1360
     if [[ "$image_url" =~ '.vmdk' ]]; then
1361
-        IMAGE="$FILES/${IMAGE_FNAME}"
1362 1361
         IMAGE_NAME="${IMAGE_FNAME%.vmdk}"
1363 1362
 
1364 1363
         # Before we can upload vmdk type images to glance, we need to know it's
... ...
@@ -1409,7 +1420,6 @@ function upload_image() {
1409 1409
     # XenServer-vhd-ovf-format images are provided as .vhd.tgz
1410 1410
     # and should not be decompressed prior to loading
1411 1411
     if [[ "$image_url" =~ '.vhd.tgz' ]]; then
1412
-        IMAGE="$FILES/${IMAGE_FNAME}"
1413 1412
         IMAGE_NAME="${IMAGE_FNAME%.vhd.tgz}"
1414 1413
         glance --os-auth-token $token --os-image-url http://$GLANCE_HOSTPORT image-create --name "$IMAGE_NAME" --is-public=True --container-format=ovf --disk-format=vhd < "${IMAGE}"
1415 1414
         return
... ...
@@ -1419,7 +1429,6 @@ function upload_image() {
1419 1419
     # and should not be decompressed prior to loading.
1420 1420
     # Setting metadata, so PV mode is used.
1421 1421
     if [[ "$image_url" =~ '.xen-raw.tgz' ]]; then
1422
-        IMAGE="$FILES/${IMAGE_FNAME}"
1423 1422
         IMAGE_NAME="${IMAGE_FNAME%.xen-raw.tgz}"
1424 1423
         glance \
1425 1424
             --os-auth-token $token \
... ...
@@ -1457,7 +1466,6 @@ function upload_image() {
1457 1457
             fi
1458 1458
             ;;
1459 1459
         *.img)
1460
-            IMAGE="$FILES/$IMAGE_FNAME";
1461 1460
             IMAGE_NAME=$(basename "$IMAGE" ".img")
1462 1461
             format=$(qemu-img info ${IMAGE} | awk '/^file format/ { print $3; exit }')
1463 1462
             if [[ ",qcow2,raw,vdi,vmdk,vpc," =~ ",$format," ]]; then
... ...
@@ -1468,20 +1476,17 @@ function upload_image() {
1468 1468
             CONTAINER_FORMAT=bare
1469 1469
             ;;
1470 1470
         *.img.gz)
1471
-            IMAGE="$FILES/${IMAGE_FNAME}"
1472 1471
             IMAGE_NAME=$(basename "$IMAGE" ".img.gz")
1473 1472
             DISK_FORMAT=raw
1474 1473
             CONTAINER_FORMAT=bare
1475 1474
             UNPACK=zcat
1476 1475
             ;;
1477 1476
         *.qcow2)
1478
-            IMAGE="$FILES/${IMAGE_FNAME}"
1479 1477
             IMAGE_NAME=$(basename "$IMAGE" ".qcow2")
1480 1478
             DISK_FORMAT=qcow2
1481 1479
             CONTAINER_FORMAT=bare
1482 1480
             ;;
1483 1481
         *.iso)
1484
-            IMAGE="$FILES/${IMAGE_FNAME}"
1485 1482
             IMAGE_NAME=$(basename "$IMAGE" ".iso")
1486 1483
             DISK_FORMAT=iso
1487 1484
             CONTAINER_FORMAT=bare