93 lines
2.7 KiB
Python
Executable File
93 lines
2.7 KiB
Python
Executable File
#!/usr/bin/env python
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
"""
|
|
Implements cfn-signal CloudFormation functionality
|
|
"""
|
|
import argparse
|
|
import logging
|
|
import os
|
|
import sys
|
|
|
|
|
|
if os.path.exists('/opt/aws/bin'):
|
|
sys.path.insert(0, '/opt/aws/bin')
|
|
from cfn_helper import *
|
|
else:
|
|
from heat_cfntools.cfntools.cfn_helper import *
|
|
|
|
|
|
description = " "
|
|
parser = argparse.ArgumentParser(description=description)
|
|
parser.add_argument('-s', '--success',
|
|
dest="success",
|
|
help="signal status to report",
|
|
default='true',
|
|
required=False)
|
|
parser.add_argument('-r', '--reason',
|
|
dest="reason",
|
|
help="The reason for the failure",
|
|
default="Configuration Complete",
|
|
required=False)
|
|
parser.add_argument('--data',
|
|
dest="data",
|
|
default="Application has completed configuration.",
|
|
help="The data to send",
|
|
required=False)
|
|
parser.add_argument('-i', '--id',
|
|
dest="unique_id",
|
|
help="the unique id to send back to the WaitCondition",
|
|
default='00000',
|
|
required=False)
|
|
parser.add_argument('-e', '--exit',
|
|
dest="exit_code",
|
|
help="The exit code from a procecc to interpret",
|
|
default=None,
|
|
required=False)
|
|
parser.add_argument('url',
|
|
help='the url to post to')
|
|
args = parser.parse_args()
|
|
|
|
log_format = '%(levelname)s [%(asctime)s] %(message)s'
|
|
logging.basicConfig(format=log_format, level=logging.DEBUG)
|
|
|
|
LOG = logging.getLogger('cfntools')
|
|
log_file_name = "/var/log/cfn-signal.log"
|
|
file_handler = logging.FileHandler(log_file_name)
|
|
file_handler.setFormatter(logging.Formatter(log_format))
|
|
LOG.addHandler(file_handler)
|
|
|
|
LOG.debug('cfn-signal called %s ' % (str(args)))
|
|
|
|
status = 'FAILURE'
|
|
if args.exit_code:
|
|
# "exit_code" takes presedence over "success".
|
|
if args.exit_code == '0':
|
|
status = 'SUCCESS'
|
|
else:
|
|
if args.success == 'true':
|
|
status = 'SUCCESS'
|
|
|
|
body = {
|
|
"Status" : status,
|
|
"Reason" : args.reason,
|
|
"UniqueId" : args.unique_id,
|
|
"Data" : args.data
|
|
}
|
|
|
|
cmd_str = "curl -X PUT -H \'Content-Type:\' --data-binary \'%s\' \"%s\"" % \
|
|
(json.dumps(body), args.url)
|
|
command = CommandRunner(cmd_str).run()
|
|
sys.exit(command.status)
|