Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

heat template - create instance using cinder volume, use it as LVM

Hi, I want to create heat template that serve the following purpose: 1. Launch Instance from image 2. Create Cinder Volume 3. Attach the Volume to the instance 4. Configure the volume on the instance as LVM, format the LVM as ext4, and finally mount it

So i create something like this:

 heat_template_version: 2015-04-30
description: >
  A template showing how to create a Nova instance, a Cinder volume and attach
  the volume to the instance. The template uses only Heat OpenStack native
  resource types.
parameters:
  key_name:
    type: string
    default: linux_key
    description:
      Name of an existing key pair to enable SSH access to the instance.
  instance_type:
    type: string
    description: Type of the instance to be created.
    default: m1.small
    constraints:
      - allowed_values: [m1.small, m1.medium, m1.large]
        description:
          Value must be one of 'm1.small', 'm1.medium' or 'm1.large'.
  image_id:
    type: string
    description: ID of the image to use for the instance to be created.
    default: linux_img
    constraints:
      - allowed_values: [ linux_img ]
        description:
          Image ID must be linux_img
  availability_zone:
    type: string
    description: The Availability Zone to launch the instance.
    default: nova
  volume_size:
    type: number
    description: Size of the volume to be created.
    default: 1
    constraints:
      - range: { min: 1, max: 1024 }
        description: must be between 1 and 1024 Gb.
resources:
  avoltest:
    type: OS::Nova::Server
    properties:
      availability_zone: { get_param: availability_zone }
      image: { get_param: image_id }
      flavor: { get_param: instance_type }
      key_name: { get_param: key_name }
      user_data_format: RAW
      user_data:
        str_replace:
          params:
            $LOGFILE: /tmp/installlog.log
            $VOLSIZE: { get_param: volume_size }
          template: |
            #!/bin/bash -v
              die() {
              _WC-NOTIFY_ --data-binary '{"status": "FAILURE"}'
                exit 1
              }
            yum install -y lvm2 >> $LOGFILE 2>&1 || die
            pvcreate /dev/sdb >> $LOGFILE 2>&1 || die
            vgcreate volgroup01 /dev/sdb >> $LOGFILE 2>&1 || die
            lvcreate -l+100%FREE -n lvol01 volgroup01 >> $LOGFILE 2>&1 || die
            mkfs.ext4 -F /dev/mapper/volgroup01-lvol01 >> $LOGFILE 2>&1 || die
            mkdir /data
            echo "/dev/mapper/volgroup01-lvol01 /data ext4 defaults 0 0" >> /etc/fstab
            mount -a
            df -ah >> $LOGFILE 2>&1 || die
  cinder_volume:
    type: OS::Cinder::Volume
    properties:
      size: { get_param: volume_size }
      availability_zone: { get_param: availability_zone }
  volume_attachment:
    type: OS::Cinder::VolumeAttachment
    properties:
      volume_id: { get_resource: cinder_volume }
      instance_uuid: { get_resource: avoltest }
      mountpoint: /dev/sdb
outputs:
  instance_ip:
    description: Public IP address of the newly created Nova instance.
    value: { get_attr: [avoltest, first_address] }

but with that template, the bash command for creating the lvm (pvcreate and so on) is executed first before the volume is being attached to the instance, so it failed. Anyone have idea how to make it in order so that the bash commands on the instance will be executed after the volume is attached? Thank you

heat template - create instance using cinder volume, use it as LVM

Hi, I want to create heat template that serve the following purpose: 1. purpose:

  1. Launch Instance from image 2. image
  2. Create Cinder Volume 3. Volume
  3. Attach the Volume to the instance 4. instance
  4. Configure the volume on the instance as LVM, format the LVM as ext4, and finally mount it

So i create something like this:

 heat_template_version: 2015-04-30
description: >
  A template showing how to create a Nova instance, a Cinder volume and attach
  the volume to the instance. The template uses only Heat OpenStack native
  resource types.
parameters:
  key_name:
    type: string
    default: linux_key
    description:
      Name of an existing key pair to enable SSH access to the instance.
  instance_type:
    type: string
    description: Type of the instance to be created.
    default: m1.small
    constraints:
      - allowed_values: [m1.small, m1.medium, m1.large]
        description:
          Value must be one of 'm1.small', 'm1.medium' or 'm1.large'.
  image_id:
    type: string
    description: ID of the image to use for the instance to be created.
    default: linux_img
    constraints:
      - allowed_values: [ linux_img ]
        description:
          Image ID must be linux_img
  availability_zone:
    type: string
    description: The Availability Zone to launch the instance.
    default: nova
  volume_size:
    type: number
    description: Size of the volume to be created.
    default: 1
    constraints:
      - range: { min: 1, max: 1024 }
        description: must be between 1 and 1024 Gb.
resources:
  avoltest:
    type: OS::Nova::Server
    properties:
      availability_zone: { get_param: availability_zone }
      image: { get_param: image_id }
      flavor: { get_param: instance_type }
      key_name: { get_param: key_name }
      user_data_format: RAW
      user_data:
        str_replace:
          params:
            $LOGFILE: /tmp/installlog.log
            $VOLSIZE: { get_param: volume_size }
          template: |
            #!/bin/bash -v
              die() {
              _WC-NOTIFY_ --data-binary '{"status": "FAILURE"}'
                exit 1
              }
            yum install -y lvm2 >> $LOGFILE 2>&1 || die
            pvcreate /dev/sdb >> $LOGFILE 2>&1 || die
            vgcreate volgroup01 /dev/sdb >> $LOGFILE 2>&1 || die
            lvcreate -l+100%FREE -n lvol01 volgroup01 >> $LOGFILE 2>&1 || die
            mkfs.ext4 -F /dev/mapper/volgroup01-lvol01 >> $LOGFILE 2>&1 || die
            mkdir /data
            echo "/dev/mapper/volgroup01-lvol01 /data ext4 defaults 0 0" >> /etc/fstab
            mount -a
            df -ah >> $LOGFILE 2>&1 || die
  cinder_volume:
    type: OS::Cinder::Volume
    properties:
      size: { get_param: volume_size }
      availability_zone: { get_param: availability_zone }
  volume_attachment:
    type: OS::Cinder::VolumeAttachment
    properties:
      volume_id: { get_resource: cinder_volume }
      instance_uuid: { get_resource: avoltest }
      mountpoint: /dev/sdb
outputs:
  instance_ip:
    description: Public IP address of the newly created Nova instance.
    value: { get_attr: [avoltest, first_address] }

but with that template, the bash command for creating the lvm (pvcreate and so on) is executed first before the volume is being attached to the instance, so it failed. failed.

Anyone have idea how to make it in order so that the bash commands on the instance will be executed after the volume is attached? Thank you

heat template - create instance using cinder volume, use it as LVM

Hi, I want to create heat template that serve the following purpose:

  1. Launch Instance from image
  2. Create Cinder Volume
  3. Attach the Volume to the instance
  4. Configure the volume on the instance as LVM, format the LVM as ext4, and finally mount it

So i create something like this:

 heat_template_version: 2015-04-30
description: >
  A template showing how to create a Nova instance, a Cinder volume and attach
  the volume to the instance. The template uses only Heat OpenStack native
  resource types.
parameters:
  key_name:
    type: string
    default: linux_key
    description:
      Name of an existing key pair to enable SSH access to the instance.
  instance_type:
    type: string
    description: Type of the instance to be created.
    default: m1.small
    constraints:
      - allowed_values: [m1.small, m1.medium, m1.large]
        description:
          Value must be one of 'm1.small', 'm1.medium' or 'm1.large'.
  image_id:
    type: string
    description: ID of the image to use for the instance to be created.
    default: linux_img
    constraints:
      - allowed_values: [ linux_img ]
        description:
          Image ID must be linux_img
  availability_zone:
    type: string
    description: The Availability Zone to launch the instance.
    default: nova
  volume_size:
    type: number
    description: Size of the volume to be created.
    default: 1
    constraints:
      - range: { min: 1, max: 1024 }
        description: must be between 1 and 1024 Gb.
resources:
  avoltest:
    type: OS::Nova::Server
    properties:
      availability_zone: { get_param: availability_zone }
      image: { get_param: image_id }
      flavor: { get_param: instance_type }
      key_name: { get_param: key_name }
      user_data_format: RAW
      user_data:
        str_replace:
          params:
            $LOGFILE: /tmp/installlog.log
            $VOLSIZE: { get_param: volume_size }
          template: |
            #!/bin/bash -v
              die() {
              _WC-NOTIFY_ --data-binary '{"status": "FAILURE"}'
                exit 1
              }
            yum install -y lvm2 >> $LOGFILE 2>&1 || die
            pvcreate /dev/sdb >> $LOGFILE 2>&1 || die
            vgcreate volgroup01 /dev/sdb >> $LOGFILE 2>&1 || die
            lvcreate -l+100%FREE -n lvol01 volgroup01 >> $LOGFILE 2>&1 || die
            mkfs.ext4 -F /dev/mapper/volgroup01-lvol01 >> $LOGFILE 2>&1 || die
            mkdir /data
            echo "/dev/mapper/volgroup01-lvol01 /data ext4 defaults 0 0" >> /etc/fstab
            mount -a
            df -ah >> $LOGFILE 2>&1 || die
  cinder_volume:
    type: OS::Cinder::Volume
    properties:
      size: { get_param: volume_size }
      availability_zone: { get_param: availability_zone }
  volume_attachment:
    type: OS::Cinder::VolumeAttachment
    properties:
      volume_id: { get_resource: cinder_volume }
      instance_uuid: { get_resource: avoltest }
      mountpoint: /dev/sdb
outputs:
  instance_ip:
    description: Public IP address of the newly created Nova instance.
    value: { get_attr: [avoltest, first_address] }

but with that template, the bash command for creating the lvm (pvcreate and so on) is executed first before the volume is being attached to the instance, so it failed.

Anyone have idea how to make it in order so that the bash commands on the instance will be executed after the volume is attached? Thank you