本文整理匯總了Python中charmhelpers.contrib.openstack.templating.get_loader方法的典型用法代碼示例。如果您正苦於以下問題:Python templating.get_loader方法的具體用法?Python templating.get_loader怎麽用?Python templating.get_loader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類charmhelpers.contrib.openstack.templating
的用法示例。
在下文中一共展示了templating.get_loader方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_get_loader_all_search_paths
# 需要導入模塊: from charmhelpers.contrib.openstack import templating [as 別名]
# 或者: from charmhelpers.contrib.openstack.templating import get_loader [as 別名]
def test_get_loader_all_search_paths(self, isdir):
'''Ensure loader reverse searches of all release template dirs'''
isdir.return_value = True
choice_loader = templating.get_loader('/tmp/foo',
os_release='icehouse')
dirs = [l.searchpath for l in choice_loader.loaders]
common_tmplts = os.path.join(os.path.dirname(templating.__file__),
'templates')
expected = [['/tmp/foo/icehouse'],
['/tmp/foo/havana'],
['/tmp/foo/grizzly'],
['/tmp/foo/folsom'],
['/tmp/foo/essex'],
['/tmp/foo/diablo'],
['/tmp/foo'],
[common_tmplts]]
self.assertEquals(dirs, expected)
示例2: test_get_loader_some_search_paths
# 需要導入模塊: from charmhelpers.contrib.openstack import templating [as 別名]
# 或者: from charmhelpers.contrib.openstack.templating import get_loader [as 別名]
def test_get_loader_some_search_paths(self, isdir):
'''Ensure loader reverse searches of some release template dirs'''
isdir.return_value = True
choice_loader = templating.get_loader('/tmp/foo', os_release='grizzly')
dirs = [l.searchpath for l in choice_loader.loaders]
common_tmplts = os.path.join(os.path.dirname(templating.__file__),
'templates')
expected = [['/tmp/foo/grizzly'],
['/tmp/foo/folsom'],
['/tmp/foo/essex'],
['/tmp/foo/diablo'],
['/tmp/foo'],
[common_tmplts]]
self.assertEquals(dirs, expected)
示例3: get_template_for_release
# 需要導入模塊: from charmhelpers.contrib.openstack import templating [as 別名]
# 或者: from charmhelpers.contrib.openstack.templating import get_loader [as 別名]
def get_template_for_release(self, os_release, mock_log):
loader = get_loader('./templates', os_release)
env = Environment(loader=loader)
return env.get_template('proxy-server.conf')
示例4: render_config
# 需要導入模塊: from charmhelpers.contrib.openstack import templating [as 別名]
# 或者: from charmhelpers.contrib.openstack.templating import get_loader [as 別名]
def render_config(self, restart_trigger):
"""Render the domain specific LDAP configuration for the application
"""
checksum = ch_host.path_hash(self.configuration_file)
core.templating.render(
source=KEYSTONE_CONF_TEMPLATE,
template_loader=os_templating.get_loader(
'templates/', self.release),
target=self.configuration_file,
context=self.adapters_instance)
if checksum != ch_host.path_hash(self.configuration_file):
restart_trigger()
示例5: get_template_for_release_and_server
# 需要導入模塊: from charmhelpers.contrib.openstack import templating [as 別名]
# 或者: from charmhelpers.contrib.openstack.templating import get_loader [as 別名]
def get_template_for_release_and_server(
self,
os_release,
server,
mock_log):
if not server:
server = 'object'
loader = get_loader('./templates', os_release)
env = Environment(loader=loader)
return env.get_template('{}-server.conf'.format(server))
示例6: render_configs
# 需要導入模塊: from charmhelpers.contrib.openstack import templating [as 別名]
# 或者: from charmhelpers.contrib.openstack.templating import get_loader [as 別名]
def render_configs(self, configs, adapters_instance=None):
"""Render the configuration files identified in the list passed as
configs.
If adapters_instance is None then the self.adapters_instance is used
that was setup in the __init__() method. Note, if no interfaces were
passed (the default) then there will be no interfaces.
TODO: need to work out how to make this function more useful - at the
moment, with a default setup, this function is only useful to
render_with_interfaces() which constructs a new adapters_instance
anyway.
:param configs: list of strings, the names of the configuration files.
:param adapters_instance: [optional] the adapters_instance to use.
"""
if adapters_instance is None:
adapters_instance = self.adapters_instance
with self.restart_on_change():
for conf in configs:
charmhelpers.core.templating.render(
source=os.path.basename(conf),
template_loader=os_templating.get_loader(
'templates/', self.release),
target=conf,
context=adapters_instance)
示例7: test_get_loader_no_templates_dir
# 需要導入模塊: from charmhelpers.contrib.openstack import templating [as 別名]
# 或者: from charmhelpers.contrib.openstack.templating import get_loader [as 別名]
def test_get_loader_no_templates_dir(self, isdir):
'''Ensure getting loader fails with no template dir'''
isdir.return_value = False
self.assertRaises(templating.OSConfigException,
templating.get_loader,
templates_dir='/tmp/foo', os_release='foo')
示例8: get_config_for_principal
# 需要導入模塊: from charmhelpers.contrib.openstack import templating [as 別名]
# 或者: from charmhelpers.contrib.openstack.templating import get_loader [as 別名]
def get_config_for_principal(self, auth_data):
"""Assuming that the configuration data is valid, return the
configuration data for the principal charm.
The format of the complete returned data is:
{
"<config file>: <string>
}
If the configuration is not complete, or we don't have auth data from
the principal charm, then we return and emtpy dictionary {}
:param auth_data: the raw dictionary received from the principal charm
:returns: structure described above.
"""
# If there is no auth_data yet, then we can't write our config.
if not auth_data:
return {}
# If the state from the assess_status is not None then we're blocked,
# so don't send any config to the principal.
state, message = self.custom_assess_status_check()
if state:
return {}
options = self.options # tiny optimisation for less typing.
# If there is no backend name, then we can't send the data yet as the
# manila-charm won't know what to do with it.
if not options.share_backend_name:
return {}
# We have the auth data & the config is reasonably sensible.
# We can try and render the config file segment.
# TODO this is horrible, and we should have something in
# charms.openstack to do this, but we need a c.r relation to be able to
# add it to the adapters_instance
manila_plugin = charms.reactive.RelationBase.from_state(
'manila-plugin.available')
self.adapters_instance.add_relation(manila_plugin)
rendered_configs = charmhelpers.core.templating.render(
source=os.path.basename(MANILA_CONF),
template_loader=os_templating.get_loader(
'templates/', self.release),
target=None,
context=self.adapters_instance)
return {
MANILA_CONF: rendered_configs
}