Merge ~smoser/cloud-init:feature/tpl-cloud-cfg into cloud-init:master

Proposed by Scott Moser
Status: Merged
Merged at revision: 41d46bfb85929c79dabcec3cf21c8d71401fd2b8
Proposed branch: ~smoser/cloud-init:feature/tpl-cloud-cfg
Merge into: cloud-init:master
Diff against target: 753 lines (+379/-157)
7 files modified
MANIFEST.in (+10/-1)
Makefile (+3/-0)
cloudinit/util.py (+28/-1)
config/cloud.cfg.tmpl (+194/-0)
dev/null (+0/-88)
setup.py (+101/-67)
tools/render-cloudcfg (+43/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Ryan Harper Approve
Review via email: mp+325192@code.launchpad.net

Commit message

Make config/cloud.cfg a template and setup.py fixes

Currently there is no real way to have a single 'cloud.cfg' file that
works everywhere. Certain modules are routinely being not applied by
various downstream distributors. Other differences include default user.

This changes cloud.cfg to be a template that we can render per-distro
versions as needed. This makes it easier to identify common themes and
differences and resolve those.

Additionally, we add some fixes to setup.py.
  - sdist now collects all the files.
  - install can now be done into a virtual env, and all the data files
    to with it.

We have also included some config changes that were found in the
redhat distro spec.
 * include some config changes from the redhat distro spec.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

After many retries, both cent6 and cent7 packages install and run.

https://copr.fedorainfracloud.org/coprs/g/cloud-init/cloud-init/

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Ryan Harper (raharper) :
review: Needs Fixing
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) :
Revision history for this message
Ryan Harper (raharper) wrote :

Couple of nits, otherwise looks fine.

Revision history for this message
Scott Moser (smoser) wrote :

addressed all.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

missed one (see inline), fix and I approve

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/MANIFEST.in b/MANIFEST.in
index 9426464..1a4d771 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,6 +1,15 @@
1include *.py MANIFEST.in ChangeLog1include *.py MANIFEST.in LICENSE* ChangeLog
2global-include *.txt *.rst *.ini *.in *.conf *.cfg *.sh2global-include *.txt *.rst *.ini *.in *.conf *.cfg *.sh
3graft config
4graft doc
5graft packages
6graft systemd
7graft sysvinit
8graft templates
9graft tests
3graft tools10graft tools
11graft udev
12graft upstart
4prune build13prune build
5prune dist14prune dist
6prune .tox15prune .tox
diff --git a/Makefile b/Makefile
index 66d1dca..a3bfaf7 100644
--- a/Makefile
+++ b/Makefile
@@ -69,6 +69,9 @@ check_version:
69 "not equal to code version '$(CODE_VERSION)'"; exit 2; \69 "not equal to code version '$(CODE_VERSION)'"; exit 2; \
70 else true; fi70 else true; fi
7171
72config/cloud.cfg:
73 $(PYVER) ./tools/render-cloudcfg config/cloud.cfg.tmpl config/cloud.cfg
74
72clean_pyc:75clean_pyc:
73 @find . -type f -name "*.pyc" -delete76 @find . -type f -name "*.pyc" -delete
7477
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 135e460..b8c3e4e 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -592,13 +592,40 @@ def get_cfg_option_int(yobj, key, default=0):
592592
593593
594def system_info():594def system_info():
595 return {595 info = {
596 'platform': platform.platform(),596 'platform': platform.platform(),
597 'release': platform.release(),597 'release': platform.release(),
598 'python': platform.python_version(),598 'python': platform.python_version(),
599 'uname': platform.uname(),599 'uname': platform.uname(),
600 'dist': platform.linux_distribution(), # pylint: disable=W1505600 'dist': platform.linux_distribution(), # pylint: disable=W1505
601 }601 }
602 plat = info['platform'].lower()
603 # Try to get more info about what it actually is, in a format
604 # that we can easily use across linux and variants...
605 if plat.startswith('darwin'):
606 info['variant'] = 'darwin'
607 elif plat.endswith("bsd"):
608 info['variant'] = 'bsd'
609 elif plat.startswith('win'):
610 info['variant'] = 'windows'
611 elif 'linux' in plat:
612 # Try to get a single string out of these...
613 linux_dist, _version, _id = info['dist']
614 linux_dist = linux_dist.lower()
615 if linux_dist in ('ubuntu', 'linuxmint', 'mint'):
616 info['variant'] = 'ubuntu'
617 else:
618 for prefix, variant in [('redhat', 'rhel'),
619 ('centos', 'centos'),
620 ('fedora', 'fedora'),
621 ('debian', 'debian')]:
622 if linux_dist.startswith(prefix):
623 info['variant'] = variant
624 if 'variant' not in info:
625 info['variant'] = 'linux'
626 if 'variant' not in info:
627 info['variant'] = 'unknown'
628 return info
602629
603630
604def get_cfg_option_list(yobj, key, default=None):631def get_cfg_option_list(yobj, key, default=None):
diff --git a/config/cloud.cfg b/config/cloud.cfg
605deleted file mode 100644632deleted file mode 100644
index 1b93e7f..0000000
--- a/config/cloud.cfg
+++ /dev/null
@@ -1,117 +0,0 @@
1# The top level settings are used as module
2# and system configuration.
3
4# A set of users which may be applied and/or used by various modules
5# when a 'default' entry is found it will reference the 'default_user'
6# from the distro configuration specified below
7users:
8 - default
9
10# If this is set, 'root' will not be able to ssh in and they
11# will get a message to login instead as the above $user (ubuntu)
12disable_root: true
13
14# This will cause the set+update hostname module to not operate (if true)
15preserve_hostname: false
16
17# Example datasource config
18# datasource:
19# Ec2:
20# metadata_urls: [ 'blah.com' ]
21# timeout: 5 # (defaults to 50 seconds)
22# max_wait: 10 # (defaults to 120 seconds)
23
24# The modules that run in the 'init' stage
25cloud_init_modules:
26 - migrator
27 - ubuntu-init-switch
28 - seed_random
29 - bootcmd
30 - write-files
31 - growpart
32 - resizefs
33 - disk_setup
34 - mounts
35 - set_hostname
36 - update_hostname
37 - update_etc_hosts
38 - ca-certs
39 - rsyslog
40 - users-groups
41 - ssh
42
43# The modules that run in the 'config' stage
44cloud_config_modules:
45# Emit the cloud config ready event
46# this can be used by upstart jobs for 'start on cloud-config'.
47 - emit_upstart
48 - snap_config
49 - ssh-import-id
50 - locale
51 - set-passwords
52 - grub-dpkg
53 - apt-pipelining
54 - apt-configure
55 - ntp
56 - timezone
57 - disable-ec2-metadata
58 - runcmd
59 - byobu
60
61# The modules that run in the 'final' stage
62cloud_final_modules:
63 - snappy
64 - package-update-upgrade-install
65 - fan
66 - landscape
67 - lxd
68 - puppet
69 - chef
70 - salt-minion
71 - mcollective
72 - rightscale_userdata
73 - scripts-vendor
74 - scripts-per-once
75 - scripts-per-boot
76 - scripts-per-instance
77 - scripts-user
78 - ssh-authkey-fingerprints
79 - keys-to-console
80 - phone-home
81 - final-message
82 - power-state-change
83
84# System and/or distro specific settings
85# (not accessible to handlers/transforms)
86system_info:
87 # This will affect which distro class gets used
88 distro: ubuntu
89 # Default user name + that default users groups (if added/used)
90 default_user:
91 name: ubuntu
92 lock_passwd: True
93 gecos: Ubuntu
94 groups: [adm, audio, cdrom, dialout, dip, floppy, lxd, netdev, plugdev, sudo, video]
95 sudo: ["ALL=(ALL) NOPASSWD:ALL"]
96 shell: /bin/bash
97 # Other config here will be given to the distro class and/or path classes
98 paths:
99 cloud_dir: /var/lib/cloud/
100 templates_dir: /etc/cloud/templates/
101 upstart_dir: /etc/init/
102 package_mirrors:
103 - arches: [i386, amd64]
104 failsafe:
105 primary: http://archive.ubuntu.com/ubuntu
106 security: http://security.ubuntu.com/ubuntu
107 search:
108 primary:
109 - http://%(ec2_region)s.ec2.archive.ubuntu.com/ubuntu/
110 - http://%(availability_zone)s.clouds.archive.ubuntu.com/ubuntu/
111 - http://%(region)s.clouds.archive.ubuntu.com/ubuntu/
112 security: []
113 - arches: [armhf, armel, default]
114 failsafe:
115 primary: http://ports.ubuntu.com/ubuntu-ports
116 security: http://ports.ubuntu.com/ubuntu-ports
117 ssh_svcname: ssh
diff --git a/config/cloud.cfg-freebsd b/config/cloud.cfg-freebsd
118deleted file mode 1006440deleted file mode 100644
index d666c39..0000000
--- a/config/cloud.cfg-freebsd
+++ /dev/null
@@ -1,88 +0,0 @@
1# The top level settings are used as module
2# and system configuration.
3
4syslog_fix_perms: root:wheel
5
6# This should not be required, but leave it in place until the real cause of
7# not beeing able to find -any- datasources is resolved.
8datasource_list: ['ConfigDrive', 'Azure', 'OpenStack', 'Ec2']
9
10# A set of users which may be applied and/or used by various modules
11# when a 'default' entry is found it will reference the 'default_user'
12# from the distro configuration specified below
13users:
14 - default
15
16# If this is set, 'root' will not be able to ssh in and they
17# will get a message to login instead as the above $user (ubuntu)
18disable_root: false
19
20# This will cause the set+update hostname module to not operate (if true)
21preserve_hostname: false
22
23# Example datasource config
24# datasource:
25# Ec2:
26# metadata_urls: [ 'blah.com' ]
27# timeout: 5 # (defaults to 50 seconds)
28# max_wait: 10 # (defaults to 120 seconds)
29
30# The modules that run in the 'init' stage
31cloud_init_modules:
32# - migrator
33 - seed_random
34 - bootcmd
35# - write-files
36 - growpart
37 - resizefs
38 - set_hostname
39 - update_hostname
40# - update_etc_hosts
41# - ca-certs
42# - rsyslog
43 - users-groups
44 - ssh
45
46# The modules that run in the 'config' stage
47cloud_config_modules:
48# - disk_setup
49# - mounts
50 - ssh-import-id
51 - locale
52 - set-passwords
53 - package-update-upgrade-install
54# - landscape
55 - timezone
56# - puppet
57# - chef
58# - salt-minion
59# - mcollective
60 - disable-ec2-metadata
61 - runcmd
62# - byobu
63
64# The modules that run in the 'final' stage
65cloud_final_modules:
66 - rightscale_userdata
67 - scripts-vendor
68 - scripts-per-once
69 - scripts-per-boot
70 - scripts-per-instance
71 - scripts-user
72 - ssh-authkey-fingerprints
73 - keys-to-console
74 - phone-home
75 - final-message
76 - power-state-change
77
78# System and/or distro specific settings
79# (not accessible to handlers/transforms)
80system_info:
81 distro: freebsd
82 default_user:
83 name: freebsd
84 lock_passwd: True
85 gecos: FreeBSD
86 groups: [wheel]
87 sudo: ["ALL=(ALL) NOPASSWD:ALL"]
88 shell: /bin/tcsh
diff --git a/config/cloud.cfg.tmpl b/config/cloud.cfg.tmpl
89new file mode 1006440new file mode 100644
index 0000000..5af2a88
--- /dev/null
+++ b/config/cloud.cfg.tmpl
@@ -0,0 +1,194 @@
1## template:jinja
2# The top level settings are used as module
3# and system configuration.
4
5{% if variant in ["bsd"] %}
6syslog_fix_perms: root:wheel
7{% endif %}
8# A set of users which may be applied and/or used by various modules
9# when a 'default' entry is found it will reference the 'default_user'
10# from the distro configuration specified below
11users:
12 - default
13
14# If this is set, 'root' will not be able to ssh in and they
15# will get a message to login instead as the default $user
16{% if variant in ["bsd"] %}
17disable_root: false
18{% else %}
19disable_root: true
20{% endif %}
21
22{% if variant in ["centos", "fedora", "rhel"] %}
23mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2']
24resize_rootfs_tmp: /dev
25ssh_deletekeys: 0
26ssh_genkeytypes: ~
27ssh_pwauth: 0
28
29{% endif %}
30# This will cause the set+update hostname module to not operate (if true)
31preserve_hostname: false
32
33{% if variant in ["bsd"] %}
34# This should not be required, but leave it in place until the real cause of
35# not beeing able to find -any- datasources is resolved.
36datasource_list: ['ConfigDrive', 'Azure', 'OpenStack', 'Ec2']
37{% endif %}
38# Example datasource config
39# datasource:
40# Ec2:
41# metadata_urls: [ 'blah.com' ]
42# timeout: 5 # (defaults to 50 seconds)
43# max_wait: 10 # (defaults to 120 seconds)
44
45# The modules that run in the 'init' stage
46cloud_init_modules:
47 - migrator
48{% if variant in ["ubuntu", "unknown", "debian"] %}
49 - ubuntu-init-switch
50{% endif %}
51 - seed_random
52 - bootcmd
53 - write-files
54 - growpart
55 - resizefs
56{% if variant not in ["bsd"] %}
57 - disk_setup
58 - mounts
59{% endif %}
60 - set_hostname
61 - update_hostname
62{% if variant not in ["bsd"] %}
63 - update_etc_hosts
64 - ca-certs
65 - rsyslog
66{% endif %}
67 - users-groups
68 - ssh
69
70# The modules that run in the 'config' stage
71cloud_config_modules:
72{% if variant in ["ubuntu", "unknown", "debian"] %}
73# Emit the cloud config ready event
74# this can be used by upstart jobs for 'start on cloud-config'.
75 - emit_upstart
76 - snap_config
77{% endif %}
78 - ssh-import-id
79 - locale
80 - set-passwords
81{% if variant in ["rhel", "fedora"] %}
82 - spacewalk
83 - yum-add-repo
84{% endif %}
85{% if variant in ["ubuntu", "unknown", "debian"] %}
86 - grub-dpkg
87 - apt-pipelining
88 - apt-configure
89{% endif %}
90{% if variant not in ["bsd"] %}
91 - ntp
92{% endif %}
93 - timezone
94 - disable-ec2-metadata
95 - runcmd
96{% if variant in ["ubuntu", "unknown", "debian"] %}
97 - byobu
98{% endif %}
99
100# The modules that run in the 'final' stage
101cloud_final_modules:
102{% if variant in ["ubuntu", "unknown", "debian"] %}
103 - snappy
104{% endif %}
105 - package-update-upgrade-install
106{% if variant in ["ubuntu", "unknown", "debian"] %}
107 - fan
108 - landscape
109 - lxd
110{% endif %}
111{% if variant not in ["bsd"] %}
112 - puppet
113 - chef
114 - salt-minion
115 - mcollective
116{% endif %}
117 - rightscale_userdata
118 - scripts-vendor
119 - scripts-per-once
120 - scripts-per-boot
121 - scripts-per-instance
122 - scripts-user
123 - ssh-authkey-fingerprints
124 - keys-to-console
125 - phone-home
126 - final-message
127 - power-state-change
128
129# System and/or distro specific settings
130# (not accessible to handlers/transforms)
131system_info:
132 # This will affect which distro class gets used
133{% if variant in ["centos", "debian", "fedora", "rhel", "ubuntu"] %}
134 distro: {{ variant }}
135{% elif variant in ["bsd"] %}
136 distro: freebsd
137{% else %}
138 # Unknown/fallback distro.
139 distro: ubuntu
140{% endif %}
141{% if variant in ["ubuntu", "unknown", "debian"] %}
142 # Default user name + that default users groups (if added/used)
143 default_user:
144 name: ubuntu
145 lock_passwd: True
146 gecos: Ubuntu
147 groups: [adm, audio, cdrom, dialout, dip, floppy, lxd, netdev, plugdev, sudo, video]
148 sudo: ["ALL=(ALL) NOPASSWD:ALL"]
149 shell: /bin/bash
150 # Other config here will be given to the distro class and/or path classes
151 paths:
152 cloud_dir: /var/lib/cloud/
153 templates_dir: /etc/cloud/templates/
154 upstart_dir: /etc/init/
155 package_mirrors:
156 - arches: [i386, amd64]
157 failsafe:
158 primary: http://archive.ubuntu.com/ubuntu
159 security: http://security.ubuntu.com/ubuntu
160 search:
161 primary:
162 - http://%(ec2_region)s.ec2.archive.ubuntu.com/ubuntu/
163 - http://%(availability_zone)s.clouds.archive.ubuntu.com/ubuntu/
164 - http://%(region)s.clouds.archive.ubuntu.com/ubuntu/
165 security: []
166 - arches: [armhf, armel, default]
167 failsafe:
168 primary: http://ports.ubuntu.com/ubuntu-ports
169 security: http://ports.ubuntu.com/ubuntu-ports
170 ssh_svcname: ssh
171{% elif variant in ["centos", "rhel", "fedora"] %}
172 # Default user name + that default users groups (if added/used)
173 default_user:
174 name: {{ variant }}
175 lock_passwd: True
176 gecos: {{ variant }} Cloud User
177 groups: [wheel, adm, systemd-journal]
178 sudo: ["ALL=(ALL) NOPASSWD:ALL"]
179 shell: /bin/bash
180 # Other config here will be given to the distro class and/or path classes
181 paths:
182 cloud_dir: /var/lib/cloud/
183 templates_dir: /etc/cloud/templates/
184 ssh_svcname: sshd
185{% elif variant in ["bsd"] %}
186 # Default user name + that default users groups (if added/used)
187 default_user:
188 name: freebsd
189 lock_passwd: True
190 gecos: FreeBSD
191 groups: [wheel]
192 sudo: ["ALL=(ALL) NOPASSWD:ALL"]
193 shell: /bin/tcsh
194{% endif %}
diff --git a/setup.py b/setup.py
index 4616599..d522328 100755
--- a/setup.py
+++ b/setup.py
@@ -10,8 +10,11 @@
1010
11from glob import glob11from glob import glob
1212
13import atexit
13import os14import os
15import shutil
14import sys16import sys
17import tempfile
1518
16import setuptools19import setuptools
17from setuptools.command.install import install20from setuptools.command.install import install
@@ -53,47 +56,15 @@ def pkg_config_read(library, var):
53 cmd = ['pkg-config', '--variable=%s' % var, library]56 cmd = ['pkg-config', '--variable=%s' % var, library]
54 try:57 try:
55 (path, err) = tiny_p(cmd)58 (path, err) = tiny_p(cmd)
59 path = path.strip()
56 except Exception:60 except Exception:
57 return fallbacks[library][var]61 path = fallbacks[library][var]
58 return str(path).strip()62 if path.startswith("/"):
63 path = path[1:]
5964
65 return path
6066
61INITSYS_FILES = {
62 'sysvinit': [f for f in glob('sysvinit/redhat/*') if is_f(f)],
63 'sysvinit_freebsd': [f for f in glob('sysvinit/freebsd/*') if is_f(f)],
64 'sysvinit_deb': [f for f in glob('sysvinit/debian/*') if is_f(f)],
65 'sysvinit_openrc': [f for f in glob('sysvinit/gentoo/*') if is_f(f)],
66 'systemd': [f for f in (glob('systemd/*.service') +
67 glob('systemd/*.target')) if is_f(f)],
68 'systemd.generators': [f for f in glob('systemd/*-generator') if is_f(f)],
69 'upstart': [f for f in glob('upstart/*') if is_f(f)],
70}
71INITSYS_ROOTS = {
72 'sysvinit': '/etc/rc.d/init.d',
73 'sysvinit_freebsd': '/usr/local/etc/rc.d',
74 'sysvinit_deb': '/etc/init.d',
75 'sysvinit_openrc': '/etc/init.d',
76 'systemd': pkg_config_read('systemd', 'systemdsystemunitdir'),
77 'systemd.generators': pkg_config_read('systemd',
78 'systemdsystemgeneratordir'),
79 'upstart': '/etc/init/',
80}
81INITSYS_TYPES = sorted([f.partition(".")[0] for f in INITSYS_ROOTS.keys()])
82
83# Install everything in the right location and take care of Linux (default) and
84# FreeBSD systems.
85USR = "/usr"
86ETC = "/etc"
87USR_LIB_EXEC = "/usr/lib"
88LIB = "/lib"
89if os.uname()[0] == 'FreeBSD':
90 USR = "/usr/local"
91 USR_LIB_EXEC = "/usr/local/lib"
92elif os.path.isfile('/etc/redhat-release'):
93 USR_LIB_EXEC = "/usr/libexec"
9467
95
96# Avoid having datafiles installed in a virtualenv...
97def in_virtualenv():68def in_virtualenv():
98 try:69 try:
99 if sys.real_prefix == sys.prefix:70 if sys.real_prefix == sys.prefix:
@@ -116,6 +87,66 @@ def read_requires():
116 return str(deps).splitlines()87 return str(deps).splitlines()
11788
11889
90def render_cloud_cfg():
91 """render cloud.cfg into a tmpdir under same dir as setup.py
92
93 This is rendered to a temporary directory under the top level
94 directory with the name 'cloud.cfg'. The reason for not just rendering
95 to config/cloud.cfg is for a.) don't want to write over contents
96 in that file if user had something there. b.) debuild will complain
97 that files are different outside of the debian directory."""
98
99 # older versions of tox use bdist (xenial), and then install from there.
100 # newer versions just use install.
101 if not (sys.argv[1] == 'install' or sys.argv[1].startswith('bdist*')):
102 return 'config/cloud.cfg.tmpl'
103 topdir = os.path.dirname(sys.argv[0])
104 tmpd = tempfile.mkdtemp(dir=topdir)
105 atexit.register(shutil.rmtree, tmpd)
106 fpath = os.path.join(tmpd, 'cloud.cfg')
107 tiny_p([sys.executable, './tools/render-cloudcfg',
108 'config/cloud.cfg.tmpl', fpath])
109 # relpath is relative to setup.py
110 relpath = os.path.join(os.path.basename(tmpd), 'cloud.cfg')
111 return relpath
112
113
114INITSYS_FILES = {
115 'sysvinit': [f for f in glob('sysvinit/redhat/*') if is_f(f)],
116 'sysvinit_freebsd': [f for f in glob('sysvinit/freebsd/*') if is_f(f)],
117 'sysvinit_deb': [f for f in glob('sysvinit/debian/*') if is_f(f)],
118 'sysvinit_openrc': [f for f in glob('sysvinit/gentoo/*') if is_f(f)],
119 'systemd': [f for f in (glob('systemd/*.service') +
120 glob('systemd/*.target')) if is_f(f)],
121 'systemd.generators': [f for f in glob('systemd/*-generator') if is_f(f)],
122 'upstart': [f for f in glob('upstart/*') if is_f(f)],
123}
124INITSYS_ROOTS = {
125 'sysvinit': 'etc/rc.d/init.d',
126 'sysvinit_freebsd': 'usr/local/etc/rc.d',
127 'sysvinit_deb': 'etc/init.d',
128 'sysvinit_openrc': 'etc/init.d',
129 'systemd': pkg_config_read('systemd', 'systemdsystemunitdir'),
130 'systemd.generators': pkg_config_read('systemd',
131 'systemdsystemgeneratordir'),
132 'upstart': 'etc/init/',
133}
134INITSYS_TYPES = sorted([f.partition(".")[0] for f in INITSYS_ROOTS.keys()])
135
136
137# Install everything in the right location and take care of Linux (default) and
138# FreeBSD systems.
139USR = "usr"
140ETC = "etc"
141USR_LIB_EXEC = "usr/lib"
142LIB = "lib"
143if os.uname()[0] == 'FreeBSD':
144 USR = "usr/local"
145 USR_LIB_EXEC = "usr/local/lib"
146elif os.path.isfile('/etc/redhat-release'):
147 USR_LIB_EXEC = "usr/libexec"
148
149
119# TODO: Is there a better way to do this??150# TODO: Is there a better way to do this??
120class InitsysInstallData(install):151class InitsysInstallData(install):
121 init_system = None152 init_system = None
@@ -155,36 +186,39 @@ class InitsysInstallData(install):
155 self.distribution.reinitialize_command('install_data', True)186 self.distribution.reinitialize_command('install_data', True)
156187
157188
158if in_virtualenv():189if not in_virtualenv():
159 data_files = []190 USR = "/" + USR
160 cmdclass = {}191 ETC = "/" + ETC
161else:192 USR_LIB_EXEC = "/" + USR_LIB_EXEC
162 data_files = [193 LIB = "/" + LIB
163 (ETC + '/cloud', glob('config/*.cfg')),194 for k in INITSYS_ROOTS.keys():
164 (ETC + '/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')),195 INITSYS_ROOTS[k] = "/" + INITSYS_ROOTS[k]
165 (ETC + '/cloud/templates', glob('templates/*')),196
166 (USR_LIB_EXEC + '/cloud-init', ['tools/ds-identify',197data_files = [
167 'tools/uncloud-init',198 (ETC + '/cloud', [render_cloud_cfg()]),
168 'tools/write-ssh-key-fingerprints']),199 (ETC + '/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')),
169 (USR + '/share/doc/cloud-init', [f for f in glob('doc/*') if is_f(f)]),200 (ETC + '/cloud/templates', glob('templates/*')),
170 (USR + '/share/doc/cloud-init/examples',201 (USR_LIB_EXEC + '/cloud-init', ['tools/ds-identify',
171 [f for f in glob('doc/examples/*') if is_f(f)]),202 'tools/uncloud-init',
172 (USR + '/share/doc/cloud-init/examples/seed',203 'tools/write-ssh-key-fingerprints']),
173 [f for f in glob('doc/examples/seed/*') if is_f(f)]),204 (USR + '/share/doc/cloud-init', [f for f in glob('doc/*') if is_f(f)]),
174 ]205 (USR + '/share/doc/cloud-init/examples',
175 if os.uname()[0] != 'FreeBSD':206 [f for f in glob('doc/examples/*') if is_f(f)]),
176 data_files.extend([207 (USR + '/share/doc/cloud-init/examples/seed',
177 (ETC + '/NetworkManager/dispatcher.d/',208 [f for f in glob('doc/examples/seed/*') if is_f(f)]),
178 ['tools/hook-network-manager']),209]
179 (ETC + '/dhcp/dhclient-exit-hooks.d/', ['tools/hook-dhclient']),210if os.uname()[0] != 'FreeBSD':
180 (LIB + '/udev/rules.d', [f for f in glob('udev/*.rules')])211 data_files.extend([
181 ])212 (ETC + '/NetworkManager/dispatcher.d/',
182 # Use a subclass for install that handles213 ['tools/hook-network-manager']),
183 # adding on the right init system configuration files214 (ETC + '/dhcp/dhclient-exit-hooks.d/', ['tools/hook-dhclient']),
184 cmdclass = {215 (LIB + '/udev/rules.d', [f for f in glob('udev/*.rules')])
185 'install': InitsysInstallData,216 ])
186 }217# Use a subclass for install that handles
187218# adding on the right init system configuration files
219cmdclass = {
220 'install': InitsysInstallData,
221}
188222
189requirements = read_requires()223requirements = read_requires()
190if sys.version_info < (3,):224if sys.version_info < (3,):
diff --git a/tools/render-cloudcfg b/tools/render-cloudcfg
191new file mode 100755225new file mode 100755
index 0000000..e624541
--- /dev/null
+++ b/tools/render-cloudcfg
@@ -0,0 +1,43 @@
1#!/usr/bin/env python3
2
3import argparse
4import os
5import sys
6
7if "avoid-pep8-E402-import-not-top-of-file":
8 _tdir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
9 sys.path.insert(0, _tdir)
10 from cloudinit import templater
11 from cloudinit import util
12 from cloudinit.atomic_helper import write_file
13
14
15def main():
16 parser = argparse.ArgumentParser()
17 variants = ["bsd", "centos", "fedora", "rhel", "ubuntu", "unknown"]
18 platform = util.system_info()
19 parser.add_argument(
20 "--variant", default=platform['variant'], action="store",
21 help="define the variant.", choices=variants)
22 parser.add_argument(
23 "template", nargs="?", action="store",
24 default='./config/cloud.cfg.tmpl',
25 help="Path to the cloud.cfg template")
26 parser.add_argument(
27 "output", nargs="?", action="store", default="-",
28 help="Output file. Use '-' to write to stdout")
29
30 args = parser.parse_args()
31
32 with open(args.template, 'r') as fh:
33 contents = fh.read()
34 tpl_params = {'variant': args.variant}
35 contents = (templater.render_string(contents, tpl_params)).rstrip() + "\n"
36 util.load_yaml(contents)
37 if args.output == "-":
38 sys.stdout.write(contents)
39 else:
40 write_file(args.output, contents, omode="w")
41
42if __name__ == '__main__':
43 main()

Subscribers

People subscribed via source and target branches