Revert back to using cheetah + adjust resultant code + templates

At this point there is a mixture of "double hash" cheetah comments and '#*'
cheetah comments.
This commit is contained in:
Joshua Harlow 2012-07-09 16:41:45 -04:00 committed by Scott Moser
parent 5e953fddfb
commit 134de1bb7b
14 changed files with 176 additions and 173 deletions

View File

@ -1,9 +1,7 @@
# Pypi requirements for cloud-init to work
# Used for templating any files or strings that are considered
# to be templates, not cheetah since it pulls in alot of extra libs.
# This one is pretty dinky and does want we want (var substituion)
Tempita
# Used for untemplating any files or strings with parameters.
cheetah
# This is used for any pretty printing of tabular data.
PrettyTable

View File

@ -45,9 +45,9 @@ from cloudinit.settings import (PER_INSTANCE, PER_ALWAYS, PER_ONCE,
CLOUD_CONFIG)
# Pretty little welcome message template
WELCOME_MSG_TPL = ("Cloud-init v. {{version}} running '{{action}}' at "
"{{timestamp}}. Up {{uptime}} seconds.")
# Pretty little cheetah formatted welcome message template
WELCOME_MSG_TPL = ("Cloud-init v. ${version} running '${action}' at "
"${timestamp}. Up ${uptime} seconds.")
# Module section template
MOD_SECTION_TPL = "cloud_%s_modules"

View File

@ -26,23 +26,20 @@ from cloudinit.settings import PER_ALWAYS
frequency = PER_ALWAYS
FINAL_MESSAGE_DEF = ("Cloud-init v. {{version}} finished at {{timestamp}}."
" Up {{uptime}} seconds.")
# Cheetah formated default message
FINAL_MESSAGE_DEF = ("Cloud-init v. ${version} finished at ${timestamp}."
" Up ${uptime} seconds.")
def handle(_name, cfg, cloud, log, args):
msg_in = None
msg_in = ''
if len(args) != 0:
msg_in = args[0]
msg_in = str(args[0])
else:
msg_in = util.get_cfg_option_str(cfg, "final_message")
if not msg_in:
template_fn = cloud.get_template_filename('final_message')
if template_fn:
msg_in = util.load_file(template_fn)
msg_in = util.get_cfg_option_str(cfg, "final_message". msg_in)
msg_in = msg_in.strip()
if not msg_in:
msg_in = FINAL_MESSAGE_DEF

View File

@ -36,11 +36,11 @@ def handle(name, cfg, cloud, log, _args):
return
# Render from a template file
distro_n = cloud.distro.name
tpl_fn_name = cloud.get_template_filename("hosts.%s" % (distro_n))
tpl_fn_name = cloud.get_template_filename("hosts.%s" %
(cloud.distro.name))
if not tpl_fn_name:
raise RuntimeError(("No hosts template could be"
" found for distro %s") % (distro_n))
" found for distro %s") % (cloud.distro.name))
out_fn = cloud.paths.join(False, '/etc/hosts')
templater.render_to_file(tpl_fn_name, out_fn,

View File

@ -20,13 +20,13 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from tempita import Template
from Cheetah.Template import Template
from cloudinit import util
def render_from_file(fn, params):
return render_string(util.load_file(fn), params, name=fn)
return render_string(util.load_file(fn), params)
def render_to_file(fn, outfn, params, mode=0644):
@ -34,8 +34,7 @@ def render_to_file(fn, outfn, params, mode=0644):
util.write_file(outfn, contents, mode=mode)
def render_string(content, params, name=None):
tpl = Template(content, name=name)
def render_string(content, params):
if not params:
params = dict()
return tpl.substitute(params)
params = {}
return Template(content, searchList=[params]).respond()

View File

@ -25,15 +25,16 @@ from cloudinit import util
import argparse
# Package names that will showup in requires to what we can actually
# use in our debian 'control' file
# use in our debian 'control' file, this is a translation of the 'requires'
# file pypi package name to a debian/ubuntu package name.
PKG_MP = {
'tempita': 'python-tempita',
'boto': 'python-boto',
'configobj': 'python-configobj',
'oauth': 'python-oauth',
'yaml': 'python-yaml',
'pyyaml': 'python-yaml',
'prettytable': 'python-prettytable',
'argparse': 'python-argparse',
'cheetah': 'python-cheetah',
}
@ -43,7 +44,7 @@ def write_debian_folder(root, version, revno):
# Fill in the change log template
templater.render_to_file(util.abs_join(find_root(),
'packages', 'debian', 'changelog'),
'packages', 'debian', 'changelog.in'),
util.abs_join(deb_dir, 'changelog'),
params={
'version': version,
@ -53,27 +54,23 @@ def write_debian_folder(root, version, revno):
# Write out the control file template
cmd = [util.abs_join(find_root(), 'tools', 'read-dependencies')]
(stdout, _stderr) = util.subp(cmd)
pkgs = [p.lower().strip() for p in stdout.splitlines()]
# Map to known packages
pkgs = [p.lower().strip() for p in stdout.splitlines()]
requires = []
for p in pkgs:
tgt_pkg = None
for name in PKG_MP.keys():
if p.find(name) != -1:
tgt_pkg = PKG_MP.get(name)
break
tgt_pkg = PKG_MP.get(p)
if not tgt_pkg:
raise RuntimeError(("Do not know how to translate %s to "
" a known package") % (p))
raise RuntimeError(("Do not know how to translate pypi dependency"
" %r to a known package") % (p))
else:
requires.append(tgt_pkg)
templater.render_to_file(util.abs_join(find_root(),
'packages', 'debian', 'control'),
'packages', 'debian', 'control.in'),
util.abs_join(deb_dir, 'control'),
params={'requires': requires})
# Just copy the following directly
for base_fn in ['dirs', 'copyright', 'compat', 'pycompat', 'rules']:
shutil.copy(util.abs_join(find_root(),
@ -143,6 +140,12 @@ def main():
cmd.extend(os.listdir(xdir))
util.subp(cmd, capture=capture)
# Copy it locally for reference
shutil.copy(util.abs_join(tdir, tar_fn),
util.abs_join(os.getcwd(), tar_fn))
print("Copied that archive to %r for local usage (if desired)." %
(util.abs_join(os.getcwd(), tar_fn)))
print("Running 'debuild' in %r" % (xdir))
with util.chdir(xdir):
cmd = ['debuild', '--preserve-envvar', 'INIT_SYSTEM']

View File

@ -31,14 +31,16 @@ from cloudinit import templater
from cloudinit import util
# Mapping of expected packages to there full name...
# this is a translation of the 'requires'
# file pypi package name to a redhat/fedora package name.
PKG_MP = {
'boto': 'python-boto',
'tempita': 'python-tempita',
'cheetah': 'python-cheetah',
'prettytable': 'python-prettytable',
'oauth': 'python-oauth',
'configobj': 'python-configobj',
'yaml': 'PyYAML',
'argparse': 'python-argparse'
'pyyaml': 'PyYAML',
'argparse': 'python-argparse',
}
# Subdirectories of the ~/rpmbuild dir
@ -106,25 +108,18 @@ def generate_spec_contents(args, tmpl_fn, arc_fn):
subs['revno'] = revno
subs['release'] = "bzr%s" % (revno)
subs['archive_name'] = arc_fn
subs['bd_requires'] = ['python-devel', 'python-setuptools']
cmd = [util.abs_join(find_root(), 'tools', 'read-dependencies')]
(stdout, _stderr) = util.subp(cmd)
# Map to known packages
pkgs = [p.lower().strip() for p in stdout.splitlines()]
# Map to known packages
requires = []
for p in pkgs:
tgt_pkg = None
for name in PKG_MP.keys():
if p.find(name) != -1:
tgt_pkg = PKG_MP.get(name)
break
tgt_pkg = PKG_MP.get(p)
if not tgt_pkg:
raise RuntimeError(("Do not know how to translate %s to "
" a known package") % (p))
raise RuntimeError(("Do not know how to translate pypi dependency"
" %r to a known package") % (p))
else:
requires.append(tgt_pkg)
subs['requires'] = requires
@ -195,8 +190,10 @@ def main():
print("Archived the code in %r" % (real_archive_fn))
# Form the spec file to be used
tmpl_fn = util.abs_join(find_root(), 'packages', 'redhat', 'cloud-init.spec')
contents = generate_spec_contents(args, tmpl_fn, os.path.basename(archive_fn))
tmpl_fn = util.abs_join(find_root(), 'packages',
'redhat', 'cloud-init.spec.in')
contents = generate_spec_contents(args, tmpl_fn,
os.path.basename(archive_fn))
spec_fn = util.abs_join(root_dir, 'cloud-init.spec')
util.write_file(spec_fn, contents)
print("Created spec file at %r" % (spec_fn))

View File

@ -1,4 +1,5 @@
cloud-init ({{version}}~{{revision}}-1) UNRELEASED; urgency=low
## This is a cheetah template
cloud-init (${version}~${revision}-1) UNRELEASED; urgency=low
* build

View File

@ -1,13 +1,16 @@
## This is a cheetah template
Source: cloud-init
Section: admin
Priority: extra
Maintainer: Scott Moser <smoser@ubuntu.com>
Build-Depends: cdbs,
debhelper (>= 5.0.38),
debhelper (>= 5.0.38),
python (>= 2.6.6-3~),
python-nose,
pyflakes,
pylint,
python-setuptools,
python-cheetah,
python-mocker,
python-setuptools
XS-Python-Version: all
@ -18,13 +21,13 @@ Architecture: all
Depends: cloud-utils,
procps,
python,
{{for r in requires}}
{{r}},
{{endfor}}
#for $r in $requires
${r},
#end for
python-software-properties,
${misc:Depends},
${python:Depends}
XB-Python-Version: ${python:Versions}
\${misc:Depends},
\${python:Depends}
XB-Python-Version: \${python:Versions}
Description: Init scripts for cloud instances
Cloud instances need special scripts to run during initialisation
to retrieve and install ssh keys and to let the user run various scripts.

View File

@ -1,3 +1,4 @@
## This is a cheetah template
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
# See: http://www.zarb.org/~jasonc/macros.php
@ -5,20 +6,21 @@
# Or: http://www.rpm.org/max-rpm/ch-rpm-inside.html
Name: cloud-init
Version: {{version}}
Release: {{release}}%{?dist}
Version: ${version}
Release: ${release}%{?dist}
Summary: Cloud instance init scripts
Group: System Environment/Base
License: GPLv3
URL: http://launchpad.net/cloud-init
Source0: {{archive_name}}
Source0: ${archive_name}
BuildArch: noarch
BuildRoot: %{_tmppath}
BuildRequires: python-devel
BuildRequires: python-setuptools
BuildRequires: python-cheetah
# System util packages needed
Requires: shadow-utils
@ -30,23 +32,23 @@ Requires: procps
Requires: shadow-utils
# Install pypi 'dynamic' requirements
{{for r in requires}}
Requires: {{r}}
{{endfor}}
#for $r in $requires
Requires: ${r}
#end for
{{if sysvinit}}
#if $sysvinit
Requires(post): chkconfig
Requires(postun): initscripts
Requires(preun): chkconfig
Requires(preun): initscripts
{{endif}}
#end if
{{if systemd}}
#if $systemd
BuildRequires: systemd-units
Requires(post): systemd-units
Requires(postun): systemd-units
Requires(preun): systemd-units
{{endif}}
#end if
%description
Cloud-init is a set of init scripts for cloud instances. Cloud instances
@ -54,89 +56,89 @@ need special scripts to run during initialization to retrieve and install
ssh keys and to let the user run various scripts.
%prep
%setup -q -n %{name}-%{version}~{{release}}
%setup -q -n %{name}-%{version}~${release}
%build
%{__python} setup.py build
%install
rm -rf $RPM_BUILD_ROOT
rm -rf \$RPM_BUILD_ROOT
%{__python} setup.py install -O1 \
--skip-build --root $RPM_BUILD_ROOT \
--init-system={{init_sys}}
--skip-build --root \$RPM_BUILD_ROOT \
--init-system=${init_sys}
# Note that /etc/rsyslog.d didn't exist by default until F15.
# el6 request: https://bugzilla.redhat.com/show_bug.cgi?id=740420
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d
mkdir -p \$RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d
cp -p tools/21-cloudinit.conf \
$RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d/21-cloudinit.conf
\$RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d/21-cloudinit.conf
%clean
rm -rf $RPM_BUILD_ROOT
rm -rf \$RPM_BUILD_ROOT
%post
{{if systemd}}
if [ $1 -eq 1 ]
#if $systemd
if [ \$1 -eq 1 ]
then
/bin/systemctl enable cloud-config.service >/dev/null 2>&1 || :
/bin/systemctl enable cloud-final.service >/dev/null 2>&1 || :
/bin/systemctl enable cloud-init.service >/dev/null 2>&1 || :
/bin/systemctl enable cloud-init-local.service >/dev/null 2>&1 || :
fi
{{endif}}
#end if
{{if sysvinit}}
#if $sysvinit
/sbin/chkconfig --add %{_initrddir}/cloud-init-local
/sbin/chkconfig --add %{_initrddir}/cloud-init
/sbin/chkconfig --add %{_initrddir}/cloud-config
/sbin/chkconfig --add %{_initrddir}/cloud-final
{{endif}}
#end if
%preun
{{if sysvinit}}
if [ $1 -eq 0 ]
#if $sysvinit
if [ \$1 -eq 0 ]
then
/sbin/service cloud-init stop >/dev/null 2>&1
/sbin/chkconfig --del cloud-init
/sbin/service cloud-init-local stop >/dev/null 2>&1
/sbin/chkconfig --del cloud-init-local
/sbin/service cloud-config stop >/dev/null 2>&1
/sbin/chkconfig --del cloud-config
/sbin/service cloud-final stop >/dev/null 2>&1
/sbin/chkconfig --del cloud-final
/sbin/service cloud-init stop >/dev/null 2>&1 || :
/sbin/chkconfig --del cloud-init || :
/sbin/service cloud-init-local stop >/dev/null 2>&1 || :
/sbin/chkconfig --del cloud-init-local || :
/sbin/service cloud-config stop >/dev/null 2>&1 || :
/sbin/chkconfig --del cloud-config || :
/sbin/service cloud-final stop >/dev/null 2>&1 || :
/sbin/chkconfig --del cloud-final || :
fi
{{endif}}
#end if
{{if systemd}}
if [ $1 -eq 0 ]
#if $systemd
if [ \$1 -eq 0 ]
then
/bin/systemctl --no-reload disable cloud-config.service >/dev/null 2>&1 || :
/bin/systemctl --no-reload disable cloud-final.service >/dev/null 2>&1 || :
/bin/systemctl --no-reload disable cloud-init.service >/dev/null 2>&1 || :
/bin/systemctl --no-reload disable cloud-init-local.service >/dev/null 2>&1 || :
fi
{{endif}}
#end if
%postun
{{if systemd}}
#if $systemd
/bin/systemctl daemon-reload >/dev/null 2>&1 || :
{{endif}}
#end if
%files
{{if sysvinit}}
#if $sysvinit
%attr(0755, root, root) %{_initddir}/cloud-config
%attr(0755, root, root) %{_initddir}/cloud-final
%attr(0755, root, root) %{_initddir}/cloud-init-local
%attr(0755, root, root) %{_initddir}/cloud-init
{{endif}}
#end if
{{if systemd}}
#if $systemd
%{_unitdir}/cloud-*
{{endif}}
#end if
# Program binaries
%{_bindir}/cloud-init*
@ -165,4 +167,4 @@ fi
%changelog
{{changelog}}
${changelog}

View File

@ -1,12 +1,12 @@
log_level :info
log_location "/var/log/chef/client.log"
ssl_verify_mode :verify_none
validation_client_name "{{validation_name}}"
validation_client_name "$validation_name"
validation_key "/etc/chef/validation.pem"
client_key "/etc/chef/client.pem"
chef_server_url "{{server_url}}"
environment "{{environment}}"
node_name "{{node_name}}"
chef_server_url "$server_url"
environment "$environment"
node_name "$node_name"
json_attribs "/etc/chef/firstboot.json"
file_cache_path "/var/cache/chef"
file_backup_path "/var/backups/chef"

View File

@ -1,22 +1,23 @@
{{# This file /etc/cloud/templates/hosts.tmpl is only utilized
#*
This file /etc/cloud/templates/hosts.redhat.tmpl is only utilized
if enabled in cloud-config. Specifically, in order to enable it
you need to add the following to config:
manage_etc_hosts: True}}
#
manage_etc_hosts: True
*#
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.tmpl
# a.) make changes to the master file in /etc/cloud/templates/hosts.redhat.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
#
# The following lines are desirable for IPv4 capable hosts
127.0.0.1 {{fqdn}} {{hostname}}
127.0.0.1 ${fqdn} ${hostname}
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4
# The following lines are desirable for IPv6 capable hosts
::1 {{fqdn}} {{hostname}}
::1 ${fqdn} ${hostname}
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

View File

@ -1,7 +1,9 @@
{{# This file /etc/cloud/templates/hosts.tmpl is only utilized
if enabled in cloud-config. Specifically, in order to enable it
you need to add the following to config:
manage_etc_hosts: True}}
## This file (/etc/cloud/templates/hosts.tmpl) is only utilized
## if enabled in cloud-config. Specifically, in order to enable it
## you need to add the following to config:
## manage_etc_hosts: True
##
## Note, double-hash commented lines will not appear in /etc/hosts
#
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
@ -10,8 +12,8 @@
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
#
# The following lines are desirable for IPv4 capable hosts
127.0.1.1 {{fqdn}} {{hostname}}
## The value '$hostname' will be replaced with the local-hostname
127.0.1.1 $fqdn $hostname
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
@ -21,4 +23,3 @@ ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

View File

@ -1,59 +1,60 @@
# Note, this file is written by cloud-init on first boot of an instance
# modifications made here will not survive a re-bundle.
# if you wish to make changes you can:
# a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
# or do the same in user-data
# b.) add sources in /etc/apt/sources.list.d
# c.) make changes to template file /etc/cloud/templates/sources.list.tmpl
\## Note, this file is written by cloud-init on first boot of an instance
\## modifications made here will not survive a re-bundle.
\## if you wish to make changes you can:
\## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
\## or do the same in user-data
\## b.) add sources in /etc/apt/sources.list.d
\## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl
\###
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb {{mirror}} {{codename}} main
deb-src {{mirror}} {{codename}} main
deb $mirror $codename main
deb-src $mirror $codename main
# Major bug fix updates produced after the final release of the
# distribution.
deb {{mirror}} {{codename}}-updates main
deb-src {{mirror}} {{codename}}-updates main
\## Major bug fix updates produced after the final release of the
\## distribution.
deb $mirror $codename-updates main
deb-src $mirror $codename-updates main
# N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
# team. Also, please note that software in universe WILL NOT receive any
# review or updates from the Ubuntu security team.
deb {{mirror}} {{codename}} universe
deb-src {{mirror}} {{codename}} universe
deb {{mirror}} {{codename}}-updates universe
deb-src {{mirror}} {{codename}}-updates universe
\## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
\## team. Also, please note that software in universe WILL NOT receive any
\## review or updates from the Ubuntu security team.
deb $mirror $codename universe
deb-src $mirror $codename universe
deb $mirror $codename-updates universe
deb-src $mirror $codename-updates universe
# N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
# team, and may not be under a free licence. Please satisfy yourself as to
# your rights to use the software. Also, please note that software in
# multiverse WILL NOT receive any review or updates from the Ubuntu
# security team.
# deb {{mirror}} {{codename}} multiverse
# deb-src {{mirror}} {{codename}} multiverse
# deb {{mirror}} {{codename}}-updates multiverse
# deb-src {{mirror}} {{codename}}-updates multiverse
\## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
\## team, and may not be under a free licence. Please satisfy yourself as to
\## your rights to use the software. Also, please note that software in
\## multiverse WILL NOT receive any review or updates from the Ubuntu
\## security team.
# deb $mirror $codename multiverse
# deb-src $mirror $codename multiverse
# deb $mirror $codename-updates multiverse
# deb-src $mirror $codename-updates multiverse
# Uncomment the following two lines to add software from the 'backports'
# repository.
# N.B. software from this repository may not have been tested as
# extensively as that contained in the main release, although it includes
# newer versions of some applications which may provide useful features.
# Also, please note that software in backports WILL NOT receive any review
# or updates from the Ubuntu security team.
# deb {{mirror}} {{codename}}-backports main restricted universe multiverse
# deb-src {{mirror}} {{codename}}-backports main restricted universe multiverse
\## Uncomment the following two lines to add software from the 'backports'
\## repository.
\## N.B. software from this repository may not have been tested as
\## extensively as that contained in the main release, although it includes
\## newer versions of some applications which may provide useful features.
\## Also, please note that software in backports WILL NOT receive any review
\## or updates from the Ubuntu security team.
# deb $mirror $codename-backports main restricted universe multiverse
# deb-src $mirror $codename-backports main restricted universe multiverse
# Uncomment the following two lines to add software from Canonical's
# 'partner' repository.
# This software is not part of Ubuntu, but is offered by Canonical and the
# respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu {{codename}} partner
# deb-src http://archive.canonical.com/ubuntu {{codename}} partner
\## Uncomment the following two lines to add software from Canonical's
\## 'partner' repository.
\## This software is not part of Ubuntu, but is offered by Canonical and the
\## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu $codename partner
# deb-src http://archive.canonical.com/ubuntu $codename partner
deb http://security.ubuntu.com/ubuntu {{codename}}-security main
deb-src http://security.ubuntu.com/ubuntu {{codename}}-security main
deb http://security.ubuntu.com/ubuntu {{codename}}-security universe
deb-src http://security.ubuntu.com/ubuntu {{codename}}-security universe
# deb http://security.ubuntu.com/ubuntu {{codename}}-security multiverse
# deb-src http://security.ubuntu.com/ubuntu {{codename}}-security multiverse
deb http://security.ubuntu.com/ubuntu $codename-security main
deb-src http://security.ubuntu.com/ubuntu $codename-security main
deb http://security.ubuntu.com/ubuntu $codename-security universe
deb-src http://security.ubuntu.com/ubuntu $codename-security universe
# deb http://security.ubuntu.com/ubuntu $codename-security multiverse
# deb-src http://security.ubuntu.com/ubuntu $codename-security multiverse