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
1=== modified file 'cloudinit/config/__init__.py'
2--- cloudinit/config/__init__.py 2012-06-29 18:20:34 +0000
3+++ cloudinit/config/__init__.py 2013-01-15 21:30:33 +0000
4@@ -52,5 +52,7 @@
5 if freq and freq not in FREQUENCIES:
6 LOG.warn("Module %s has an unknown frequency %s", mod, freq)
7 if not hasattr(mod, 'distros'):
8- setattr(mod, 'distros', None)
9+ setattr(mod, 'distros', [])
10+ if not hasattr(mod, 'osfamilies'):
11+ setattr(mod, 'osfamilies', [])
12 return mod
13
14=== modified file 'cloudinit/distros/__init__.py'
15--- cloudinit/distros/__init__.py 2013-01-07 16:36:10 +0000
16+++ cloudinit/distros/__init__.py 2013-01-15 21:30:33 +0000
17@@ -35,6 +35,11 @@
18
19 from cloudinit.distros.parsers import hosts
20
21+OSFAMILIES = {
22+ 'debian': ['debian', 'ubuntu'],
23+ 'redhat': ['fedora', 'rhel']
24+}
25+
26 LOG = logging.getLogger(__name__)
27
28
29@@ -143,6 +148,16 @@
30 def _select_hostname(self, hostname, fqdn):
31 raise NotImplementedError()
32
33+ @staticmethod
34+ def expand_osfamily(family_list):
35+ distros = []
36+ for family in family_list:
37+ if not family in OSFAMILIES:
38+ raise ValueError("No distibutions found for osfamily %s"
39+ % (family))
40+ distros.extend(OSFAMILIES[family])
41+ return distros
42+
43 def update_hostname(self, hostname, fqdn, prev_hostname_fn):
44 applying_hostname = hostname
45
46
47=== modified file 'cloudinit/distros/debian.py'
48--- cloudinit/distros/debian.py 2012-11-13 23:24:53 +0000
49+++ cloudinit/distros/debian.py 2013-01-15 21:30:33 +0000
50@@ -48,6 +48,7 @@
51 # calls from repeatly happening (when they
52 # should only happen say once per instance...)
53 self._runner = helpers.Runners(paths)
54+ self.osfamily = 'debian'
55
56 def apply_locale(self, locale, out_fn=None):
57 if not out_fn:
58
59=== modified file 'cloudinit/distros/rhel.py'
60--- cloudinit/distros/rhel.py 2012-11-13 06:14:31 +0000
61+++ cloudinit/distros/rhel.py 2013-01-15 21:30:33 +0000
62@@ -60,6 +60,7 @@
63 # calls from repeatly happening (when they
64 # should only happen say once per instance...)
65 self._runner = helpers.Runners(paths)
66+ self.osfamily = 'redhat'
67
68 def install_packages(self, pkglist):
69 self.package_command('install', pkglist)
70
71=== modified file 'cloudinit/stages.py'
72--- cloudinit/stages.py 2012-12-17 13:41:11 +0000
73+++ cloudinit/stages.py 2013-01-15 21:30:33 +0000
74@@ -529,11 +529,16 @@
75 freq = mod.frequency
76 if not freq in FREQUENCIES:
77 freq = PER_INSTANCE
78- worked_distros = mod.distros
79+
80+ worked_distros = set(mod.distros)
81+ worked_distros.update(
82+ distros.Distro.expand_osfamily(mod.osfamilies))
83+
84 if (worked_distros and d_name not in worked_distros):
85 LOG.warn(("Module %s is verified on %s distros"
86 " but not on %s distro. It may or may not work"
87- " correctly."), name, worked_distros, d_name)
88+ " correctly."), name, list(worked_distros),
89+ d_name)
90 # Use the configs logger and not our own
91 # TODO(harlowja): possibly check the module
92 # for having a LOG attr and just give it back