summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2013-01-21 19:51:10 -0800
committerJoshua Harlow <harlowja@gmail.com>2013-01-21 19:51:10 -0800
commit079a670b10ba16420dbb87edf2b6846179b552f6 (patch)
tree2ccdba0196f3d2f370cb030c6cbc6c23f9219d36
parente561742aeab1e8090467f0fa304ee06e82e85f2c (diff)
parent5d4f4df6804995d74e7962f60dcd72b26bcac69b (diff)
downloadvyos-cloud-init-079a670b10ba16420dbb87edf2b6846179b552f6.tar.gz
vyos-cloud-init-079a670b10ba16420dbb87edf2b6846179b552f6.zip
Add support for operating system families
Often it is convenient to classify a distro as being part of an operating system family. for instance, file templates may be identical for both debian and ubuntu, but to support this under the current templating code, one would need multiple templates for the same code. Similarly, configuration handlers often fall into the same bucket: the configuraton is known to work/has been tested on a particular family of operating systems. right now this is handled with a declaration like: distros = ['fedora', 'rhel'] This fix seeks to address both of these issues. it allows for the simplification of the above line to: osfamilies = ['redhat'] It also provides a mechanism for operating system family templates.
-rw-r--r--cloudinit/config/__init__.py4
-rw-r--r--cloudinit/distros/__init__.py15
-rw-r--r--cloudinit/distros/debian.py1
-rw-r--r--cloudinit/distros/rhel.py1
-rw-r--r--cloudinit/stages.py9
5 files changed, 27 insertions, 3 deletions
diff --git a/cloudinit/config/__init__.py b/cloudinit/config/__init__.py
index 69a8cc68..d57453be 100644
--- a/cloudinit/config/__init__.py
+++ b/cloudinit/config/__init__.py
@@ -52,5 +52,7 @@ def fixup_module(mod, def_freq=PER_INSTANCE):
if freq and freq not in FREQUENCIES:
LOG.warn("Module %s has an unknown frequency %s", mod, freq)
if not hasattr(mod, 'distros'):
- setattr(mod, 'distros', None)
+ setattr(mod, 'distros', [])
+ if not hasattr(mod, 'osfamilies'):
+ setattr(mod, 'osfamilies', [])
return mod
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index 38b2f829..5a2092c0 100644
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -35,6 +35,11 @@ from cloudinit import util
from cloudinit.distros.parsers import hosts
+OSFAMILIES = {
+ 'debian': ['debian', 'ubuntu'],
+ 'redhat': ['fedora', 'rhel']
+}
+
LOG = logging.getLogger(__name__)
@@ -143,6 +148,16 @@ class Distro(object):
def _select_hostname(self, hostname, fqdn):
raise NotImplementedError()
+ @staticmethod
+ def expand_osfamily(family_list):
+ distros = []
+ for family in family_list:
+ if not family in OSFAMILIES:
+ raise ValueError("No distibutions found for osfamily %s"
+ % (family))
+ distros.extend(OSFAMILIES[family])
+ return distros
+
def update_hostname(self, hostname, fqdn, prev_hostname_fn):
applying_hostname = hostname
diff --git a/cloudinit/distros/debian.py b/cloudinit/distros/debian.py
index 7422f4f0..49b73477 100644
--- a/cloudinit/distros/debian.py
+++ b/cloudinit/distros/debian.py
@@ -48,6 +48,7 @@ class Distro(distros.Distro):
# calls from repeatly happening (when they
# should only happen say once per instance...)
self._runner = helpers.Runners(paths)
+ self.osfamily = 'debian'
def apply_locale(self, locale, out_fn=None):
if not out_fn:
diff --git a/cloudinit/distros/rhel.py b/cloudinit/distros/rhel.py
index bc0877d5..e65be8d7 100644
--- a/cloudinit/distros/rhel.py
+++ b/cloudinit/distros/rhel.py
@@ -60,6 +60,7 @@ class Distro(distros.Distro):
# calls from repeatly happening (when they
# should only happen say once per instance...)
self._runner = helpers.Runners(paths)
+ self.osfamily = 'redhat'
def install_packages(self, pkglist):
self.package_command('install', pkglist)
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
index 8d3213b4..d7d1dea0 100644
--- a/cloudinit/stages.py
+++ b/cloudinit/stages.py
@@ -529,11 +529,16 @@ class Modules(object):
freq = mod.frequency
if not freq in FREQUENCIES:
freq = PER_INSTANCE
- worked_distros = mod.distros
+
+ worked_distros = set(mod.distros)
+ worked_distros.update(
+ distros.Distro.expand_osfamily(mod.osfamilies))
+
if (worked_distros and d_name not in worked_distros):
LOG.warn(("Module %s is verified on %s distros"
" but not on %s distro. It may or may not work"
- " correctly."), name, worked_distros, d_name)
+ " correctly."), name, list(worked_distros),
+ d_name)
# Use the configs logger and not our own
# TODO(harlowja): possibly check the module
# for having a LOG attr and just give it back