~niedbalski/charm-helpers/fetch_is-package-installed

« back to all changes in this revision

Viewing changes to charmhelpers/contrib/templating/contexts.py

  • Committer: Michael Nelson
  • Date: 2014-04-08 14:55:46 UTC
  • mfrom: (136.2.5 fresh-relations)
  • Revision ID: michael.nelson@canonical.com-20140408145546-n74be213bcqt115t
[r=bloodearnest] Simplify the relations dict provided in the ansible helpers to just use hookenv.relations() and add current_relation to context.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    # Add any relation data prefixed with the relation type.
24
24
    relation_type = charmhelpers.core.hookenv.relation_type()
25
25
    relations = []
 
26
    context['current_relation'] = {}
26
27
    if relation_type is not None:
27
28
        relation_data = charmhelpers.core.hookenv.relation_get()
 
29
        context['current_relation'] = relation_data
 
30
        # Deprecated: the following use of relation data as keys
 
31
        # directly in the context will be removed.
28
32
        relation_data = dict(
29
33
            ("{relation_type}{namespace_separator}{key}".format(
30
34
                relation_type=relation_type,
36
40
        relations = charmhelpers.core.hookenv.relations_of_type(relation_type)
37
41
        relations = [dict_keys_without_hyphens(rel) for rel in relations]
38
42
 
39
 
    if 'relations' not in context:
40
 
        context['relations'] = {}
 
43
    if 'relations_deprecated' not in context:
 
44
        context['relations_deprecated'] = {}
41
45
    if relation_type is not None:
42
46
        relation_type = relation_type.replace('-', '_')
43
 
        context['relations'][relation_type] = relations
 
47
        context['relations_deprecated'][relation_type] = relations
 
48
 
 
49
    context['relations'] = charmhelpers.core.hookenv.relations()
44
50
 
45
51
 
46
52
def juju_state_to_yaml(yaml_path, namespace_separator=':',