Browse code

Attempt to retrieve the vmdk descriptor data-pair

VMDK formats such as monolithicFlat and vmfs require two files to be
fully consumable by the Nova drivers (a descriptor-data pair: *.vmdk and
*-flat.vmdk).
On the upload of the descriptor (*.vmdk), upload_image.sh should attempt to
retrieve the *-flat.vmdk. The same way, the descriptor should be
retrieved when a flat disk is uploaded.
On success, the upload script will be able to use the flat disk as the image
content and the relevant descriptor settings as the image metadata.

Change-Id: I9214754029c46dd60b9e7d606d84d8819a498a8d
Closes-Bug: #1252443

Arnaud Legendre authored on 2013/11/23 09:05:39
Showing 1 changed files
... ...
@@ -1351,10 +1351,9 @@ function upload_image() {
1351 1351
 
1352 1352
     # Create a directory for the downloaded image tarballs.
1353 1353
     mkdir -p $FILES/images
1354
-
1354
+    IMAGE_FNAME=`basename "$image_url"`
1355 1355
     if [[ $image_url != file* ]]; then
1356 1356
         # Downloads the image (uec ami+aki style), then extracts it.
1357
-        IMAGE_FNAME=`basename "$image_url"`
1358 1357
         if [[ ! -f $FILES/$IMAGE_FNAME || "$(stat -c "%s" $FILES/$IMAGE_FNAME)" = "0" ]]; then
1359 1358
              wget -c $image_url -O $FILES/$IMAGE_FNAME
1360 1359
              if [[ $? -ne 0 ]]; then
... ...
@@ -1410,13 +1409,92 @@ function upload_image() {
1410 1410
         vmdk_create_type="$(head -25 $IMAGE | grep -a -F -m 1 'createType=' $IMAGE)"
1411 1411
         vmdk_create_type="${vmdk_create_type#*\"}"
1412 1412
         vmdk_create_type="${vmdk_create_type%?}"
1413
+
1414
+        descriptor_data_pair_msg="Monolithic flat and VMFS disks "`
1415
+                                 `"should use a descriptor-data pair."
1413 1416
         if [[ "$vmdk_create_type" = "monolithicSparse" ]]; then
1414 1417
             vmdk_disktype="sparse"
1415
-        elif [[ "$vmdk_create_type" = "monolithicFlat" ]]; then
1416
-            die $LINENO "Monolithic flat disks should use a descriptor-data pair." \
1417
-            "Please provide the disk and not the descriptor."
1418
+        elif [[ "$vmdk_create_type" = "monolithicFlat" || \
1419
+        "$vmdk_create_type" = "vmfs" ]]; then
1420
+            # Attempt to retrieve the *-flat.vmdk
1421
+            flat_fname="$(head -25 $IMAGE | grep -G 'RW\|RDONLY [0-9]+ FLAT\|VMFS' $IMAGE)"
1422
+            flat_fname="${flat_fname#*\"}"
1423
+            flat_fname="${flat_fname%?}"
1424
+            if [[ -z "$flat_name" ]]; then
1425
+                flat_fname="$IMAGE_NAME-flat.vmdk"
1426
+            fi
1427
+            path_len=`expr ${#image_url} - ${#IMAGE_FNAME}`
1428
+            flat_url="${image_url:0:$path_len}$flat_fname"
1429
+            warn $LINENO "$descriptor_data_pair_msg"`
1430
+                         `" Attempt to retrieve the *-flat.vmdk: $flat_url"
1431
+            if [[ $flat_url != file* ]]; then
1432
+                if [[ ! -f $FILES/$flat_fname || \
1433
+                "$(stat -c "%s" $FILES/$flat_fname)" = "0" ]]; then
1434
+                    wget -c $flat_url -O $FILES/$flat_fname
1435
+                    if [[ $? -ne 0 ]]; then
1436
+                        echo "Flat disk not found: $flat_url"
1437
+                        flat_found=false
1438
+                    fi
1439
+                fi
1440
+                if $flat_found; then
1441
+                    IMAGE="$FILES/${flat_fname}"
1442
+                fi
1443
+            else
1444
+                IMAGE=$(echo $flat_url | sed "s/^file:\/\///g")
1445
+                if [[ ! -f $IMAGE || "$(stat -c "%s" $IMAGE)" == "0" ]]; then
1446
+                    echo "Flat disk not found: $flat_url"
1447
+                    flat_found=false
1448
+                fi
1449
+                if ! $flat_found; then
1450
+                    IMAGE=$(echo $image_url | sed "s/^file:\/\///g")
1451
+                fi
1452
+            fi
1453
+            if $flat_found; then
1454
+                IMAGE_NAME="${flat_fname}"
1455
+            fi
1456
+            vmdk_disktype="preallocated"
1457
+        elif [[ -z "$vmdk_create_type" ]]; then
1458
+            # *-flat.vmdk provided: attempt to retrieve the descriptor (*.vmdk)
1459
+            # to retrieve appropriate metadata
1460
+            if [[ ${IMAGE_NAME: -5} != "-flat" ]]; then
1461
+                warn $LINENO "Expected filename suffix: '-flat'."`
1462
+                            `" Filename provided: ${IMAGE_NAME}"
1463
+            else
1464
+                descriptor_fname="${IMAGE_NAME:0:${#IMAGE_NAME} - 5}.vmdk"
1465
+                path_len=`expr ${#image_url} - ${#IMAGE_FNAME}`
1466
+                flat_path="${image_url:0:$path_len}"
1467
+                descriptor_url=$flat_path$descriptor_fname
1468
+                warn $LINENO "$descriptor_data_pair_msg"`
1469
+                             `" Attempt to retrieve the descriptor *.vmdk: $descriptor_url"
1470
+                if [[ $flat_path != file* ]]; then
1471
+                    if [[ ! -f $FILES/$descriptor_fname || \
1472
+                    "$(stat -c "%s" $FILES/$descriptor_fname)" = "0" ]]; then
1473
+                        wget -c $descriptor_url -O $FILES/$descriptor_fname
1474
+                        if [[ $? -ne 0 ]]; then
1475
+                            warn $LINENO "Descriptor not found $descriptor_url"
1476
+                            descriptor_found=false
1477
+                        fi
1478
+                    fi
1479
+                    descriptor_url="$FILES/$descriptor_fname"
1480
+                else
1481
+                    descriptor_url=$(echo $descriptor_url | sed "s/^file:\/\///g")
1482
+                    if [[ ! -f $descriptor_url || \
1483
+                    "$(stat -c "%s" $descriptor_url)" == "0" ]]; then
1484
+                         warn $LINENO "Descriptor not found $descriptor_url"
1485
+                         descriptor_found=false
1486
+                    fi
1487
+                fi
1488
+                if $descriptor_found; then
1489
+                    vmdk_adapter_type="$(head -25 $descriptor_url |"`
1490
+                    `"grep -a -F -m 1 'ddb.adapterType =' $descriptor_url)"
1491
+                    vmdk_adapter_type="${vmdk_adapter_type#*\"}"
1492
+                    vmdk_adapter_type="${vmdk_adapter_type%?}"
1493
+                 fi
1494
+             fi
1495
+             #TODO(alegendre): handle streamOptimized once supported by the VMware driver.
1496
+             vmdk_disktype="preallocated"
1418 1497
         else
1419
-            #TODO(alegendre): handle streamOptimized once supported by VMware driver.
1498
+            #TODO(alegendre): handle streamOptimized once supported by the VMware driver.
1420 1499
             vmdk_disktype="preallocated"
1421 1500
         fi
1422 1501