Port Cheetah templates to Jinja2
Cheetah is unmaintained since 2010 and it's unlikely to get Python3 support soon. Also, the rest of OpenStack (mostly) standardized on Jinja2. Implements: blueprint jinja-templating-conversion Change-Id: Ia15f00ee96d3c1d55d7c290f20ccc988e4c52e1a
This commit is contained in:
parent
c3e8517a46
commit
fa0d61084e
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 %}
|
||||
|
@ -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):
|
||||
|
@ -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 %}
|
||||
|
@ -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 %}
|
||||
|
@ -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):
|
||||
|
@ -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) }}
|
||||
|
@ -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):
|
||||
|
@ -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 %}
|
||||
|
@ -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})
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user