本文整理汇总了Python中charmhelpers.core.templating.render方法的典型用法代码示例。如果您正苦于以下问题:Python templating.render方法的具体用法?Python templating.render怎么用?Python templating.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类charmhelpers.core.templating
的用法示例。
在下文中一共展示了templating.render方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from charmhelpers.core import templating [as 别名]
# 或者: from charmhelpers.core.templating import render [as 别名]
def __call__(self, manager, service_name, event_name):
pre_checksum = ''
if self.on_change_action and os.path.isfile(self.target):
pre_checksum = host.file_hash(self.target)
service = manager.get_service(service_name)
context = {'ctx': {}}
for ctx in service.get('required_data', []):
context.update(ctx)
context['ctx'].update(ctx)
result = templating.render(self.source, self.target, context,
self.owner, self.group, self.perms,
template_loader=self.template_loader)
if self.on_change_action:
if pre_checksum == host.file_hash(self.target):
hookenv.log(
'No change detected: {}'.format(self.target),
hookenv.DEBUG)
else:
self.on_change_action()
return result
# Convenience aliases for templates
示例2: persist_settings
# 需要导入模块: from charmhelpers.core import templating [as 别名]
# 或者: from charmhelpers.core.templating import render [as 别名]
def persist_settings(settings_dict):
# Write all settings to /etc/hdparm.conf
""" This will persist the hard drive settings to the /etc/hdparm.conf file
The settings_dict should be in the form of {"uuid": {"key":"value"}}
:param settings_dict: dict of settings to save
"""
if not settings_dict:
return
try:
templating.render(source='hdparm.conf', target=HDPARM_FILE,
context=settings_dict)
except IOError as err:
log("Unable to open {path} because of error: {error}".format(
path=HDPARM_FILE, error=err), level=ERROR)
except Exception as e:
# The templating.render can raise a jinja2 exception if the
# template is not found. Rather than polluting the import
# space of this charm, simply catch Exception
log('Unable to render {path} due to error: {error}'.format(
path=HDPARM_FILE, error=e), level=ERROR)