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]
|
[run]
|
||||||
branch = True
|
branch = True
|
||||||
source = nova
|
source = nova
|
||||||
omit = nova/tests/*,nova/openstack/*,DynamicallyCompiledCheetahTemplate.py
|
omit = nova/tests/*,nova/openstack/*
|
||||||
|
|
||||||
[report]
|
[report]
|
||||||
ignore-errors = True
|
ignore-errors = True
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
|
|
||||||
# NOVA user connection
|
# NOVA user connection
|
||||||
# Edit the following lines to point to your cert files:
|
# Edit the following lines to point to your cert files:
|
||||||
cert $certfile
|
cert {{ certfile }}
|
||||||
key $keyfile
|
key {{ keyfile }}
|
||||||
|
|
||||||
ca cacert.pem
|
ca cacert.pem
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ client
|
|||||||
dev tap
|
dev tap
|
||||||
proto udp
|
proto udp
|
||||||
|
|
||||||
remote $ip $port
|
remote {{ ip }} {{ port }}
|
||||||
resolv-retry infinite
|
resolv-retry infinite
|
||||||
nobind
|
nobind
|
||||||
|
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
# One time password use with time window
|
# One time password use with time window
|
||||||
OTP ALLOW IPCHECK HTTP 60
|
OTP ALLOW IPCHECK HTTP 60
|
||||||
#if $multiplex_port
|
{% if multiplex_port %}
|
||||||
MULTIPLEX $multiplex_port
|
MULTIPLEX {{ multiplex_port }}
|
||||||
#end if
|
{% endif %}
|
||||||
|
|
||||||
#for $pool in $pools
|
{% for pool in pools %}
|
||||||
POOL $pool.address
|
POOL {{ pool.address }}
|
||||||
DOMAIN $pool.address
|
DOMAIN {{ pool.address }}
|
||||||
MANAGER root $pool.password
|
MANAGER root {{ pool.password }}
|
||||||
HOST $pool.address
|
HOST {{ pool.address }}
|
||||||
VM - dummy 0123456789ABCDEF
|
VM - dummy 0123456789ABCDEF
|
||||||
#for $console in $pool.consoles
|
{% for console in pool.console %}
|
||||||
VM #if $multiplex_port then '-' else $console.port # $console.instance_name $pass_encode($console.password)
|
VM {% if multiplex_port %}-{% else %}{{ console.port }} # {{ console.instance_name }} {{ console.password|pass_encode }}{% endif %}
|
||||||
#end for
|
{% endfor %}
|
||||||
#end for
|
{% endfor %}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
|
|
||||||
from Cheetah import Template
|
import jinja2
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
from nova import context
|
from nova import context
|
||||||
@ -108,11 +108,12 @@ class XVPConsoleProxy(object):
|
|||||||
self._xvp_stop()
|
self._xvp_stop()
|
||||||
return
|
return
|
||||||
conf_data = {'multiplex_port': CONF.console_xvp_multiplex_port,
|
conf_data = {'multiplex_port': CONF.console_xvp_multiplex_port,
|
||||||
'pools': pools,
|
'pools': pools}
|
||||||
'pass_encode': self.fix_console_password}
|
tmpl_path, tmpl_file = os.path.split(CONF.injected_network_template)
|
||||||
config = str(Template.Template(self.xvpconf_template,
|
env = jinja2.Environment(loader=jinja2.FileSystemLoader(tmpl_path))
|
||||||
searchList=[conf_data]))
|
env.filters['pass_encode'] = self.fix_console_password
|
||||||
self._write_conf(config)
|
template = env.get_template(tmpl_file)
|
||||||
|
self._write_conf(template.render(conf_data))
|
||||||
self._xvp_restart()
|
self._xvp_restart()
|
||||||
|
|
||||||
def _write_conf(self, config):
|
def _write_conf(self, config):
|
||||||
|
@ -7,12 +7,11 @@
|
|||||||
auto lo
|
auto lo
|
||||||
iface lo inet loopback
|
iface lo inet loopback
|
||||||
|
|
||||||
#for $ifc in $interfaces
|
{% for ifc in interfaces -%}
|
||||||
auto ${ifc.name}
|
auto {{ ifc.name }}
|
||||||
iface ${ifc.name} inet dhcp
|
iface {{ ifc.name }} inet dhcp
|
||||||
|
|
||||||
#if $use_ipv6
|
{% if use_ipv6 -%}
|
||||||
iface ${ifc.name} inet6 dhcp
|
iface {{ ifc.name }} inet6 dhcp
|
||||||
#end if
|
{%- endif %}
|
||||||
|
{%- endfor %}
|
||||||
#end for
|
|
||||||
|
@ -7,21 +7,21 @@
|
|||||||
auto lo
|
auto lo
|
||||||
iface lo inet loopback
|
iface lo inet loopback
|
||||||
|
|
||||||
#for $ifc in $interfaces
|
{% for ifc in interfaces -%}
|
||||||
auto ${ifc.name}
|
auto {{ ifc.name }}
|
||||||
iface ${ifc.name} inet static
|
iface {{ ifc.name }} inet static
|
||||||
address ${ifc.address}
|
address {{ ifc.address }}
|
||||||
netmask ${ifc.netmask}
|
netmask {{ ifc.netmask }}
|
||||||
gateway ${ifc.gateway}
|
gateway {{ ifc.gateway }}
|
||||||
#if $ifc.dns
|
{%- if ifc.dns %}
|
||||||
dns-nameservers ${ifc.dns}
|
dns-nameservers {{ ifc.dns }}
|
||||||
#end if
|
{%- endif %}
|
||||||
|
|
||||||
#if $use_ipv6
|
{% if use_ipv6 -%}
|
||||||
iface ${ifc.name} inet6 static
|
iface {{ ifc.name }} inet6 static
|
||||||
address ${ifc.address_v6}
|
address {{ ifc.address_v6 }}
|
||||||
netmask ${ifc.netmask_v6}
|
netmask {{ ifc.netmask_v6 }}
|
||||||
gateway ${ifc.gateway_v6}
|
gateway {{ ifc.gateway_v6 }}
|
||||||
#end if
|
{%- endif %}
|
||||||
|
|
||||||
#end for
|
{%- endfor %}
|
||||||
|
@ -23,6 +23,7 @@ Class for PXE bare-metal nodes.
|
|||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import jinja2
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
from nova.compute import flavors
|
from nova.compute import flavors
|
||||||
@ -71,16 +72,6 @@ CONF.register_group(baremetal_group)
|
|||||||
CONF.register_opts(pxe_opts, baremetal_group)
|
CONF.register_opts(pxe_opts, baremetal_group)
|
||||||
CONF.import_opt('use_ipv6', 'nova.netconf')
|
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):
|
def build_pxe_network_config(network_info):
|
||||||
interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6)
|
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_append_params': CONF.baremetal.pxe_append_params,
|
||||||
'pxe_network_config': network_config,
|
'pxe_network_config': network_config,
|
||||||
}
|
}
|
||||||
cheetah = _get_cheetah()
|
tmpl_path, tmpl_file = os.path.split(CONF.baremetal.pxe_config_template)
|
||||||
pxe_config = str(cheetah(
|
env = jinja2.Environment(loader=jinja2.FileSystemLoader(tmpl_path))
|
||||||
open(CONF.baremetal.pxe_config_template).read(),
|
template = env.get_template(tmpl_file)
|
||||||
searchList=[{'pxe_options': pxe_options,
|
return template.render({'pxe_options': pxe_options,
|
||||||
'ROOT': '${ROOT}',
|
'ROOT': '${ROOT}'})
|
||||||
}]))
|
|
||||||
return pxe_config
|
|
||||||
|
|
||||||
|
|
||||||
def build_network_config(network_info):
|
def build_network_config(network_info):
|
||||||
interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6)
|
interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6)
|
||||||
cheetah = _get_cheetah()
|
tmpl_path, tmpl_file = os.path.split(CONF.baremetal.net_config_template)
|
||||||
network_config = str(cheetah(
|
env = jinja2.Environment(loader=jinja2.FileSystemLoader(tmpl_path))
|
||||||
open(CONF.baremetal.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_deploy_aki_id(instance_type):
|
def get_deploy_aki_id(instance_type):
|
||||||
|
@ -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} troubleshoot=0 ${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 }} troubleshoot=0 {{ 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} ${pxe_options.pxe_network_config}
|
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 base64
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import jinja2
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
from nova.compute import flavors
|
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',
|
CONF.import_opt('net_config_template', 'nova.virt.baremetal.pxe',
|
||||||
group='baremetal')
|
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):
|
def build_network_config(network_info):
|
||||||
interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6)
|
interfaces = bm_utils.map_network_interfaces(network_info, CONF.use_ipv6)
|
||||||
cheetah = _get_cheetah()
|
tmpl_path, tmpl_file = os.path.split(CONF.baremetal.net_config_template)
|
||||||
network_config = str(cheetah(
|
env = jinja2.Environment(loader=jinja2.FileSystemLoader(tmpl_path))
|
||||||
open(CONF.baremetal.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):
|
||||||
|
@ -7,26 +7,26 @@
|
|||||||
auto lo
|
auto lo
|
||||||
iface lo inet loopback
|
iface lo inet loopback
|
||||||
|
|
||||||
#for $ifc in $interfaces
|
{% for ifc in interfaces -%}
|
||||||
auto ${ifc.name}
|
auto {{ ifc.name }}
|
||||||
iface ${ifc.name} inet static
|
iface {{ ifc.name }} inet static
|
||||||
address ${ifc.address}
|
address {{ ifc.address }}
|
||||||
netmask ${ifc.netmask}
|
netmask {{ ifc.netmask }}
|
||||||
broadcast ${ifc.broadcast}
|
broadcast {{ ifc.broadcast }}
|
||||||
#if $ifc.gateway
|
{%- if ifc.gateway %}
|
||||||
gateway ${ifc.gateway}
|
gateway {{ ifc.gateway }}
|
||||||
#end if
|
{%- endif %}
|
||||||
#if $ifc.dns
|
{%- if ifc.dns %}
|
||||||
dns-nameservers ${ifc.dns}
|
dns-nameservers {{ ifc.dns }}
|
||||||
#end if
|
{%- endif %}
|
||||||
|
|
||||||
#if $use_ipv6
|
{% if use_ipv6 -%}
|
||||||
iface ${ifc.name} inet6 static
|
iface {{ ifc.name }} inet6 static
|
||||||
address ${ifc.address_v6}
|
address {{ ifc.address_v6 }}
|
||||||
netmask ${ifc.netmask_v6}
|
netmask {{ ifc.netmask_v6 }}
|
||||||
#if $ifc.gateway_v6
|
{%- if ifc.gateway_v6 %}
|
||||||
gateway ${ifc.gateway_v6}
|
gateway {{ ifc.gateway_v6 }}
|
||||||
#end if
|
{%- endif %}
|
||||||
#end if
|
{%- endif %}
|
||||||
|
|
||||||
#end for
|
{%- endfor %}
|
||||||
|
@ -21,7 +21,9 @@
|
|||||||
|
|
||||||
"""Network-related utilities for supporting libvirt connection code."""
|
"""Network-related utilities for supporting libvirt connection code."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
import jinja2
|
||||||
import netaddr
|
import netaddr
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
@ -32,16 +34,6 @@ CONF = cfg.CONF
|
|||||||
CONF.import_opt('use_ipv6', 'nova.netconf')
|
CONF.import_opt('use_ipv6', 'nova.netconf')
|
||||||
CONF.import_opt('injected_network_template', 'nova.virt.disk.api')
|
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):
|
def get_net_and_mask(cidr):
|
||||||
net = netaddr.IPNetwork(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):
|
def build_template(template, nets, ipv6_is_available):
|
||||||
_late_load_cheetah()
|
tmpl_path, tmpl_file = os.path.split(CONF.injected_network_template)
|
||||||
|
env = jinja2.Environment(loader=jinja2.FileSystemLoader(tmpl_path))
|
||||||
ifc_template = open(template).read()
|
template = env.get_template(tmpl_file)
|
||||||
return str(Template(ifc_template,
|
return template.render({'interfaces': nets,
|
||||||
searchList=[{'interfaces': nets,
|
'use_ipv6': ipv6_is_available})
|
||||||
'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
|
prepares the ssh key and the network configuration file to be
|
||||||
injected into the disk image
|
injected into the disk image
|
||||||
"""
|
"""
|
||||||
#do the import here - Cheetah.Template will be loaded
|
#do the import here - Jinja2 will be loaded only if injection is performed
|
||||||
#only if injection is performed
|
import jinja2
|
||||||
from Cheetah import Template as t
|
tmpl_path, tmpl_file = os.path.split(CONF.injected_network_template)
|
||||||
template = t.Template
|
env = jinja2.Environment(loader=jinja2.FileSystemLoader(tmpl_path))
|
||||||
template_data = open(CONF.injected_network_template).read()
|
template = env.get_template(tmpl_file)
|
||||||
|
|
||||||
metadata = inst['metadata']
|
metadata = inst['metadata']
|
||||||
key = str(inst['key_data'])
|
key = str(inst['key_data'])
|
||||||
@ -2301,9 +2301,8 @@ def _prepare_injectables(inst, network_info):
|
|||||||
interfaces_info.append(interface_info)
|
interfaces_info.append(interface_info)
|
||||||
|
|
||||||
if interfaces_info:
|
if interfaces_info:
|
||||||
net = str(template(template_data,
|
net = template.render({'interfaces': interfaces_info,
|
||||||
searchList=[{'interfaces': interfaces_info,
|
'use_ipv6': CONF.use_ipv6})
|
||||||
'use_ipv6': CONF.use_ipv6}]))
|
|
||||||
return key, net, metadata
|
return key, net, metadata
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
d2to1>=0.2.10,<0.3
|
d2to1>=0.2.10,<0.3
|
||||||
pbr>=0.5.16,<0.6
|
pbr>=0.5.16,<0.6
|
||||||
SQLAlchemy>=0.7.8,<0.7.99
|
SQLAlchemy>=0.7.8,<0.7.99
|
||||||
Cheetah>=2.4.4
|
|
||||||
amqplib>=0.6.1
|
amqplib>=0.6.1
|
||||||
anyjson>=0.2.4
|
anyjson>=0.2.4
|
||||||
argparse
|
argparse
|
||||||
boto
|
boto
|
||||||
eventlet>=0.9.17
|
eventlet>=0.9.17
|
||||||
|
Jinja2
|
||||||
kombu>=1.0.4
|
kombu>=1.0.4
|
||||||
lxml>=2.3
|
lxml>=2.3
|
||||||
routes>=1.12.3
|
routes>=1.12.3
|
||||||
|
Loading…
Reference in New Issue
Block a user