Merge lp:~craigtracey/cloud-init/osfamilies into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Craig Tracey
Status: Merged
Merged at revision: 761
Proposed branch: lp:~craigtracey/cloud-init/osfamilies
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 92 lines (+27/-3)
5 files modified
cloudinit/config/__init__.py (+3/-1)
cloudinit/distros/__init__.py (+15/-0)
cloudinit/distros/debian.py (+1/-0)
cloudinit/distros/rhel.py (+1/-0)
cloudinit/stages.py (+7/-2)
To merge this branch: bzr merge lp:~craigtracey/cloud-init/osfamilies
Reviewer Review Type Date Requested Status
Joshua Harlow (community) Approve
Review via email: mp+143410@code.launchpad.net

Commit message

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']

and provides a mechanism for operating system family templates.

Description of the change

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']

and provides a mechanism for operating system family templates.

To post a comment you must log in.
Revision history for this message
Joshua Harlow (harlowja) wrote :

Looks good, will get this in soon :-)

Revision history for this message
Joshua Harlow (harlowja) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'cloudinit/config/__init__.py'
--- cloudinit/config/__init__.py 2012-06-29 18:20:34 +0000
+++ cloudinit/config/__init__.py 2013-01-15 21:30:33 +0000
@@ -52,5 +52,7 @@
52 if freq and freq not in FREQUENCIES:52 if freq and freq not in FREQUENCIES:
53 LOG.warn("Module %s has an unknown frequency %s", mod, freq)53 LOG.warn("Module %s has an unknown frequency %s", mod, freq)
54 if not hasattr(mod, 'distros'):54 if not hasattr(mod, 'distros'):
55 setattr(mod, 'distros', None)55 setattr(mod, 'distros', [])
56 if not hasattr(mod, 'osfamilies'):
57 setattr(mod, 'osfamilies', [])
56 return mod58 return mod
5759
=== modified file 'cloudinit/distros/__init__.py'
--- cloudinit/distros/__init__.py 2013-01-07 16:36:10 +0000
+++ cloudinit/distros/__init__.py 2013-01-15 21:30:33 +0000
@@ -35,6 +35,11 @@
3535
36from cloudinit.distros.parsers import hosts36from cloudinit.distros.parsers import hosts
3737
38OSFAMILIES = {
39 'debian': ['debian', 'ubuntu'],
40 'redhat': ['fedora', 'rhel']
41}
42
38LOG = logging.getLogger(__name__)43LOG = logging.getLogger(__name__)
3944
4045
@@ -143,6 +148,16 @@
143 def _select_hostname(self, hostname, fqdn):148 def _select_hostname(self, hostname, fqdn):
144 raise NotImplementedError()149 raise NotImplementedError()
145150
151 @staticmethod
152 def expand_osfamily(family_list):
153 distros = []
154 for family in family_list:
155 if not family in OSFAMILIES:
156 raise ValueError("No distibutions found for osfamily %s"
157 % (family))
158 distros.extend(OSFAMILIES[family])
159 return distros
160
146 def update_hostname(self, hostname, fqdn, prev_hostname_fn):161 def update_hostname(self, hostname, fqdn, prev_hostname_fn):
147 applying_hostname = hostname162 applying_hostname = hostname
148163
149164
=== modified file 'cloudinit/distros/debian.py'
--- cloudinit/distros/debian.py 2012-11-13 23:24:53 +0000
+++ cloudinit/distros/debian.py 2013-01-15 21:30:33 +0000
@@ -48,6 +48,7 @@
48 # calls from repeatly happening (when they48 # calls from repeatly happening (when they
49 # should only happen say once per instance...)49 # should only happen say once per instance...)
50 self._runner = helpers.Runners(paths)50 self._runner = helpers.Runners(paths)
51 self.osfamily = 'debian'
5152
52 def apply_locale(self, locale, out_fn=None):53 def apply_locale(self, locale, out_fn=None):
53 if not out_fn:54 if not out_fn:
5455
=== modified file 'cloudinit/distros/rhel.py'
--- cloudinit/distros/rhel.py 2012-11-13 06:14:31 +0000
+++ cloudinit/distros/rhel.py 2013-01-15 21:30:33 +0000
@@ -60,6 +60,7 @@
60 # calls from repeatly happening (when they60 # calls from repeatly happening (when they
61 # should only happen say once per instance...)61 # should only happen say once per instance...)
62 self._runner = helpers.Runners(paths)62 self._runner = helpers.Runners(paths)
63 self.osfamily = 'redhat'
6364
64 def install_packages(self, pkglist):65 def install_packages(self, pkglist):
65 self.package_command('install', pkglist)66 self.package_command('install', pkglist)
6667
=== modified file 'cloudinit/stages.py'
--- cloudinit/stages.py 2012-12-17 13:41:11 +0000
+++ cloudinit/stages.py 2013-01-15 21:30:33 +0000
@@ -529,11 +529,16 @@
529 freq = mod.frequency529 freq = mod.frequency
530 if not freq in FREQUENCIES:530 if not freq in FREQUENCIES:
531 freq = PER_INSTANCE531 freq = PER_INSTANCE
532 worked_distros = mod.distros532
533 worked_distros = set(mod.distros)
534 worked_distros.update(
535 distros.Distro.expand_osfamily(mod.osfamilies))
536
533 if (worked_distros and d_name not in worked_distros):537 if (worked_distros and d_name not in worked_distros):
534 LOG.warn(("Module %s is verified on %s distros"538 LOG.warn(("Module %s is verified on %s distros"
535 " but not on %s distro. It may or may not work"539 " but not on %s distro. It may or may not work"
536 " correctly."), name, worked_distros, d_name)540 " correctly."), name, list(worked_distros),
541 d_name)
537 # Use the configs logger and not our own542 # Use the configs logger and not our own
538 # TODO(harlowja): possibly check the module543 # TODO(harlowja): possibly check the module
539 # for having a LOG attr and just give it back544 # for having a LOG attr and just give it back