From 9b2b2c28f11fbc75509b1dbf42fe2b2c7056017f Mon Sep 17 00:00:00 2001 From: Dan Mick Date: Fri, 31 Jan 2014 16:07:52 -0800 Subject: [PATCH] misc.py: helper roles_to_remotes for generic use roles_to_remotes will take a config key, 'roles' by default, and search cluster.remotes for those roles, returning a list of remotes that hold it. The list is uniquified by default, but that can be overridden. So you can have a task that should run on specific roles, configure it with "roles: [mon.0 server.0 osd.2]", and call this to get a list of remotes that contain those roles. Signed-off-by: Dan Mick --- teuthology/misc.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/teuthology/misc.py b/teuthology/misc.py index 1bc2fa65b2..2f7495332b 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -872,6 +872,21 @@ def replace_all_with_clients(cluster, config): norm_config['client.{id}'.format(id=client)] = config['all'] return norm_config +def roles_to_remotes(cluster, config, attrname='roles', unique=True): + """ + Get a list of roles from attrname, and return a list of + remotes corresponding to those roles. If 'unique' is False, + allow duplicates in the returned remote list (if a remote serves + multiple roles). attrname may not exist, in which case the + returned list is empty. + """ + roles = config.get(attrname, list()) + remotes = [] + for role in roles: + rem = cluster.only(role).remotes.keys()[0] + if (not unique) or (rem not in remotes): + remotes.append(rem) + return remotes def deep_merge(a, b): if a is None: -- 2.39.5