--- a/README Thu Feb 26 19:16:25 2015 +0200
+++ b/README Thu Feb 26 19:26:15 2015 +0200
@@ -45,35 +45,19 @@
=== Include directories ===
Host configs can be included:
- $ cat etc/hosts/test/test
+ $ cat etc/hosts/test
include = test.d/
- $ cat etc/hosts/test/test.d/foo
+ $ cat etc/hosts/test.d/foo
ip = 192.0.2.1
- $ cat etc/hosts/test/test.d/bar
+ $ cat etc/hosts/test.d/bar
ip = 192.0.2.2
- $ bin/pvl.hosts-forward etc/hosts/test/test
+ $ bin/pvl.hosts-forward etc/hosts/test
foo A 192.0.2.1
bar A 192.0.2.2
-And an entire directory of hosts-files, containing sub-domains, can be given:
-
- $ ls etc/hosts/test/
- asdf.test test test.d
-
- $ cat etc/hosts/test/asdf.test
- [quux]
- ip = 192.0.2.5
-
- $ bin/pvl.hosts-forward etc/hosts/test/
- foo A 192.0.2.1
- bar A 192.0.2.2
- quux.asdf A 192.0.2.5
-
-Note that the (include) directory name itself is NOT treated as a domain name. However, the file names which are included are.
-
Including a directory of files is equivalent to substituiting each file as a named section at the level of the include = statement. Note that this means that included files are treated directly as host definitions, IOW, you should NOT include a section name in an included host file unless you want to declare an additional subdomain:
$ cat etc/hosts/wrong.test
@@ -198,3 +182,34 @@
fixed-address 10.2.0.1;
}
+== Host structure ==
+
+Creating a tree of symlinks for managing split zonefile domains can be useful:
+
+ $ tree etc/zones/
+ etc/zones/
+ ├── forward
+ │ └── test
+ │ ├── asdf.test -> ../../../hosts/asdf.test
+ │ └── test -> ../../../hosts/test
+ └── reverse
+ └── 192.0.2
+ ├── asdf.test -> ../../../hosts/asdf.test
+ └── test -> ../../../hosts/test
+
+Given a structure like above, the `pvl.hosts-forward` can generate a single forward zone containing all sub-domains:
+
+ $ bin/pvl.hosts-forward --hosts-include etc/hosts/ etc/zones/forward/test/
+ foo A 192.0.2.1
+ bar A 192.0.2.2
+ quux.asdf A 192.0.2.5
+
+Note that the directory name is treated separately as a zone origin; the file names within the domain are still treated as a flat namespace independent of the directory name (which is different than *pvl.hosts* would behave for `include = etc/zones/forward/test/`).
+
+The same trick also works for `pvl.hosts-reverse`:
+
+ $ bin/pvl.hosts-reverse --hosts-include etc/hosts/ etc/zones/reverse/192.0.2/
+ 1 PTR foo.test.
+ 2 PTR bar.test.
+ 5 PTR quux.asdf.test.
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/etc/hosts/asdf.test Thu Feb 26 19:26:15 2015 +0200
@@ -0,0 +1,2 @@
+[quux]
+ ip = 192.0.2.5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/etc/hosts/test Thu Feb 26 19:26:15 2015 +0200
@@ -0,0 +1,1 @@
+include = test.d/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/etc/hosts/test.d/bar Thu Feb 26 19:26:15 2015 +0200
@@ -0,0 +1,1 @@
+ip = 192.0.2.2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/etc/hosts/test.d/foo Thu Feb 26 19:26:15 2015 +0200
@@ -0,0 +1,2 @@
+ip = 192.0.2.1
+
--- a/etc/hosts/test/asdf.test Thu Feb 26 19:16:25 2015 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-[quux]
- ip = 192.0.2.5
--- a/etc/hosts/test/test Thu Feb 26 19:16:25 2015 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-include = test.d/
--- a/etc/hosts/test/test.d/bar Thu Feb 26 19:16:25 2015 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-ip = 192.0.2.2
--- a/etc/hosts/test/test.d/foo Thu Feb 26 19:16:25 2015 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-ip = 192.0.2.1
-
--- a/etc/zones/reverse/192.0.2/asdf.test Thu Feb 26 19:16:25 2015 +0200
+++ b/etc/zones/reverse/192.0.2/asdf.test Thu Feb 26 19:26:15 2015 +0200
@@ -1,1 +1,1 @@
-../../../hosts/test/asdf.test
\ No newline at end of file
+../../../hosts/asdf.test
\ No newline at end of file
--- a/etc/zones/reverse/192.0.2/test Thu Feb 26 19:16:25 2015 +0200
+++ b/etc/zones/reverse/192.0.2/test Thu Feb 26 19:26:15 2015 +0200
@@ -1,1 +1,1 @@
-../../../hosts/test/test
\ No newline at end of file
+../../../hosts/test
\ No newline at end of file
--- a/pvl/hosts/tests.py Thu Feb 26 19:16:25 2015 +0200
+++ b/pvl/hosts/tests.py Thu Feb 26 19:26:15 2015 +0200
@@ -130,20 +130,7 @@
])
def testApplyIncludes(self):
- self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/test/test']), [
- ('foo@test', dict(
- ip = ipaddr.IPAddress('192.0.2.1'),
- )),
- ('bar@test', dict(
- ip = ipaddr.IPAddress('192.0.2.2'),
- )),
- ])
-
- def testApplyDirectory(self):
- self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/test/']), [
- ('quux@asdf.test', dict(
- ip = ipaddr.IPAddress('192.0.2.5'),
- )),
+ self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/hosts/test']), [
('foo@test', dict(
ip = ipaddr.IPAddress('192.0.2.1'),
)),
@@ -153,7 +140,7 @@
])
def testApplyIncludePath(self):
- self.options.hosts_include = 'etc/hosts/test'
+ self.options.hosts_include = 'etc/hosts'
self.assertHostsEqual(config.apply_hosts_files(self.options, ['etc/zones/forward/test']), [
('quux@asdf.test', dict(
ip = ipaddr.IPAddress('192.0.2.5'),