summaryrefslogtreecommitdiff
path: root/morphlib/morph2.py
diff options
context:
space:
mode:
authorTiago Gomes <tiago.gomes@codethink.co.uk>2013-08-16 08:56:00 +0000
committerTiago Gomes <tiago.gomes@codethink.co.uk>2013-08-16 13:05:18 +0000
commit10a788b3642608de1c0ecc7a41055f950c0652dd (patch)
tree587e3438b5acd5e2566b00102cec29369efb0ba2 /morphlib/morph2.py
parent2514eb9717ab6f8161d1fb403ca2bfff9e1169ea (diff)
downloadmorph-10a788b3642608de1c0ecc7a41055f950c0652dd.tar.gz
Add support for a `cluster` type of morphology.
Add the necessary tests to keep CoverageTestRunner happy.
Diffstat (limited to 'morphlib/morph2.py')
-rw-r--r--morphlib/morph2.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/morphlib/morph2.py b/morphlib/morph2.py
index d949c696..a733ce77 100644
--- a/morphlib/morph2.py
+++ b/morphlib/morph2.py
@@ -60,7 +60,8 @@ class Morphology(object):
('arch', None),
('system-kind', None),
('configuration-extensions', []),
- ]
+ ],
+ 'cluster': []
}
@staticmethod
@@ -129,6 +130,27 @@ class Morphology(object):
if name in names:
raise ValueError('Duplicate chunk "%s"' % name)
names.add(name)
+ elif self['kind'] == 'cluster':
+ if not 'systems' in self:
+ raise KeyError('"systems" not found')
+ if not self['systems']:
+ raise ValueError('"systems" is empty')
+ for system in self['systems']:
+ if 'morph' not in system:
+ raise KeyError('"morph" not found')
+ if 'deploy-defaults' in system:
+ if not isinstance(system['deploy-defaults'], dict):
+ raise ValueError('deploy defaults for morph "%s" '
+ 'are not a mapping: %r'
+ % (system['morph'],
+ system['deploy-defaults']))
+ if 'deploy' in system:
+ for system_id, deploy_params in system['deploy'].items():
+ if not isinstance(deploy_params, dict):
+ raise ValueError('deployment parameters for '
+ 'system "%s" are not a mapping:'
+ ' %r'
+ % (system_id, deploy_params))
def _set_default_value(self, target_dict, key, value):
'''Change a value in the in-memory representation of the morphology
@@ -157,6 +179,8 @@ class Morphology(object):
if self['kind'] == 'stratum':
self._set_stratum_defaults()
+ elif self['kind'] == 'cluster':
+ self._set_cluster_defaults()
def _set_stratum_defaults(self):
for source in self['chunks']:
@@ -171,6 +195,18 @@ class Morphology(object):
if 'prefix' not in source:
self._set_default_value(source, 'prefix', '/usr')
+ def _set_cluster_defaults(self):
+ if 'systems' in self and self['systems']:
+ for system in self['systems']:
+ if 'deploy-defaults' not in system:
+ self._set_default_value(system,
+ 'deploy-defaults',
+ dict())
+ if 'deploy' not in system:
+ self._set_default_value(system,
+ 'deploy',
+ dict())
+
def _parse_size(self, size):
if isinstance(size, basestring):
size = size.lower()