]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
misc.py: helper roles_to_remotes for generic use
authorDan Mick <dan.mick@inktank.com>
Sat, 1 Feb 2014 00:07:52 +0000 (16:07 -0800)
committerDan Mick <dan.mick@inktank.com>
Tue, 4 Feb 2014 03:37:59 +0000 (19:37 -0800)
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>
teuthology/misc.py

index 1bc2fa65b21483a1f4071cae375336eb051c70b2..2f7495332bc8495a8c0e688afa38c4fe9a9c7deb 100644 (file)
@@ -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: