2015-06-12 16:27:31 +00:00
|
|
|
import operator
|
|
|
|
|
|
|
|
|
2015-06-12 17:02:52 +00:00
|
|
|
def invert_fedmsg_policy(groups, vars, env):
|
2015-06-12 16:27:31 +00:00
|
|
|
""" Given hostvars that map hosts -> topics, invert that
|
|
|
|
and return a dict that maps topics -> hosts.
|
|
|
|
|
|
|
|
Really, returns a list of tuples -- not a dict.
|
|
|
|
"""
|
|
|
|
|
2015-06-12 17:02:52 +00:00
|
|
|
if env == 'staging':
|
2019-05-22 00:09:09 +00:00
|
|
|
hosts = groups['all'] + groups['staging'] + groups['fedmsg_qa_network_stg'] + groups['openshift_pseudohosts_stg']
|
2015-06-12 17:02:52 +00:00
|
|
|
else:
|
2019-05-20 17:36:07 +00:00
|
|
|
hosts = [h for h in groups['all'] if h not in groups['staging'] + groups['openshift_pseudohosts_stg']]
|
2015-06-12 17:02:52 +00:00
|
|
|
|
2015-06-12 16:27:31 +00:00
|
|
|
inverted = {}
|
2015-06-12 16:45:41 +00:00
|
|
|
for host in hosts:
|
2015-06-12 16:27:31 +00:00
|
|
|
prefix = '.'.join([vars[host]['fedmsg_prefix'],
|
|
|
|
vars[host]['fedmsg_env']])
|
2015-06-12 16:47:53 +00:00
|
|
|
fqdn = vars[host].get('fedmsg_fqdn', host)
|
2015-06-12 16:27:31 +00:00
|
|
|
|
2015-06-12 16:29:45 +00:00
|
|
|
for cert in vars[host]['fedmsg_certs']:
|
2015-06-12 16:27:31 +00:00
|
|
|
for topic in cert.get('can_send', []):
|
|
|
|
key = prefix + '.' + topic
|
|
|
|
inverted[key] = inverted.get(key, [])
|
|
|
|
inverted[key].append(cert['service'] + '-' + fqdn)
|
|
|
|
|
|
|
|
result = inverted.items()
|
2015-06-12 16:51:36 +00:00
|
|
|
# Sort things so they come out in a reliable order (idempotence)
|
|
|
|
[inverted[key].sort() for key in inverted]
|
2015-06-12 16:27:31 +00:00
|
|
|
result.sort(key=operator.itemgetter(0))
|
|
|
|
return result
|
2015-06-12 16:30:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FilterModule(object):
|
|
|
|
def filters(self):
|
|
|
|
return {
|
2015-06-12 16:42:46 +00:00
|
|
|
"invert_fedmsg_policy": invert_fedmsg_policy,
|
2015-06-12 16:30:46 +00:00
|
|
|
}
|