Browse code

Use vmdk descriptor to populate image properties

image_upload.sh doesn't use the descriptor properties embedded inside
the vmdk file. This requires the user to manually change the filename of the
vmdk file to add the properties (disk type, storage adapter and network
adapter).
In case of a sparse monolithic sparse or stream-optimized sparse, these
properties are extracted from the descriptor.
The user can still override these values by modifying the filename.

Change-Id: I1734311c66efe60a1a30e3ea63cc2a9da9cdb5b4
Closes-Bug: #1247300

Arnaud Legendre authored on 2013/11/02 08:42:54
Showing 1 changed files
... ...
@@ -1320,18 +1320,42 @@ function upload_image() {
1320 1320
 
1321 1321
         # Before we can upload vmdk type images to glance, we need to know it's
1322 1322
         # disk type, storage adapter, and networking adapter. These values are
1323
-        # passed to glance as custom properties. We take these values from the
1323
+        # passed to glance as custom properties. 
1324
+        # We take these values from the vmdk file if populated. Otherwise, we use
1324 1325
         # vmdk filename, which is expected in the following format:
1325 1326
         #
1326 1327
         #     <name>-<disk type>:<storage adapter>:<network adapter>
1327 1328
         #
1328 1329
         # If the filename does not follow the above format then the vsphere
1329 1330
         # driver will supply default values.
1331
+
1332
+        # vmdk adapter type
1333
+        vmdk_adapter_type="$(head -25 $IMAGE | grep -a -F -m 1 'ddb.adapterType =' $IMAGE)"
1334
+        vmdk_adapter_type="${vmdk_adapter_type#*\"}"
1335
+        vmdk_adapter_type="${vmdk_adapter_type%?}"
1336
+
1337
+        # vmdk disk type
1338
+        vmdk_create_type="$(head -25 $IMAGE | grep -a -F -m 1 'createType=' $IMAGE)"
1339
+        vmdk_create_type="${vmdk_create_type#*\"}"
1340
+        vmdk_create_type="${vmdk_create_type%?}"
1341
+        if [[ "$vmdk_create_type" = "monolithicSparse" ]]; then
1342
+            vmdk_disktype="sparse"
1343
+        elif [[ "$vmdk_create_type" = "monolithicFlat" ]]; then
1344
+            die $LINENO "Monolithic flat disks should use a descriptor-data pair." \
1345
+            "Please provide the disk and not the descriptor."
1346
+        else
1347
+            #TODO(alegendre): handle streamOptimized once supported by VMware driver.
1348
+            vmdk_disktype="preallocated"
1349
+        fi
1330 1350
         property_string=`echo "$IMAGE_NAME" | grep -oP '(?<=-)(?!.*-).+:.+:.+$'`
1331 1351
         if [[ ! -z "$property_string" ]]; then
1332 1352
             IFS=':' read -a props <<< "$property_string"
1333
-            vmdk_disktype="${props[0]}"
1334
-            vmdk_adapter_type="${props[1]}"
1353
+            if [[ ! -z "${props[0]}" ]]; then
1354
+                vmdk_disktype="${props[0]}"
1355
+            fi
1356
+            if [[ ! -z "${props[1]}" ]]; then
1357
+                vmdk_adapter_type="${props[1]}"
1358
+            fi
1335 1359
             vmdk_net_adapter="${props[2]}"
1336 1360
         fi
1337 1361