Software config hook to provision using cfn-init

This hook uses heat-cfntools cfn_helper as a lib and loads the
metadata directly, then invokes the cfn_init directly.

Change-Id: Iebc184a0fa65eb6424df8f751cb172186c9ec30e
Closes-Bug: #1279065
This commit is contained in:
Steve Baker 2014-04-03 13:51:36 +13:00
parent b011cd466f
commit 50ff119093
4 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,3 @@
A hook which consumes configuration in the format of AWS::CloudFormation::Init
metadata. It is provided to enable migrating from CloudFormation metadata
configuration to configuration using config and deployment resources.

View File

@ -0,0 +1,6 @@
#!/bin/bash
set -x
SCRIPTDIR=$(dirname $0)
install -D -g root -o root -m 0755 ${SCRIPTDIR}/hook-cfn-init.py /var/lib/heat-config/hooks/cfn-init

View File

@ -0,0 +1,20 @@
#!/usr/bin/env python
from heat_cfntools.cfntools import cfn_helper
import json
import sys
def main(argv=sys.argv):
c = json.load(sys.stdin)
config = c.get('config', {})
if not isinstance(config, dict):
config = json.loads(config)
meta = {'AWS::CloudFormation::Init': config}
metadata = cfn_helper.Metadata(None, None)
metadata.retrieve(meta_str=json.dumps(meta))
metadata.cfn_init()
if __name__ == '__main__':
sys.exit(main(sys.argv))

View File

@ -0,0 +1,98 @@
heat_template_version: 2013-05-23
parameters:
key_name:
type: string
flavor:
type: string
image:
type: string
default: fedora-software-config
resources:
the_sg:
type: OS::Neutron::SecurityGroup
properties:
name: the_sg
description: Ping and SSH
rules:
- protocol: icmp
- protocol: tcp
port_range_min: 22
port_range_max: 22
config:
type: OS::Heat::StructuredConfig
properties:
group: cfn-init
inputs:
- name: bar
config:
config:
files:
/tmp/foo:
content:
get_input: bar
mode: '000644'
check_tmp_foo:
type: OS::Heat::SoftwareConfig
properties:
group: script
outputs:
- name: result
config: |
#!/bin/sh
echo -n "The file /tmp/foo contains `cat /tmp/foo` for server $deploy_server_id during $deploy_action" > $heat_outputs_path.result
deployment:
type: OS::Heat::StructuredDeployment
properties:
name: 10_deployment
signal_transport: NO_SIGNAL
config:
get_resource: config
server:
get_resource: server
input_values:
bar: baaaaa
other_deployment:
type: OS::Heat::StructuredDeployment
properties:
name: 20_other_deployment
signal_transport: NO_SIGNAL
config:
get_resource: config
server:
get_resource: server
input_values:
bar: barmy
actions:
- CREATE
- UPDATE
- SUSPEND
- RESUME
deploy_check_tmp_foo:
type: OS::Heat::SoftwareDeployment
properties:
name: 30_deploy_check_tmp_foo
config:
get_resource: check_tmp_foo
server:
get_resource: server
server:
type: OS::Nova::Server
properties:
image: {get_param: image}
flavor: {get_param: flavor}
key_name: {get_param: key_name}
security_groups:
- {get_resource: the_sg}
user_data_format: SOFTWARE_CONFIG
outputs:
result:
value:
get_attr: [deploy_check_tmp_foo, result]