mirror of
https://github.com/ceph/ceph
synced 2024-12-28 14:34:13 +00:00
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 <dan.mick@inktank.com>
This commit is contained in:
parent
c1bc7fcc7f
commit
9b2b2c28f1
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user