30
30
from jinja2 import FileSystemLoader, ChoiceLoader, Environment, exceptions
31
31
except ImportError:
32
# python-jinja2 may not be installed yet, or we're running unittests.
33
FileSystemLoader = ChoiceLoader = Environment = exceptions = None
32
apt_update(fatal=True)
33
apt_install('python-jinja2', fatal=True)
34
from jinja2 import FileSystemLoader, ChoiceLoader, Environment, exceptions
36
37
class OSConfigException(Exception):
40
def os_template_dirs(templates_dir, os_release):
41
tmpl_dirs = [(rel, os.path.join(templates_dir, rel))
42
for rel in six.itervalues(OPENSTACK_CODENAMES)]
44
if not os.path.isdir(templates_dir):
45
log('Templates directory not found @ %s.' % templates_dir,
47
raise OSConfigException
48
dirs = [templates_dir]
49
helper_templates = os.path.join(os.path.dirname(__file__), 'templates')
50
if os.path.isdir(helper_templates):
51
dirs.append(helper_templates)
53
for rel, tmpl_dir in tmpl_dirs:
54
if os.path.isdir(tmpl_dir):
55
dirs.insert(0, tmpl_dir)
58
ch_templates = os.path.dirname(__file__) + '/charmhelpers/contrib/openstack/templates'
59
dirs.append(ch_templates)
60
log('Template search path: %s' %
61
' '.join(dirs), level=INFO)
65
41
def get_loader(templates_dir, os_release):
67
43
Create a jinja2.ChoiceLoader containing template dirs up to
138
114
def complete_contexts(self):
140
Return a list of interfaces that have atisfied contexts.
116
Return a list of interfaces that have satisfied contexts.
142
118
if self._complete_contexts:
143
119
return self._complete_contexts
318
294
[interfaces.extend(i.complete_contexts())
319
295
for i in six.itervalues(self.templates)]
320
296
return interfaces
298
def get_incomplete_context_data(self, interfaces):
300
Return dictionary of relation status of interfaces and any missing
301
required context data. Example:
302
{'amqp': {'missing_data': ['rabbitmq_password'], 'related': True},
303
'zeromq-configuration': {'related': False}}
305
incomplete_context_data = {}
307
for i in six.itervalues(self.templates):
308
for context in i.contexts:
309
for interface in interfaces:
311
if interface in context.interfaces:
312
related = context.get_related()
313
missing_data = context.missing_data
315
incomplete_context_data[interface] = {'missing_data': missing_data}
317
if incomplete_context_data.get(interface):
318
incomplete_context_data[interface].update({'related': True})
320
incomplete_context_data[interface] = {'related': True}
322
incomplete_context_data[interface] = {'related': False}
323
return incomplete_context_data