diff options
-rw-r--r-- | cloudinit/distros/__init__.py | 1 | ||||
-rw-r--r-- | cloudinit/distros/debian.py | 23 | ||||
-rw-r--r-- | cloudinit/distros/rhel.py | 26 | ||||
-rw-r--r-- | config/cloud.cfg | 4 | ||||
-rw-r--r-- | doc/examples/cloud-config-user-groups.txt | 4 |
5 files changed, 40 insertions, 18 deletions
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/rhel.py b/cloudinit/distros/rhel.py index 9b95d0d4..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') @@ -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/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 |