Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

Merge pull request #23024 from phile314/cloud-init-update

cloud-init: 0.7.6 -> 0.7.9 + module improvements

authored by Frederik Rietdijk and committed by GitHub a2598e4c 5e75c735

+179 -56
+56 -50
nixos/modules/services/system/cloud-init.nix
··· 3 3 with lib; 4 4 5 5 let cfg = config.services.cloud-init; 6 - path = with pkgs; [ cloud-init nettools utillinux e2fsprogs shadow dmidecode openssh ]; 7 - configFile = pkgs.writeText "cloud-init.cfg" '' 8 - users: 9 - - root 10 - 11 - disable_root: false 12 - preserve_hostname: false 13 - 14 - cloud_init_modules: 15 - - migrator 16 - - seed_random 17 - - bootcmd 18 - - write-files 19 - - growpart 20 - - resizefs 21 - - set_hostname 22 - - update_hostname 23 - - update_etc_hosts 24 - - ca-certs 25 - - rsyslog 26 - - users-groups 27 - 28 - cloud_config_modules: 29 - - emit_upstart 30 - - disk_setup 31 - - mounts 32 - - ssh-import-id 33 - - set-passwords 34 - - timezone 35 - - disable-ec2-metadata 36 - - runcmd 37 - - ssh 38 - 39 - cloud_final_modules: 40 - - rightscale_userdata 41 - - scripts-vendor 42 - - scripts-per-once 43 - - scripts-per-boot 44 - - scripts-per-instance 45 - - scripts-user 46 - - ssh-authkey-fingerprints 47 - - keys-to-console 48 - - phone-home 49 - - final-message 50 - - power-state-change 51 - ''; 6 + path = with pkgs; [ cloud-init nettools utillinux e2fsprogs shadow openssh iproute ]; 52 7 in 53 8 { 54 9 options = { ··· 74 29 ''; 75 30 }; 76 31 32 + config = mkOption { 33 + type = types.str; 34 + default = '' 35 + system_info: 36 + distro: nixos 37 + users: 38 + - root 39 + 40 + disable_root: false 41 + preserve_hostname: false 42 + 43 + cloud_init_modules: 44 + - migrator 45 + - seed_random 46 + - bootcmd 47 + - write-files 48 + - growpart 49 + - resizefs 50 + - update_etc_hosts 51 + - ca-certs 52 + - rsyslog 53 + - users-groups 54 + 55 + cloud_config_modules: 56 + - disk_setup 57 + - mounts 58 + - ssh-import-id 59 + - set-passwords 60 + - timezone 61 + - disable-ec2-metadata 62 + - runcmd 63 + - ssh 64 + 65 + cloud_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 + description = ''cloud-init configuration.''; 79 + }; 80 + 77 81 }; 78 82 79 83 }; 80 84 81 85 config = mkIf cfg.enable { 82 86 87 + environment.etc."cloud/cloud.cfg".text = cfg.config; 88 + 83 89 systemd.services.cloud-init-local = 84 90 { description = "Initial cloud-init job (pre-networking)"; 85 91 wantedBy = [ "multi-user.target" ]; ··· 88 94 path = path; 89 95 serviceConfig = 90 96 { Type = "oneshot"; 91 - ExecStart = "${pkgs.cloud-init}/bin/cloud-init -f ${configFile} init --local"; 97 + ExecStart = "${pkgs.cloud-init}/bin/cloud-init init --local"; 92 98 RemainAfterExit = "yes"; 93 99 TimeoutSec = "0"; 94 100 StandardOutput = "journal+console"; ··· 105 111 path = path; 106 112 serviceConfig = 107 113 { Type = "oneshot"; 108 - ExecStart = "${pkgs.cloud-init}/bin/cloud-init -f ${configFile} init"; 114 + ExecStart = "${pkgs.cloud-init}/bin/cloud-init init"; 109 115 RemainAfterExit = "yes"; 110 116 TimeoutSec = "0"; 111 117 StandardOutput = "journal+console"; ··· 121 127 path = path; 122 128 serviceConfig = 123 129 { Type = "oneshot"; 124 - ExecStart = "${pkgs.cloud-init}/bin/cloud-init -f ${configFile} modules --mode=config"; 130 + ExecStart = "${pkgs.cloud-init}/bin/cloud-init modules --mode=config"; 125 131 RemainAfterExit = "yes"; 126 132 TimeoutSec = "0"; 127 133 StandardOutput = "journal+console"; ··· 137 143 path = path; 138 144 serviceConfig = 139 145 { Type = "oneshot"; 140 - ExecStart = "${pkgs.cloud-init}/bin/cloud-init -f ${configFile} modules --mode=final"; 146 + ExecStart = "${pkgs.cloud-init}/bin/cloud-init modules --mode=final"; 141 147 RemainAfterExit = "yes"; 142 148 TimeoutSec = "0"; 143 149 StandardOutput = "journal+console";
+113
pkgs/tools/virtualization/cloud-init/add-nixos-support.patch
··· 1 + diff -ruN cloud-init-0.7.6.orig/cloudinit/distros/__init__.py cloud-init-0.7.6/cloudinit/distros/__init__.py 2 + --- cloud-init-0.7.6.orig/cloudinit/distros/__init__.py 2014-10-10 15:26:25.000000000 +0000 3 + +++ cloud-init-0.7.6/cloudinit/distros/__init__.py 2016-06-08 07:51:45.230357099 +0000 4 + @@ -43,6 +43,7 @@ 5 + 'freebsd': ['freebsd'], 6 + 'suse': ['sles'], 7 + 'arch': ['arch'], 8 + + 'nixos': ['nixos'], 9 + } 10 + 11 + LOG = logging.getLogger(__name__) 12 + diff -ruN cloud-init-0.7.6.orig/cloudinit/distros/nixos.py cloud-init-0.7.6/cloudinit/distros/nixos.py 13 + --- cloud-init-0.7.6.orig/cloudinit/distros/nixos.py 1970-01-01 00:00:00.000000000 +0000 14 + +++ cloud-init-0.7.6/cloudinit/distros/nixos.py 2016-06-08 07:50:58.602616595 +0000 15 + @@ -0,0 +1,98 @@ 16 + +# vi: ts=4 expandtab 17 + +# 18 + +# Copyright (C) 2012 Canonical Ltd. 19 + +# Copyright (C) 2012 Hewlett-Packard Development Company, L.P. 20 + +# Copyright (C) 2012 Yahoo! Inc. 21 + +# 22 + +# Author: Scott Moser <scott.moser@canonical.com> 23 + +# Author: Juerg Haefliger <juerg.haefliger@hp.com> 24 + +# Author: Joshua Harlow <harlowja@yahoo-inc.com> 25 + +# 26 + +# This program is free software: you can redistribute it and/or modify 27 + +# it under the terms of the GNU General Public License version 3, as 28 + +# published by the Free Software Foundation. 29 + +# 30 + +# This program is distributed in the hope that it will be useful, 31 + +# but WITHOUT ANY WARRANTY; without even the implied warranty of 32 + +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33 + +# GNU General Public License for more details. 34 + +# 35 + +# You should have received a copy of the GNU General Public License 36 + +# along with this program. If not, see <http://www.gnu.org/licenses/>. 37 + + 38 + +from cloudinit import distros 39 + +from cloudinit import helpers 40 + +from cloudinit import log as logging 41 + +from cloudinit import util 42 + + 43 + +from cloudinit.distros.parsers.hostname import HostnameConf 44 + + 45 + +LOG = logging.getLogger(__name__) 46 + + 47 + +class Distro(distros.Distro): 48 + + 49 + + def __init__(self, name, cfg, paths): 50 + + distros.Distro.__init__(self, name, cfg, paths) 51 + + # This will be used to restrict certain 52 + + # calls from repeatly happening (when they 53 + + # should only happen say once per instance...) 54 + + self._runner = helpers.Runners(paths) 55 + + self.osfamily = 'nixos' 56 + + 57 + + def _select_hostname(self, hostname, fqdn): 58 + + # Prefer the short hostname over the long 59 + + # fully qualified domain name 60 + + if not hostname: 61 + + return fqdn 62 + + return hostname 63 + + 64 + + def _write_hostname(self, your_hostname, out_fn): 65 + + conf = None 66 + + try: 67 + + # Try to update the previous one 68 + + # so lets see if we can read it first. 69 + + conf = self._read_hostname_conf(out_fn) 70 + + except IOError: 71 + + pass 72 + + if not conf: 73 + + conf = HostnameConf('') 74 + + conf.set_hostname(your_hostname) 75 + + util.write_file(out_fn, str(conf), 0644) 76 + + 77 + + def _read_system_hostname(self): 78 + + sys_hostname = self._read_hostname(self.hostname_conf_fn) 79 + + return (self.hostname_conf_fn, sys_hostname) 80 + + 81 + + def _read_hostname_conf(self, filename): 82 + + conf = HostnameConf(util.load_file(filename)) 83 + + conf.parse() 84 + + return conf 85 + + 86 + + def _read_hostname(self, filename, default=None): 87 + + hostname = None 88 + + try: 89 + + conf = self._read_hostname_conf(filename) 90 + + hostname = conf.hostname 91 + + except IOError: 92 + + pass 93 + + if not hostname: 94 + + return default 95 + + return hostname 96 + + 97 + + def _write_network(self, settings): 98 + + raise NotImplementedError() 99 + + 100 + + def apply_locale(self, locale, out_fn=None): 101 + + raise NotImplementedError() 102 + + 103 + + def install_packages(self, pkglist): 104 + + raise NotImplementedError() 105 + + 106 + + def package_command(self, command, args=None, pkgs=None): 107 + + raise NotImplementedError() 108 + + 109 + + def set_timezone(self, tz): 110 + + raise NotImplementedError() 111 + + 112 + + def update_package_sources(self): 113 + + raise NotImplementedError()
+10 -6
pkgs/tools/virtualization/cloud-init/default.nix
··· 1 - { lib, pythonPackages, fetchurl }: 1 + { lib, pythonPackages, fetchurl, kmod, systemd, cloud-utils }: 2 2 3 - let version = "0.7.6"; 3 + let version = "0.7.9"; 4 4 5 5 in pythonPackages.buildPythonApplication rec { 6 6 name = "cloud-init-${version}"; ··· 8 8 9 9 src = fetchurl { 10 10 url = "https://launchpad.net/cloud-init/trunk/${version}/+download/cloud-init-${version}.tar.gz"; 11 - sha256 = "1mry5zdkfaq952kn1i06wiggc66cqgfp6qgnlpk0mr7nnwpd53wy"; 11 + sha256 = "0wnl76pdcj754pl99wxx76hkir1s61x0bg0lh27sdgdxy45vivbn"; 12 12 }; 13 13 14 - patchPhase = '' 14 + patches = [ ./add-nixos-support.patch ]; 15 + prePatch = '' 15 16 patchShebangs ./tools 16 17 17 18 substituteInPlace setup.py \ ··· 19 20 --replace /etc $out/etc \ 20 21 --replace /lib/systemd $out/lib/systemd \ 21 22 --replace 'self.init_system = ""' 'self.init_system = "systemd"' 23 + 24 + substituteInPlace cloudinit/config/cc_growpart.py \ 25 + --replace 'util.subp(["growpart"' 'util.subp(["${cloud-utils}/bin/growpart"' 22 26 ''; 23 27 24 28 propagatedBuildInputs = with pythonPackages; [ cheetah jinja2 prettytable 25 - oauth pyserial configobj pyyaml argparse requests jsonpatch ]; 29 + oauthlib pyserial configobj pyyaml argparse requests jsonpatch ]; 26 30 27 31 meta = { 28 32 homepage = http://cloudinit.readthedocs.org; 29 33 description = "Provides configuration and customization of cloud instance"; 30 - maintainers = [ lib.maintainers.madjar ]; 34 + maintainers = [ lib.maintainers.madjar lib.maintainers.phile314 ]; 31 35 platforms = lib.platforms.all; 32 36 }; 33 37 }