From a6273b9378622318057c2f5f685022389a066818 Mon Sep 17 00:00:00 2001 From: Ryan Hsu Date: Wed, 4 Sep 2013 23:51:29 -0700 Subject: [PATCH] Provide a means of setting vmdk custom properties via image filename Custom properties for vmdk disk type, storage adapter type, and networking adapter type can now be retrieved from a vmdk image's filename. The filename format is defined as: -:: An example filename following this format would be debian-2.6.32-i646-thin:ide:VirtualE1000. If the vmdk filename does not match the above format then underlying nova driver will supply default values. Change-Id: I83483d20f984250bd8154d8e270b2e801d2df303 Closes-bug: #1221044 --- functions | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/functions b/functions index df8166a0e2..d14c973715 100644 --- a/functions +++ b/functions @@ -1256,7 +1256,25 @@ function upload_image() { if [[ "$image_url" =~ '.vmdk' ]]; then IMAGE="$FILES/${IMAGE_FNAME}" IMAGE_NAME="${IMAGE_FNAME%.vmdk}" - 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="preallocated" < "${IMAGE}" + + # Before we can upload vmdk type images to glance, we need to know it's + # disk type, storage adapter, and networking adapter. These values are + # passed to glance as custom properties. We take these values from the + # vmdk filename, which is expected in the following format: + # + # -:: + # + # If the filename does not follow the above format then the vsphere + # driver will supply default values. + property_string=`echo "$IMAGE_NAME" | grep -oP '(?<=-)(?!.*-).+:.+:.+$'` + if [[ ! -z "$property_string" ]]; then + IFS=':' read -a props <<< "$property_string" + vmdk_disktype="${props[0]}" + vmdk_adapter_type="${props[1]}" + vmdk_net_adapter="${props[2]}" + fi + + 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}" return fi