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 1 commit
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
26 changes: 24 additions & 2 deletions images/portal/resources/toolset/toolset/commands/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from toolset.io import fire, run
from toolset.tool import Template
from yaml import YAMLError
import re
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you really need re ? can't you use regex using fnmatch ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fnmatch seems to work. Will update the pull request.


#: Our ochopod logger.
logger = logging.getLogger('ochopod')
Expand Down Expand Up @@ -110,9 +111,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 re.search(key, qualified)]
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 +354,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