summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-09-28 13:20:55 -0700
committerScott Moser <smoser@brickies.net>2017-06-08 12:59:48 -0400
commit41d46bfb85929c79dabcec3cf21c8d71401fd2b8 (patch)
treea8d1dfca99db8f172f936f2ae22b486d2749241e /setup.py
parente7c95208451422cfd3da7edfbd67dd271e7aa337 (diff)
downloadvyos-cloud-init-41d46bfb85929c79dabcec3cf21c8d71401fd2b8.tar.gz
vyos-cloud-init-41d46bfb85929c79dabcec3cf21c8d71401fd2b8.zip
cloud.cfg: move to a template. setup.py changes along the way.
Here we move the config/cloud.cfg to be rendered as a template. That allows us to maintain deltas between distros in one place. Currently we use 'variant' variable to make decisions. A tools/render-cloudcfg is provided to render the file. There were changes to setup.py, MANIFEST.in to allow us to put all files into a virtual env installation and to render the cloud-config file in 'install' or 'bdist' targets. We have also included some config changes that were found in the redhat distro spec. * include some config changes from the redhat distro spec. The rendered cloud.cfg has some differences. Ubuntu: white space and comment changes only. Freebsd: - whitespace changes and comment changes - datasource_list definition moved to be closer to 'datasource'. - enable modules: migrator, write_files - move package-update-upgrade-install to final. The initial work was done by Josh Harlow.
Diffstat (limited to 'setup.py')
-rwxr-xr-xsetup.py168
1 files changed, 101 insertions, 67 deletions
diff --git a/setup.py b/setup.py
index 4616599b..d5223285 100755
--- a/setup.py
+++ b/setup.py
@@ -10,8 +10,11 @@
from glob import glob
+import atexit
import os
+import shutil
import sys
+import tempfile
import setuptools
from setuptools.command.install import install
@@ -53,47 +56,15 @@ def pkg_config_read(library, var):
cmd = ['pkg-config', '--variable=%s' % var, library]
try:
(path, err) = tiny_p(cmd)
+ path = path.strip()
except Exception:
- return fallbacks[library][var]
- return str(path).strip()
+ path = fallbacks[library][var]
+ if path.startswith("/"):
+ path = path[1:]
+ return path
-INITSYS_FILES = {
- 'sysvinit': [f for f in glob('sysvinit/redhat/*') if is_f(f)],
- 'sysvinit_freebsd': [f for f in glob('sysvinit/freebsd/*') if is_f(f)],
- 'sysvinit_deb': [f for f in glob('sysvinit/debian/*') if is_f(f)],
- 'sysvinit_openrc': [f for f in glob('sysvinit/gentoo/*') if is_f(f)],
- 'systemd': [f for f in (glob('systemd/*.service') +
- glob('systemd/*.target')) if is_f(f)],
- 'systemd.generators': [f for f in glob('systemd/*-generator') if is_f(f)],
- 'upstart': [f for f in glob('upstart/*') if is_f(f)],
-}
-INITSYS_ROOTS = {
- 'sysvinit': '/etc/rc.d/init.d',
- 'sysvinit_freebsd': '/usr/local/etc/rc.d',
- 'sysvinit_deb': '/etc/init.d',
- 'sysvinit_openrc': '/etc/init.d',
- 'systemd': pkg_config_read('systemd', 'systemdsystemunitdir'),
- 'systemd.generators': pkg_config_read('systemd',
- 'systemdsystemgeneratordir'),
- 'upstart': '/etc/init/',
-}
-INITSYS_TYPES = sorted([f.partition(".")[0] for f in INITSYS_ROOTS.keys()])
-
-# Install everything in the right location and take care of Linux (default) and
-# FreeBSD systems.
-USR = "/usr"
-ETC = "/etc"
-USR_LIB_EXEC = "/usr/lib"
-LIB = "/lib"
-if os.uname()[0] == 'FreeBSD':
- USR = "/usr/local"
- USR_LIB_EXEC = "/usr/local/lib"
-elif os.path.isfile('/etc/redhat-release'):
- USR_LIB_EXEC = "/usr/libexec"
-
-# Avoid having datafiles installed in a virtualenv...
def in_virtualenv():
try:
if sys.real_prefix == sys.prefix:
@@ -116,6 +87,66 @@ def read_requires():
return str(deps).splitlines()
+def render_cloud_cfg():
+ """render cloud.cfg into a tmpdir under same dir as setup.py
+
+ This is rendered to a temporary directory under the top level
+ directory with the name 'cloud.cfg'. The reason for not just rendering
+ to config/cloud.cfg is for a.) don't want to write over contents
+ in that file if user had something there. b.) debuild will complain
+ that files are different outside of the debian directory."""
+
+ # older versions of tox use bdist (xenial), and then install from there.
+ # newer versions just use install.
+ if not (sys.argv[1] == 'install' or sys.argv[1].startswith('bdist*')):
+ return 'config/cloud.cfg.tmpl'
+ topdir = os.path.dirname(sys.argv[0])
+ tmpd = tempfile.mkdtemp(dir=topdir)
+ atexit.register(shutil.rmtree, tmpd)
+ fpath = os.path.join(tmpd, 'cloud.cfg')
+ tiny_p([sys.executable, './tools/render-cloudcfg',
+ 'config/cloud.cfg.tmpl', fpath])
+ # relpath is relative to setup.py
+ relpath = os.path.join(os.path.basename(tmpd), 'cloud.cfg')
+ return relpath
+
+
+INITSYS_FILES = {
+ 'sysvinit': [f for f in glob('sysvinit/redhat/*') if is_f(f)],
+ 'sysvinit_freebsd': [f for f in glob('sysvinit/freebsd/*') if is_f(f)],
+ 'sysvinit_deb': [f for f in glob('sysvinit/debian/*') if is_f(f)],
+ 'sysvinit_openrc': [f for f in glob('sysvinit/gentoo/*') if is_f(f)],
+ 'systemd': [f for f in (glob('systemd/*.service') +
+ glob('systemd/*.target')) if is_f(f)],
+ 'systemd.generators': [f for f in glob('systemd/*-generator') if is_f(f)],
+ 'upstart': [f for f in glob('upstart/*') if is_f(f)],
+}
+INITSYS_ROOTS = {
+ 'sysvinit': 'etc/rc.d/init.d',
+ 'sysvinit_freebsd': 'usr/local/etc/rc.d',
+ 'sysvinit_deb': 'etc/init.d',
+ 'sysvinit_openrc': 'etc/init.d',
+ 'systemd': pkg_config_read('systemd', 'systemdsystemunitdir'),
+ 'systemd.generators': pkg_config_read('systemd',
+ 'systemdsystemgeneratordir'),
+ 'upstart': 'etc/init/',
+}
+INITSYS_TYPES = sorted([f.partition(".")[0] for f in INITSYS_ROOTS.keys()])
+
+
+# Install everything in the right location and take care of Linux (default) and
+# FreeBSD systems.
+USR = "usr"
+ETC = "etc"
+USR_LIB_EXEC = "usr/lib"
+LIB = "lib"
+if os.uname()[0] == 'FreeBSD':
+ USR = "usr/local"
+ USR_LIB_EXEC = "usr/local/lib"
+elif os.path.isfile('/etc/redhat-release'):
+ USR_LIB_EXEC = "usr/libexec"
+
+
# TODO: Is there a better way to do this??
class InitsysInstallData(install):
init_system = None
@@ -155,36 +186,39 @@ class InitsysInstallData(install):
self.distribution.reinitialize_command('install_data', True)
-if in_virtualenv():
- data_files = []
- cmdclass = {}
-else:
- data_files = [
- (ETC + '/cloud', glob('config/*.cfg')),
- (ETC + '/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')),
- (ETC + '/cloud/templates', glob('templates/*')),
- (USR_LIB_EXEC + '/cloud-init', ['tools/ds-identify',
- 'tools/uncloud-init',
- 'tools/write-ssh-key-fingerprints']),
- (USR + '/share/doc/cloud-init', [f for f in glob('doc/*') if is_f(f)]),
- (USR + '/share/doc/cloud-init/examples',
- [f for f in glob('doc/examples/*') if is_f(f)]),
- (USR + '/share/doc/cloud-init/examples/seed',
- [f for f in glob('doc/examples/seed/*') if is_f(f)]),
- ]
- if os.uname()[0] != 'FreeBSD':
- data_files.extend([
- (ETC + '/NetworkManager/dispatcher.d/',
- ['tools/hook-network-manager']),
- (ETC + '/dhcp/dhclient-exit-hooks.d/', ['tools/hook-dhclient']),
- (LIB + '/udev/rules.d', [f for f in glob('udev/*.rules')])
- ])
- # Use a subclass for install that handles
- # adding on the right init system configuration files
- cmdclass = {
- 'install': InitsysInstallData,
- }
-
+if not in_virtualenv():
+ USR = "/" + USR
+ ETC = "/" + ETC
+ USR_LIB_EXEC = "/" + USR_LIB_EXEC
+ LIB = "/" + LIB
+ for k in INITSYS_ROOTS.keys():
+ INITSYS_ROOTS[k] = "/" + INITSYS_ROOTS[k]
+
+data_files = [
+ (ETC + '/cloud', [render_cloud_cfg()]),
+ (ETC + '/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')),
+ (ETC + '/cloud/templates', glob('templates/*')),
+ (USR_LIB_EXEC + '/cloud-init', ['tools/ds-identify',
+ 'tools/uncloud-init',
+ 'tools/write-ssh-key-fingerprints']),
+ (USR + '/share/doc/cloud-init', [f for f in glob('doc/*') if is_f(f)]),
+ (USR + '/share/doc/cloud-init/examples',
+ [f for f in glob('doc/examples/*') if is_f(f)]),
+ (USR + '/share/doc/cloud-init/examples/seed',
+ [f for f in glob('doc/examples/seed/*') if is_f(f)]),
+]
+if os.uname()[0] != 'FreeBSD':
+ data_files.extend([
+ (ETC + '/NetworkManager/dispatcher.d/',
+ ['tools/hook-network-manager']),
+ (ETC + '/dhcp/dhclient-exit-hooks.d/', ['tools/hook-dhclient']),
+ (LIB + '/udev/rules.d', [f for f in glob('udev/*.rules')])
+ ])
+# Use a subclass for install that handles
+# adding on the right init system configuration files
+cmdclass = {
+ 'install': InitsysInstallData,
+}
requirements = read_requires()
if sys.version_info < (3,):