def get_version(template_data, available_versions): version_keys = set(key for key, version in available_versions) candidate_keys = set(k for k, v in six.iteritems(template_data) if isinstance(v, six.string_types)) keys_present = version_keys & candidate_keys if len(keys_present) > 1: explanation = _('Ambiguous versions (%s)') % ', '.join(keys_present) raise exception.InvalidTemplateVersion(explanation=explanation) try: version_key = keys_present.pop() except KeyError: explanation = _('Template version was not provided') raise exception.InvalidTemplateVersion(explanation=explanation) return version_key, template_data[version_key]
def get_template_class(plugin_mgr, template_data): global _template_classes if _template_classes is None: tmpl_mapping = plugin_manager.PluginMapping('template') _template_classes = dict(tmpl_mapping.load_all(plugin_mgr)) available_versions = _template_classes.keys() version = get_version(template_data, available_versions) version_type = version[0] try: return _template_classes[version] except KeyError: av_list = [v for k, v in available_versions if k == version_type] msg_data = { 'version': ': '.join(version), 'version_type': version_type, 'available': ', '.join(v for v in av_list) } if len(av_list) > 1: explanation = _('"%(version)s". "%(version_type)s" ' 'should be one of: %(available)s') % msg_data else: explanation = _('"%(version)s". "%(version_type)s" ' 'should be: %(available)s') % msg_data raise exception.InvalidTemplateVersion(explanation=explanation)
def get_template_class(plugin_mgr, template_data): global _template_classes if _template_classes is None: mgr = extension.ExtensionManager(namespace='heat.templates', invoke_on_load=False, verify_requirements=True) _template_classes = dict( (tuple(name.split('.')), mgr[name].plugin) for name in mgr.names()) available_versions = _template_classes.keys() version = get_version(template_data, available_versions) version_type = version[0] try: return _template_classes[version] except KeyError: av_list = [v for k, v in available_versions if k == version_type] msg_data = { 'version': ': '.join(version), 'version_type': version_type, 'available': ', '.join(v for v in av_list) } if len(av_list) > 1: explanation = _('"%(version)s". "%(version_type)s" ' 'should be one of: %(available)s') % msg_data else: explanation = _('"%(version)s". "%(version_type)s" ' 'should be: %(available)s') % msg_data raise exception.InvalidTemplateVersion(explanation=explanation)
def get_version(template_data, available_versions): version_keys = set(key for key, version in available_versions) candidate_keys = set(k for k, v in template_data.iteritems() if isinstance(v, basestring)) keys_present = version_keys & candidate_keys if not keys_present: return DEFAULT_VERSION if len(keys_present) > 1: explanation = _('Ambiguous versions (%s)') % ', '.join(keys_present) raise exception.InvalidTemplateVersion(explanation=explanation) version_key = keys_present.pop() return version_key, template_data[version_key]
def get_template_class(plugin_mgr, template_data): global _template_classes if _template_classes is None: tmpl_mapping = plugin_manager.PluginMapping('template') _template_classes = dict(tmpl_mapping.load_all(plugin_mgr)) available_versions = _template_classes.keys() version = get_version(template_data, available_versions) try: return _template_classes[version] except KeyError: msg_data = { 'version': ': '.join(version), 'available': ', '.join(v for vk, v in available_versions) } explanation = _('Unknown version (%(version)s). ' 'Should be one of: %(available)s') % msg_data raise exception.InvalidTemplateVersion(explanation=explanation)
def get_template_class(template_data): available_versions = _template_classes.keys() version = get_version(template_data, available_versions) version_type = version[0] try: return _template_classes[version] except KeyError: av_list = [v for k, v in available_versions if k == version_type] msg_data = {'version': ': '.join(version), 'version_type': version_type, 'available': ', '.join(v for v in av_list)} if len(av_list) > 1: explanation = _('"%(version)s". "%(version_type)s" ' 'should be one of: %(available)s') % msg_data else: explanation = _('"%(version)s". "%(version_type)s" ' 'should be: %(available)s') % msg_data raise exception.InvalidTemplateVersion(explanation=explanation)
def validate(self): exp = (_("The function %s is not supported in this version of HOT.") % self.fn_name) raise exception.InvalidTemplateVersion(explanation=exp)
def __init__(self, stack, fn_name, args): exp = (_("The function %s is not supported in this version of HOT.") % fn_name) raise exception.InvalidTemplateVersion(explanation=exp)