~openstack-charmers-archive/charms/precise/swift-storage/old-1501

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/openstack/templating.py

  • Committer: james.page at ubuntu
  • Date: 2014-07-28 11:54:32 UTC
  • mfrom: (32.1.3 swift-storage)
  • Revision ID: james.page@ubuntu.com-20140728115432-em4ntc388qe058e3
[corey.bryant,r=james-page] Add amulet tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    loading dir.
31
31
 
32
32
    A charm may also ship a templates dir with this module
33
 
    and it will be appended to the bottom of the search list, eg:
34
 
    hooks/charmhelpers/contrib/openstack/templates.
35
 
 
36
 
    :param templates_dir: str: Base template directory containing release
37
 
                               sub-directories.
38
 
    :param os_release   : str: OpenStack release codename to construct template
39
 
                               loader.
40
 
 
41
 
    :returns            : jinja2.ChoiceLoader constructed with a list of
42
 
                          jinja2.FilesystemLoaders, ordered in descending
43
 
                          order by OpenStack release.
 
33
    and it will be appended to the bottom of the search list, eg::
 
34
 
 
35
        hooks/charmhelpers/contrib/openstack/templates
 
36
 
 
37
    :param templates_dir (str): Base template directory containing release
 
38
        sub-directories.
 
39
    :param os_release (str): OpenStack release codename to construct template
 
40
        loader.
 
41
    :returns: jinja2.ChoiceLoader constructed with a list of
 
42
        jinja2.FilesystemLoaders, ordered in descending
 
43
        order by OpenStack release.
44
44
    """
45
45
    tmpl_dirs = [(rel, os.path.join(templates_dir, rel))
46
46
                 for rel in OPENSTACK_CODENAMES.itervalues()]
111
111
    and ease the burden of managing config templates across multiple OpenStack
112
112
    releases.
113
113
 
114
 
    Basic usage:
 
114
    Basic usage::
 
115
 
115
116
        # import some common context generates from charmhelpers
116
117
        from charmhelpers.contrib.openstack import context
117
118
 
131
132
        # write out all registered configs
132
133
        configs.write_all()
133
134
 
134
 
    Details:
 
135
    **OpenStack Releases and template loading**
135
136
 
136
 
    OpenStack Releases and template loading
137
 
    ---------------------------------------
138
137
    When the object is instantiated, it is associated with a specific OS
139
138
    release.  This dictates how the template loader will be constructed.
140
139
 
141
140
    The constructed loader attempts to load the template from several places
142
141
    in the following order:
143
 
        - from the most recent OS release-specific template dir (if one exists)
144
 
        - the base templates_dir
145
 
        - a template directory shipped in the charm with this helper file.
146
 
 
147
 
 
148
 
    For the example above, '/tmp/templates' contains the following structure:
 
142
    - from the most recent OS release-specific template dir (if one exists)
 
143
    - the base templates_dir
 
144
    - a template directory shipped in the charm with this helper file.
 
145
 
 
146
    For the example above, '/tmp/templates' contains the following structure::
 
147
 
149
148
        /tmp/templates/nova.conf
150
149
        /tmp/templates/api-paste.ini
151
150
        /tmp/templates/grizzly/api-paste.ini
169
168
    $CHARM/hooks/charmhelpers/contrib/openstack/templates.  This allows
170
169
    us to ship common templates (haproxy, apache) with the helpers.
171
170
 
172
 
    Context generators
173
 
    ---------------------------------------
 
171
    **Context generators**
 
172
 
174
173
    Context generators are used to generate template contexts during hook
175
174
    execution.  Doing so may require inspecting service relations, charm
176
175
    config, etc.  When registered, a config file is associated with a list