| Steve Baker | a5bd912 | 2014-08-11 14:39:00 +1200 | [diff] [blame] | 1 | heat_template_version: 2013-05-23 | 
|  | 2 |  | 
|  | 3 | parameters: | 
|  | 4 | key_name: | 
|  | 5 | type: string | 
|  | 6 | description: keypair to enable SSH access to the instance. | 
|  | 7 |  | 
|  | 8 | instance_type: | 
|  | 9 | type: string | 
|  | 10 | description: Type of the instance to be created. | 
|  | 11 | default: m1.small | 
|  | 12 |  | 
|  | 13 | image_id: | 
|  | 14 | type: string | 
|  | 15 | description: ID of the image to use for the instance to be created. | 
|  | 16 |  | 
|  | 17 | timeout: | 
|  | 18 | type: number | 
|  | 19 | description: Stack creation timeout | 
|  | 20 |  | 
|  | 21 | dev_name: | 
|  | 22 | type: string | 
|  | 23 | description: Expected device name for volume | 
|  | 24 | default: vdb | 
|  | 25 |  | 
|  | 26 | rescan_timeout: | 
|  | 27 | type: number | 
|  | 28 | description: Max number of seconds to wait for volume after rescan | 
|  | 29 | default: 120 | 
|  | 30 |  | 
|  | 31 | backup_id: | 
|  | 32 | type: string | 
|  | 33 | description: backup_id to create volume from | 
|  | 34 |  | 
|  | 35 | network: | 
|  | 36 | type: string | 
|  | 37 |  | 
|  | 38 | volume_description: | 
|  | 39 | type: string | 
|  | 40 | description: Description of volume | 
|  | 41 | default: A volume description | 
|  | 42 |  | 
|  | 43 | resources: | 
|  | 44 | volume: | 
|  | 45 | type: OS::Cinder::Volume | 
|  | 46 | properties: | 
|  | 47 | backup_id: { get_param: backup_id } | 
|  | 48 | description: { get_param: volume_description } | 
|  | 49 |  | 
|  | 50 | volume_attachment: | 
|  | 51 | type: OS::Cinder::VolumeAttachment | 
|  | 52 | properties: | 
|  | 53 | volume_id: { get_resource: volume } | 
|  | 54 | instance_uuid: { get_resource: instance } | 
|  | 55 |  | 
|  | 56 | instance: | 
|  | 57 | type: OS::Nova::Server | 
|  | 58 | properties: | 
|  | 59 | image: { get_param: image_id } | 
|  | 60 | flavor: { get_param: instance_type } | 
|  | 61 | key_name: { get_param: key_name } | 
|  | 62 | networks: | 
|  | 63 | - uuid: {get_param: network} | 
|  | 64 | user_data_format: RAW | 
|  | 65 | user_data: | 
|  | 66 | str_replace: | 
|  | 67 | template: | | 
|  | 68 | #!/bin/sh | 
|  | 69 | # Trigger rescan to ensure we see the attached volume | 
|  | 70 | for i in /sys/class/scsi_host/*; do echo "- - -" > $i/scan; done | 
|  | 71 | # Wait for the rescan as the volume doesn't appear immediately | 
|  | 72 | for i in $(seq 1 rescan_timeout) | 
|  | 73 | do | 
|  | 74 | grep -q dev_name /proc/partitions && break | 
|  | 75 | sleep 1 | 
|  | 76 | done | 
|  | 77 | if grep -q dev_name /proc/partitions | 
|  | 78 | then | 
|  | 79 | mount /dev/dev_name /mnt | 
|  | 80 | TESTDATA=$(cat /mnt/testfile) | 
|  | 81 | curl -X PUT -H 'Content-Type:' --data-binary '{"Status": "SUCCESS", "Reason": "Test Complete", "Data": "Volume Data:'$TESTDATA'", "UniqueId": "instance1"}' "wc_url" | 
|  | 82 | else | 
|  | 83 | curl -X PUT -H 'Content-Type:' --data-binary '{"Status": "FAILURE", "Reason": "Test Failed", "Data": "Expected device dev_name not found.", "UniqueId": "instance1"}' "wc_url" | 
|  | 84 | fi | 
|  | 85 | params: | 
|  | 86 | wc_url: { get_resource: wait_handle } | 
|  | 87 | dev_name: { get_param: dev_name } | 
|  | 88 | rescan_timeout: { get_param: rescan_timeout } | 
|  | 89 |  | 
|  | 90 | wait_handle: | 
|  | 91 | type: OS::Heat::UpdateWaitConditionHandle | 
|  | 92 |  | 
|  | 93 | wait_condition: | 
|  | 94 | type: AWS::CloudFormation::WaitCondition | 
|  | 95 | properties: | 
|  | 96 | Count: 1 | 
|  | 97 | Handle: { get_resource: wait_handle } | 
|  | 98 | Timeout: { get_param: timeout } | 
|  | 99 |  | 
|  | 100 |  | 
|  | 101 | outputs: | 
|  | 102 | status: | 
|  | 103 | description: status | 
|  | 104 | value: { get_attr: ['volume', 'status'] } | 
|  | 105 |  | 
|  | 106 | size: | 
|  | 107 | description: size | 
|  | 108 | value: { get_attr: ['volume', 'size'] } | 
|  | 109 |  | 
|  | 110 | display_description: | 
|  | 111 | description: display_description | 
|  | 112 | value: { get_attr: ['volume', 'display_description'] } | 
|  | 113 |  | 
|  | 114 | volume_id: | 
|  | 115 | value: { get_resource: volume } | 
|  | 116 |  | 
|  | 117 | testfile_data: | 
|  | 118 | description: Contents of /mnt/testfile from the mounted volume | 
|  | 119 | value: { get_attr: ['wait_condition', 'Data'] } |