Replace Cheetah with Jinja2
Other projects are already using Jinja2. Partial port of nova commit fa0d61084e50c264f3231f997e4243b8037919f8 Change-Id: Id87c8dff3c60ef7155c1cd940ada8316678711d6 Closes-Bug: Bug #1233251
This commit is contained in:
		| @@ -18,12 +18,11 @@ | ||||
| PXE Driver and supporting meta-classes. | ||||
| """ | ||||
|  | ||||
| from Cheetah import Template | ||||
|  | ||||
| import datetime | ||||
| import os | ||||
| import tempfile | ||||
|  | ||||
| import jinja2 | ||||
| from oslo.config import cfg | ||||
|  | ||||
| from ironic.common import exception | ||||
| @@ -138,7 +137,6 @@ def _build_pxe_config(node, pxe_info): | ||||
|     :returns: A formated string with the file content. | ||||
|     """ | ||||
|     LOG.debug(_("Building PXE config for deployment %s.") % node['id']) | ||||
|     cheetah = Template.Template | ||||
|  | ||||
|     pxe_options = { | ||||
|             'deployment_id': node['id'], | ||||
| @@ -151,12 +149,11 @@ def _build_pxe_config(node, pxe_info): | ||||
|             'pxe_append_params': CONF.pxe.pxe_append_params, | ||||
|         } | ||||
|  | ||||
|     pxe_config = str(cheetah( | ||||
|             open(CONF.pxe.pxe_config_template).read(), | ||||
|             searchList=[{'pxe_options': pxe_options, | ||||
|                          'ROOT': '${ROOT}', | ||||
|             }])) | ||||
|     return pxe_config | ||||
|     tmpl_path, tmpl_file = os.path.split(CONF.pxe.pxe_config_template) | ||||
|     env = jinja2.Environment(loader=jinja2.FileSystemLoader(tmpl_path)) | ||||
|     template = env.get_template(tmpl_file) | ||||
|     return template.render({'pxe_options': pxe_options, | ||||
|                             'ROOT': '{{ ROOT }}'}) | ||||
|  | ||||
|  | ||||
| def _get_node_mac_addresses(task, node): | ||||
|   | ||||
| @@ -1,11 +1,11 @@ | ||||
| default deploy | ||||
|  | ||||
| label deploy | ||||
| kernel ${pxe_options.deployment_aki_path} | ||||
| append initrd=${pxe_options.deployment_ari_path} selinux=0 disk=cciss/c0d0,sda,hda,vda iscsi_target_iqn=${pxe_options.deployment_iscsi_iqn} deployment_id=${pxe_options.deployment_id} deployment_key=${pxe_options.deployment_key} ${pxe_options.pxe_append_params} | ||||
| kernel {{ pxe_options.deployment_aki_path }} | ||||
| append initrd={{ pxe_options.deployment_ari_path }} selinux=0 disk=cciss/c0d0,sda,hda,vda iscsi_target_iqn={{ pxe_options.deployment_iscsi_iqn }} deployment_id={{ pxe_options.deployment_id }} deployment_key={{ pxe_options.deployment_key }} {{ pxe_options.pxe_append_params|default("", true) }} | ||||
| ipappend 3 | ||||
|  | ||||
|  | ||||
| label boot | ||||
| kernel ${pxe_options.aki_path} | ||||
| append initrd=${pxe_options.ari_path} root=${ROOT} ro ${pxe_options.pxe_append_params} | ||||
| kernel {{ pxe_options.aki_path }} | ||||
| append initrd={{ pxe_options.ari_path }} root={{ ROOT }} ro {{ pxe_options.pxe_append_params|default("", true) }} | ||||
|   | ||||
| @@ -22,6 +22,7 @@ Class for Tilera bare-metal nodes. | ||||
| import base64 | ||||
| import os | ||||
|  | ||||
| import jinja2 | ||||
| from oslo.config import cfg | ||||
|  | ||||
| from nova.compute import instance_types | ||||
| @@ -46,16 +47,6 @@ CONF = cfg.CONF | ||||
| CONF.register_opts(tilera_opts) | ||||
| CONF.import_opt('use_ipv6', 'ironic.netconf') | ||||
|  | ||||
| CHEETAH = None | ||||
|  | ||||
|  | ||||
| def _get_cheetah(): | ||||
|     global CHEETAH | ||||
|     if CHEETAH is None: | ||||
|         from Cheetah import Template | ||||
|         CHEETAH = Template.Template | ||||
|     return CHEETAH | ||||
|  | ||||
|  | ||||
| def build_network_config(network_info): | ||||
|     try: | ||||
| @@ -83,15 +74,11 @@ def build_network_config(network_info): | ||||
|             } | ||||
|         interfaces.append(interface) | ||||
|  | ||||
|     cheetah = _get_cheetah() | ||||
|     network_config = str(cheetah( | ||||
|             open(CONF.net_config_template).read(), | ||||
|             searchList=[ | ||||
|                 {'interfaces': interfaces, | ||||
|                  'use_ipv6': CONF.use_ipv6, | ||||
|                 } | ||||
|             ])) | ||||
|     return network_config | ||||
|     tmpl_path, tmpl_file = os.path.split(CONF.net_config_template) | ||||
|     env = jinja2.Environment(loader=jinja2.FileSystemLoader(tmpl_path)) | ||||
|     template = env.get_template(tmpl_file) | ||||
|     return template.render({'interfaces': interfaces, | ||||
|                             'use_ipv6': CONF.use_ipv6}) | ||||
|  | ||||
|  | ||||
| def get_image_dir_path(instance): | ||||
|   | ||||
| @@ -8,4 +8,4 @@ ipappend 3 | ||||
|  | ||||
| label boot | ||||
| kernel /tftpboot/instance_uuid_123/kernel | ||||
| append initrd=/tftpboot/instance_uuid_123/ramdisk root=${ROOT} ro test_param | ||||
| append initrd=/tftpboot/instance_uuid_123/ramdisk root={{ ROOT }} ro test_param | ||||
| @@ -21,6 +21,6 @@ oslo.config>=1.2.0 | ||||
| pecan>=0.2.0 | ||||
| six | ||||
| jsonpatch>=1.1 | ||||
| Cheetah>=2.4.4 | ||||
| WSME>=0.5b5 | ||||
| Jinja2 | ||||
| pyghmi | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Lucas Alvares Gomes
					Lucas Alvares Gomes