From: Angus Salkeld Date: Fri, 27 Apr 2012 03:02:58 +0000 (+1000) Subject: Add cfn-get-metadata make all cfn tools more consistent X-Git-Tag: 2014.1~1912 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f7c677354261a78cacc1affab27ddb48a209ba6c;p=openstack-build%2Fheat-build.git Add cfn-get-metadata make all cfn tools more consistent Signed-off-by: Angus Salkeld --- diff --git a/heat/cfntools/cfn-get-metadata b/heat/cfntools/cfn-get-metadata new file mode 100755 index 00000000..9a9468b8 --- /dev/null +++ b/heat/cfntools/cfn-get-metadata @@ -0,0 +1,83 @@ +#!/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-get-metadata CloudFormation functionality +""" +import argparse +import io +import logging +import os +import os.path +import sys + + +if os.path.exists('/opt/aws/bin'): + sys.path.insert(0, '/opt/aws/bin') + from cfn_helper import * +else: + from heat.cfntools.cfn_helper import * + +description = " " +parser = argparse.ArgumentParser(description=description) +parser.add_argument('-s', '--stack', + dest="stack_name", + help="A Heat stack name", + required=False) +parser.add_argument('-r', '--resource', + dest="logical_resource_id", + help="A Heat logical resource ID", + required=False) +parser.add_argument('--access-key', + dest="access_key", + help="A Keystone access key", + required=False) +parser.add_argument('--secret-key', + dest="secret_key", + help="A Keystone secret key", + required=False) +parser.add_argument('--region', + dest="region", + help="Openstack region", + required=False) +parser.add_argument('--credential-file', + dest="credential_file", + help="credential-file", + required=False) +parser.add_argument('-u', '--url', + dest="url", + help="service url", + required=False) +parser.add_argument('-k', '--key', + dest="key", + help="key", + required=False) +args = parser.parse_args() + +log_format = '%(levelname)s [%(asctime)s] %(message)s' +logging.basicConfig(format=log_format, level=logging.DEBUG) + +logger = logging.getLogger('cfn-get-metadata') +log_file_name = "/var/log/cfn-get-metadata.log" +file_handler = logging.FileHandler(log_file_name) +file_handler.setFormatter(logging.Formatter(log_format)) +logger.addHandler(file_handler) + +metadata = Metadata(args.stack_name, + args.logical_resource_id, + access_key=args.access_key, + secret_key=args.secret_key, + region=args.region) +metadata.retrieve() +print str(metadata) diff --git a/heat/cfntools/cfn-hup b/heat/cfntools/cfn-hup index 1291e67b..d4ea2897 100755 --- a/heat/cfntools/cfn-hup +++ b/heat/cfntools/cfn-hup @@ -47,20 +47,19 @@ parser.add_argument('-v', '--verbose', help="Verbose logging", required=False) args = parser.parse_args() -# FIXME: implement real arg -logger = logging.getLogger('cfn-hup') -log_file_name = "/var/log/cfn-hup.log" log_format = '%(levelname)s [%(asctime)s] %(message)s' -file_handler = logging.FileHandler(log_file_name) -file_handler.setFormatter(logging.Formatter(log_format)) -logging.getLogger().addHandler(file_handler) - if args.verbose: logging.basicConfig(format=log_format, level=logging.DEBUG) else: logging.basicConfig(format=log_format, level=logging.INFO) +logger = logging.getLogger('cfn-hup') +log_file_name = "/var/log/cfn-hup.log" +file_handler = logging.FileHandler(log_file_name) +file_handler.setFormatter(logging.Formatter(log_format)) +logger.addHandler(file_handler) + main_conf_path = '/etc/cfn/cfn-hup.conf' try: main_config_file = open(main_conf_path) diff --git a/heat/cfntools/cfn-init b/heat/cfntools/cfn-init index 6eb9715b..9008170a 100755 --- a/heat/cfntools/cfn-init +++ b/heat/cfntools/cfn-init @@ -14,20 +14,6 @@ """ Implements cfn-init CloudFormation functionality - -Resource metadata currently implemented: - * config/packages - * config/services - -Not implemented yet: - * config sets - * config/sources - * config/commands - * config/files - * config/users - * config/groups - * command line args - - placeholders are ignored """ import argparse @@ -42,14 +28,6 @@ if os.path.exists('/opt/aws/bin'): else: from heat.cfntools.cfn_helper import * -logger = logging.getLogger('cfn-init') -log_file_name = "/var/log/cfn-init.log" -log_format = '%(levelname)s [%(asctime)s] %(message)s' -file_handler = logging.FileHandler(log_file_name) -file_handler.setFormatter(logging.Formatter(log_format)) -logging.getLogger().addHandler(file_handler) -logging.basicConfig(format=log_format, level=logging.DEBUG) - description = " " parser = argparse.ArgumentParser(description=description) parser.add_argument('-s', '--stack', @@ -73,7 +51,15 @@ parser.add_argument('--region', help="Openstack region", required=False) args = parser.parse_args() -# FIXME: implement real arg + +log_format = '%(levelname)s [%(asctime)s] %(message)s' +logging.basicConfig(format=log_format, level=logging.DEBUG) + +logger = logging.getLogger('cfn-init') +log_file_name = "/var/log/cfn-init.log" +file_handler = logging.FileHandler(log_file_name) +file_handler.setFormatter(logging.Formatter(log_format)) +logger.addHandler(file_handler) metadata = Metadata(args.stack_name, args.logical_resource_id, diff --git a/heat/cfntools/cfn_helper.py b/heat/cfntools/cfn_helper.py index 637cdab3..4d69dbd8 100644 --- a/heat/cfntools/cfn_helper.py +++ b/heat/cfntools/cfn_helper.py @@ -681,6 +681,9 @@ class Metadata(object): else: self._metadata = self._data + def __str__(self): + return self._metadata + def _is_valid_metadata(self): """ Should find the AWS::CloudFormation::Init json key diff --git a/heat/utils.py b/heat/utils.py index df4756fe..5d7e1532 100644 --- a/heat/utils.py +++ b/heat/utils.py @@ -137,7 +137,9 @@ def jeos_create(options, arguments): # and injecting them into the TDL at the appropriate place if instance_type == 'cfntools': tdl_xml = libxml2.parseFile(tdl_path) - for cfnname in ['cfn-init', 'cfn-hup', 'cfn-signal', 'cfn_helper.py']: + cfn_tools = ['cfn-init', 'cfn-hup', 'cfn-signal', \ + 'cfn-get-metadata', 'cfn_helper.py'] + for cfnname in cfn_tools: f = open('%s/%s' % (cfntools_path, cfnname), 'r') cfscript_e64 = base64.b64encode(f.read()) f.close()