#!/bin/sh

. /etc/sysconfig/heat-params

DOCKER_DEV=/dev/disk/by-id/virtio-${DOCKER_VOLUME:0:20}

attempts=60
while [[ ! -b $DOCKER_DEV && $attempts != 0 ]]; do
    echo "waiting for disk $DOCKER_DEV"
    sleep 0.5
    udevadm trigger
    let attempts--
done

if ! [ -b $DOCKER_DEV ]; then
    echo "ERROR: device $DOCKER_DEV does not exist" >&2
    exit 1
fi

pvcreate $DOCKER_DEV
vgcreate docker $DOCKER_DEV

cat > /etc/sysconfig/docker-storage-setup <<EOF
VG=docker
EOF

#!/bin/sh

. /etc/sysconfig/heat-params

attempts=60
while [ ${attempts} -gt 0 ]; do
    device_name=$(ls /dev/disk/by-id | grep ${DOCKER_VOLUME:0:20}$)
    if [ -n "${device_name}" ]; then
        break
    fi   
    echo "waiting for disk device"
    sleep 0.5
    udevadm trigger
    let attempts--
done

if [ -z "${device_name}" ]; then
    echo "ERROR: disk device does not exist" >&2
    exit 1
fi

device_path=/dev/disk/by-id/${device_name}
pvcreate ${device_path}
vgcreate docker ${device_path}

cat > /etc/sysconfig/docker-storage-setup << EOF
VG=docker
EOF

Add support for different disk bus
Add support for different disk bus

Different disk bus has different device path, so we should change
our way to find device path.

examples:
virtio => virtio-5e7ef7f7-da5b-4b6c-9
scsi => scsi-0QEMU_QEMU_HARDDISK_ab5b3fab-f848-4a00-8
ide => ata-QEMU_HARDDISK_e4bb1070-3ff0-4470-a

I have confirmed with my colleague who is familiar with qemu.
The device path ends with the prefix of the volume id. For example,
when the volume id is e4bb1070-3ff0-4470-ad5a-3edbb30ae011, the ide
device path is ata-QEMU_HARDDISK_e4bb1070-3ff0-4470-a. The last 20
charaters of device path is same as the first 20 charaters of the
volume id. But I can not find any official docs for it now.

Change-Id: I8fc7aa0c0f8722a24f7189c0a8c118dbb724c1d3
Partially-Implements: blueprint support-for-different-volume-type
