summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-07-03 16:04:58 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-07-03 16:04:58 -0700
commitd0665e19efd69eee31344f1a1af212639dda0943 (patch)
treed1ffec27799d7b7309a9f94074dae30ee9d88ad4
parent21117bb5c26abcb42a7dcc5f318190e734c849bd (diff)
downloadvyos-cloud-init-d0665e19efd69eee31344f1a1af212639dda0943.tar.gz
vyos-cloud-init-d0665e19efd69eee31344f1a1af212639dda0943.zip
Add the ability to have setup.py have a CLI option that specifies the daemon type
which then later affects the installation of certain config files, which then can be extracted during package creation as needed.
-rwxr-xr-xpackages/brpm1
-rw-r--r--packages/redhat/cloud-init.spec38
-rwxr-xr-xsetup.py72
3 files changed, 78 insertions, 33 deletions
diff --git a/packages/brpm b/packages/brpm
index 3abd9f15..1212b0e4 100755
--- a/packages/brpm
+++ b/packages/brpm
@@ -150,6 +150,7 @@ def generate_spec_contents(args, tmpl_fn):
else:
subs['systemd'] = False
+ subs['daemon_type'] = args.boot
return templater.render_from_file(tmpl_fn, params=subs)
diff --git a/packages/redhat/cloud-init.spec b/packages/redhat/cloud-init.spec
index e9ce087a..df13bcb7 100644
--- a/packages/redhat/cloud-init.spec
+++ b/packages/redhat/cloud-init.spec
@@ -1,6 +1,6 @@
%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
-# See: See: http://www.zarb.org/~jasonc/macros.php
+# See: http://www.zarb.org/~jasonc/macros.php
# Or: http://fedoraproject.org/wiki/Packaging:ScriptletSnippets
# Or: http://www.rpm.org/max-rpm/ch-rpm-inside.html
@@ -61,7 +61,9 @@ ssh keys and to let the user run various scripts.
%install
rm -rf $RPM_BUILD_ROOT
-%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT
+%{__python} setup.py install -O1 \
+ --skip-build --root $RPM_BUILD_ROOT \
+ --daemon-type={{daemon_type}}
# Note that /etc/rsyslog.d didn't exist by default until F15.
# el6 request: https://bugzilla.redhat.com/show_bug.cgi?id=740420
@@ -69,24 +71,6 @@ mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d
cp -p tools/21-cloudinit.conf \
$RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d/21-cloudinit.conf
-{{if init_d}}
-mkdir -p $RPM_BUILD_ROOT/%{_initddir}/
-{{endif}}
-{{if init_d_local}}
-cp -p initd/cloud-init-local $RPM_BUILD_ROOT/%{_initddir}/
-cp -p initd/cloud-config $RPM_BUILD_ROOT/%{_initddir}/
-cp -p initd/cloud-final $RPM_BUILD_ROOT/%{_initddir}/
-{{elif init_d}}
-cp -p initd/cloud-init $RPM_BUILD_ROOT/%{_initddir}/
-cp -p initd/cloud-config $RPM_BUILD_ROOT/%{_initddir}/
-cp -p initd/cloud-final $RPM_BUILD_ROOT/%{_initddir}/
-{{endif}}
-
-{{if systemd}}
-mkdir -p $RPM_BUILD_ROOT/%{_unitdir}
-cp -p systemd/* $RPM_BUILD_ROOT/%{_unitdir}
-{{endif}}
-
%clean
rm -rf $RPM_BUILD_ROOT
@@ -103,13 +87,13 @@ fi
{{endif}}
{{if init_d_local}}
-/sbin/chkconfig --add /etc/rc.d/init.d/cloud-init-local
+/sbin/chkconfig --add %{_initrddir}/cloud-init-local
{{elif init_d}}
-/sbin/chkconfig --add /etc/rc.d/init.d/cloud-init
+/sbin/chkconfig --add %{_initrddir}/cloud-init
{{endif}}
{{if init_d}}
-/sbin/chkconfig --add /etc/rc.d/init.d/cloud-config
-/sbin/chkconfig --add /etc/rc.d/init.d/cloud-final
+/sbin/chkconfig --add %{_initrddir}/cloud-config
+/sbin/chkconfig --add %{_initrddir}/cloud-final
{{endif}}
%preun
@@ -166,11 +150,7 @@ fi
{{endif}}
{{if systemd}}
-%{_unitdir}/cloud-config.service
-%{_unitdir}/cloud-config.target
-%{_unitdir}/cloud-init.service
-%{_unitdir}/cloud-init-local.service
-%{_unitdir}/cloud-final.service
+%{_unitdir}/cloud-*
{{endif}}
# Program binaries
diff --git a/setup.py b/setup.py
index d6253384..50e95e9d 100755
--- a/setup.py
+++ b/setup.py
@@ -26,10 +26,45 @@ import os
import re
import setuptools
+from setuptools.command.install import install
+
+from distutils.command.install_data import install_data
+from distutils.errors import DistutilsArgError
import subprocess
+def is_f(p):
+ return os.path.isfile(p)
+
+
+DAEMON_FILES = {
+ 'initd': filter((lambda x: is_f(x)
+ and x.find('local') == -1), glob('initd/*')),
+ 'initd-local': filter((lambda x: is_f(x)
+ and not x.endswith('cloud-init')), glob('initd/*')),
+ 'systemd': filter((lambda x: is_f(x)), glob('systemd/*')),
+ 'upstart': filter((lambda x: is_f(x)
+ and x.find('local') == -1
+ and x.find('nonet') == -1), glob('upstart/*')),
+ 'upstart-nonet': filter((lambda x: is_f(x)
+ and x.find('local') == -1
+ and not x.endswith('cloud-init.conf')), glob('upstart/*')),
+ 'upstart-local': filter((lambda x: is_f(x)
+ and x.find('nonet') == -1
+ and not x.endswith('cloud-init.conf')), glob('upstart/*')),
+}
+DAEMON_ROOTS = {
+ 'initd': '/etc/rc.d/init.d',
+ 'initd-local': '/etc/rc.d/init.d',
+ 'systemd': '/etc/systemd/system/',
+ 'upstart': '/etc/init/',
+ 'upstart-nonet': '/etc/init/',
+ 'upstart-local': '/etc/init/',
+}
+DAEMON_TYPES = sorted(list(DAEMON_ROOTS.keys()))
+
+
def tiny_p(cmd, capture=True):
# Darn python 2.6 doesn't have check_output (argggg)
stdout = subprocess.PIPE
@@ -46,10 +81,6 @@ def tiny_p(cmd, capture=True):
return (out, err)
-def is_f(p):
- return os.path.isfile(p)
-
-
def get_version():
cmd = ['tools/read-version']
(ver, _e) = tiny_p(cmd)
@@ -62,6 +93,34 @@ def read_requires():
return deps.splitlines()
+# TODO: Is there a better way to do this??
+class DaemonInstallData(install):
+ user_options = install.user_options + [
+ # This will magically show up in member variable 'daemon_type'
+ ('daemon-type=', None,
+ ('daemon type to configure (%s) [default: None]') %
+ (", ".join(DAEMON_TYPES))
+ ),
+ ]
+
+ def initialize_options(self):
+ install.initialize_options(self)
+ self.daemon_type = None
+
+ def finalize_options(self):
+ install.finalize_options(self)
+ if self.daemon_type and self.daemon_type not in DAEMON_TYPES:
+ raise DistutilsArgError(
+ ("You must specify one of (%s) when"
+ " specifying a daemon type!") % (", ".join(DAEMON_TYPES))
+ )
+ elif self.daemon_type:
+ self.distribution.data_files.append((DAEMON_ROOTS[self.daemon_type],
+ DAEMON_FILES[self.daemon_type]))
+ # Force that command to reinitalize (with new file list)
+ self.distribution.reinitialize_command('install_data', True)
+
+
setuptools.setup(name='cloud-init',
version=get_version(),
description='EC2 initialisation magic',
@@ -84,4 +143,9 @@ setuptools.setup(name='cloud-init',
('/usr/share/doc/cloud-init/examples/seed', filter(is_f, glob('doc/examples/seed/*'))),
],
install_requires=read_requires(),
+ cmdclass = {
+ # Use a subclass for install that handles
+ # adding on the right daemon configuration files
+ 'install': DaemonInstallData,
+ },
)