Match class mappings against entity name incl. subdir
If a node is defined in a subdirectory, then match class mappings
against the entire (relative) path of the node, including its
subdirectory.
For instance, you might have your nodes arranged in subdirectories
according to the datacentre that they are in:
- zurich/host1.example.ch
- zurich/host2.example.ch
- munich/host1.example.de
- munich/host2.example.de
A class mapping such as
/^([^\/]+)\// hosted-in-\\1
would now automatically assign the hosted-in-zurich and hosted-in-munich
classes to the hosts, according to which subdirectory their (yaml_fs)
files reside in.
The information is transported in the so-called entity name, so other
storage backends can also introduce such "tags", they need not be
related to a filesystem path.
Signed-off-by: martin f. krafft <madduck@madduck.net>
diff --git a/doc/source/operations.rst b/doc/source/operations.rst
index 0819bfb..2085bc8 100644
--- a/doc/source/operations.rst
+++ b/doc/source/operations.rst
@@ -43,8 +43,8 @@
Nodes may be defined in subdirectories. However, node names (filename) must be
unique across all subdirectories, and |reclass| will exit with an error if
a node is defined multiple times. Subdirectories therefore really only exist
-for the administrator's sanity (and may be used in the future to tag
-additional classes onto nodes).
+for the administrator's local data structuring. They may be used in mappings
+(see below) to tag additional classes onto nodes.
Data merging
------------
@@ -112,13 +112,12 @@
- /\.(\S+)$/ tld-\\1
Furthermore, since the outer slashes ('/') are used to "quote" the regular
-expression, *any* slashes within the regular expression must be escaped::
+expression, *any* slashes within the regular expression must be escaped. For
+instance, the following class mapping assigns a ``subdir-X`` class to all
+nodes that are defined in a subdirectory (using yaml_fs).
class_mappings:
- - /^([^\/]+)\// \\1
-
-This is a bit theoretical right now, as nodenames cannot (yet) include
-slashes, but that might come…
+ - /^([^\/]+)\// subdir-\\1
Parameter interpolation
------------------------