df923a
From d700165bae742fe63b535bd86aed9a5067fe8fbb Mon Sep 17 00:00:00 2001
df923a
From: Miroslav Rezanina <mrezanin@redhat.com>
df923a
Date: Thu, 31 May 2018 16:45:23 +0200
df923a
Subject: Add initial redhat setup
df923a
df923a
---
df923a
 cloudinit/config/cc_chef.py           |   6 +-
df923a
 cloudinit/settings.py                 |   7 +-
df923a
 redhat/.gitignore                     |   1 +
df923a
 redhat/Makefile                       |  71 ++++++++
df923a
 redhat/Makefile.common                |  35 ++++
df923a
 redhat/cloud-init-tmpfiles.conf       |   1 +
df923a
 redhat/cloud-init.spec.template       | 306 +++++++++++++++++++++++++++++++
df923a
 redhat/rpmbuild/BUILD/.gitignore      |   3 +
df923a
 redhat/rpmbuild/RPMS/.gitignore       |   3 +
df923a
 redhat/rpmbuild/SOURCES/.gitignore    |   3 +
df923a
 redhat/rpmbuild/SPECS/.gitignore      |   3 +
df923a
 redhat/rpmbuild/SRPMS/.gitignore      |   3 +
df923a
 redhat/scripts/frh.py                 |  27 +++
df923a
 redhat/scripts/git-backport-diff      | 327 ++++++++++++++++++++++++++++++++++
df923a
 redhat/scripts/git-compile-check      | 215 ++++++++++++++++++++++
df923a
 redhat/scripts/process-patches.sh     |  73 ++++++++
df923a
 redhat/scripts/tarball_checksum.sh    |   3 +
df923a
 rhel/README.rhel                      |   5 +
df923a
 rhel/cloud-init-tmpfiles.conf         |   1 +
df923a
 rhel/cloud.cfg                        |  66 +++++++
df923a
 rhel/systemd/cloud-config.service     |  18 ++
df923a
 rhel/systemd/cloud-config.target      |  11 ++
df923a
 rhel/systemd/cloud-final.service      |  19 ++
df923a
 rhel/systemd/cloud-init-local.service |  31 ++++
df923a
 rhel/systemd/cloud-init.service       |  25 +++
df923a
 setup.py                              |  64 +------
df923a
 tools/read-version                    |  19 +-
df923a
 27 files changed, 1262 insertions(+), 84 deletions(-)
df923a
 create mode 100644 redhat/.gitignore
df923a
 create mode 100644 redhat/Makefile
df923a
 create mode 100644 redhat/Makefile.common
df923a
 create mode 100644 redhat/cloud-init-tmpfiles.conf
df923a
 create mode 100644 redhat/cloud-init.spec.template
df923a
 create mode 100644 redhat/rpmbuild/BUILD/.gitignore
df923a
 create mode 100644 redhat/rpmbuild/RPMS/.gitignore
df923a
 create mode 100644 redhat/rpmbuild/SOURCES/.gitignore
df923a
 create mode 100644 redhat/rpmbuild/SPECS/.gitignore
df923a
 create mode 100644 redhat/rpmbuild/SRPMS/.gitignore
df923a
 create mode 100755 redhat/scripts/frh.py
df923a
 create mode 100755 redhat/scripts/git-backport-diff
df923a
 create mode 100755 redhat/scripts/git-compile-check
df923a
 create mode 100755 redhat/scripts/process-patches.sh
df923a
 create mode 100755 redhat/scripts/tarball_checksum.sh
df923a
 create mode 100644 rhel/README.rhel
df923a
 create mode 100644 rhel/cloud-init-tmpfiles.conf
df923a
 create mode 100644 rhel/cloud.cfg
df923a
 create mode 100644 rhel/systemd/cloud-config.service
df923a
 create mode 100644 rhel/systemd/cloud-config.target
df923a
 create mode 100644 rhel/systemd/cloud-final.service
df923a
 create mode 100644 rhel/systemd/cloud-init-local.service
df923a
 create mode 100644 rhel/systemd/cloud-init.service
df923a
df923a
diff --git a/cloudinit/config/cc_chef.py b/cloudinit/config/cc_chef.py
df923a
index 46abedd..fe7bda8 100644
df923a
--- a/cloudinit/config/cc_chef.py
df923a
+++ b/cloudinit/config/cc_chef.py
df923a
@@ -33,7 +33,7 @@ file).
df923a
 
df923a
     chef:
df923a
        directories: (defaulting to /etc/chef, /var/log/chef, /var/lib/chef,
df923a
-                     /var/cache/chef, /var/backups/chef, /var/run/chef)
df923a
+                     /var/cache/chef, /var/backups/chef, /run/chef)
df923a
        validation_cert: (optional string to be written to file validation_key)
df923a
                         special value 'system' means set use existing file
df923a
        validation_key: (optional the path for validation_cert. default
df923a
@@ -88,7 +88,7 @@ CHEF_DIRS = tuple([
df923a
     '/var/lib/chef',
df923a
     '/var/cache/chef',
df923a
     '/var/backups/chef',
df923a
-    '/var/run/chef',
df923a
+    '/run/chef',
df923a
 ])
df923a
 REQUIRED_CHEF_DIRS = tuple([
df923a
     '/etc/chef',
df923a
@@ -112,7 +112,7 @@ CHEF_RB_TPL_DEFAULTS = {
df923a
     'json_attribs': CHEF_FB_PATH,
df923a
     'file_cache_path': "/var/cache/chef",
df923a
     'file_backup_path': "/var/backups/chef",
df923a
-    'pid_file': "/var/run/chef/client.pid",
df923a
+    'pid_file': "/run/chef/client.pid",
df923a
     'show_time': True,
df923a
 }
df923a
 CHEF_RB_TPL_BOOL_KEYS = frozenset(['show_time'])
df923a
diff --git a/cloudinit/settings.py b/cloudinit/settings.py
df923a
index dde5749..a5a1eec 100644
df923a
--- a/cloudinit/settings.py
df923a
+++ b/cloudinit/settings.py
df923a
@@ -43,13 +43,16 @@ CFG_BUILTIN = {
df923a
     ],
df923a
     'def_log_file': '/var/log/cloud-init.log',
df923a
     'log_cfgs': [],
df923a
-    'syslog_fix_perms': ['syslog:adm', 'root:adm', 'root:wheel'],
df923a
+    'mount_default_fields': [None, None, 'auto', 'defaults,nofail', '0', '2'],
df923a
+    'ssh_deletekeys': False,
df923a
+    'ssh_genkeytypes': [],
df923a
+    'syslog_fix_perms': [],
df923a
     'system_info': {
df923a
         'paths': {
df923a
             'cloud_dir': '/var/lib/cloud',
df923a
             'templates_dir': '/etc/cloud/templates/',
df923a
         },
df923a
-        'distro': 'ubuntu',
df923a
+        'distro': 'rhel',
df923a
         'network': {'renderers': None},
df923a
     },
df923a
     'vendor_data': {'enabled': True, 'prefix': []},
df923a
diff --git a/rhel/README.rhel b/rhel/README.rhel
df923a
new file mode 100644
df923a
index 0000000..aa29630
df923a
--- /dev/null
df923a
+++ b/rhel/README.rhel
df923a
@@ -0,0 +1,5 @@
df923a
+The following cloud-init modules are currently unsupported on this OS:
df923a
+ - apt_update_upgrade ('apt_update', 'apt_upgrade', 'apt_mirror', 'apt_preserve_sources_list', 'apt_old_mirror', 'apt_sources', 'debconf_selections', 'packages' options)
df923a
+ - byobu ('byobu_by_default' option)
df923a
+ - chef
df923a
+ - grub_dpkg
df923a
diff --git a/rhel/cloud-init-tmpfiles.conf b/rhel/cloud-init-tmpfiles.conf
df923a
new file mode 100644
df923a
index 0000000..0c6d2a3
df923a
--- /dev/null
df923a
+++ b/rhel/cloud-init-tmpfiles.conf
df923a
@@ -0,0 +1 @@
df923a
+d /run/cloud-init 0700 root root - -
df923a
diff --git a/rhel/cloud.cfg b/rhel/cloud.cfg
df923a
new file mode 100644
df923a
index 0000000..986f241
df923a
--- /dev/null
df923a
+++ b/rhel/cloud.cfg
df923a
@@ -0,0 +1,66 @@
df923a
+users:
df923a
+ - default
df923a
+
df923a
+disable_root: 1
df923a
+ssh_pwauth:   0
df923a
+
df923a
+mount_default_fields: [~, ~, 'auto', 'defaults,nofail', '0', '2']
df923a
+resize_rootfs_tmp: /dev
df923a
+ssh_deletekeys:   0
df923a
+ssh_genkeytypes:  ~
df923a
+syslog_fix_perms: ~
df923a
+
df923a
+cloud_init_modules:
df923a
+ - migrator
df923a
+ - bootcmd
df923a
+ - write-files
df923a
+ - growpart
df923a
+ - resizefs
df923a
+ - set_hostname
df923a
+ - update_hostname
df923a
+ - update_etc_hosts
df923a
+ - rsyslog
df923a
+ - users-groups
df923a
+ - ssh
df923a
+
df923a
+cloud_config_modules:
df923a
+ - mounts
df923a
+ - locale
df923a
+ - set-passwords
df923a
+ - rh_subscription
df923a
+ - yum-add-repo
df923a
+ - package-update-upgrade-install
df923a
+ - timezone
df923a
+ - puppet
df923a
+ - chef
df923a
+ - salt-minion
df923a
+ - mcollective
df923a
+ - disable-ec2-metadata
df923a
+ - runcmd
df923a
+
df923a
+cloud_final_modules:
df923a
+ - rightscale_userdata
df923a
+ - scripts-per-once
df923a
+ - scripts-per-boot
df923a
+ - scripts-per-instance
df923a
+ - scripts-user
df923a
+ - ssh-authkey-fingerprints
df923a
+ - keys-to-console
df923a
+ - phone-home
df923a
+ - final-message
df923a
+
df923a
+system_info:
df923a
+  default_user:
df923a
+    name: cloud-user
df923a
+    lock_passwd: true
df923a
+    gecos: Cloud User
df923a
+    groups: [wheel, adm, systemd-journal]
df923a
+    sudo: ["ALL=(ALL) NOPASSWD:ALL"]
df923a
+    shell: /bin/bash
df923a
+  distro: rhel
df923a
+  paths:
df923a
+    cloud_dir: /var/lib/cloud
df923a
+    templates_dir: /etc/cloud/templates
df923a
+  ssh_svcname: sshd
df923a
+
df923a
+# vim:syntax=yaml
df923a
diff --git a/rhel/systemd/cloud-config.service b/rhel/systemd/cloud-config.service
df923a
new file mode 100644
df923a
index 0000000..12ca9df
df923a
--- /dev/null
df923a
+++ b/rhel/systemd/cloud-config.service
df923a
@@ -0,0 +1,18 @@
df923a
+[Unit]
df923a
+Description=Apply the settings specified in cloud-config
df923a
+After=network-online.target cloud-config.target
df923a
+Wants=network-online.target cloud-config.target
df923a
+ConditionPathExists=!/etc/cloud/cloud-init.disabled
df923a
+ConditionKernelCommandLine=!cloud-init=disabled
df923a
+
df923a
+[Service]
df923a
+Type=oneshot
df923a
+ExecStart=/usr/bin/cloud-init modules --mode=config
df923a
+RemainAfterExit=yes
df923a
+TimeoutSec=0
df923a
+
df923a
+# Output needs to appear in instance console output
df923a
+StandardOutput=journal+console
df923a
+
df923a
+[Install]
df923a
+WantedBy=multi-user.target
df923a
diff --git a/rhel/systemd/cloud-config.target b/rhel/systemd/cloud-config.target
df923a
new file mode 100644
df923a
index 0000000..ae9b7d0
df923a
--- /dev/null
df923a
+++ b/rhel/systemd/cloud-config.target
df923a
@@ -0,0 +1,11 @@
df923a
+# cloud-init normally emits a "cloud-config" upstart event to inform third
df923a
+# parties that cloud-config is available, which does us no good when we're
df923a
+# using systemd.  cloud-config.target serves as this synchronization point
df923a
+# instead.  Services that would "start on cloud-config" with upstart can
df923a
+# instead use "After=cloud-config.target" and "Wants=cloud-config.target"
df923a
+# as appropriate.
df923a
+
df923a
+[Unit]
df923a
+Description=Cloud-config availability
df923a
+Wants=cloud-init-local.service cloud-init.service
df923a
+After=cloud-init-local.service cloud-init.service
df923a
diff --git a/rhel/systemd/cloud-final.service b/rhel/systemd/cloud-final.service
df923a
new file mode 100644
df923a
index 0000000..32a83d8
df923a
--- /dev/null
df923a
+++ b/rhel/systemd/cloud-final.service
df923a
@@ -0,0 +1,19 @@
df923a
+[Unit]
df923a
+Description=Execute cloud user/final scripts
df923a
+After=network-online.target cloud-config.service rc-local.service
df923a
+Wants=network-online.target cloud-config.service
df923a
+ConditionPathExists=!/etc/cloud/cloud-init.disabled
df923a
+ConditionKernelCommandLine=!cloud-init=disabled
df923a
+
df923a
+[Service]
df923a
+Type=oneshot
df923a
+ExecStart=/usr/bin/cloud-init modules --mode=final
df923a
+RemainAfterExit=yes
df923a
+TimeoutSec=0
df923a
+KillMode=process
df923a
+
df923a
+# Output needs to appear in instance console output
df923a
+StandardOutput=journal+console
df923a
+
df923a
+[Install]
df923a
+WantedBy=multi-user.target
df923a
diff --git a/rhel/systemd/cloud-init-local.service b/rhel/systemd/cloud-init-local.service
df923a
new file mode 100644
df923a
index 0000000..656eddb
df923a
--- /dev/null
df923a
+++ b/rhel/systemd/cloud-init-local.service
df923a
@@ -0,0 +1,31 @@
df923a
+[Unit]
df923a
+Description=Initial cloud-init job (pre-networking)
df923a
+DefaultDependencies=no
df923a
+Wants=network-pre.target
df923a
+After=systemd-remount-fs.service
df923a
+Requires=dbus.socket
df923a
+After=dbus.socket
df923a
+Before=NetworkManager.service network.service
df923a
+Before=network-pre.target
df923a
+Before=shutdown.target
df923a
+Before=firewalld.target
df923a
+Conflicts=shutdown.target
df923a
+RequiresMountsFor=/var/lib/cloud
df923a
+ConditionPathExists=!/etc/cloud/cloud-init.disabled
df923a
+ConditionKernelCommandLine=!cloud-init=disabled
df923a
+
df923a
+[Service]
df923a
+Type=oneshot
df923a
+ExecStartPre=/bin/mkdir -p /run/cloud-init
df923a
+ExecStartPre=/sbin/restorecon /run/cloud-init
df923a
+ExecStartPre=/usr/bin/touch /run/cloud-init/enabled
df923a
+ExecStart=/usr/bin/cloud-init init --local
df923a
+ExecStart=/bin/touch /run/cloud-init/network-config-ready
df923a
+RemainAfterExit=yes
df923a
+TimeoutSec=0
df923a
+
df923a
+# Output needs to appear in instance console output
df923a
+StandardOutput=journal+console
df923a
+
df923a
+[Install]
df923a
+WantedBy=multi-user.target
df923a
diff --git a/rhel/systemd/cloud-init.service b/rhel/systemd/cloud-init.service
df923a
new file mode 100644
df923a
index 0000000..68fc5f1
df923a
--- /dev/null
df923a
+++ b/rhel/systemd/cloud-init.service
df923a
@@ -0,0 +1,25 @@
df923a
+[Unit]
df923a
+Description=Initial cloud-init job (metadata service crawler)
df923a
+Wants=cloud-init-local.service
df923a
+Wants=sshd-keygen.service
df923a
+Wants=sshd.service
df923a
+After=cloud-init-local.service
df923a
+After=NetworkManager.service network.service
df923a
+Before=network-online.target
df923a
+Before=sshd-keygen.service
df923a
+Before=sshd.service
df923a
+Before=systemd-user-sessions.service
df923a
+ConditionPathExists=!/etc/cloud/cloud-init.disabled
df923a
+ConditionKernelCommandLine=!cloud-init=disabled
df923a
+
df923a
+[Service]
df923a
+Type=oneshot
df923a
+ExecStart=/usr/bin/cloud-init init
df923a
+RemainAfterExit=yes
df923a
+TimeoutSec=0
df923a
+
df923a
+# Output needs to appear in instance console output
df923a
+StandardOutput=journal+console
df923a
+
df923a
+[Install]
df923a
+WantedBy=multi-user.target
df923a
diff --git a/setup.py b/setup.py
df923a
index bc3f52a..47cf842 100755
df923a
--- a/setup.py
df923a
+++ b/setup.py
df923a
@@ -125,11 +125,6 @@ INITSYS_FILES = {
df923a
     'sysvinit_deb': [f for f in glob('sysvinit/debian/*') if is_f(f)],
df923a
     'sysvinit_openrc': [f for f in glob('sysvinit/gentoo/*') if is_f(f)],
df923a
     'sysvinit_suse': [f for f in glob('sysvinit/suse/*') if is_f(f)],
df923a
-    'systemd': [render_tmpl(f)
df923a
-                for f in (glob('systemd/*.tmpl') +
df923a
-                          glob('systemd/*.service') +
df923a
-                          glob('systemd/*.target')) if is_f(f)],
df923a
-    'systemd.generators': [f for f in glob('systemd/*-generator') if is_f(f)],
df923a
     'upstart': [f for f in glob('upstart/*') if is_f(f)],
df923a
 }
df923a
 INITSYS_ROOTS = {
df923a
@@ -138,9 +133,6 @@ INITSYS_ROOTS = {
df923a
     'sysvinit_deb': 'etc/init.d',
df923a
     'sysvinit_openrc': 'etc/init.d',
df923a
     'sysvinit_suse': 'etc/init.d',
df923a
-    'systemd': pkg_config_read('systemd', 'systemdsystemunitdir'),
df923a
-    'systemd.generators': pkg_config_read('systemd',
df923a
-                                          'systemdsystemgeneratordir'),
df923a
     'upstart': 'etc/init/',
df923a
 }
df923a
 INITSYS_TYPES = sorted([f.partition(".")[0] for f in INITSYS_ROOTS.keys()])
df923a
@@ -178,47 +170,6 @@ class MyEggInfo(egg_info):
df923a
         return ret
df923a
 
df923a
 
df923a
-# TODO: Is there a better way to do this??
df923a
-class InitsysInstallData(install):
df923a
-    init_system = None
df923a
-    user_options = install.user_options + [
df923a
-        # This will magically show up in member variable 'init_sys'
df923a
-        ('init-system=', None,
df923a
-         ('init system(s) to configure (%s) [default: None]' %
df923a
-          (", ".join(INITSYS_TYPES)))),
df923a
-    ]
df923a
-
df923a
-    def initialize_options(self):
df923a
-        install.initialize_options(self)
df923a
-        self.init_system = ""
df923a
-
df923a
-    def finalize_options(self):
df923a
-        install.finalize_options(self)
df923a
-
df923a
-        if self.init_system and isinstance(self.init_system, str):
df923a
-            self.init_system = self.init_system.split(",")
df923a
-
df923a
-        if len(self.init_system) == 0:
df923a
-            self.init_system = ['systemd']
df923a
-
df923a
-        bad = [f for f in self.init_system if f not in INITSYS_TYPES]
df923a
-        if len(bad) != 0:
df923a
-            raise DistutilsArgError(
df923a
-                "Invalid --init-system: %s" % (','.join(bad)))
df923a
-
df923a
-        for system in self.init_system:
df923a
-            # add data files for anything that starts with '<system>.'
df923a
-            datakeys = [k for k in INITSYS_ROOTS
df923a
-                        if k.partition(".")[0] == system]
df923a
-            for k in datakeys:
df923a
-                if not INITSYS_FILES[k]:
df923a
-                    continue
df923a
-                self.distribution.data_files.append(
df923a
-                    (INITSYS_ROOTS[k], INITSYS_FILES[k]))
df923a
-        # Force that command to reinitalize (with new file list)
df923a
-        self.distribution.reinitialize_command('install_data', True)
df923a
-
df923a
-
df923a
 if not in_virtualenv():
df923a
     USR = "/" + USR
df923a
     ETC = "/" + ETC
df923a
@@ -228,11 +179,9 @@ if not in_virtualenv():
df923a
         INITSYS_ROOTS[k] = "/" + INITSYS_ROOTS[k]
df923a
 
df923a
 data_files = [
df923a
-    (ETC + '/cloud', [render_tmpl("config/cloud.cfg.tmpl")]),
df923a
     (ETC + '/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')),
df923a
     (ETC + '/cloud/templates', glob('templates/*')),
df923a
-    (USR_LIB_EXEC + '/cloud-init', ['tools/ds-identify',
df923a
-                                    'tools/uncloud-init',
df923a
+    (USR_LIB_EXEC + '/cloud-init', ['tools/uncloud-init',
df923a
                                     'tools/write-ssh-key-fingerprints']),
df923a
     (USR + '/share/doc/cloud-init', [f for f in glob('doc/*') if is_f(f)]),
df923a
     (USR + '/share/doc/cloud-init/examples',
df923a
@@ -244,15 +193,8 @@ if os.uname()[0] != 'FreeBSD':
df923a
     data_files.extend([
df923a
         (ETC + '/NetworkManager/dispatcher.d/',
df923a
          ['tools/hook-network-manager']),
df923a
-        (ETC + '/dhcp/dhclient-exit-hooks.d/', ['tools/hook-dhclient']),
df923a
-        (LIB + '/udev/rules.d', [f for f in glob('udev/*.rules')])
df923a
+        ('/usr/lib/udev/rules.d', [f for f in glob('udev/*.rules')])
df923a
     ])
df923a
-# Use a subclass for install that handles
df923a
-# adding on the right init system configuration files
df923a
-cmdclass = {
df923a
-    'install': InitsysInstallData,
df923a
-    'egg_info': MyEggInfo,
df923a
-}
df923a
 
df923a
 requirements = read_requires()
df923a
 
df923a
@@ -267,8 +209,6 @@ setuptools.setup(
df923a
     scripts=['tools/cloud-init-per'],
df923a
     license='Dual-licensed under GPLv3 or Apache 2.0',
df923a
     data_files=data_files,
df923a
-    install_requires=requirements,
df923a
-    cmdclass=cmdclass,
df923a
     entry_points={
df923a
         'console_scripts': [
df923a
             'cloud-init = cloudinit.cmd.main:main'
df923a
diff --git a/tools/read-version b/tools/read-version
df923a
index 3ea9e66..d43cc8f 100755
df923a
--- a/tools/read-version
df923a
+++ b/tools/read-version
df923a
@@ -65,23 +65,8 @@ output_json = '--json' in sys.argv
df923a
 src_version = ci_version.version_string()
df923a
 version_long = None
df923a
 
df923a
-if is_gitdir(_tdir) and which("git"):
df923a
-    flags = []
df923a
-    if use_tags:
df923a
-        flags = ['--tags']
df923a
-    cmd = ['git', 'describe', '--abbrev=8', '--match=[0-9]*'] + flags
df923a
-
df923a
-    version = tiny_p(cmd).strip()
df923a
-
df923a
-    if not version.startswith(src_version):
df923a
-        sys.stderr.write("git describe version (%s) differs from "
df923a
-                         "cloudinit.version (%s)\n" % (version, src_version))
df923a
-        sys.exit(1)
df923a
-
df923a
-    version_long = tiny_p(cmd + ["--long"]).strip()
df923a
-else:
df923a
-    version = src_version
df923a
-    version_long = None
df923a
+version = src_version
df923a
+version_long = None
df923a
 
df923a
 # version is X.Y.Z[+xxx.gHASH]
df923a
 # version_long is None or X.Y.Z-xxx-gHASH
df923a
-- 
df923a
1.8.3.1
df923a