diff options
author | Kenneth Wilke <kenneth.wilke@rackspace.com> | 2013-07-23 16:29:29 -0500 |
---|---|---|
committer | Michael Basnight <mbasnight@gmail.com> | 2013-07-31 10:35:27 -0700 |
commit | 80c22c517a7bda1cbde5dc42f7a661f1af3b2d5a (patch) | |
tree | 22f4a39bcc9cdcfc72e49c27f555559ff7e4df20 /trove/common/template.py | |
parent | a9eb50ec601ef09de261c635856ecf8884dc7d4c (diff) | |
download | trove-80c22c517a7bda1cbde5dc42f7a661f1af3b2d5a.tar.gz |
Added docs and made template filename variable
Changed how jinja ENV is created
Added docstrings to functions in template.py
Renamed _location_types private attribute of
SingleInstanceConfigTemplate to _config_paths
SingleInstanceConfigTemplate constructor now uses filename based on
service type
SingleInstanceConfigTemplate render method now returns the result
Tests updated to use new style of render method
mysql.config.template duplicated to percona.config.template
implements blueprint redis-servicetype
Change-Id: Id9317b560236d5d4967b888d0dc3a4135f1822dc
Diffstat (limited to 'trove/common/template.py')
-rw-r--r-- | trove/common/template.py | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/trove/common/template.py b/trove/common/template.py index dafc626b..df5dc4e6 100644 --- a/trove/common/template.py +++ b/trove/common/template.py @@ -12,35 +12,40 @@ # License for the specific language governing permissions and limitations # under the License. -_ENV = None - import jinja2 - -def get_env(): - global _ENV - if not _ENV: - _ENV = create_env() - return _ENV +ENV = jinja2.Environment(loader=jinja2.ChoiceLoader([ + jinja2.FileSystemLoader("/etc/trove/templates"), + jinja2.PackageLoader("trove", "templates") +])) -def create_env(): - loader = jinja2.ChoiceLoader([ - jinja2.FileSystemLoader("/etc/trove/templates"), - jinja2.PackageLoader("trove", "templates") - ]) - return jinja2.Environment(loader=loader) +class SingleInstanceConfigTemplate(object): + """ This class selects a single configuration file by database type for + rendering on the guest """ + _config_paths = {'mysql': '/etc/mysql/my.cnf', + 'percona': '/etc/mysql/my.cnf'} + def __init__(self, service_type, flavor_dict): + """ Constructor -class SingleInstanceConfigTemplate(object): - _location_types = {'mysql': '/etc/mysql/my.cnf', - 'percona': '/etc/mysql/my.cnf'} + :param service_type: The database type. + :type name: str. + :param flavor_dict: dict containing flavor details for use in jinja. + :type flavor_dict: dict. - def __init__(self, location_type, flavor_dict): - self.config_location = self._location_types[location_type] + """ + self.config_location = self._config_paths[service_type] self.flavor_dict = flavor_dict - self.template = get_env().get_template("mysql.config.template") + template_filename = "%s.config.template" % service_type + self.template = ENV.get_template(template_filename) def render(self): + """ Renders the jinja template + + :returns: str -- The rendered configuration file + + """ self.config_contents = self.template.render( flavor=self.flavor_dict) + return self.config_contents |