summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--cloudinit/config/cc_landscape.py3
-rw-r--r--cloudinit/distros/__init__.py1
-rw-r--r--cloudinit/distros/debian.py23
-rw-r--r--cloudinit/distros/fedora.py3
-rw-r--r--cloudinit/distros/rhel.py28
-rw-r--r--cloudinit/sources/__init__.py2
-rw-r--r--config/cloud.cfg4
-rw-r--r--doc/examples/cloud-config-user-groups.txt4
-rw-r--r--upstart/cloud-init-container.conf51
-rw-r--r--upstart/cloud-init-nonet.conf2
11 files changed, 100 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index 283d1464..aca34d6e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
0.7.0:
+ - do not 'start networking' in cloud-init-nonet, but add
+ cloud-init-container job that runs only if in container and emits
+ net-device-added (LP: #1031065)
- search only top level dns for 'instance-data' in DataSourceEc2 (LP: #1040200)
- add support for config-drive-v2 (LP:#1037567)
- support creating users, including the default user.
diff --git a/cloudinit/config/cc_landscape.py b/cloudinit/config/cc_landscape.py
index d351d941..7cfb8296 100644
--- a/cloudinit/config/cc_landscape.py
+++ b/cloudinit/config/cc_landscape.py
@@ -79,7 +79,8 @@ def handle(_name, cfg, cloud, log, _args):
util.write_file(lsc_client_fn, contents.getvalue())
log.debug("Wrote landscape config file to %s", lsc_client_fn)
- util.write_file(LS_DEFAULT_FILE, "RUN=1\n")
+ if ls_cloudcfg:
+ util.write_file(LS_DEFAULT_FILE, "RUN=1\n")
def merge_together(objs):
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 40c6aa4f..3e9d934d 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -239,6 +239,7 @@ class Distro(object):
"shell": '--shell',
"expiredate": '--expiredate',
"inactive": '--inactive',
+ "selinux_user": '--selinux-user',
}
adduser_opts_flags = {
diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
index da8c1a5b..5b4aa9f8 100644
--- a/cloudinit/distros/debian.py
+++ b/cloudinit/distros/debian.py
@@ -46,11 +46,8 @@ class Distro(distros.Distro):
out_fn = self._paths.join(False, '/etc/default/locale')
util.subp(['locale-gen', locale], capture=False)
util.subp(['update-locale', locale], capture=False)
- contents = [
- "# Created by cloud-init",
- 'LANG="%s"' % (locale),
- ]
- util.write_file(out_fn, "\n".join(contents))
+ lines = ["# Created by cloud-init", 'LANG="%s"' % (locale), ""]
+ util.write_file(out_fn, "\n".join(lines))
def install_packages(self, pkglist):
self.update_package_sources()
@@ -69,11 +66,8 @@ class Distro(distros.Distro):
util.subp(['hostname', hostname])
def _write_hostname(self, hostname, out_fn):
- lines = []
- lines.append("# Created by cloud-init")
- lines.append(str(hostname))
- contents = "\n".join(lines)
- util.write_file(out_fn, contents, 0644)
+ # "" gives trailing newline.
+ util.write_file(out_fn, "%s\n" % str(hostname), 0644)
def update_hostname(self, hostname, prev_fn):
hostname_prev = self._read_hostname(prev_fn)
@@ -123,13 +117,10 @@ class Distro(distros.Distro):
if not os.path.isfile(tz_file):
raise RuntimeError(("Invalid timezone %s,"
" no file found at %s") % (tz, tz_file))
- tz_lines = [
- "# Created by cloud-init",
- str(tz),
- ]
- tz_contents = "\n".join(tz_lines)
+ # "" provides trailing newline during join
+ tz_lines = ["# Created by cloud-init", str(tz), ""]
tz_fn = self._paths.join(False, "/etc/timezone")
- util.write_file(tz_fn, tz_contents)
+ util.write_file(tz_fn, "\n".join(tz_lines))
util.copy(tz_file, self._paths.join(False, "/etc/localtime"))
def package_command(self, command, args=None):
diff --git a/cloudinit/distros/fedora.py b/cloudinit/distros/fedora.py
index c777845d..9f76a116 100644
--- a/cloudinit/distros/fedora.py
+++ b/cloudinit/distros/fedora.py
@@ -28,4 +28,5 @@ LOG = logging.getLogger(__name__)
class Distro(rhel.Distro):
- pass
+ distro_name = 'fedora'
+ default_user = 'ec2-user'
diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py
index d81ee5fb..ec4dc2cc 100644
--- a/cloudinit/distros/rhel.py
+++ b/cloudinit/distros/rhel.py
@@ -68,12 +68,26 @@ class Distro(distros.Distro):
def install_packages(self, pkglist):
self.package_command('install', pkglist)
+ def _write_resolve(self, dns_servers, search_servers):
+ contents = []
+ if dns_servers:
+ for s in dns_servers:
+ contents.append("nameserver %s" % (s))
+ if search_servers:
+ contents.append("search %s" % (" ".join(search_servers)))
+ if contents:
+ resolve_rw_fn = self._paths.join(False, "/etc/resolv.conf")
+ contents.insert(0, '# Created by cloud-init')
+ util.write_file(resolve_rw_fn, "\n".join(contents), 0644)
+
def _write_network(self, settings):
# TODO(harlowja) fix this... since this is the ubuntu format
entries = translate_network(settings)
LOG.debug("Translated ubuntu style network settings %s into %s",
settings, entries)
# Make the intermediate format as the rhel format...
+ nameservers = []
+ searchservers = []
for (dev, info) in entries.iteritems():
net_fn = NETWORK_FN_TPL % (dev)
net_ro_fn = self._paths.join(True, net_fn)
@@ -102,11 +116,17 @@ class Distro(distros.Distro):
if mac_addr:
net_cfg["MACADDR"] = mac_addr
lines = net_cfg.write()
+ if 'dns-nameservers' in info:
+ nameservers.extend(info['dns-nameservers'])
+ if 'dns-search' in info:
+ searchservers.extend(info['dns-search'])
if not prev_exist:
lines.insert(0, '# Created by cloud-init')
w_contents = "\n".join(lines)
net_rw_fn = self._paths.join(False, net_fn)
util.write_file(net_rw_fn, w_contents, 0644)
+ if nameservers or searchservers:
+ self._write_resolve(nameservers, searchservers)
def set_hostname(self, hostname):
out_fn = self._paths.join(False, '/etc/sysconfig/network')
@@ -208,7 +228,7 @@ class Distro(distros.Distro):
def update_package_sources(self):
self._runner.run("update-sources", self.package_command,
- ["update"], freq=PER_INSTANCE)
+ ["makecache"], freq=PER_INSTANCE)
# This class helps adjust the configobj
@@ -314,6 +334,12 @@ def translate_network(settings):
val = info[k].strip().lower()
if val:
iface_info[k] = val
+ # Name server info provided??
+ if 'dns-nameservers' in info:
+ iface_info['dns-nameservers'] = info['dns-nameservers'].split()
+ # Name server search info provided??
+ if 'dns-search' in info:
+ iface_info['dns-search'] = info['dns-search'].split()
# Is any mac address spoofing going on??
if 'hwaddress' in info:
hw_info = info['hwaddress'].lower().strip()
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
index 3f611d44..6f126091 100644
--- a/cloudinit/sources/__init__.py
+++ b/cloudinit/sources/__init__.py
@@ -173,7 +173,7 @@ class DataSource(object):
# make up a hostname (LP: #475354) in format ip-xx.xx.xx.xx
lhost = self.metadata['local-hostname']
if util.is_ipv4(lhost):
- toks = "ip-%s" % lhost.replace(".", "-")
+ toks = [ "ip-%s" % lhost.replace(".", "-") ]
else:
toks = lhost.split(".")
diff --git a/config/cloud.cfg b/config/cloud.cfg
index d5079721..b3411d11 100644
--- a/config/cloud.cfg
+++ b/config/cloud.cfg
@@ -88,6 +88,6 @@ system_info:
security: []
- arches: [armhf, armel, default]
failsafe:
- primary: http://ports.ubuntu.com/ubuntu
- security: http://ports.ubuntu.com/ubuntu
+ primary: http://ports.ubuntu.com/ubuntu-ports
+ security: http://ports.ubuntu.com/ubuntu-ports
ssh_svcname: ssh
diff --git a/doc/examples/cloud-config-user-groups.txt b/doc/examples/cloud-config-user-groups.txt
index d0b3e2ff..1da0d717 100644
--- a/doc/examples/cloud-config-user-groups.txt
+++ b/doc/examples/cloud-config-user-groups.txt
@@ -12,6 +12,7 @@ users:
gecos: Foo B. Bar
primary-group: foobar
groups: users
+ selinux-user: staff_u
expiredate: 2012-09-01
ssh-import-id: foobar
lock-passwd: false
@@ -38,6 +39,9 @@ users:
# primary-group: define the primary group. Defaults to a new group created
# named after the user.
# groups: Optional. Additional groups to add the user to. Defaults to none
+# selinux-user: Optional. The SELinux user for the user's login, such as
+# "staff_u". When this is omitted the system will select the default
+# SELinux user.
# lock-passwd: Defaults to true. Lock the password to disable password login
# inactive: Create the user as inactive
# passwd: The hash -- not the password itself -- of the password you want
diff --git a/upstart/cloud-init-container.conf b/upstart/cloud-init-container.conf
new file mode 100644
index 00000000..051c6e50
--- /dev/null
+++ b/upstart/cloud-init-container.conf
@@ -0,0 +1,51 @@
+# in a lxc container, events for network interfaces do not
+# get created or may be missed. This helps cloud-init-nonet along
+# by emitting those events if they have not been emitted.
+
+start on container
+stop on static-network-up
+task
+
+emits net-device-added
+
+console output
+
+script
+ # if we are inside a container, then we may have to emit the ifup
+ # events for 'auto' network devices.
+ set -f
+
+ # from /etc/network/if-up.d/upstart
+ MARK_DEV_PREFIX="/run/network/ifup."
+ MARK_STATIC_NETWORK_EMITTED="/run/network/static-network-up-emitted"
+ # if the all static network interfaces are already up, nothing to do
+ [ -f "$MARK_STATIC_NETWORK_EMITTED" ] && exit 0
+
+ # get list of all 'auto' interfaces. if there are none, nothing to do.
+ auto_list=$(ifquery --list --allow auto 2>/dev/null) || :
+ [ -z "$auto_list" ] && exit 0
+ set -- ${auto_list}
+ [ "$*" = "lo" ] && exit 0
+
+ # we only want to emit for interfaces that do not exist, so filter
+ # out anything that does not exist.
+ for iface in "$@"; do
+ [ "$iface" = "lo" ] && continue
+ # skip interfaces that are already up
+ [ -f "${MARK_DEV_PREFIX}${iface}" ] && continue
+
+ if [ -d /sys/net ]; then
+ # if /sys is mounted, and there is no /sys/net/iface, then no device
+ [ -e "/sys/net/$iface" ] && continue
+ else
+ # sys wasn't mounted, so just check via 'ifconfig'
+ ifconfig "$iface" >/dev/null 2>&1 || continue
+ fi
+ initctl emit --no-wait net-device-added "INTERFACE=$iface" &&
+ emitted="$emitted $iface" ||
+ echo "warn: ${UPSTART_JOB} failed to emit net-device-added INTERFACE=$iface"
+ done
+
+ [ -z "${emitted# }" ] ||
+ echo "${UPSTART_JOB}: emitted ifup for ${emitted# }"
+end script
diff --git a/upstart/cloud-init-nonet.conf b/upstart/cloud-init-nonet.conf
index 7b69e584..118ffc1c 100644
--- a/upstart/cloud-init-nonet.conf
+++ b/upstart/cloud-init-nonet.conf
@@ -18,8 +18,6 @@ script
[ -f /var/lib/cloud/instance/obj.pkl ] && exit 0
- start networking >/dev/null
-
short=10; long=120;
sleep ${short}
echo $UPSTART_JOB "waiting ${long} seconds for a network device."