Ask Your Question

Revision history [back]

There need to be more examples on how to do this, it is non-trivial

Here's mine

  config_mount_volume:
    type: OS::Heat::SoftwareConfig
    properties:
      group: ungrouped
      config:
        str_replace:
          template: |
            #!/bin/bash
            set -e
            voldata_id=PARAM_voldata_id
            mount_dir=PARAM_voldata_mount/
            echo "Mount volume ${voldata_id} to ${mount_dir}"
            voldata_dev="/dev/disk/by-id/virtio-$(echo ${voldata_id} | cut -c -20)"
            partition_dev="${voldata_dev}-part1"

            while [ ! -e ${voldata_dev} ]; do echo Waiting for volume ${voldata_id} to attach; sleep 1; done

            if [[ ! $(ls ${voldata_dev}-part*) ]]; then
              echo "No partitions found, create ${partition_dev}"
              echo ",+," | sfdisk ${voldata_dev}
            fi

            if [[ ! $(file -sL ${partition_dev} | grep ext4) ]]; then
              echo "Partitions not formated, format it as ext4"
              # yes /dev/disk/by-id/, partprobe and hdparm show it is there, but no it is is not ready
              sleep 1
              mkfs.ext4 ${partition_dev}
              file -sL /dev/disk/by-id/*
            fi
            mkdir -pv ${mount_dir}
            # mount on reboot
            echo "${partition_dev} ${mount_dir} ext4 defaults,nofail 0 0" >> /etc/fstab
            # mount now
            mount ${mount_dir}
          params:
            PARAM_voldata_id: { get_param: data_volume }
            PARAM_voldata_mount: { get_param: data_dir }