--- a/pvl/hosts/config.py Thu Feb 26 16:37:24 2015 +0200
+++ b/pvl/hosts/config.py Thu Feb 26 16:38:31 2015 +0200
@@ -136,10 +136,7 @@
return Host.build(name, domain, **fields)
-def apply_host_config (options, parent, name,
- domain=None,
- **config
-):
+def apply_host_config (options, parent, name, **config):
"""
Yield Hosts from a given config section.
@@ -151,7 +148,8 @@
**config host parameters
"""
- if domain:
+ if '@' in name:
+ name, domain = name.split('@', 1)
log.debug("%s: using explicit domain: %s", name, domain)
elif '.' in name:
log.debug("%s: using as fqdn without domain", name)
--- a/pvl/hosts/host.py Thu Feb 26 16:37:24 2015 +0200
+++ b/pvl/hosts/host.py Thu Feb 26 16:38:31 2015 +0200
@@ -202,4 +202,6 @@
return pvl.dns.fqdn(self.name)
def __str__ (self):
- return "{self.name}@{self.domain}".format(self=self)
+ return "{self.name}@{domain}".format(self=self,
+ domain = self.domain or '',
+ )
--- a/pvl/hosts/tests.py Thu Feb 26 16:37:24 2015 +0200
+++ b/pvl/hosts/tests.py Thu Feb 26 16:38:31 2015 +0200
@@ -61,8 +61,17 @@
ethernet = {None: '01:23:45:67:89:ab'},
)),
])
+
+ def testApplyHostFqdn(self):
+ self.assertHostsEqual(config.apply_host_config(self.options, 'test', 'asdf@foo.test'), [
+ ('asdf@foo.test', dict()),
+ ])
- def testApplyHostsExpand(self):
+ self.assertHostsEqual(config.apply_host_config(self.options, 'test', 'asdf.test2'), [
+ ('asdf.test2@', dict()),
+ ])
+
+ def testApplyHostExpand(self):
self.assertHostsEqual(config.apply_host_config(self.options, 'asdf', 'asdf{1-3}', ip='10.100.100.$'), [
('asdf1@asdf', dict(ip=ipaddr.IPAddress('10.100.100.1'))),
('asdf2@asdf', dict(ip=ipaddr.IPAddress('10.100.100.2'))),