diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-04-13 11:22:28 +0000 |
---|---|---|
committer | Baserock Gerrit <gerrit@baserock.org> | 2015-04-21 11:03:13 +0000 |
commit | 1c01f18a0c6501d7b5206bfef68d9128b7ba1996 (patch) | |
tree | 71e426cf6ba3f217b00f5c5aa99c5975346fd10a /morphlib/plugins | |
parent | f323af122fcfbf31061a04309adc21fbcdae25fa (diff) | |
download | morph-1c01f18a0c6501d7b5206bfef68d9128b7ba1996.tar.gz |
deploy: Factor out a bit of code into its own function
This behaviour is complex, it shouldn't be hidden away in a larger
function.
Change-Id: I953c9477e0210d395b97f5f8219eaebe4dbcd272
Diffstat (limited to 'morphlib/plugins')
-rw-r--r-- | morphlib/plugins/deploy_plugin.py | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py index 63cc4688..d31bf8e8 100644 --- a/morphlib/plugins/deploy_plugin.py +++ b/morphlib/plugins/deploy_plugin.py @@ -26,6 +26,41 @@ import cliapp import morphlib +def configuration_for_system(system_id, vars_from_commandline, + deploy_defaults, deploy_params): + '''Collect all configuration variables for deploying one system. + + This function collects variables from the following places: + + - the values specified in the 'deploy-defaults' section of the cluster + .morph file. + - values specified in the stanza for the system in the cluster.morph file + - environment variables of the running `morph deploy` process + - values specified on the `morph deploy` commandline, for example + `mysystem.HOSTNAME=foo`. + + Later values override earlier ones, so 'deploy-defaults' has the lowest + precidence and the `morph deploy` commandline has highest precidence. + + ''' + commandline_vars_for_system = [ + pair[len(system_id)+1:] for pair in vars_from_commandline + if pair.startswith(system_id)] + + user_env = morphlib.util.parse_environment_pairs( + os.environ, commandline_vars_for_system) + + # Order is important here: the second dict overrides the first, the third + # overrides the second. + final_env = dict(deploy_defaults.items() + + deploy_params.items() + + user_env.items()) + + morphlib.util.sanitize_environment(final_env) + + return final_env + + class DeployPlugin(cliapp.Plugin): def enable(self): @@ -453,15 +488,8 @@ class DeployPlugin(cliapp.Plugin): system_status_prefix, system_id) self.app.status_prefix = deployment_status_prefix try: - user_env = morphlib.util.parse_environment_pairs( - os.environ, - [pair[len(system_id)+1:] - for pair in env_vars - if pair.startswith(system_id)]) - - final_env = dict(deploy_defaults.items() + - deploy_params.items() + - user_env.items()) + final_env = configuration_for_system( + system_id, env_vars, deploy_defaults, deploy_params) is_upgrade = ('yes' if self.app.settings['upgrade'] else 'no') @@ -477,7 +505,6 @@ class DeployPlugin(cliapp.Plugin): raise morphlib.Error('"location" is undefined ' 'for system "%s"' % system_id) - morphlib.util.sanitize_environment(final_env) self.check_deploy(root_repo_dir, ref, deployment_type, location, final_env) system_tree = self.setup_deploy(build_command, |