Browse code

Update vsphere image filename pattern

The vsphere image filename pattern has been updated so that semi-
colons are used to delimit image properties rather than colons,
which are not permitted in Windows filesystems. To support back-
wards compatibility, colons can still be used.

Change-Id: I29a3ac03dcae294326dc8813a66512a79f705f81
Closes-Bug: #1250319

Ryan Hsu authored on 2013/11/12 14:20:14
Showing 1 changed files
... ...
@@ -1362,15 +1362,19 @@ function upload_image() {
1362 1362
 
1363 1363
         # Before we can upload vmdk type images to glance, we need to know it's
1364 1364
         # disk type, storage adapter, and networking adapter. These values are
1365
-        # passed to glance as custom properties. 
1365
+        # passed to glance as custom properties.
1366 1366
         # We take these values from the vmdk file if populated. Otherwise, we use
1367 1367
         # vmdk filename, which is expected in the following format:
1368 1368
         #
1369
-        #     <name>-<disk type>:<storage adapter>:<network adapter>
1369
+        #     <name>-<disk type>;<storage adapter>;<network adapter>
1370 1370
         #
1371 1371
         # If the filename does not follow the above format then the vsphere
1372 1372
         # driver will supply default values.
1373 1373
 
1374
+        vmdk_adapter_type=""
1375
+        vmdk_disktype=""
1376
+        vmdk_net_adapter=""
1377
+
1374 1378
         # vmdk adapter type
1375 1379
         vmdk_adapter_type="$(head -25 $IMAGE | grep -a -F -m 1 'ddb.adapterType =' $IMAGE)"
1376 1380
         vmdk_adapter_type="${vmdk_adapter_type#*\"}"
... ...
@@ -1389,17 +1393,15 @@ function upload_image() {
1389 1389
             #TODO(alegendre): handle streamOptimized once supported by VMware driver.
1390 1390
             vmdk_disktype="preallocated"
1391 1391
         fi
1392
-        property_string=`echo "$IMAGE_NAME" | grep -oP '(?<=-)(?!.*-).+:.+:.+$'`
1393
-        if [[ ! -z "$property_string" ]]; then
1394
-            IFS=':' read -a props <<< "$property_string"
1395
-            if [[ ! -z "${props[0]}" ]]; then
1396
-                vmdk_disktype="${props[0]}"
1397
-            fi
1398
-            if [[ ! -z "${props[1]}" ]]; then
1399
-                vmdk_adapter_type="${props[1]}"
1400
-            fi
1401
-            vmdk_net_adapter="${props[2]}"
1402
-        fi
1392
+
1393
+        # NOTE: For backwards compatibility reasons, colons may be used in place
1394
+        # of semi-colons for property delimiters but they are not permitted
1395
+        # characters in NTFS filesystems.
1396
+        property_string=`echo "$IMAGE_NAME" | grep -oP '(?<=-)(?!.*-).+[:;].+[:;].+$'`
1397
+        IFS=':;' read -a props <<< "$property_string"
1398
+        vmdk_disktype="${props[0]:-$vmdk_disktype}"
1399
+        vmdk_adapter_type="${props[1]:-$vmdk_adapter_type}"
1400
+        vmdk_net_adapter="${props[2]:-$vmdk_net_adapter}"
1403 1401
 
1404 1402
         glance --os-auth-token $token --os-image-url http://$GLANCE_HOSTPORT image-create --name "$IMAGE_NAME" --is-public=True --container-format bare --disk-format vmdk --property vmware_disktype="$vmdk_disktype" --property vmware_adaptertype="$vmdk_adapter_type" --property hw_vif_model="$vmdk_net_adapter" < "${IMAGE}"
1405 1403
         return