Browse Source

Add retries for throttling events, add jinja loop extensions, minor bugfixes

master
Stefan Reimer 3 years ago
parent
commit
25c375728a
  1. 16
      cloudbender/connection.py
  2. 5
      cloudbender/core.py
  3. 8
      cloudbender/jinja.py
  4. 2
      cloudbender/stack.py
  5. 2
      cloudbender/stackgroup.py

16
cloudbender/connection.py

@ -1,4 +1,5 @@
import os
import time
import boto3
import botocore.session
@ -51,5 +52,16 @@ class BotoConnection():
def call(self, service, command, kwargs={}, profile=None, region=None):
client = self._get_client(service, profile, region)
return getattr(client, command)(**kwargs)
while True:
try:
client = self._get_client(service, profile, region)
return getattr(client, command)(**kwargs)
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == 'Throttling':
logger.warning("Throttling exception occured during {} - retry after 3s".format(command))
time.sleep(3)
pass
else:
raise e

5
cloudbender/core.py

@ -21,6 +21,9 @@ class CloudBender(object):
"parameter_path": os.path.join(self.root, "parameters"),
"artifact_paths": [os.path.join(self.root, "artifacts")]
}
self.default_settings = {
'vars': { 'Mode': 'FortyTwo' }
}
if not os.path.isdir(self.root):
raise "Check '{0}' exists and is a valid project folder.".format(root_path)
@ -54,7 +57,7 @@ class CloudBender(object):
ensure_dir(self.ctx[k])
self.sg = StackGroup(self.ctx['config_path'], self.ctx)
self.sg.read_config()
self.sg.read_config(self.default_settings)
self.all_stacks = self.sg.get_stacks()

8
cloudbender/jinja.py

@ -149,15 +149,17 @@ def pyminify(source, obfuscate=False, minify=True):
#source = pyminifier.obfuscate.apply_obfuscation(source)
source = pyminifier.token_utils.untokenize(tokens)
# logger.debug(source)
#logger.info(source)
minified_source = pyminifier.compression.gz_pack(source)
logger.info("Compressed python code to {}".format(len(minified_source)))
return minified_source
def JinjaEnv(template_locations=[]):
jenv = jinja2.Environment(trim_blocks=True, lstrip_blocks=True, undefined=jinja2.Undefined)
jenv = jinja2.Environment(trim_blocks=True,
lstrip_blocks=True,
undefined=jinja2.Undefined,
extensions=['jinja2.ext.loopcontrols'])
jinja_loaders = []
for _dir in template_locations:

2
cloudbender/stack.py

@ -62,7 +62,7 @@ class Stack(object):
def read_config(self):
_config = read_yaml_file(self.path)
for p in ["stackname", "template", "dependencies", "default_lock", "multi_delete", "provides"]:
for p in ["region", "stackname", "template", "dependencies", "default_lock", "multi_delete", "provides"]:
if p in _config:
setattr(self, p, _config[p])

2
cloudbender/stackgroup.py

@ -56,7 +56,7 @@ class StackGroup(object):
profile = _config.get('profile', '')
stackname_prefix = _config.get('stacknameprefix', '')
logger.info("StackGroup {} added.".format(self.name))
logger.debug("StackGroup {} added.".format(self.name))
# Add stacks
stacks = [s for s in glob.glob(os.path.join(self.path, '*.yaml')) if not s.endswith("config.yaml")]

Loading…
Cancel
Save