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 <dan.mick@inktank.com>
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: