~openstack-charmers-archive/charms/trusty/neutron-gateway/trunk

« back to all changes in this revision

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

  • Committer: James Page
  • Date: 2015-10-22 13:23:58 UTC
  • Revision ID: james.page@ubuntu.com-20151022132358-qin1nvlnqn4aezaz
Tags: 15.10
15.10 Charm release

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import six
20
20
 
21
 
from charmhelpers.fetch import apt_install
 
21
from charmhelpers.fetch import apt_install, apt_update
22
22
from charmhelpers.core.hookenv import (
23
23
    log,
24
24
    ERROR,
29
29
try:
30
30
    from jinja2 import FileSystemLoader, ChoiceLoader, Environment, exceptions
31
31
except ImportError:
 
32
    apt_update(fatal=True)
32
33
    apt_install('python-jinja2', fatal=True)
33
34
    from jinja2 import FileSystemLoader, ChoiceLoader, Environment, exceptions
34
35
 
112
113
 
113
114
    def complete_contexts(self):
114
115
        '''
115
 
        Return a list of interfaces that have atisfied contexts.
 
116
        Return a list of interfaces that have satisfied contexts.
116
117
        '''
117
118
        if self._complete_contexts:
118
119
            return self._complete_contexts
293
294
        [interfaces.extend(i.complete_contexts())
294
295
         for i in six.itervalues(self.templates)]
295
296
        return interfaces
 
297
 
 
298
    def get_incomplete_context_data(self, interfaces):
 
299
        '''
 
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}}
 
304
        '''
 
305
        incomplete_context_data = {}
 
306
 
 
307
        for i in six.itervalues(self.templates):
 
308
            for context in i.contexts:
 
309
                for interface in interfaces:
 
310
                    related = False
 
311
                    if interface in context.interfaces:
 
312
                        related = context.get_related()
 
313
                        missing_data = context.missing_data
 
314
                        if missing_data:
 
315
                            incomplete_context_data[interface] = {'missing_data': missing_data}
 
316
                        if related:
 
317
                            if incomplete_context_data.get(interface):
 
318
                                incomplete_context_data[interface].update({'related': True})
 
319
                            else:
 
320
                                incomplete_context_data[interface] = {'related': True}
 
321
                        else:
 
322
                            incomplete_context_data[interface] = {'related': False}
 
323
        return incomplete_context_data