def determine_timeout(self, node_definition):
        def possible_timeouts():
            yield 'node_desc', self.node_description.get('create_timeout')
            yield 'node_def', node_definition.get('create_timeout')
            yield 'config_default', self.default_timeout

        src, timeout = util.find_effective_setting(possible_timeouts(), True)

        log.debug('Effective timeout is %r (from %s)', timeout, src)
        return timeout
    def determine_timeout(self, node_definition):
        def possible_timeouts():
            yield 'node_desc', self.node_description.get('create_timeout')
            yield 'node_def', node_definition.get('create_timeout')
            yield 'config_default', self.default_timeout

        src, timeout = util.find_effective_setting(possible_timeouts(), True)

        log.debug('Effective timeout is %r (from %s)', timeout, src)
        return timeout
Example #3
0
    def extract_template(self, temp_name, node_definition):

        def context_list():
            # `context_template` is also removed from the definition, as
            # it will be replaced with the rendered `context`
            yield ('node_definition',
                   node_definition.pop(temp_name, None))

            yield 'default', ''

        src, template = util.find_effective_setting(context_list())
        datalog.debug('Context template from %s:\n%s', src, template)

        return jinja2.Template(template)
Example #4
0
    def extract_template(self, node_definition):
        def context_list():
            # `context_variables` is also removed from the definition, as
            # it will be replaced with the rendered `context`
            context_section = node_definition.get('contextualisation', None)
            yield ('node_definition',
                   context_section.pop('context_variables', None))

            yield 'default', ''

        src, template = util.find_effective_setting(context_list())

        if isinstance(template, dict):
            template = yaml.dump(template, default_flow_style=False)

        datalog.debug('Context template from %s:\n%s', src, template)

        return jinja2.Template(template)
Example #5
0
    def extract_template(self, node_definition):

        def context_list():
            # `context_template` is also removed from the definition, as
            # it will be replaced with the rendered `context`
            context_section = node_definition.get('contextualisation', None)
            yield ('node_definition',
                   context_section.pop('context_template', None))

            yield 'default', ''

        src, template = util.find_effective_setting(context_list())

        if isinstance(template, dict):
              template="#cloud-config\n"+yaml.dump(template)

        datalog.debug('Context template from %s:\n%s', src, template)

        return jinja2.Template(template)
    def extract_template(self, temp_name, node_definition):

        def context_list():
            # `context_template` is also removed from the definition, as
            # it will be replaced with the rendered `context`
            yield ('node_definition',
                   node_definition.pop(temp_name, None))

            from occo.infobroker import main_info_broker
            sc_data = main_info_broker.get(
                'service_composer.aux_data',
                node_definition['service_composer_id'])
            yield ('service_composer_default',
                   sc_data.get(temp_name, None))

            yield 'default', ''

        src, template = util.find_effective_setting(context_list())
        datalog.debug('Context template from %s:\n%s', src, template)

        return jinja2.Template(template)
Example #7
0
    def test_find_effective_setting(self):
        def testsettings():
            yield 'a', None
            yield 'b', 1
            yield 'c', 2

        def badsettings():
            yield 'a', None
            yield 'b', None
            yield 'c', None

        with self.assertRaises(TypeError):
            util.find_effective_setting([None, None, 2])
        with self.assertRaises(RuntimeError):
            util.find_effective_setting(badsettings())
        s, d = util.find_effective_setting(badsettings(), True)
        self.assertEqual((s, d), ('default', None))
        s, d = util.find_effective_setting(testsettings(), True)
        self.assertEqual((s, d), ('b', 1))
Example #8
0
    def test_find_effective_setting(self):
        def testsettings():
            yield 'a', None
            yield 'b', 1
            yield 'c', 2

        def badsettings():
            yield 'a', None
            yield 'b', None
            yield 'c', None

        with self.assertRaises(TypeError):
            util.find_effective_setting([None, None, 2])
        with self.assertRaises(RuntimeError):
            util.find_effective_setting(badsettings())
        s, d = util.find_effective_setting(badsettings(), True)
        self.assertEqual((s, d), ('default', None))
        s, d = util.find_effective_setting(testsettings(), True)
        self.assertEqual((s, d), ('b', 1))