Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More options when working with override files #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 25 additions & 2 deletions images/portal/resources/toolset/toolset/commands/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import time
import yaml

from fnmatch import fnmatch
from ochopod.core.fsm import diagnostic
from ochopod.core.utils import merge, retry, shell
from random import choice
Expand All @@ -30,6 +31,7 @@
from toolset.tool import Template
from yaml import YAMLError


#: Our ochopod logger.
logger = logging.getLogger('ochopod')

Expand Down Expand Up @@ -110,9 +112,29 @@ def run(self):
stamp = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d-%H-%M-%S')
qualified = '%s.%s' % (self.namespace, cfg['cluster'])
application = 'ochopod.%s-%s' % (qualified, stamp)

#
# - use regexps to look for overrides
# - can match multiple overrides
# - used for general properties
#
matches = [key for key, _ in self.overrides.iteritems()
if key != qualified and fnmatch(qualified, key)]
blk = {}
if matches:
# iterate trough all the key matches merging the overrides
for key in matches:
blk = merge(blk, self.overrides[key])
#
# - use the most specific overrides over the general ones
#
if qualified in self.overrides:
blk = merge(blk, self.overrides[qualified])

blk = self.overrides[qualified]
#
# - merge the overrides with the current configuration
#
if blk:
logger.debug('%s : overriding %d settings (%s)' % (self.template, len(blk), qualified))
cfg['settings'] = merge(cfg['settings'], blk)

Expand Down Expand Up @@ -333,7 +355,8 @@ def body(self, args, _, proxy):
for path in args.overrides:
try:
with open(path, 'r') as f:
overrides.update(yaml.load(f))
logger.debug('merging %s into overrides' % path)
overrides = merge(overrides, yaml.load(f))

except IOError:

Expand Down