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:
Lucas Alvares Gomes
2013-09-30 17:44:37 +01:00
parent 85e237361f
commit cbf214b513
5 changed files with 18 additions and 34 deletions

View File

@@ -18,12 +18,11 @@
PXE Driver and supporting meta-classes. PXE Driver and supporting meta-classes.
""" """
from Cheetah import Template
import datetime import datetime
import os import os
import tempfile import tempfile
import jinja2
from oslo.config import cfg from oslo.config import cfg
from ironic.common import exception from ironic.common import exception
@@ -138,7 +137,6 @@ def _build_pxe_config(node, pxe_info):
:returns: A formated string with the file content. :returns: A formated string with the file content.
""" """
LOG.debug(_("Building PXE config for deployment %s.") % node['id']) LOG.debug(_("Building PXE config for deployment %s.") % node['id'])
cheetah = Template.Template
pxe_options = { pxe_options = {
'deployment_id': node['id'], 'deployment_id': node['id'],
@@ -151,12 +149,11 @@ def _build_pxe_config(node, pxe_info):
'pxe_append_params': CONF.pxe.pxe_append_params, 'pxe_append_params': CONF.pxe.pxe_append_params,
} }
pxe_config = str(cheetah( tmpl_path, tmpl_file = os.path.split(CONF.pxe.pxe_config_template)
open(CONF.pxe.pxe_config_template).read(), env = jinja2.Environment(loader=jinja2.FileSystemLoader(tmpl_path))
searchList=[{'pxe_options': pxe_options, template = env.get_template(tmpl_file)
'ROOT': '${ROOT}', return template.render({'pxe_options': pxe_options,
}])) 'ROOT': '{{ ROOT }}'})
return pxe_config
def _get_node_mac_addresses(task, node): def _get_node_mac_addresses(task, node):

View File

@@ -1,11 +1,11 @@
default deploy default deploy
label deploy label deploy
kernel ${pxe_options.deployment_aki_path} 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} 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 ipappend 3
label boot label boot
kernel ${pxe_options.aki_path} kernel {{ pxe_options.aki_path }}
append initrd=${pxe_options.ari_path} root=${ROOT} ro ${pxe_options.pxe_append_params} append initrd={{ pxe_options.ari_path }} root={{ ROOT }} ro {{ pxe_options.pxe_append_params|default("", true) }}

View File

@@ -22,6 +22,7 @@ Class for Tilera bare-metal nodes.
import base64 import base64
import os import os
import jinja2
from oslo.config import cfg from oslo.config import cfg
from nova.compute import instance_types from nova.compute import instance_types
@@ -46,16 +47,6 @@ CONF = cfg.CONF
CONF.register_opts(tilera_opts) CONF.register_opts(tilera_opts)
CONF.import_opt('use_ipv6', 'ironic.netconf') 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): def build_network_config(network_info):
try: try:
@@ -83,15 +74,11 @@ def build_network_config(network_info):
} }
interfaces.append(interface) interfaces.append(interface)
cheetah = _get_cheetah() tmpl_path, tmpl_file = os.path.split(CONF.net_config_template)
network_config = str(cheetah( env = jinja2.Environment(loader=jinja2.FileSystemLoader(tmpl_path))
open(CONF.net_config_template).read(), template = env.get_template(tmpl_file)
searchList=[ return template.render({'interfaces': interfaces,
{'interfaces': interfaces, 'use_ipv6': CONF.use_ipv6})
'use_ipv6': CONF.use_ipv6,
}
]))
return network_config
def get_image_dir_path(instance): def get_image_dir_path(instance):

View File

@@ -8,4 +8,4 @@ ipappend 3
label boot label boot
kernel /tftpboot/instance_uuid_123/kernel 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

View File

@@ -21,6 +21,6 @@ oslo.config>=1.2.0
pecan>=0.2.0 pecan>=0.2.0
six six
jsonpatch>=1.1 jsonpatch>=1.1
Cheetah>=2.4.4
WSME>=0.5b5 WSME>=0.5b5
Jinja2
pyghmi pyghmi