On Tue, May 27, 2014 at 09:58:39AM +0100, Adam Coldrick wrote:
Instead of taking the name of a cluster morphology and zero or more
parameters for overriding the cluster morphology, morph deploy should
take the name of a cluster morphology and the names of zero or more
system deployments that are defined in the cluster morphology. If no
deployment names are given then all deployments are deployed.
The parameters can still be passed in the same format as before using
the `--param="SYSTEM.KEY=VALUE"` option.
This part of the commit message is left over from the previous version.
---
morphlib/plugins/deploy_plugin.py | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py
index 1d58294..378df21 100644
--- a/morphlib/plugins/deploy_plugin.py
+++ b/morphlib/plugins/deploy_plugin.py
@@ -35,10 +35,9 @@ class DeployPlugin(cliapp.Plugin):
'existing cluster of systems rather than do '
'an initial deployment',
group=group_deploy)
-
self.app.add_subcommand(
'deploy', self.deploy,
- arg_synopsis='CLUSTER [SYSTEM.KEY=VALUE]')
+ arg_synopsis='CLUSTER [DEPLOYMENT...] [SYSTEM.KEY=VALUE]')
def disable(self):
pass
@@ -275,7 +274,6 @@ class DeployPlugin(cliapp.Plugin):
'/', 0)
cluster_name = morphlib.util.strip_morph_extension(args[0])
- env_vars = args[1:]
ws = morphlib.workspace.open('.')
sb = morphlib.sysbranchdir.open_from_within('.')
@@ -302,6 +300,17 @@ class DeployPlugin(cliapp.Plugin):
"Error: morph deploy is only supported for cluster"
" morphologies.")
+ # parse the rest of the args
+ all_deployments = set()
+ deployments = set()
+ for system in cluster_morphology['systems']:
+ all_deployments.update([sys_id for sys_id in system['deploy']])
You can use a generator expression here instead of a list comprehension
by omitting the outer [].
+ for item in args[1:]:
+ if not item in all_deployments:
+ break
+ deployments.add(item)
+ env_vars = args[len(deployments) + 1:]
I'm not suggesting you should use this, but the following does the same
thing in a more functional manner. It may be of interest to you.
res = dict(itertools.groupby(args[1:], x.__contains__))
deployments = set(res[True])
env_vars = set(res[False])
@@ -343,7 +352,11 @@ class DeployPlugin(cliapp.Plugin):
def deploy_system(self, build_command, deploy_tempdir,
root_repo_dir, build_repo, ref, system, env_vars,
- parent_location):
+ deployments, parent_location):
+ sys_ids = [sys_id for sys_id, _ in system['deploy'].iteritems()]
You don't use sys_ids for anything but the test here, so I'd be tempted
to create sys_ids as a set instead, as the lookup is cheaper after you
get past trivial sizes.
+ if deployments and not \
+ any(sys_id in deployments for sys_id in sys_ids):
+ return
old_status_prefix = self.app.status_prefix
system_status_prefix = '%s[%s]' % (old_status_prefix,
system['morph'])
self.app.status_prefix = system_status_prefix