From 0ae8b2f5d1fda34f1efa50de8defd127a7907576 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Fri, 8 Aug 2014 19:18:42 +0000 Subject: merge: These are the changes from the freebsd-static-networking branch. --- cloudinit/distros/freebsd.py | 83 +++++++++++++++++++++++--- tests/unittests/test_distros/test_netconfig.py | 36 +++++++++++ 2 files changed, 111 insertions(+), 8 deletions(-) diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py index d98f9578..1085185b 100644 --- a/cloudinit/distros/freebsd.py +++ b/cloudinit/distros/freebsd.py @@ -26,6 +26,9 @@ from cloudinit import log as logging from cloudinit import ssh_util from cloudinit import util +from cloudinit.distros import net_util +from cloudinit.distros.parsers.resolv_conf import ResolvConf + LOG = logging.getLogger(__name__) @@ -33,6 +36,7 @@ class Distro(distros.Distro): rc_conf_fn = "/etc/rc.conf" login_conf_fn = '/etc/login.conf' login_conf_fn_bak = '/etc/login.conf.orig' + resolv_conf_fn = '/etc/resolv.conf' def __init__(self, name, cfg, paths): distros.Distro.__init__(self, name, cfg, paths) @@ -44,30 +48,34 @@ class Distro(distros.Distro): # Updates a key in /etc/rc.conf. def updatercconf(self, key, value): - LOG.debug("updatercconf: %s => %s", key, value) + LOG.debug("Checking %s for: %s = %s", self.rc_conf_fn, key, value) conf = self.loadrcconf() config_changed = False for item in conf: if item == key and conf[item] != value: conf[item] = value - LOG.debug("[rc.conf]: Value %s for key %s needs to be changed", - value, key) + LOG.debug("Changing key in %s: %s = %s", self.rc_conf_fn, key, + value) config_changed = True if config_changed: - LOG.debug("Writing new %s file", self.rc_conf_fn) + LOG.info("Writing %s", self.rc_conf_fn) buf = StringIO() for keyval in conf.items(): - buf.write("%s=%s\n" % keyval) + buf.write('%s="%s"\n' % keyval) util.write_file(self.rc_conf_fn, buf.getvalue()) - # Load the contents of /etc/rc.conf and store all keys in a dict. + # Load the contents of /etc/rc.conf and store all keys in a dict. Make sure + # quotes are ignored: + # hostname="bla" def loadrcconf(self): conf = {} lines = util.load_file(self.rc_conf_fn).splitlines() for line in lines: tok = line.split('=') - conf[tok[0]] = tok[1].rstrip() + key = tok[0] + val = re.sub(r'^"|"$', '', tok[1].rstrip()) + conf[key] = val return conf def readrcconf(self, key): @@ -218,7 +226,66 @@ class Distro(distros.Distro): ssh_util.setup_user_keys(keys, name, options=None) def _write_network(self, settings): - return + entries = net_util.translate_network(settings) + LOG.debug("Translated network settings") + LOG.debug("\n========== UBUNTU FORMAT START ==========") + LOG.debug("%s\n========== UBUNTU FORMAT END ==========", settings) + LOG.debug("\n========== GENERIC FORMAT START ==========") + LOG.debug("%s\n========== GENERIC FORMAT END ==========", entries) + + nameservers = [] + searchdomains = [] + dev_names = entries.keys() + for (dev, info) in entries.iteritems(): + # Skip the loopback interface. + if dev == 'lo0': + continue + + LOG.info('Configuring interface %s', dev) + + if info.get('bootproto') == 'static': + LOG.debug('Configuring dev %s with %s / %s', dev, info.get('address'), info.get('netmask')) + # Configure an ipv4 address. + ifconfig = info.get('address') + ' netmask ' + info.get('netmask') + + # Configure the gateway. + self.updatercconf('defaultrouter', info.get('gateway')) + + if 'dns-nameservers' in info: + nameservers.extend(info['dns-nameservers']) + if 'dns-search' in info: + searchservers.extend(info['dns-search']) + else: + ifconfig = 'DHCP' + + self.updatercconf('ifconfig_' + dev, ifconfig) + + # Try to read the /etc/resolv.conf or just start from scratch if that + # fails. + try: + resolvconf = ResolvConf(util.load_file(self.resolv_conf_fn)) + resolvconf.parse() + except IOError: + util.logexc(LOG, "Failed to parse %s, use new empty file", self.resolv_conf_fn) + resolvconf = ResolvConf('') + resolvconf.parse() + + # Add some nameservers + for server in nameservers: + try: + resolvconf.add_nameserver(server) + except ValueError: + util.logexc(LOG, "Failed to add nameserver %s", server) + + # And add any searchdomains. + for domain in searchdomains: + try: + resolvconf.add_search_domain(domain) + except ValueError: + util.logexc(LOG, "Failed to add search domain %s", domain) + util.write_file(self.resolv_conf_fn, str(resolvconf), 0644) + + return dev_names def apply_locale(self, locale, out_fn=None): # Adjust the locals value to the new value diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py index 9763b14b..96379025 100644 --- a/tests/unittests/test_distros/test_netconfig.py +++ b/tests/unittests/test_distros/test_netconfig.py @@ -173,3 +173,39 @@ NETWORKING=yes ''' self.assertCfgEquals(expected_buf, str(write_buf)) self.assertEquals(write_buf.mode, 0644) + + def test_simple_write_freebsd(self): + fbsd_distro = self._get_distro('freebsd') + util_mock = self.mocker.replace(util.write_file, + spec=False, passthrough=False) + exists_mock = self.mocker.replace(os.path.isfile, + spec=False, passthrough=False) + + exists_mock(mocker.ARGS) + self.mocker.count(0, None) + self.mocker.result(False) + + write_bufs = {} + + def replace_write(filename, content, mode=0644, omode="wb"): + buf = WriteBuffer() + buf.mode = mode + buf.omode = omode + buf.write(content) + write_bufs[filename] = buf + + util_mock(mocker.ARGS) + self.mocker.call(replace_write) + self.mocker.replay() + fbsd_distro.apply_network(BASE_NET_CFG, False) + + self.assertIn('/etc/rc.conf', write_bufs) + write_buf = write_bufs['/etc/rc.conf'] + expected_buf = ''' +ifconfig_eth0="192.168.1.5 netmask 255.255.255.0" +ifconfig_eth1="DHCP" +defaultrouter="192.168.1.254" +''' + self.assertCfgEquals(expected_buf, str(write_buf)) + self.assertEquals(write_buf.mode, 0644) + -- cgit v1.2.3 From 019c90f07061adeda54173ea9afd7752cd11cd90 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Fri, 8 Aug 2014 19:23:56 +0000 Subject: fix: Skip lines from /etc/rc.conf not matching the pattern key=value. --- cloudinit/distros/freebsd.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py index 1085185b..b4d841f8 100644 --- a/cloudinit/distros/freebsd.py +++ b/cloudinit/distros/freebsd.py @@ -72,6 +72,11 @@ class Distro(distros.Distro): conf = {} lines = util.load_file(self.rc_conf_fn).splitlines() for line in lines: + if not re.match(r'^(.+)=(.+)', line): + LOG.debug("Skipping line from /etc/rc.conf: %s", line) + continue + + # TODO: just use the matches please... tok = line.split('=') key = tok[0] val = re.sub(r'^"|"$', '', tok[1].rstrip()) -- cgit v1.2.3 From c6ca246c3fe44cb21c068ff9fe5fb134c2230ebb Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Fri, 8 Aug 2014 20:44:48 +0000 Subject: new: Config for FreeBSD. This doesn't differ much from the regular (linux) config, but currently it helps while testing and setting up fbsd cloud instances. --- config/cloud.freebsd.cfg | 107 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 config/cloud.freebsd.cfg diff --git a/config/cloud.freebsd.cfg b/config/cloud.freebsd.cfg new file mode 100644 index 00000000..bcf5adc7 --- /dev/null +++ b/config/cloud.freebsd.cfg @@ -0,0 +1,107 @@ +# The top level settings are used as module +# and system configuration. + +syslog_fix_perms: root:wheel +datasource_list: ['OpenStack'] + +# A set of users which may be applied and/or used by various modules +# when a 'default' entry is found it will reference the 'default_user' +# from the distro configuration specified below +users: + - default + +# If this is set, 'root' will not be able to ssh in and they +# will get a message to login instead as the above $user (ubuntu) +disable_root: false + +# This will cause the set+update hostname module to not operate (if true) +preserve_hostname: false + +# Example datasource config +# datasource: +# Ec2: +# metadata_urls: [ 'blah.com' ] +# timeout: 5 # (defaults to 50 seconds) +# max_wait: 10 # (defaults to 120 seconds) + +# The modules that run in the 'init' stage +cloud_init_modules: + - migrator + - seed_random + - bootcmd + - write-files + - growpart + - resizefs + - set_hostname + - update_hostname + - update_etc_hosts + - ca-certs + - rsyslog + - users-groups + - ssh + +# The modules that run in the 'config' stage +cloud_config_modules: + - disk_setup + - mounts + - ssh-import-id + - locale + - set-passwords + - package-update-upgrade-install + - landscape + - timezone + - puppet + - chef + - salt-minion + - mcollective + - disable-ec2-metadata + - runcmd + - byobu + +# The modules that run in the 'final' stage +cloud_final_modules: + - rightscale_userdata + - scripts-vendor + - scripts-per-once + - scripts-per-boot + - scripts-per-instance + - scripts-user + - ssh-authkey-fingerprints + - keys-to-console + - phone-home + - final-message + - power-state-change + +# System and/or distro specific settings +# (not accessible to handlers/transforms) +system_info: + # This will affect which distro class gets used + distro: freebsd + # Default user name + that default users groups (if added/used) + default_user: + name: beastie + lock_passwd: True + gecos: FreeBSD + groups: [wheel] + sudo: ["ALL=(ALL) NOPASSWD:ALL"] + shell: /bin/sh + # Other config here will be given to the distro class and/or path classes + paths: + cloud_dir: /var/lib/cloud/ + templates_dir: /etc/cloud/templates/ + upstart_dir: /etc/init/ + package_mirrors: + - arches: [i386, amd64] + failsafe: + primary: http://archive.ubuntu.com/ubuntu + security: http://security.ubuntu.com/ubuntu + search: + primary: + - http://%(ec2_region)s.ec2.archive.ubuntu.com/ubuntu/ + - http://%(availability_zone)s.clouds.archive.ubuntu.com/ubuntu/ + security: [] + - arches: [armhf, armel, default] + failsafe: + primary: http://ports.ubuntu.com/ubuntu-ports + security: http://ports.ubuntu.com/ubuntu-ports + ssh_svcname: ssh -- cgit v1.2.3 From ca1e2e17e5ae4af811826518f46631c9962f8292 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 9 Aug 2014 08:09:02 +0000 Subject: fix: The correct path end with an s. --- sysvinit/freebsd/cloudconfig | 6 +++--- sysvinit/freebsd/cloudfinal | 6 +++--- sysvinit/freebsd/cloudinit | 6 +++--- sysvinit/freebsd/cloudinitlocal | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sysvinit/freebsd/cloudconfig b/sysvinit/freebsd/cloudconfig index 15d7ab95..73877b6f 100755 --- a/sysvinit/freebsd/cloudconfig +++ b/sysvinit/freebsd/cloudconfig @@ -18,9 +18,9 @@ start_cmd="cloudconfig_start" cloudinit_override() { - # If there exist sysconfig/default variable override files use it... - if [ -f /etc/default/cloud-init ]; then - . /etc/default/cloud-init + # If there exist sysconfig/defaults variable override files use it... + if [ -f /etc/defaults/cloud-init ]; then + . /etc/defaults/cloud-init fi } diff --git a/sysvinit/freebsd/cloudfinal b/sysvinit/freebsd/cloudfinal index 49945ecd..292dd8fb 100755 --- a/sysvinit/freebsd/cloudfinal +++ b/sysvinit/freebsd/cloudfinal @@ -18,9 +18,9 @@ start_cmd="cloudfinal_start" cloudinit_override() { - # If there exist sysconfig/default variable override files use it... - if [ -f /etc/default/cloud-init ]; then - . /etc/default/cloud-init + # If there exist sysconfig/defaults variable override files use it... + if [ -f /etc/defaults/cloud-init ]; then + . /etc/defaults/cloud-init fi } diff --git a/sysvinit/freebsd/cloudinit b/sysvinit/freebsd/cloudinit index 8d5ff10e..23a1247b 100755 --- a/sysvinit/freebsd/cloudinit +++ b/sysvinit/freebsd/cloudinit @@ -18,9 +18,9 @@ start_cmd="cloudinit_start" cloudinit_override() { - # If there exist sysconfig/default variable override files use it... - if [ -f /etc/default/cloud-init ]; then - . /etc/default/cloud-init + # If there exist sysconfig/defaults variable override files use it... + if [ -f /etc/defaults/cloud-init ]; then + . /etc/defaults/cloud-init fi } diff --git a/sysvinit/freebsd/cloudinitlocal b/sysvinit/freebsd/cloudinitlocal index b55705c0..b96d1513 100755 --- a/sysvinit/freebsd/cloudinitlocal +++ b/sysvinit/freebsd/cloudinitlocal @@ -18,9 +18,9 @@ start_cmd="cloudlocal_start" cloudinit_override() { - # If there exist sysconfig/default variable override files use it... - if [ -f /etc/default/cloud-init ]; then - . /etc/default/cloud-init + # If there exist sysconfig/defaults variable override files use it... + if [ -f /etc/defaults/cloud-init ]; then + . /etc/defaults/cloud-init fi } -- cgit v1.2.3 From 9e10017821eb6f197aebd89545444cdb7bea5056 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 9 Aug 2014 08:12:35 +0000 Subject: fix: To install the new freebsd sysvinit scripts, accept a new sysvinit_freebsd argument. Specifying sysvinit will install the RH scripts, which is wrong. --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index 556103b9..7b061824 100755 --- a/setup.py +++ b/setup.py @@ -63,12 +63,14 @@ def systemd_unitdir(): 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)], 'systemd': [f for f in glob('systemd/*') 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', 'systemd': systemd_unitdir(), 'upstart': '/etc/init/', -- cgit v1.2.3 From f72be738ba5e8556aae3bccd765754ea01555389 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 9 Aug 2014 09:58:12 +0000 Subject: change: Cloud-init config should go under /usr/local since /etc/ is reserved for base. --- sysvinit/freebsd/cloudconfig | 2 +- sysvinit/freebsd/cloudfinal | 2 +- sysvinit/freebsd/cloudinit | 2 +- sysvinit/freebsd/cloudinitlocal | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sysvinit/freebsd/cloudconfig b/sysvinit/freebsd/cloudconfig index 73877b6f..0a058ddb 100755 --- a/sysvinit/freebsd/cloudconfig +++ b/sysvinit/freebsd/cloudconfig @@ -14,7 +14,7 @@ rcvar="cloudinit_enable" start_precmd="cloudinit_override" start_cmd="cloudconfig_start" -: ${cloudinit_config:="/etc/cloud/cloud.cfg"} +: ${cloudinit_config:="/usr/local/etc/cloud/cloud.cfg"} cloudinit_override() { diff --git a/sysvinit/freebsd/cloudfinal b/sysvinit/freebsd/cloudfinal index 292dd8fb..a97e65f9 100755 --- a/sysvinit/freebsd/cloudfinal +++ b/sysvinit/freebsd/cloudfinal @@ -14,7 +14,7 @@ rcvar="cloudinit_enable" start_precmd="cloudinit_override" start_cmd="cloudfinal_start" -: ${cloudinit_config:="/etc/cloud/cloud.cfg"} +: ${cloudinit_config:="/usr/local/etc/cloud/cloud.cfg"} cloudinit_override() { diff --git a/sysvinit/freebsd/cloudinit b/sysvinit/freebsd/cloudinit index 23a1247b..f751963b 100755 --- a/sysvinit/freebsd/cloudinit +++ b/sysvinit/freebsd/cloudinit @@ -14,7 +14,7 @@ rcvar="cloudinit_enable" start_precmd="cloudinit_override" start_cmd="cloudinit_start" -: ${cloudinit_config:="/etc/cloud/cloud.cfg"} +: ${cloudinit_config:="/usr/local/etc/cloud/cloud.cfg"} cloudinit_override() { diff --git a/sysvinit/freebsd/cloudinitlocal b/sysvinit/freebsd/cloudinitlocal index b96d1513..2b5df3c9 100755 --- a/sysvinit/freebsd/cloudinitlocal +++ b/sysvinit/freebsd/cloudinitlocal @@ -14,7 +14,7 @@ rcvar="cloudinit_enable" start_precmd="cloudinit_override" start_cmd="cloudlocal_start" -: ${cloudinit_config:="/etc/cloud/cloud.cfg"} +: ${cloudinit_config:="/usr/local/etc/cloud/cloud.cfg"} cloudinit_override() { -- cgit v1.2.3 From ffc621738b172c9805c083c265eed13b415bb3f4 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 9 Aug 2014 10:11:50 +0000 Subject: fix: Command (the binary) is cloud-init, not cloud_init. --- sysvinit/freebsd/cloudfinal | 2 +- sysvinit/freebsd/cloudinit | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sysvinit/freebsd/cloudfinal b/sysvinit/freebsd/cloudfinal index a97e65f9..f044f1f3 100755 --- a/sysvinit/freebsd/cloudfinal +++ b/sysvinit/freebsd/cloudfinal @@ -7,7 +7,7 @@ . /etc/rc.subr name="cloudfinal" -command="/usr/bin/cloud_init" +command="/usr/bin/cloud-init" start_cmd="cloudfinal_start" stop_cmd=":" rcvar="cloudinit_enable" diff --git a/sysvinit/freebsd/cloudinit b/sysvinit/freebsd/cloudinit index f751963b..571b57d0 100755 --- a/sysvinit/freebsd/cloudinit +++ b/sysvinit/freebsd/cloudinit @@ -7,7 +7,7 @@ . /etc/rc.subr name="cloudinit" -command="/usr/bin/cloud_init" +command="/usr/bin/cloud-init" start_cmd="cloudinit_start" stop_cmd=":" rcvar="cloudinit_enable" -- cgit v1.2.3 From 590685594897069fe57753f197753aab5cb440e9 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 9 Aug 2014 10:14:41 +0000 Subject: change: C-i is installed in /usr/local/. --- sysvinit/freebsd/cloudconfig | 2 +- sysvinit/freebsd/cloudfinal | 2 +- sysvinit/freebsd/cloudinit | 2 +- sysvinit/freebsd/cloudinitlocal | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sysvinit/freebsd/cloudconfig b/sysvinit/freebsd/cloudconfig index 0a058ddb..b40257ab 100755 --- a/sysvinit/freebsd/cloudconfig +++ b/sysvinit/freebsd/cloudconfig @@ -7,7 +7,7 @@ . /etc/rc.subr name="cloudconfig" -command="/usr/bin/cloud-init" +command="/usr/local/bin/cloud-init" start_cmd="cloudconfig_start" stop_cmd=":" rcvar="cloudinit_enable" diff --git a/sysvinit/freebsd/cloudfinal b/sysvinit/freebsd/cloudfinal index f044f1f3..5f2c4155 100755 --- a/sysvinit/freebsd/cloudfinal +++ b/sysvinit/freebsd/cloudfinal @@ -7,7 +7,7 @@ . /etc/rc.subr name="cloudfinal" -command="/usr/bin/cloud-init" +command="/usr/local/bin/cloud-init" start_cmd="cloudfinal_start" stop_cmd=":" rcvar="cloudinit_enable" diff --git a/sysvinit/freebsd/cloudinit b/sysvinit/freebsd/cloudinit index 571b57d0..14b0257e 100755 --- a/sysvinit/freebsd/cloudinit +++ b/sysvinit/freebsd/cloudinit @@ -7,7 +7,7 @@ . /etc/rc.subr name="cloudinit" -command="/usr/bin/cloud-init" +command="/usr/local/bin/cloud-init" start_cmd="cloudinit_start" stop_cmd=":" rcvar="cloudinit_enable" diff --git a/sysvinit/freebsd/cloudinitlocal b/sysvinit/freebsd/cloudinitlocal index 2b5df3c9..fdab2a12 100755 --- a/sysvinit/freebsd/cloudinitlocal +++ b/sysvinit/freebsd/cloudinitlocal @@ -7,7 +7,7 @@ . /etc/rc.subr name="cloudinitlocal" -command="/usr/bin/cloud-init" +command="/usr/local/bin/cloud-init" start_cmd="cloudlocal_start" stop_cmd=":" rcvar="cloudinit_enable" -- cgit v1.2.3 From c08262be060f6a4e89c94f81f83d7e884b66a5cf Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 9 Aug 2014 10:24:34 +0000 Subject: fix: Use -f to properly load the configfile. --- sysvinit/freebsd/cloudconfig | 2 +- sysvinit/freebsd/cloudfinal | 2 +- sysvinit/freebsd/cloudinit | 2 +- sysvinit/freebsd/cloudinitlocal | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sysvinit/freebsd/cloudconfig b/sysvinit/freebsd/cloudconfig index b40257ab..985fb259 100755 --- a/sysvinit/freebsd/cloudconfig +++ b/sysvinit/freebsd/cloudconfig @@ -27,7 +27,7 @@ cloudinit_override() cloudconfig_start() { echo "${command} starting" - ${command} ${cloudinit_config} modules --mode config + ${command} -f ${cloudinit_config} modules --mode config } load_rc_config $name diff --git a/sysvinit/freebsd/cloudfinal b/sysvinit/freebsd/cloudfinal index 5f2c4155..dd02b081 100755 --- a/sysvinit/freebsd/cloudfinal +++ b/sysvinit/freebsd/cloudfinal @@ -27,7 +27,7 @@ cloudinit_override() cloudfinal_start() { echo -n "${command} starting" - ${command} ${cloudinit_config} modules --mode final + ${command} -f ${cloudinit_config} modules --mode final } load_rc_config $name diff --git a/sysvinit/freebsd/cloudinit b/sysvinit/freebsd/cloudinit index 14b0257e..17eaa547 100755 --- a/sysvinit/freebsd/cloudinit +++ b/sysvinit/freebsd/cloudinit @@ -27,7 +27,7 @@ cloudinit_override() cloudinit_start() { echo -n "${command} starting" - ${command} ${cloudinit_config} init + ${command} -f ${cloudinit_config} init } load_rc_config $name diff --git a/sysvinit/freebsd/cloudinitlocal b/sysvinit/freebsd/cloudinitlocal index fdab2a12..4b122ee5 100755 --- a/sysvinit/freebsd/cloudinitlocal +++ b/sysvinit/freebsd/cloudinitlocal @@ -27,7 +27,7 @@ cloudinit_override() cloudlocal_start() { echo -n "${command} starting" - ${command} ${cloudinit_config} init --local + ${command} -f ${cloudinit_config} init --local } load_rc_config $name -- cgit v1.2.3 From d2d12dda2ddd576504adc32f71944eab72d6481a Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 9 Aug 2014 10:27:28 +0000 Subject: new: Buildscript for installing on FreeBSD. This should do until a proper port is created. --- tools/build-on-freebsd | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 tools/build-on-freebsd diff --git a/tools/build-on-freebsd b/tools/build-on-freebsd new file mode 100755 index 00000000..03cba7fc --- /dev/null +++ b/tools/build-on-freebsd @@ -0,0 +1,40 @@ +#!/bin/sh +# Since there is no official FreeBSD port yet, we need some way of building and +# installing cloud-init. This script takes care of building and installing. It +# will optionally make a first run at the end. + +# Check dependencies: +[ ! -f /tmp/c-i.dependencieschecked ] && pkg install py27-cheetah py27-Jinja2 py27-prettytable py27-oauth py27-serial py27-configobj py27-yaml py27-argparse py27-requests py27-six +touch /tmp/c-i.dependencieschecked + +# Required but unavailable port/pkg: py27-jsonpatch +# Luckily, the install step will take care of this by installing it from pypi... + +# Build the code and install in /usr/local/: +python setup.py build +python setup.py install -O1 --skip-build --prefix /usr/local/ --init-system sysvinit_freebsd + +# Move the configdir to /usr/local/ and use freebsd.cfg: +[ -d /usr/local/etc/cloud ] && rm -rf /usr/local/etc/cloud +mv /etc/cloud /usr/local/etc/ +mv /usr/local/etc/cloud/cloud.freebsd.cfg /usr/local/etc/cloud/cloud.cfg + +# Enable cloud-init in /etc/rc.conf: +sed -i.bak -e "/cloudinit_enable=.*/d" /etc/rc.conf +echo 'cloudinit_enable="YES"' >> /etc/rc.conf + +echo "Installation completed." + +if [ "$1" = "run" ] +then + echo "Ok, now let's see if it works." + + # Remove old metadata + rm -rf /var/lib/cloud + + # Just log everything, quick&dirty + rm /usr/local/etc/cloud/cloud.cfg.d/05_logging.cfg + + # Start: + /usr/local/etc/rc.d/cloudinit start +fi -- cgit v1.2.3 From 38c9c67ea18fefbb83aaf5c9151858c4488e2e24 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 9 Aug 2014 10:51:04 +0000 Subject: change: Add an important comment. --- config/cloud.freebsd.cfg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/cloud.freebsd.cfg b/config/cloud.freebsd.cfg index bcf5adc7..40e2374a 100644 --- a/config/cloud.freebsd.cfg +++ b/config/cloud.freebsd.cfg @@ -2,6 +2,9 @@ # and system configuration. syslog_fix_perms: root:wheel + +# This should not be required, but leave it in place until the real cause of +# not beeing able to find -any- datasources is resolved. datasource_list: ['OpenStack'] # A set of users which may be applied and/or used by various modules -- cgit v1.2.3 From aff5c13ac9e3723e99d7414ac82f30c853f453fd Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 9 Aug 2014 10:56:13 +0000 Subject: fix: More dependencies. --- tools/build-on-freebsd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build-on-freebsd b/tools/build-on-freebsd index 03cba7fc..52bceb21 100755 --- a/tools/build-on-freebsd +++ b/tools/build-on-freebsd @@ -4,7 +4,7 @@ # will optionally make a first run at the end. # Check dependencies: -[ ! -f /tmp/c-i.dependencieschecked ] && pkg install py27-cheetah py27-Jinja2 py27-prettytable py27-oauth py27-serial py27-configobj py27-yaml py27-argparse py27-requests py27-six +[ ! -f /tmp/c-i.dependencieschecked ] && pkg install py27-cheetah py27-Jinja2 py27-prettytable py27-oauth py27-serial py27-configobj py27-yaml py27-argparse py27-requests py27-six py27-boto gpart sudo touch /tmp/c-i.dependencieschecked # Required but unavailable port/pkg: py27-jsonpatch -- cgit v1.2.3 From 5d96928ee2a2573aaf49727adafc91120daa1d36 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 9 Aug 2014 10:57:28 +0000 Subject: new: Some datasources (like Smartos) use dmidecode to gather some specific information, so install it. --- tools/build-on-freebsd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build-on-freebsd b/tools/build-on-freebsd index 52bceb21..ff59bd25 100755 --- a/tools/build-on-freebsd +++ b/tools/build-on-freebsd @@ -4,7 +4,7 @@ # will optionally make a first run at the end. # Check dependencies: -[ ! -f /tmp/c-i.dependencieschecked ] && pkg install py27-cheetah py27-Jinja2 py27-prettytable py27-oauth py27-serial py27-configobj py27-yaml py27-argparse py27-requests py27-six py27-boto gpart sudo +[ ! -f /tmp/c-i.dependencieschecked ] && pkg install py27-cheetah py27-Jinja2 py27-prettytable py27-oauth py27-serial py27-configobj py27-yaml py27-argparse py27-requests py27-six py27-boto gpart sudo dmidecode touch /tmp/c-i.dependencieschecked # Required but unavailable port/pkg: py27-jsonpatch -- cgit v1.2.3 From 33826c4e1b6cbb10a27633a5dd9627fcb88808b4 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 9 Aug 2014 11:34:46 +0000 Subject: fix: Pass -y to growfs to keep it from asking for confirmation. --- cloudinit/config/cc_resizefs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinit/config/cc_resizefs.py b/cloudinit/config/cc_resizefs.py index be406034..e290efe0 100644 --- a/cloudinit/config/cc_resizefs.py +++ b/cloudinit/config/cc_resizefs.py @@ -41,7 +41,7 @@ def _resize_xfs(mount_point, devpth): # pylint: disable=W0613 def _resize_ufs(mount_point, devpth): # pylint: disable=W0613 - return ('growfs', devpth) + return ('growfs', '-y', devpth) # Do not use a dictionary as these commands should be able to be used # for multiple filesystem types if possible, e.g. one command for -- cgit v1.2.3 From f1202c1b0aeae7378589215887c74f325e6c77cd Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 9 Aug 2014 21:24:19 +0000 Subject: change: Create a symlink to python2.7, to make sure running plain python works. --- tools/build-on-freebsd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/build-on-freebsd b/tools/build-on-freebsd index ff59bd25..0a545207 100755 --- a/tools/build-on-freebsd +++ b/tools/build-on-freebsd @@ -3,6 +3,9 @@ # installing cloud-init. This script takes care of building and installing. It # will optionally make a first run at the end. +# Since there is no python by default, create a symlink for convenience sake: +ln -sf /usr/local/bin/python2.7 /usr/local/bin/python + # Check dependencies: [ ! -f /tmp/c-i.dependencieschecked ] && pkg install py27-cheetah py27-Jinja2 py27-prettytable py27-oauth py27-serial py27-configobj py27-yaml py27-argparse py27-requests py27-six py27-boto gpart sudo dmidecode touch /tmp/c-i.dependencieschecked -- cgit v1.2.3 From 7e0407491345989a2640149a9a365b6f7167c7af Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 9 Aug 2014 21:25:54 +0000 Subject: change: Make note of another python lib pypi takes care of. --- tools/build-on-freebsd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/build-on-freebsd b/tools/build-on-freebsd index 0a545207..da33e4b0 100755 --- a/tools/build-on-freebsd +++ b/tools/build-on-freebsd @@ -10,7 +10,7 @@ ln -sf /usr/local/bin/python2.7 /usr/local/bin/python [ ! -f /tmp/c-i.dependencieschecked ] && pkg install py27-cheetah py27-Jinja2 py27-prettytable py27-oauth py27-serial py27-configobj py27-yaml py27-argparse py27-requests py27-six py27-boto gpart sudo dmidecode touch /tmp/c-i.dependencieschecked -# Required but unavailable port/pkg: py27-jsonpatch +# Required but unavailable port/pkg: py27-jsonpatch py27-jsonpointer # Luckily, the install step will take care of this by installing it from pypi... # Build the code and install in /usr/local/: -- cgit v1.2.3 From 891496973520c91fd02ccfc55aa606234418accb Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sun, 10 Aug 2014 09:41:42 +0000 Subject: change: Save and restore the SSH keys between builds. --- tools/build-on-freebsd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/build-on-freebsd b/tools/build-on-freebsd index da33e4b0..7d19f44c 100755 --- a/tools/build-on-freebsd +++ b/tools/build-on-freebsd @@ -32,6 +32,9 @@ if [ "$1" = "run" ] then echo "Ok, now let's see if it works." + # Backup SSH keys + mv /etc/ssh/ssh_host_* /tmp/ + # Remove old metadata rm -rf /var/lib/cloud @@ -40,4 +43,7 @@ then # Start: /usr/local/etc/rc.d/cloudinit start + + # Restore SSH keys + mv /tmp/ssh_host_* /etc/ssh/ fi -- cgit v1.2.3 From de0e832b51624603664eab189a083e612554125a Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sun, 10 Aug 2014 11:38:22 +0000 Subject: fix: Set the environment var CLOUD_CFG to specify the location of cloud.cfg since -f is not used for that. Given the importance of this file/location, it's explicitly beeing set in the initscripts instead of trusting on something in /etc/defaults. --- sysvinit/freebsd/cloudconfig | 6 +++--- sysvinit/freebsd/cloudfinal | 6 +++--- sysvinit/freebsd/cloudinit | 6 +++--- sysvinit/freebsd/cloudinitlocal | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sysvinit/freebsd/cloudconfig b/sysvinit/freebsd/cloudconfig index 985fb259..44c216b3 100755 --- a/sysvinit/freebsd/cloudconfig +++ b/sysvinit/freebsd/cloudconfig @@ -6,6 +6,8 @@ . /etc/rc.subr +export CLOUD_CFG=/usr/local/etc/cloud/cloud.cfg + name="cloudconfig" command="/usr/local/bin/cloud-init" start_cmd="cloudconfig_start" @@ -14,8 +16,6 @@ rcvar="cloudinit_enable" start_precmd="cloudinit_override" start_cmd="cloudconfig_start" -: ${cloudinit_config:="/usr/local/etc/cloud/cloud.cfg"} - cloudinit_override() { # If there exist sysconfig/defaults variable override files use it... @@ -27,7 +27,7 @@ cloudinit_override() cloudconfig_start() { echo "${command} starting" - ${command} -f ${cloudinit_config} modules --mode config + ${command} modules --mode config } load_rc_config $name diff --git a/sysvinit/freebsd/cloudfinal b/sysvinit/freebsd/cloudfinal index dd02b081..f668e036 100755 --- a/sysvinit/freebsd/cloudfinal +++ b/sysvinit/freebsd/cloudfinal @@ -6,6 +6,8 @@ . /etc/rc.subr +export CLOUD_CFG=/usr/local/etc/cloud/cloud.cfg + name="cloudfinal" command="/usr/local/bin/cloud-init" start_cmd="cloudfinal_start" @@ -14,8 +16,6 @@ rcvar="cloudinit_enable" start_precmd="cloudinit_override" start_cmd="cloudfinal_start" -: ${cloudinit_config:="/usr/local/etc/cloud/cloud.cfg"} - cloudinit_override() { # If there exist sysconfig/defaults variable override files use it... @@ -27,7 +27,7 @@ cloudinit_override() cloudfinal_start() { echo -n "${command} starting" - ${command} -f ${cloudinit_config} modules --mode final + ${command} modules --mode final } load_rc_config $name diff --git a/sysvinit/freebsd/cloudinit b/sysvinit/freebsd/cloudinit index 17eaa547..c5478678 100755 --- a/sysvinit/freebsd/cloudinit +++ b/sysvinit/freebsd/cloudinit @@ -6,6 +6,8 @@ . /etc/rc.subr +export CLOUD_CFG=/usr/local/etc/cloud/cloud.cfg + name="cloudinit" command="/usr/local/bin/cloud-init" start_cmd="cloudinit_start" @@ -14,8 +16,6 @@ rcvar="cloudinit_enable" start_precmd="cloudinit_override" start_cmd="cloudinit_start" -: ${cloudinit_config:="/usr/local/etc/cloud/cloud.cfg"} - cloudinit_override() { # If there exist sysconfig/defaults variable override files use it... @@ -27,7 +27,7 @@ cloudinit_override() cloudinit_start() { echo -n "${command} starting" - ${command} -f ${cloudinit_config} init + ${command} init } load_rc_config $name diff --git a/sysvinit/freebsd/cloudinitlocal b/sysvinit/freebsd/cloudinitlocal index 4b122ee5..c340d5d0 100755 --- a/sysvinit/freebsd/cloudinitlocal +++ b/sysvinit/freebsd/cloudinitlocal @@ -6,6 +6,8 @@ . /etc/rc.subr +export CLOUD_CFG=/usr/local/etc/cloud/cloud.cfg + name="cloudinitlocal" command="/usr/local/bin/cloud-init" start_cmd="cloudlocal_start" @@ -14,8 +16,6 @@ rcvar="cloudinit_enable" start_precmd="cloudinit_override" start_cmd="cloudlocal_start" -: ${cloudinit_config:="/usr/local/etc/cloud/cloud.cfg"} - cloudinit_override() { # If there exist sysconfig/defaults variable override files use it... @@ -27,7 +27,7 @@ cloudinit_override() cloudlocal_start() { echo -n "${command} starting" - ${command} -f ${cloudinit_config} init --local + ${command} init --local } load_rc_config $name -- cgit v1.2.3 From 833ebcba6ca333183284d1f9a0fe5f53df802712 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sun, 10 Aug 2014 11:50:19 +0000 Subject: change: Install everything in the right location on both Linux (which ofcourse already was good) and FreeBSD (which realy likes /usr/local for this). --- setup.py | 51 ++++++++++++++++++++++++++++++++++++-------------- tools/build-on-freebsd | 4 +--- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/setup.py b/setup.py index 7b061824..b09c0456 100755 --- a/setup.py +++ b/setup.py @@ -90,6 +90,42 @@ def read_requires(): return str(deps).splitlines() +# Install everything in the right location and take care of Linux (default) and +# FreeBSD systems. +def read_datafiles(): + sysname = os.uname()[0] + if sysname == 'FreeBSD': + return [ + ('/usr/local/etc/cloud', glob('config/*.cfg')), + ('/usr/local/etc/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')), + ('/usr/local/etc/cloud/templates', glob('templates/*')), + ('/usr/local/share/cloud-init', []), + ('/usr/local/lib/cloud-init', + ['tools/uncloud-init', 'tools/write-ssh-key-fingerprints']), + ('/usr/local/share/doc/cloud-init', + [f for f in glob('doc/*') if is_f(f)]), + ('/usr/local/share/doc/cloud-init/examples', + [f for f in glob('doc/examples/*') if is_f(f)]), + ('/usr/local/share/doc/cloud-init/examples/seed', + [f for f in glob('doc/examples/seed/*') if is_f(f)]), + ] + else: + return [ + ('/etc/cloud', glob('config/*.cfg')), + ('/etc/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')), + ('/etc/cloud/templates', glob('templates/*')), + ('/usr/share/cloud-init', []), + ('/usr/lib/cloud-init', + ['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)]), + ] + + # TODO: Is there a better way to do this?? class InitsysInstallData(install): init_system = None @@ -138,20 +174,7 @@ setuptools.setup(name='cloud-init', 'tools/cloud-init-per', ], license='GPLv3', - data_files=[('/etc/cloud', glob('config/*.cfg')), - ('/etc/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')), - ('/etc/cloud/templates', glob('templates/*')), - ('/usr/share/cloud-init', []), - ('/usr/lib/cloud-init', - ['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)]), - ], + data_files=read_datafiles(), install_requires=read_requires(), cmdclass={ # Use a subclass for install that handles diff --git a/tools/build-on-freebsd b/tools/build-on-freebsd index 7d19f44c..6e6ce8b6 100755 --- a/tools/build-on-freebsd +++ b/tools/build-on-freebsd @@ -17,9 +17,7 @@ touch /tmp/c-i.dependencieschecked python setup.py build python setup.py install -O1 --skip-build --prefix /usr/local/ --init-system sysvinit_freebsd -# Move the configdir to /usr/local/ and use freebsd.cfg: -[ -d /usr/local/etc/cloud ] && rm -rf /usr/local/etc/cloud -mv /etc/cloud /usr/local/etc/ +# Use the correct config file: mv /usr/local/etc/cloud/cloud.freebsd.cfg /usr/local/etc/cloud/cloud.cfg # Enable cloud-init in /etc/rc.conf: -- cgit v1.2.3 From c36d75552221e165f84493c5105318c088b44514 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sun, 10 Aug 2014 11:54:28 +0000 Subject: change: Cancel execution of several modules that are definately not tested or supported yet. --- config/cloud.freebsd.cfg | 56 +++++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 39 deletions(-) diff --git a/config/cloud.freebsd.cfg b/config/cloud.freebsd.cfg index 40e2374a..2d65aac4 100644 --- a/config/cloud.freebsd.cfg +++ b/config/cloud.freebsd.cfg @@ -29,37 +29,37 @@ preserve_hostname: false # The modules that run in the 'init' stage cloud_init_modules: - - migrator +# - migrator - seed_random - bootcmd - - write-files +# - write-files - growpart - resizefs - set_hostname - update_hostname - - update_etc_hosts - - ca-certs - - rsyslog +# - update_etc_hosts +# - ca-certs +# - rsyslog - users-groups - - ssh +# - ssh # The modules that run in the 'config' stage cloud_config_modules: - - disk_setup - - mounts +# - disk_setup +# - mounts - ssh-import-id - locale - - set-passwords - - package-update-upgrade-install - - landscape - - timezone - - puppet - - chef - - salt-minion - - mcollective +# - set-passwords +# - package-update-upgrade-install +# - landscape +# - timezone +# - puppet +# - chef +# - salt-minion +# - mcollective - disable-ec2-metadata - runcmd - - byobu +# - byobu # The modules that run in the 'final' stage cloud_final_modules: @@ -78,9 +78,7 @@ cloud_final_modules: # System and/or distro specific settings # (not accessible to handlers/transforms) system_info: - # This will affect which distro class gets used distro: freebsd - # Default user name + that default users groups (if added/used) default_user: name: beastie lock_passwd: True @@ -88,23 +86,3 @@ system_info: groups: [wheel] sudo: ["ALL=(ALL) NOPASSWD:ALL"] shell: /bin/sh - # Other config here will be given to the distro class and/or path classes - paths: - cloud_dir: /var/lib/cloud/ - templates_dir: /etc/cloud/templates/ - upstart_dir: /etc/init/ - package_mirrors: - - arches: [i386, amd64] - failsafe: - primary: http://archive.ubuntu.com/ubuntu - security: http://security.ubuntu.com/ubuntu - search: - primary: - - http://%(ec2_region)s.ec2.archive.ubuntu.com/ubuntu/ - - http://%(availability_zone)s.clouds.archive.ubuntu.com/ubuntu/ - security: [] - - arches: [armhf, armel, default] - failsafe: - primary: http://ports.ubuntu.com/ubuntu-ports - security: http://ports.ubuntu.com/ubuntu-ports - ssh_svcname: ssh -- cgit v1.2.3 From 604ea8b8b56f5b02a365180b7cc7fc385cc5ad03 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Wed, 13 Aug 2014 16:45:24 +0000 Subject: change: Run the ssh module. --- config/cloud.freebsd.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/cloud.freebsd.cfg b/config/cloud.freebsd.cfg index 2d65aac4..bb3a4a51 100644 --- a/config/cloud.freebsd.cfg +++ b/config/cloud.freebsd.cfg @@ -41,7 +41,7 @@ cloud_init_modules: # - ca-certs # - rsyslog - users-groups -# - ssh + - ssh # The modules that run in the 'config' stage cloud_config_modules: -- cgit v1.2.3 From 57b5f63467dcc74b0b39a14b5baeb1974cdc3373 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Thu, 14 Aug 2014 16:18:15 +0000 Subject: fix: Install the python package that will install the required link to the python2.7 binary. This defaults to 2.7, which is fine. --- tools/build-on-freebsd | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/build-on-freebsd b/tools/build-on-freebsd index 6e6ce8b6..6a3f38ec 100755 --- a/tools/build-on-freebsd +++ b/tools/build-on-freebsd @@ -3,11 +3,8 @@ # installing cloud-init. This script takes care of building and installing. It # will optionally make a first run at the end. -# Since there is no python by default, create a symlink for convenience sake: -ln -sf /usr/local/bin/python2.7 /usr/local/bin/python - # Check dependencies: -[ ! -f /tmp/c-i.dependencieschecked ] && pkg install py27-cheetah py27-Jinja2 py27-prettytable py27-oauth py27-serial py27-configobj py27-yaml py27-argparse py27-requests py27-six py27-boto gpart sudo dmidecode +[ ! -f /tmp/c-i.dependencieschecked ] && pkg install python py27-cheetah py27-Jinja2 py27-prettytable py27-oauth py27-serial py27-configobj py27-yaml py27-argparse py27-requests py27-six py27-boto gpart sudo dmidecode touch /tmp/c-i.dependencieschecked # Required but unavailable port/pkg: py27-jsonpatch py27-jsonpointer -- cgit v1.2.3 From f181c7cbdc08222f195fa84a379f35a456d26123 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 16 Aug 2014 17:55:42 +0000 Subject: fix: Don't create a directory that will never be used anyway. --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index b09c0456..0e609d6e 100755 --- a/setup.py +++ b/setup.py @@ -99,7 +99,6 @@ def read_datafiles(): ('/usr/local/etc/cloud', glob('config/*.cfg')), ('/usr/local/etc/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')), ('/usr/local/etc/cloud/templates', glob('templates/*')), - ('/usr/local/share/cloud-init', []), ('/usr/local/lib/cloud-init', ['tools/uncloud-init', 'tools/write-ssh-key-fingerprints']), ('/usr/local/share/doc/cloud-init', -- cgit v1.2.3 From 31ef77ec5a948e02def84791084ccf37ac2b6180 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 22 Aug 2014 16:43:32 -0400 Subject: setup.py: remove read_datafiles, use globals for ETC and USR --- setup.py | 57 +++++++++++++++++++++------------------------------------ 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/setup.py b/setup.py index 0e609d6e..9be88e53 100755 --- a/setup.py +++ b/setup.py @@ -77,6 +77,14 @@ INITSYS_ROOTS = { } INITSYS_TYPES = sorted(list(INITSYS_ROOTS.keys())) +# Install everything in the right location and take care of Linux (default) and +# FreeBSD systems. +USR = "/usr" +ETC = "/etc" +if os.uname()[0] == 'FreeBSD': + USR = "/usr/local" + ETC = "/usr/local/etc" + def get_version(): cmd = ['tools/read-version'] @@ -90,41 +98,6 @@ def read_requires(): return str(deps).splitlines() -# Install everything in the right location and take care of Linux (default) and -# FreeBSD systems. -def read_datafiles(): - sysname = os.uname()[0] - if sysname == 'FreeBSD': - return [ - ('/usr/local/etc/cloud', glob('config/*.cfg')), - ('/usr/local/etc/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')), - ('/usr/local/etc/cloud/templates', glob('templates/*')), - ('/usr/local/lib/cloud-init', - ['tools/uncloud-init', 'tools/write-ssh-key-fingerprints']), - ('/usr/local/share/doc/cloud-init', - [f for f in glob('doc/*') if is_f(f)]), - ('/usr/local/share/doc/cloud-init/examples', - [f for f in glob('doc/examples/*') if is_f(f)]), - ('/usr/local/share/doc/cloud-init/examples/seed', - [f for f in glob('doc/examples/seed/*') if is_f(f)]), - ] - else: - return [ - ('/etc/cloud', glob('config/*.cfg')), - ('/etc/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')), - ('/etc/cloud/templates', glob('templates/*')), - ('/usr/share/cloud-init', []), - ('/usr/lib/cloud-init', - ['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)]), - ] - - # TODO: Is there a better way to do this?? class InitsysInstallData(install): init_system = None @@ -173,7 +146,19 @@ setuptools.setup(name='cloud-init', 'tools/cloud-init-per', ], license='GPLv3', - data_files=read_datafiles(), + data_files=[(ETC '/cloud', glob('config/*.cfg')), + (ETC '/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')), + (ETC '/cloud/templates', glob('templates/*')), + (USR '/lib/cloud-init', + ['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)]), + ], install_requires=read_requires(), cmdclass={ # Use a subclass for install that handles -- cgit v1.2.3 From 9d8628772131bbe127bfefd6337cda34025723c8 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 22 Aug 2014 16:50:47 -0400 Subject: build-on-freebsd: minor cleanups/bikeshedding --- tools/build-on-freebsd | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tools/build-on-freebsd b/tools/build-on-freebsd index 6a3f38ec..66b95d68 100755 --- a/tools/build-on-freebsd +++ b/tools/build-on-freebsd @@ -3,8 +3,22 @@ # installing cloud-init. This script takes care of building and installing. It # will optionally make a first run at the end. +fail() { echo "FAILED:" "$@" 1>&2; exit 1; } + # Check dependencies: -[ ! -f /tmp/c-i.dependencieschecked ] && pkg install python py27-cheetah py27-Jinja2 py27-prettytable py27-oauth py27-serial py27-configobj py27-yaml py27-argparse py27-requests py27-six py27-boto gpart sudo dmidecode +depscheck=/tmp/c-i.dependencieschecked +pkgs=" + dmidecode + py27-argparse + py27-boto gpart sudo + py27-configobj py27-yaml + py27-Jinja2 + py27-oauth py27-serial + py27-prettytable + py27-requests py27-six + python py27-cheetah +" +[ -f "$depschecked" ] || pkg install ${pkgs} || fail "install packages" touch /tmp/c-i.dependencieschecked # Required but unavailable port/pkg: py27-jsonpatch py27-jsonpointer @@ -23,8 +37,7 @@ echo 'cloudinit_enable="YES"' >> /etc/rc.conf echo "Installation completed." -if [ "$1" = "run" ] -then +if [ "$1" = "run" ]; then echo "Ok, now let's see if it works." # Backup SSH keys -- cgit v1.2.3 From c728de2115aacbe0f48d65661c076caace5e16e7 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 23 Aug 2014 12:06:51 +0000 Subject: fix: Use the correct variable. --- tools/build-on-freebsd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/build-on-freebsd b/tools/build-on-freebsd index 66b95d68..b0203cb8 100755 --- a/tools/build-on-freebsd +++ b/tools/build-on-freebsd @@ -6,7 +6,7 @@ fail() { echo "FAILED:" "$@" 1>&2; exit 1; } # Check dependencies: -depscheck=/tmp/c-i.dependencieschecked +depschecked=/tmp/c-i.dependencieschecked pkgs=" dmidecode py27-argparse @@ -19,7 +19,7 @@ pkgs=" python py27-cheetah " [ -f "$depschecked" ] || pkg install ${pkgs} || fail "install packages" -touch /tmp/c-i.dependencieschecked +touch $depschecked # Required but unavailable port/pkg: py27-jsonpatch py27-jsonpointer # Luckily, the install step will take care of this by installing it from pypi... -- cgit v1.2.3 From f68dfa3fd17e0a5eb228e6c7621d6da26e962c9a Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 23 Aug 2014 12:10:30 +0000 Subject: fix: Syntax. --- setup.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 9be88e53..4d20f16c 100755 --- a/setup.py +++ b/setup.py @@ -146,17 +146,17 @@ setuptools.setup(name='cloud-init', 'tools/cloud-init-per', ], license='GPLv3', - data_files=[(ETC '/cloud', glob('config/*.cfg')), - (ETC '/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')), - (ETC '/cloud/templates', glob('templates/*')), - (USR '/lib/cloud-init', + data_files=[(ETC + '/cloud', glob('config/*.cfg')), + (ETC + '/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')), + (ETC + '/cloud/templates', glob('templates/*')), + (USR + '/lib/cloud-init', ['tools/uncloud-init', 'tools/write-ssh-key-fingerprints']), - (USR '/share/doc/cloud-init', + (USR + '/share/doc/cloud-init', [f for f in glob('doc/*') if is_f(f)]), - (USR '/share/doc/cloud-init/examples', + (USR + '/share/doc/cloud-init/examples', [f for f in glob('doc/examples/*') if is_f(f)]), - (USR '/share/doc/cloud-init/examples/seed', + (USR + '/share/doc/cloud-init/examples/seed', [f for f in glob('doc/examples/seed/*') if is_f(f)]), ], install_requires=read_requires(), -- cgit v1.2.3 From 9fcb3f2c7c129576f9a2175614bcb384d492f63e Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 23 Aug 2014 12:16:03 +0000 Subject: change: Rename the config file to cloud.cfg-freebsd so it doesn't get copied per default. Packaging will take care of installing this configfile on the BSD platform. --- config/cloud.cfg-freebsd | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ config/cloud.freebsd.cfg | 88 ------------------------------------------------ tools/build-on-freebsd | 4 +-- 3 files changed, 90 insertions(+), 90 deletions(-) create mode 100644 config/cloud.cfg-freebsd delete mode 100644 config/cloud.freebsd.cfg diff --git a/config/cloud.cfg-freebsd b/config/cloud.cfg-freebsd new file mode 100644 index 00000000..bb3a4a51 --- /dev/null +++ b/config/cloud.cfg-freebsd @@ -0,0 +1,88 @@ +# The top level settings are used as module +# and system configuration. + +syslog_fix_perms: root:wheel + +# This should not be required, but leave it in place until the real cause of +# not beeing able to find -any- datasources is resolved. +datasource_list: ['OpenStack'] + +# A set of users which may be applied and/or used by various modules +# when a 'default' entry is found it will reference the 'default_user' +# from the distro configuration specified below +users: + - default + +# If this is set, 'root' will not be able to ssh in and they +# will get a message to login instead as the above $user (ubuntu) +disable_root: false + +# This will cause the set+update hostname module to not operate (if true) +preserve_hostname: false + +# Example datasource config +# datasource: +# Ec2: +# metadata_urls: [ 'blah.com' ] +# timeout: 5 # (defaults to 50 seconds) +# max_wait: 10 # (defaults to 120 seconds) + +# The modules that run in the 'init' stage +cloud_init_modules: +# - migrator + - seed_random + - bootcmd +# - write-files + - growpart + - resizefs + - set_hostname + - update_hostname +# - update_etc_hosts +# - ca-certs +# - rsyslog + - users-groups + - ssh + +# The modules that run in the 'config' stage +cloud_config_modules: +# - disk_setup +# - mounts + - ssh-import-id + - locale +# - set-passwords +# - package-update-upgrade-install +# - landscape +# - timezone +# - puppet +# - chef +# - salt-minion +# - mcollective + - disable-ec2-metadata + - runcmd +# - byobu + +# The modules that run in the 'final' stage +cloud_final_modules: + - rightscale_userdata + - scripts-vendor + - scripts-per-once + - scripts-per-boot + - scripts-per-instance + - scripts-user + - ssh-authkey-fingerprints + - keys-to-console + - phone-home + - final-message + - power-state-change + +# System and/or distro specific settings +# (not accessible to handlers/transforms) +system_info: + distro: freebsd + default_user: + name: beastie + lock_passwd: True + gecos: FreeBSD + groups: [wheel] + sudo: ["ALL=(ALL) NOPASSWD:ALL"] + shell: /bin/sh diff --git a/config/cloud.freebsd.cfg b/config/cloud.freebsd.cfg deleted file mode 100644 index bb3a4a51..00000000 --- a/config/cloud.freebsd.cfg +++ /dev/null @@ -1,88 +0,0 @@ -# The top level settings are used as module -# and system configuration. - -syslog_fix_perms: root:wheel - -# This should not be required, but leave it in place until the real cause of -# not beeing able to find -any- datasources is resolved. -datasource_list: ['OpenStack'] - -# A set of users which may be applied and/or used by various modules -# when a 'default' entry is found it will reference the 'default_user' -# from the distro configuration specified below -users: - - default - -# If this is set, 'root' will not be able to ssh in and they -# will get a message to login instead as the above $user (ubuntu) -disable_root: false - -# This will cause the set+update hostname module to not operate (if true) -preserve_hostname: false - -# Example datasource config -# datasource: -# Ec2: -# metadata_urls: [ 'blah.com' ] -# timeout: 5 # (defaults to 50 seconds) -# max_wait: 10 # (defaults to 120 seconds) - -# The modules that run in the 'init' stage -cloud_init_modules: -# - migrator - - seed_random - - bootcmd -# - write-files - - growpart - - resizefs - - set_hostname - - update_hostname -# - update_etc_hosts -# - ca-certs -# - rsyslog - - users-groups - - ssh - -# The modules that run in the 'config' stage -cloud_config_modules: -# - disk_setup -# - mounts - - ssh-import-id - - locale -# - set-passwords -# - package-update-upgrade-install -# - landscape -# - timezone -# - puppet -# - chef -# - salt-minion -# - mcollective - - disable-ec2-metadata - - runcmd -# - byobu - -# The modules that run in the 'final' stage -cloud_final_modules: - - rightscale_userdata - - scripts-vendor - - scripts-per-once - - scripts-per-boot - - scripts-per-instance - - scripts-user - - ssh-authkey-fingerprints - - keys-to-console - - phone-home - - final-message - - power-state-change - -# System and/or distro specific settings -# (not accessible to handlers/transforms) -system_info: - distro: freebsd - default_user: - name: beastie - lock_passwd: True - gecos: FreeBSD - groups: [wheel] - sudo: ["ALL=(ALL) NOPASSWD:ALL"] - shell: /bin/sh diff --git a/tools/build-on-freebsd b/tools/build-on-freebsd index b0203cb8..23bdf487 100755 --- a/tools/build-on-freebsd +++ b/tools/build-on-freebsd @@ -28,8 +28,8 @@ touch $depschecked python setup.py build python setup.py install -O1 --skip-build --prefix /usr/local/ --init-system sysvinit_freebsd -# Use the correct config file: -mv /usr/local/etc/cloud/cloud.freebsd.cfg /usr/local/etc/cloud/cloud.cfg +# Install the correct config file: +cp config/cloud.cfg-freebsd /usr/local/etc/cloud/cloud.cfg # Enable cloud-init in /etc/rc.conf: sed -i.bak -e "/cloudinit_enable=.*/d" /etc/rc.conf -- cgit v1.2.3 From a0e3506c6dddf140589228c1ac74f48d2a7cde49 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Sat, 23 Aug 2014 12:19:09 +0000 Subject: fix: Drop some overly loud debug messages. --- cloudinit/distros/freebsd.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py index b4d841f8..415c6ba6 100644 --- a/cloudinit/distros/freebsd.py +++ b/cloudinit/distros/freebsd.py @@ -232,12 +232,6 @@ class Distro(distros.Distro): def _write_network(self, settings): entries = net_util.translate_network(settings) - LOG.debug("Translated network settings") - LOG.debug("\n========== UBUNTU FORMAT START ==========") - LOG.debug("%s\n========== UBUNTU FORMAT END ==========", settings) - LOG.debug("\n========== GENERIC FORMAT START ==========") - LOG.debug("%s\n========== GENERIC FORMAT END ==========", entries) - nameservers = [] searchdomains = [] dev_names = entries.keys() -- cgit v1.2.3 From 1b9b66be04aafcb39f349ccb48905afc393cfc32 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Tue, 26 Aug 2014 18:10:03 +0000 Subject: change: Use a compiled regex and use the included match groups instead of matching yet again. --- cloudinit/distros/freebsd.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py index 415c6ba6..9c923480 100644 --- a/cloudinit/distros/freebsd.py +++ b/cloudinit/distros/freebsd.py @@ -69,17 +69,17 @@ class Distro(distros.Distro): # quotes are ignored: # hostname="bla" def loadrcconf(self): + RE_MATCH = re.compile(r'^(\w+)="?(\w+)"?') conf = {} lines = util.load_file(self.rc_conf_fn).splitlines() for line in lines: - if not re.match(r'^(.+)=(.+)', line): + m = RE_MATCH.match(line) + if not m: LOG.debug("Skipping line from /etc/rc.conf: %s", line) continue - # TODO: just use the matches please... - tok = line.split('=') - key = tok[0] - val = re.sub(r'^"|"$', '', tok[1].rstrip()) + key = m.group(1).rstrip() + val = m.group(2).rstrip() conf[key] = val return conf -- cgit v1.2.3 From 5fbdb88b843bfa3b5fb2c454219779b9889cf787 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Thu, 28 Aug 2014 17:50:24 +0000 Subject: fix: Make sure this freebsd test succeeds on all platforms (harlowja). --- tests/unittests/test_distros/test_netconfig.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py index 96379025..ed997a1d 100644 --- a/tests/unittests/test_distros/test_netconfig.py +++ b/tests/unittests/test_distros/test_netconfig.py @@ -180,12 +180,17 @@ NETWORKING=yes spec=False, passthrough=False) exists_mock = self.mocker.replace(os.path.isfile, spec=False, passthrough=False) + load_mock = self.mocker.replace(util.load_file, + spec=False, passthrough=False) exists_mock(mocker.ARGS) self.mocker.count(0, None) self.mocker.result(False) write_bufs = {} + read_bufs = { + '/etc/rc.conf': '', + } def replace_write(filename, content, mode=0644, omode="wb"): buf = WriteBuffer() @@ -194,8 +199,24 @@ NETWORKING=yes buf.write(content) write_bufs[filename] = buf + def replace_read(fname, read_cb=None, quiet=False): + if fname not in read_bufs: + if fname in write_bufs: + return str(write_bufs[fname]) + raise IOError("%s not found" % fname) + else: + if fname in write_bufs: + return str(write_bufs[fname]) + return read_bufs[fname] + util_mock(mocker.ARGS) self.mocker.call(replace_write) + self.mocker.count(0, None) + + load_mock(mocker.ARGS) + self.mocker.call(replace_read) + self.mocker.count(0, None) + self.mocker.replay() fbsd_distro.apply_network(BASE_NET_CFG, False) -- cgit v1.2.3 From fbfd3789ede42ad50e0b79f202ab18b65537af52 Mon Sep 17 00:00:00 2001 From: Harm Weites Date: Thu, 28 Aug 2014 17:54:00 +0000 Subject: fix: The original regex was a little harsh, the rest of the bits regarding keys and values from /etc/rc.conf is tweaked as well (harlowja). --- cloudinit/distros/freebsd.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/cloudinit/distros/freebsd.py b/cloudinit/distros/freebsd.py index 9c923480..42ef2290 100644 --- a/cloudinit/distros/freebsd.py +++ b/cloudinit/distros/freebsd.py @@ -51,12 +51,18 @@ class Distro(distros.Distro): LOG.debug("Checking %s for: %s = %s", self.rc_conf_fn, key, value) conf = self.loadrcconf() config_changed = False - for item in conf: - if item == key and conf[item] != value: - conf[item] = value - LOG.debug("Changing key in %s: %s = %s", self.rc_conf_fn, key, - value) - config_changed = True + if key not in conf: + LOG.debug("Adding key in %s: %s = %s", self.rc_conf_fn, key, + value) + conf[key] = value + config_changed = True + else: + for item in conf.keys(): + if item == key and conf[item] != value: + conf[item] = value + LOG.debug("Changing key in %s: %s = %s", self.rc_conf_fn, + key, value) + config_changed = True if config_changed: LOG.info("Writing %s", self.rc_conf_fn) @@ -69,7 +75,7 @@ class Distro(distros.Distro): # quotes are ignored: # hostname="bla" def loadrcconf(self): - RE_MATCH = re.compile(r'^(\w+)="?(\w+)"?') + RE_MATCH = re.compile(r'^(\w+)\s*=\s*(.*)\s*') conf = {} lines = util.load_file(self.rc_conf_fn).splitlines() for line in lines: @@ -77,9 +83,17 @@ class Distro(distros.Distro): if not m: LOG.debug("Skipping line from /etc/rc.conf: %s", line) continue - key = m.group(1).rstrip() val = m.group(2).rstrip() + # Kill them quotes (not completely correct, aka won't handle + # quoted values, but should be ok ...) + if val[0] in ('"', "'"): + val = val[1:] + if val[-1] in ('"', "'"): + val = val[0:-1] + if len(val) == 0: + LOG.debug("Skipping empty value from /etc/rc.conf: %s", line) + continue conf[key] = val return conf @@ -237,7 +251,7 @@ class Distro(distros.Distro): dev_names = entries.keys() for (dev, info) in entries.iteritems(): # Skip the loopback interface. - if dev == 'lo0': + if dev.startswith('lo'): continue LOG.info('Configuring interface %s', dev) -- cgit v1.2.3