Toolset to render and manage AWS CloudFormation ( )
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.0 KiB

4 years ago
import os
import yaml
import copy
import logging
import boto3
logger = logging.getLogger(__name__)
4 years ago
def read_yaml_file(path):
data = {}
if os.path.exists(path):
with open(path, 'r') as config_file_contents:
logger.debug("Reading config file: {}".format(path))
_data = yaml.load(
if _data:
except Exception as e:
logger.warning("Error reading config file: {} ({})".format(path, e))
4 years ago
return data
def dict_merge(a, b):
""" Deep merge to allow proper inheritance for config files"""
if not a:
return b
if not b:
return a
if not isinstance(a, dict) or not isinstance(b, dict):
4 years ago
raise TypeError
result = copy.deepcopy(a)
for k, v in b.items():
if k in result and isinstance(result[k], dict):
result[k] = dict_merge(result[k], v)
4 years ago
result[k] = copy.deepcopy(v)
return result
def ensure_dir(path):
"""Creates dir if it does not already exist."""
if not os.path.exists(path):
os.makedirs(path)'Created directory: %s', path)
def setup_logging(debug):
if debug:
our_level = logging.DEBUG
# logging.getLogger("botocore").setLevel(logging.INFO)
formatter = logging.Formatter(
fmt="[%(asctime)s] %(name)s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S"
4 years ago
our_level = logging.INFO
formatter = logging.Formatter(
fmt="[%(asctime)s] %(message)s",
datefmt="%Y-%m-%d %H:%M:%S"
4 years ago
log_handler = logging.StreamHandler()
logger = logging.getLogger("cloudbender")
return logger