aboutsummaryrefslogtreecommitdiffstats
path: root/charms/trusty/ceilometer-contrail/hooks/ceilometer_contrail_utils.py
blob: 6bab06e3263d31532feb29bbf2a1eb339d014529 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from collections import OrderedDict

import yaml

from charmhelpers.core.hookenv import (
    related_units,
    relation_get,
    relation_ids
)

def ordereddict_representer(dumper, data):
    return dumper.represent_mapping("tag:yaml.org,2002:map", data.items())

yaml.add_representer(OrderedDict, ordereddict_representer)

def contrail_analytics_api_units():
    """Return a list of contrail analytics api units"""
    return [ unit for rid in relation_ids("contrail-analytics-api")
                  for unit in related_units(rid)
                  if relation_get("port", unit, rid) ]

def units(relation):
    """Return a list of units for the specified relation"""
    return [ unit for rid in relation_ids(relation)
                  for unit in related_units(rid) ]