diff --git a/.coveragerc b/.coveragerc index c89967dfe40d..ba208274fed3 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,7 +1,7 @@ [run] branch = True source = nova -omit = nova/tests/*,nova/openstack/*,DynamicallyCompiledCheetahTemplate.py +omit = nova/tests/*,nova/openstack/* [report] ignore-errors = True diff --git a/nova/cloudpipe/client.ovpn.template b/nova/cloudpipe/client.ovpn.template index e127eb9f021c..07bb605f4a89 100644 --- a/nova/cloudpipe/client.ovpn.template +++ b/nova/cloudpipe/client.ovpn.template @@ -18,8 +18,8 @@ # NOVA user connection # Edit the following lines to point to your cert files: -cert $certfile -key $keyfile +cert {{ certfile }} +key {{ keyfile }} ca cacert.pem @@ -27,7 +27,7 @@ client dev tap proto udp -remote $ip $port +remote {{ ip }} {{ port }} resolv-retry infinite nobind diff --git a/nova/console/xvp.conf.template b/nova/console/xvp.conf.template index 695ddbe964df..d0f27223d941 100644 --- a/nova/console/xvp.conf.template +++ b/nova/console/xvp.conf.template @@ -1,16 +1,16 @@ # One time password use with time window OTP ALLOW IPCHECK HTTP 60 -#if $multiplex_port -MULTIPLEX $multiplex_port -#end if +{% if multiplex_port %} +MULTIPLEX {{ multiplex_port }} +{% endif %} -#for $pool in $pools -POOL $pool.address - DOMAIN $pool.address - MANAGER root $pool.password - HOST $pool.address +{% for pool in pools %} +POOL {{ pool.address }} + DOMAIN {{ pool.address }} + MANAGER root {{ pool.password }} + HOST {{ pool.address }} VM - dummy 0123456789ABCDEF - #for $console in $pool.consoles - VM #if $multiplex_port then '-' else $console.port # $console.instance_name $pass_encode($console.password) - #end for -#end for + {% for console in pool.console %} + VM {% if multiplex_port %}-{% else %}{{ console.port }} # {{ console.instance_name }} {{ console.password|pass_encode }}{% endif %} + {% endfor %} +{% endfor %} diff --git a/nova/console/xvp.py b/nova/console/xvp.py index 12e5c0156b58..bedbdceae6b5 100644 --- a/nova/console/xvp.py +++ b/nova/console/xvp.py @@ -20,7 +20,7 @@ import os import signal -from Cheetah import Template +import jinja2 from oslo.config import cfg from nova import context @@ -108,11 +108,12 @@ class XVPConsoleProxy(object): self._xvp_stop() return conf_data = {'multiplex_port': CONF.console_xvp_multiplex_port, - 'pools': pools, - 'pass_encode': self.fix_console_password} - config = str(Template.Template(self.xvpconf_template, - searchList=[conf_data])) - self._write_conf(config) + 'pools': pools} + tmpl_path, tmpl_file = os.path.split(CONF.injected_network_template) + env = jinja2.Environment(loader=jinja2.FileSystemLoader(tmpl_path)) + env.filters['pass_encode'] = self.fix_console_password + template = env.get_template(tmpl_file) + self._write_conf(template.render(conf_data)) self._xvp_restart() def _write_conf(self, config): diff --git a/nova/virt/baremetal/net-dhcp.ubuntu.template b/nova/virt/baremetal/net-dhcp.ubuntu.template index 34a9e8be7c85..a845a30fb7e1 100644 --- a/nova/virt/baremetal/net-dhcp.ubuntu.template +++ b/nova/virt/baremetal/net-dhcp.ubuntu.template @@ -7,12 +7,11 @@ auto lo iface lo inet loopback -#for $ifc in $interfaces -auto ${ifc.name} -iface ${ifc.name} inet dhcp +{% for ifc in interfaces -%} +auto {{ ifc.name }} +iface {{ ifc.name }} inet dhcp -#if $use_ipv6 -iface ${ifc.name} inet6 dhcp -#end if - -#end for +{% if use_ipv6 -%} +iface {{ ifc.name }} inet6 dhcp +{%- endif %} +{%- endfor %} diff --git a/nova/virt/baremetal/net-static.ubuntu.template b/nova/virt/baremetal/net-static.ubuntu.template index 1fe5a1ab8ca3..cee573dffd69 100644 --- a/nova/virt/baremetal/net-static.ubuntu.template +++ b/nova/virt/baremetal/net-static.ubuntu.template @@ -7,21 +7,21 @@ auto lo iface lo inet loopback -#for $ifc in $interfaces -auto ${ifc.name} -iface ${ifc.name} inet static - address ${ifc.address} - netmask ${ifc.netmask} - gateway ${ifc.gateway} -#if $ifc.dns - dns-nameservers ${ifc.dns} -#end if +{% for ifc in interfaces -%} +auto {{ ifc.name }} +iface {{ ifc.name }} inet static + address {{ ifc.address }} + netmask {{ ifc.netmask }} + gateway {{ ifc.gateway }} +{%- if ifc.dns %} + dns-nameservers {{ ifc.dns }} +{%- endif %} -#if $use_ipv6 -iface ${ifc.name} inet6 static - address ${ifc.address_v6} - netmask ${ifc.netmask_v6} - gateway ${ifc.gateway_v6} -#end if +{% if use_ipv6 -%} +iface {{ ifc.name }} inet6 static + address {{ ifc.address_v6 }} + netmask {{ ifc.netmask_v6 }} + gateway {{ ifc.gateway_v6 }} +{%- endif %} -#end for +{%- endfor %} diff --git a/nova/virt/baremetal/pxe.py b/nova/virt/baremetal/pxe.py index 354bca84a530..71ee9c35abb3 100644 --- a/nova/virt/baremetal/pxe.py +++ b/nova/virt/baremetal/pxe.py @@ -23,6 +23,7 @@ Class for PXE bare-metal nodes. import datetime import os +import jinja2 from oslo.config import cfg from nova.compute import flavors @@ -71,16 +72,6 @@ CONF.register_group(baremetal_group) CONF.register_opts(pxe_opts, baremetal_group) CONF.import_opt('use_ipv6', 'nova.netconf') -CHEETAH = None - - -def _get_cheetah(): - global CHEETAH - if CHEETAH is None: - from Cheetah import Template - CHEETAH = Template.Template - return CHEETAH - def build_pxe_network_config(network_info): interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6) @@ -124,26 +115,20 @@ def build_pxe_config(deployment_id, deployment_key, deployment_iscsi_iqn, 'pxe_append_params': CONF.baremetal.pxe_append_params, 'pxe_network_config': network_config, } - cheetah = _get_cheetah() - pxe_config = str(cheetah( - open(CONF.baremetal.pxe_config_template).read(), - searchList=[{'pxe_options': pxe_options, - 'ROOT': '${ROOT}', - }])) - return pxe_config + tmpl_path, tmpl_file = os.path.split(CONF.baremetal.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 build_network_config(network_info): interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6) - cheetah = _get_cheetah() - network_config = str(cheetah( - open(CONF.baremetal.net_config_template).read(), - searchList=[ - {'interfaces': interfaces, - 'use_ipv6': CONF.use_ipv6, - } - ])) - return network_config + tmpl_path, tmpl_file = os.path.split(CONF.baremetal.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_deploy_aki_id(instance_type): diff --git a/nova/virt/baremetal/pxe_config.template b/nova/virt/baremetal/pxe_config.template index ba97f598bf6e..1780de19892e 100644 --- a/nova/virt/baremetal/pxe_config.template +++ b/nova/virt/baremetal/pxe_config.template @@ -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} troubleshoot=0 ${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 }} troubleshoot=0 {{ 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} ${pxe_options.pxe_network_config} +kernel {{ pxe_options.aki_path }} +append initrd={{ pxe_options.ari_path }} root={{ ROOT }} ro {{ pxe_options.pxe_append_params|default("", true) }} {{ pxe_options.pxe_network_config|default("", true) }} diff --git a/nova/virt/baremetal/tilera.py b/nova/virt/baremetal/tilera.py index 6431901f5d92..7b6667790387 100755 --- a/nova/virt/baremetal/tilera.py +++ b/nova/virt/baremetal/tilera.py @@ -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 flavors @@ -44,28 +45,14 @@ CONF.import_opt('use_ipv6', 'nova.netconf') CONF.import_opt('net_config_template', 'nova.virt.baremetal.pxe', group='baremetal') -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): interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6) - cheetah = _get_cheetah() - network_config = str(cheetah( - open(CONF.baremetal.net_config_template).read(), - searchList=[ - {'interfaces': interfaces, - 'use_ipv6': CONF.use_ipv6, - } - ])) - return network_config + tmpl_path, tmpl_file = os.path.split(CONF.baremetal.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): diff --git a/nova/virt/interfaces.template b/nova/virt/interfaces.template index ba01064ccc21..f9c25fd1186c 100644 --- a/nova/virt/interfaces.template +++ b/nova/virt/interfaces.template @@ -7,26 +7,26 @@ auto lo iface lo inet loopback -#for $ifc in $interfaces -auto ${ifc.name} -iface ${ifc.name} inet static - address ${ifc.address} - netmask ${ifc.netmask} - broadcast ${ifc.broadcast} -#if $ifc.gateway - gateway ${ifc.gateway} -#end if -#if $ifc.dns - dns-nameservers ${ifc.dns} -#end if +{% for ifc in interfaces -%} +auto {{ ifc.name }} +iface {{ ifc.name }} inet static + address {{ ifc.address }} + netmask {{ ifc.netmask }} + broadcast {{ ifc.broadcast }} +{%- if ifc.gateway %} + gateway {{ ifc.gateway }} +{%- endif %} +{%- if ifc.dns %} + dns-nameservers {{ ifc.dns }} +{%- endif %} -#if $use_ipv6 -iface ${ifc.name} inet6 static - address ${ifc.address_v6} - netmask ${ifc.netmask_v6} -#if $ifc.gateway_v6 - gateway ${ifc.gateway_v6} -#end if -#end if +{% if use_ipv6 -%} +iface {{ ifc.name }} inet6 static + address {{ ifc.address_v6 }} + netmask {{ ifc.netmask_v6 }} +{%- if ifc.gateway_v6 %} + gateway {{ ifc.gateway_v6 }} +{%- endif %} +{%- endif %} -#end for +{%- endfor %} diff --git a/nova/virt/netutils.py b/nova/virt/netutils.py index 7ac2b2d6dacf..b36b533bdf30 100644 --- a/nova/virt/netutils.py +++ b/nova/virt/netutils.py @@ -21,7 +21,9 @@ """Network-related utilities for supporting libvirt connection code.""" +import os +import jinja2 import netaddr from oslo.config import cfg @@ -32,16 +34,6 @@ CONF = cfg.CONF CONF.import_opt('use_ipv6', 'nova.netconf') CONF.import_opt('injected_network_template', 'nova.virt.disk.api') -Template = None - - -def _late_load_cheetah(): - global Template - if Template is None: - t = __import__('Cheetah.Template', globals(), locals(), - ['Template'], -1) - Template = t.Template - def get_net_and_mask(cidr): net = netaddr.IPNetwork(cidr) @@ -138,9 +130,8 @@ def get_injected_network_template(network_info, use_ipv6=CONF.use_ipv6, def build_template(template, nets, ipv6_is_available): - _late_load_cheetah() - - ifc_template = open(template).read() - return str(Template(ifc_template, - searchList=[{'interfaces': nets, - 'use_ipv6': ipv6_is_available}])) + tmpl_path, tmpl_file = os.path.split(CONF.injected_network_template) + env = jinja2.Environment(loader=jinja2.FileSystemLoader(tmpl_path)) + template = env.get_template(tmpl_file) + return template.render({'interfaces': nets, + 'use_ipv6': ipv6_is_available}) diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 2070c5ed5e87..de170886fe49 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -2214,11 +2214,11 @@ def _prepare_injectables(inst, network_info): prepares the ssh key and the network configuration file to be injected into the disk image """ - #do the import here - Cheetah.Template will be loaded - #only if injection is performed - from Cheetah import Template as t - template = t.Template - template_data = open(CONF.injected_network_template).read() + #do the import here - Jinja2 will be loaded only if injection is performed + import jinja2 + tmpl_path, tmpl_file = os.path.split(CONF.injected_network_template) + env = jinja2.Environment(loader=jinja2.FileSystemLoader(tmpl_path)) + template = env.get_template(tmpl_file) metadata = inst['metadata'] key = str(inst['key_data']) @@ -2301,9 +2301,8 @@ def _prepare_injectables(inst, network_info): interfaces_info.append(interface_info) if interfaces_info: - net = str(template(template_data, - searchList=[{'interfaces': interfaces_info, - 'use_ipv6': CONF.use_ipv6}])) + net = template.render({'interfaces': interfaces_info, + 'use_ipv6': CONF.use_ipv6}) return key, net, metadata diff --git a/requirements.txt b/requirements.txt index b8e8c443e26c..2e4705abe400 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,12 @@ d2to1>=0.2.10,<0.3 pbr>=0.5.16,<0.6 SQLAlchemy>=0.7.8,<0.7.99 -Cheetah>=2.4.4 amqplib>=0.6.1 anyjson>=0.2.4 argparse boto eventlet>=0.9.17 +Jinja2 kombu>=1.0.4 lxml>=2.3 routes>=1.12.3