# HG changeset patch # User Tero Marttila # Date 1425232460 -7200 # Node ID 15946375b154866f3c7d2ec8f76b225e12789aec # Parent 5461fb49234501f1c094de3d652cab1dae89e785 pvl.hosts.config: support ethernet = ... + ethernet.ethX = ... diff -r 5461fb492345 -r 15946375b154 pvl/hosts/config.py --- a/pvl/hosts/config.py Sun Mar 01 19:41:38 2015 +0200 +++ b/pvl/hosts/config.py Sun Mar 01 19:54:20 2015 +0200 @@ -101,7 +101,10 @@ name - (expanded) name of host domain - domain for host config - host config fields to parse - + + Fields can either be scalar string values, or instance'd dicts. If a field has both a non-instance'd value and instance'd values, + the non-instance'd value will be use instance=None: + Raises ValueError. """ @@ -115,16 +118,17 @@ f = extensions.setdefault(extension, {}) else: f = fields - - if not instance and field not in f: - f[field] = value - elif field not in f: - f[field] = {instance: value} - elif isinstance(f[field], dict): - f.setdefault(field, {})[instance] = value + if instance: + if field not in f: + f[field] = { } + elif not isinstance(f[field], dict): + # convert to dict + f[field] = {None: f[field]} + + f[field][instance] = value else: - raise ValueError("override instanced {field} value: {value}".format(field=field, value=value)) + f[field] = value return Host.build(name, domain, **fields) diff -r 5461fb492345 -r 15946375b154 pvl/hosts/tests.py --- a/pvl/hosts/tests.py Sun Mar 01 19:41:38 2015 +0200 +++ b/pvl/hosts/tests.py Sun Mar 01 19:54:20 2015 +0200 @@ -57,12 +57,19 @@ } )) - def testApplyHostsConfigErrorDict(self): - with self.assertRaises(ValueError): - config.apply_host('test', 'foo', { - 'ethernet': 'foo', - 'ethernet.eth0': 'bar', - }) + def testApplyHostsConfigErrorExtra(self): + host = config.apply_host('foo', 'test', { + 'ethernet': '00:11:22:33:44:55', + 'ethernet.eth1': '00:11:22:33:44:66', + }) + + self.assertHostEqual(host, 'foo@test', dict( + ethernet = { + None: '00:11:22:33:44:55', + 'eth1': '00:11:22:33:44:66', + } + )) + def testApplyHostConfigExtensions(self): host = config.apply_host('foo', 'test', {